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


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

        self.hostid = None
        self.host = None
        self.available = None
        self.description = None
        self.flags = None
        self.inventory_mode = None
        self.ipmi_authtype = None
        self.ipmi_available = None
        self.ipmi_disable_until = None
        self.ipmi_error = None
        self.ipmi_errors_from = None
        self.ipmi_password = None
        self.ipmi_privilege = None
        self.ipmi_username = None
        self.jmx_available = None
        self.jmx_disable_until = None
        self.jmx_error = None
        self.jmx_errors_from = None
        self.maintenance_from = None
        self.maintenance_status = None
        self.maintenance_type = None
        self.maintenanceid = None
        self.name = None
        self.proxy_hostid = None
        self.snmp_available = None
        self.snmp_disable_until = None
        self.snmp_error = None
        self.snmp_errors_from = None
        self.interfaces = None
        self.groupids = None
        self.tags = None
        self.templateids = None
        self.macros = None
        self.inventory = None
        self.status = None
        self.tls_connect = None
        self.tls_accept = None
        self.tls_issuer = None
        self.tls_subject = None
        self.tls_psk_identity = None
        self.tls_psk = None

        self.api = UtilsRequest()

    def get_response(self):
        base = ApiBase()
        base.dict_add_key(_key="hostid", value=self.hostid)
        base.dict_add_key(_key="host", value=self.host)
        base.dict_add_key(_key="available", value=self.available)
        base.dict_add_key(_key="description", value=self.description)
        base.dict_add_key(_key="flags", value=self.flags)
        base.dict_add_key(_key="inventory_mode", value=self.inventory_mode)
        base.dict_add_key(_key="ipmiAuthtype", value=self.ipmi_authtype)
        base.dict_add_key(_key="ipmiAvailable", value=self.ipmi_available)
        base.dict_add_key(_key="ipmiDisable_until", value=self.ipmi_disable_until)
        base.dict_add_key(_key="ipmiError", value=self.ipmi_error)
        base.dict_add_key(_key="ipmiErrorsFrom", value=self.ipmi_errors_from)
        base.dict_add_key(_key="ipmiPassword", value=self.ipmi_password)
        base.dict_add_key(_key="ipmiPrivilege", value=self.ipmi_privilege)
        base.dict_add_key(_key="ipmiUsername", value=self.ipmi_username)
        base.dict_add_key(_key="jmxAvailable", value=self.jmx_available)
        base.dict_add_key(_key="jmxDisableUntil", value=self.jmx_disable_until)
        base.dict_add_key(_key="jmxError", value=self.jmx_error)
        base.dict_add_key(_key="jmxErrorsFrom", value=self.jmx_errors_from)
        base.dict_add_key(_key="maintenanceFrom", value=self.maintenance_from)
        base.dict_add_key(_key="maintenanceStatus", value=self.maintenance_status)
        base.dict_add_key(_key="maintenanceType", value=self.maintenance_type)
        base.dict_add_key(_key="maintenanceid", value=self.maintenanceid)
        base.dict_add_key(_key="name", value=self.name)
        base.dict_add_key(_key="proxyHostid", value=self.proxy_hostid)
        base.dict_add_key(_key="snmpAvailable", value=self.snmp_available)
        base.dict_add_key(_key="snmpDisableUntil", value=self.snmp_disable_until)
        base.dict_add_key(_key="snmpError", value=self.snmp_error)
        base.dict_add_key(_key="snmpErrorsFrom", value=self.snmp_errors_from)
        base.dict_add_key(_key="interfaces", value=self.interfaces)
        base.dict_add_key(_key="groupids", value=self.groupids)
        base.dict_add_key(_key="tags", value=self.tags)
        base.dict_add_key(_key="templateids", value=self.templateids)
        base.dict_add_key(_key="macros", value=self.macros)
        base.dict_add_key(_key="inventory", value=self.inventory)
        base.dict_add_key(_key="status", value=self.status)
        base.dict_add_key(_key="tlsConnect", value=self.tls_connect)
        base.dict_add_key(_key="tlsAccept", value=self.tls_accept)
        base.dict_add_key(_key="tlsIssuer", value=self.tls_issuer)
        base.dict_add_key(_key="tlsSubject", value=self.tls_subject)
        base.dict_add_key(_key="tlsPskIdentity", value=self.tls_psk_identity)
        base.dict_add_key(_key="tlsPsk", value=self.tls_psk)
        self.local_json = base._json
        self._json = self.local_json
        self.response = self.api.post(url=self._url, json=self._json)
