# -*- 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, host=None, description=None, groupids=None, interfaces=None, tags=None, templateids=None, macros=None,
                 inventory=None, status=None, tls_accept=None, tls_psk_identity=None, tls_psk=None):
        """
        :param _host: 域名
        :param host:
        :param description:
        :param groupids:
        :param interfaces:
        :param tags:
        :param templateids:
        :param macros:
        :param inventory:
        :param status:
        :param tls_accept:
        :param tls_psk_identity:
        :param tls_psk:
        :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.host = host
        self.description = description
        self.groupids = groupids
        self.interfaces = interfaces
        self.tags = tags
        self.templateids = templateids
        self.macros = macros
        self.inventory = inventory
        self.status = status
        self.tls_accept = tls_accept
        self.tls_psk_identity = tls_psk_identity
        self.tls_psk = tls_psk

        self.api = UtilsRequest()

    def get_response(self):
        base = ApiBase()
        base.dict_add_key(_key="host", value=self.host)
        base.dict_add_key(_key="description", value=self.description)
        base.dict_add_key(_key="groupids", value=self.groupids)
        base.dict_add_key(_key="interfaces", value=self.interfaces)
        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="tlsAccept", value=self.tls_accept)
        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)
