Esempio n. 1
0
File: v1.py Progetto: 49257620/cmdb
    def post(self, request, *args, **kwargs):
        _ip = kwargs.get('ip', '')
        _json = self.get_json()

        record = Resource()
        record.ip = _ip
        record.cpu = _json.get('cpu', 0)
        record.mem = _json.get('mem', 0)
        record.save()

        return self.respones(record.as_dict())
Esempio n. 2
0
 def v2_runner_on_ok(self, result, **kwargs):
     if result.task_name == 'collect_server_info':
         facts = result._result.get('ansible_facts', {})
         ip = facts.get('ansible_default_ipv4', {}).get('address', '')
         self._cache_host[result._host.name] = ip
     elif result.task_name == 'copy_file':
         pass
     elif result.task_name == 'collect_resource':
         ip = self._cache_host.get(result._host.name)
         resource = result._result.get('stdout_lines', [])
         record = Resource()
         record.ip = ip
         record.cpu = resource[0]
         record.mem = resource[1]
         record.save()