# -*- coding: utf-8 -*-
# 自动发现资产确认
# 作者: 陈磊
# 时间: 2019-12-11
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog
from WorkApi.ApiBase import ApiBase, GetBase


class HostsDiscoveryCreate(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 = "/hostdiscovery/create"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self._data = {}
        self.response = ""

        self.token = {}

        self.hostid = None
        self.hostName = None
        self.hostType = None
        self.manageLevel = None
        self.iplist = None
        self.port = None
        self.dns = None
        self.monitorInterface = None
        self.monitorType = None
        self.parentHost = None
        self.businessIds = None
        self.businessTree = None
        self.opsPerson = None
        self.snmpCommunity = None
        self.ipmiAuthtype = None
        self.ipmiPrivilege = None
        self.ipmiUsername = None
        self.ipmiPassword = None
        self.factoryId = None
        self.model = None
        self.version = None
        self.serialnumber = None
        self.description = None
        self.monitorStatus = None

        self.api = UtilsRequest()

    def get_response(self):
        base = ApiBase()
        base.dict_add_key(_key="token", value=self.token)
        self._headers = base._json

        base = ApiBase()
        base.dict_add_key(_key="hostid", value=self.hostid)
        base.dict_add_key(_key="hostName", value=self.hostName)
        base.dict_add_key(_key="hostType", value=self.hostType)
        base.dict_add_key(_key="manageLevel", value=self.manageLevel)
        base.dict_add_key(_key="iplist", value=self.iplist)
        base.dict_add_key(_key="port", value=self.port)
        base.dict_add_key(_key="dns", value=self.dns)
        base.dict_add_key(_key="monitorInterface", value=self.monitorInterface)
        base.dict_add_key(_key="monitorType", value=self.monitorType)
        base.dict_add_key(_key="parentHost", value=self.parentHost)
        base.dict_add_key(_key="businessIds", value=self.businessIds)
        base.dict_add_key(_key="businessTree", value=self.businessTree)
        base.dict_add_key(_key="opsPerson", value=self.opsPerson)
        base.dict_add_key(_key="snmpCommunity", value=self.snmpCommunity)
        base.dict_add_key(_key="ipmiAuthtype", value=self.ipmiAuthtype)
        base.dict_add_key(_key="ipmiPrivilege", value=self.ipmiPrivilege)
        base.dict_add_key(_key="ipmiUsername", value=self.ipmiUsername)
        base.dict_add_key(_key="ipmiPassword", value=self.ipmiPassword)
        base.dict_add_key(_key="factoryId", value=self.factoryId)
        base.dict_add_key(_key="model", value=self.model)
        base.dict_add_key(_key="version", value=self.version)
        base.dict_add_key(_key="serialnumber", value=self.serialnumber)
        base.dict_add_key(_key="description", value=self.description)
        base.dict_add_key(_key="monitorStatus", value=self.monitorStatus)

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