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])
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])
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())
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()
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()