# -*- coding: utf-8 -*-
# 创建主机接口
# 作者: 陈磊
# 时间: 2019-11-11
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog
from WorkApi.ApiBase import ApiBase


class HostInterfaceCreate(object):
    def __init__(self, _host):
        """
        :param _host: 域名
        :return:
        """
        self.log = UtilsLog()
        self.log.info("调用创建主机接口")
        self.log.info(self.__class__)

        self._host = _host
        self._headers = {}
        self._path = "/hostinterface/create"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self.local_json = {}
        self.response = ""

        self.dns = None
        self.hostid = None
        self.ip = None
        self.main = None
        self.port = None
        self.type = None
        self.useip = None
        self.bulk = None

        self.api = UtilsRequest()

    def get_response(self):
        base = ApiBase()
        base.dict_add_key(_key="dns", value=self.dns)
        base.dict_add_key(_key="hostid", value=self.hostid)
        base.dict_add_key(_key="ip", value=self.ip)
        base.dict_add_key(_key="main", value=self.main)
        base.dict_add_key(_key="port", value=self.port)
        base.dict_add_key(_key="type", value=self.type)
        base.dict_add_key(_key="useip", value=self.useip)
        base.dict_add_key(_key="bulk", value=self.bulk)

        self.local_json = base._json
        self._json = self.local_json
        self.response = self.api.post(url=self._url, json=self._json)
