def execute(self, data, parent_data): executor = parent_data.get_one_of_inputs('executor') biz_cc_id = parent_data.get_one_of_inputs('biz_cc_id') client = get_client_by_user(executor) if parent_data.get_one_of_inputs('language'): setattr(self, 'language', parent_data.get_one_of_inputs('language')) original_source_files = data.get_one_of_inputs('job_source_files', []) file_source = [] for item in original_source_files: ip_info = cc_get_ips_info_by_str(executor, biz_cc_id, item['ip']) file_source.append({ 'file': item['files'].strip(), 'ip_list': [{ 'ip': _ip['InnerIP'], 'source': _ip['Source'] } for _ip in ip_info['ip_result']], 'account': item['account'].strip(), }) original_ip_list = data.get_one_of_inputs('job_ip_list') ip_info = cc_get_ips_info_by_str(executor, biz_cc_id, original_ip_list) ip_list = [{ 'ip': _ip['InnerIP'], 'source': _ip['Source'] } for _ip in ip_info['ip_result']] job_kwargs = { 'app_id': biz_cc_id, 'file_source': file_source, 'ip_list': ip_list, 'account': data.get_one_of_inputs('job_account'), 'file_target_path': data.get_one_of_inputs('job_target_path'), } job_result = client.job.fast_push_file(job_kwargs) if job_result['result']: data.set_outputs('job_inst_id', job_result['data']['taskInstanceId']) data.set_outputs('job_inst_name', job_result['data']['taskInstanceName']) data.set_outputs('client', client) return True else: data.set_outputs('ex_data', job_result['message']) return False
def get_value(self): var_ip_picker = self.value username = self.pipeline_data['executor'] biz_cc_id = self.pipeline_data['biz_cc_id'] produce_method = var_ip_picker['var_ip_method'] if produce_method == 'custom': custom_value = var_ip_picker['var_ip_custom_value'] data = cc_get_ips_info_by_str(username, biz_cc_id, custom_value) ip_list = data['ip_result'] data = ','.join(['%s:%s' % (ip['Source'], ip['InnerIP'])for ip in ip_list]) else: select_data = var_ip_picker['var_ip_tree'] select_module = map(lambda x: int(x.split("_")[1]), filter(lambda x: x.split("_")[0] == "module", select_data)) if select_module: ip_result = cc_get_inner_ip_by_module_id( username, biz_cc_id, select_module ) select_module_ip = map(lambda x: x['host']['bk_host_innerip'], ip_result) else: select_module_ip = [] select_ip = map(lambda x: get_ip_by_regex(x)[0], filter(lambda x: get_ip_by_regex(x), select_data)) data = ','.join(list(set(select_ip + select_module_ip))) return data
def execute(self, data, parent_data): executor = parent_data.get_one_of_inputs('executor') biz_cc_id = parent_data.get_one_of_inputs('biz_cc_id') client = get_client_by_user(executor) if parent_data.get_one_of_inputs('language'): setattr(client, 'language', parent_data.get_one_of_inputs('language')) original_global_var = data.get_one_of_inputs('job_global_var') global_var = [] for _value in original_global_var: # 1-字符串,2-IP if _value['type'] == 2: var_ip = cc_get_ips_info_by_str(executor, biz_cc_id, _value['value']) ip_list = [ '%s:%s' % (_ip['Source'], _ip['InnerIP']) for _ip in var_ip['ip_result'] ] global_var.append({ 'id': _value['id'], 'name': _value['name'], 'ipList': ','.join(ip_list), }) else: global_var.append({ 'id': _value['id'], 'name': _value['name'], 'value': _value['value'].strip(), }) job_kwargs = { 'app_id': biz_cc_id, 'task_id': data.get_one_of_inputs('job_task_id'), 'global_var': global_var, } job_result = client.job.execute_task_ext(job_kwargs) if job_result['result']: data.set_outputs('job_inst_id', job_result['data']['taskInstanceId']) data.set_outputs('job_inst_name', job_result['data']['taskInstanceName']) data.set_outputs('client', client) return True else: data.set_outputs('ex_data', job_result['message']) return False
def execute(self, data, parent_data): executor = parent_data.get_one_of_inputs('executor') biz_cc_id = parent_data.get_one_of_inputs('biz_cc_id') client = get_client_by_user(executor) if parent_data.get_one_of_inputs('language'): setattr(client, 'language', parent_data.get_one_of_inputs('language')) original_ip_list = data.get_one_of_inputs('job_ip_list') ip_info = cc_get_ips_info_by_str(executor, biz_cc_id, original_ip_list) ip_list = [{ 'ip': _ip['InnerIP'], 'source': _ip['Source'] } for _ip in ip_info['ip_result']] job_kwargs = { 'app_id': biz_cc_id, 'type': data.get_one_of_inputs('job_script_type'), 'content': base64.b64encode( data.get_one_of_inputs('job_content').encode('utf-8')), 'script_param': data.get_one_of_inputs('job_script_param'), 'script_timeout': data.get_one_of_inputs('job_script_timeout'), 'account': data.get_one_of_inputs('job_account'), 'ip_list': ip_list, } job_result = client.job.fast_execute_script(job_kwargs) if job_result['result']: data.set_outputs('job_inst_id', job_result['data']['taskInstanceId']) data.set_outputs('job_inst_name', job_result['data']['taskInstanceName']) data.set_outputs('client', client) return True else: data.set_outputs('ex_data', job_result['message']) return False
def get_value(self): var_ip_picker = self.value username = self.pipeline_data['executor'] biz_cc_id = self.pipeline_data['biz_cc_id'] value_type = var_ip_picker['var_ip_value_type'] ip_list = [] dns_list = [] produce_method = var_ip_picker['var_ip_method'] if produce_method == 'custom': custom_value = var_ip_picker['var_ip_custom_value'] if value_type == 'ip': data = cc_get_ips_info_by_str(username, biz_cc_id, custom_value) ip_list = data['ip_result'] elif value_type == 'dns': dns_list = custom_value.split('\n') else: data = re.findall(r"\d+", custom_value) kwargs = { "appid": biz_cc_id, "zoneids": ",".join(data), "type": "gamedb", } ips = get_ip_by_zoneid(kwargs) if ips["code"] == 0: # 请求成功 for item in ips["data"].values(): dns_list += item['dbs'] dns_list = list(set(dns_list)) else: message = 'gcs get_ip_by_zoneid error: kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(ips)) logger.error(message) raise VariableHydrateException(message) elif produce_method == 'select': select_set = var_ip_picker['var_ip_select_set'] select_module = var_ip_picker['var_ip_select_module'] # 配置平台暂无DNS相关信息,所以只需要取IP if value_type == 'ip': ip_list = cc_get_ips_by_set_and_module( username, biz_cc_id, select_set, None, select_module, ) else: input_set = var_ip_picker['var_ip_input_set'] input_module = var_ip_picker['var_ip_input_module'] set_names = input_set.split(',') module_names = input_module.split(',') # 配置平台暂无DNS相关信息,所以只需要取IP if value_type == 'ip': ip_list = cc_get_ips_by_set_and_module( username, biz_cc_id, None, set_names, module_names, ) if value_type == 'ip': data = ','.join(['%s:%s' % (ip['Source'], ip['InnerIP']) for ip in ip_list]) else: data = ','.join(dns_list) return data