예제 #1
0
 def v2_runner_on_ok(self, result, **kwargs):
     if result.task_name == 'collect_host':
         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 == 'copyfile':
         pass
     elif result.task_name == 'collect_resource':
         ip = self._cache_host.get(result._host.name)
         resource = result._result.get('stdout_lines')
         Resource.create_obj(ip, resource[0], resource[1])
예제 #2
0
 def v2_runner_on_ok(self, result, **kwargs):
     if result.task_name == 'collect_host':
         facts = result._result.get('ansible_facts', {})
         ip = facts.get('ansible_default_ipv4', {}).get('address', '')
         self._cache_host[result._host.name] = ip  #主要是通过主机名去获取IP
         # print(self._cache_host)
     elif result.task_name == 'collect_copy':
         pass
     elif result.task_name == 'collect_command':  #task_name表示任务名称
         ip = self._cache_host.get(result._host.name)  #一台主机执行一次
         resource = result._result.get('stdout_lines', [])
         Resource.create_obj(ip, resource[0], resource[1])
예제 #3
0
    def post(self, request, *args, **kwargs):
        _ip = kwargs.get("ip", "")
        _json = self.get_json()

        Resource.create_obj(_ip, _json.get('cpu'), _json.get('mem'))
        return self.response()