Пример #1
0
    def invoke_cmd(self, cmd, args=None, script=False):
        command = '{0}({1})'.format(cmd, args) if args else cmd
        type_ = 'script' if script else 'cmd'
        params = {'key': settings.STARTAGETN_KEY,
                  'exeurl': type_ + '://' + command,
                  'timestamp': int(time.time())}

        if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", self.host):
            params['ip'] = self.host
        else:
            params['hostname'] = self.host

        params['sync'] = 'true' if self.async else 'false'
        params['sign'] = self._sign(params)

        print params
        print settings.STARTAGENT_URL

        response = RequestClient.query(url=settings.STARTAGENT_URL + '/api/task',method="GET", params=params)
        if response.status_code != 200:
            raise ServiceRequestError(response.content)
        else:
            try:
                content = response.json()
            except ValueError:
                print "Error"
                content = response.content
        return content
Пример #2
0
    def query_nodegroups_by_appnode(cls, appnode):
        url = settings.ARMORY_URL + '/page/api/free/product/getnodeinfo.htm'
        params = {
            'appname': appnode,
            '_username': settings.ARMORY_USERNAME,
        }

        response = RequestClient.query(url, params=params)
        if response.status_code != 200:
            raise HTTPError("armroy api return error")
        result = json.loads(response.content)["nodegroup"].values()
        return result
Пример #3
0
    def query_nodegroups_by_appnode(cls, appnode):
        url = settings.ARMORY_URL + '/page/api/free/product/getnodeinfo.htm'
        params = {
            'appname': appnode,
            '_username': settings.ARMORY_USERNAME,
        }

        response = RequestClient.query(url, params=params)
        if response.status_code != 200:
            raise HTTPError("armroy api return error")
        result = json.loads(response.content)["nodegroup"].values()
        return result
Пример #4
0
    def _common_device_query(cls, attr, value):
        url = settings.ARMORY_URL + '/page/api/free/opsfreeInterface/search.htm'
        params = {
            'from': 'device',
            '_username': settings.ARMORY_USERNAME,
            'q': "{0}=={1}".format(attr, value),
            'num': '0',
        }

        response = RequestClient.query(url, params=params)
        if response.status_code != 200:
            raise HTTPError("armroy api return error")
        result = json.loads(response.content)['result']
        return result
Пример #5
0
    def _common_device_query(cls, attr, value):
        url = settings.ARMORY_URL + '/page/api/free/opsfreeInterface/search.htm'
        params = {
            'from': 'device',
            '_username': settings.ARMORY_USERNAME,
            'q': "{0}=={1}".format(attr, value),
            'num': '0',
        }

        response = RequestClient.query(url, params=params)
        if response.status_code != 200:
            raise HTTPError("armroy api return error")
        result = json.loads(response.content)['result']
        return result
Пример #6
0
 def get_result(cls, tid):
     params = {'key': settings.STARTAGETN_KEY, 'tid': tid, 'timestamp': int(time.time())}
     params['sign'] = cls._sign(params)
     print "get_result",params
     response = RequestClient.query(url=settings.STARTAGENT_URL + '/api/query', method="GET", params=params)
     if response.status_code != 200:
         raise ServiceRequestError(response.content)
     else:
         try:
             print "content: json"
             content = response.json()
         except ValueError:
             print "content:content"
             content = response.content
     print content
     return content