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


class HostInterfaceUpdate(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/update"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self.local_json = {}
        self.response = ""

        self.interfaceid = None
        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="interfaceid", value=self.interfaceid)
        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)
