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


class ApplicationCreate(object):
    def __init__(self, _host, applicationid=None, hostid=None, name=None, flags=None, templateids=None):
        """
        :param _host: 域名
        :param applicationid: 应用ID
        :param hostid : 主机组的ID
        :param name: 应用名称
        :param flags: 应用程序的来源
        :param templateids: 父模板应用程序的ID
        :return:
        """
        self.log = UtilsLog()
        self.log.info("调用创建应用")
        self.log.info(self.__class__)

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

        self.applicationid = applicationid
        self.hostid = hostid
        self.name = name
        self.flags = flags
        self.templateids = templateids

        self.api = UtilsRequest()

    def get_response(self):
        self._json = {
            "applicationid": self.applicationid,
            "hostid": self.hostid,
            "name": self.name,
            "flags": self.flags,
            "templateids": self.templateids
        }
        self.response = self.api.post(url=self._url, json=self._json)
