コード例 #1
0
    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
コード例 #2
0
ファイル: cc.py プロジェクト: Q-skyworker/BK_project
    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)
        client.set_bk_api_ver('v2')
        if parent_data.get_one_of_inputs('language'):
            setattr(client, 'language',
                    parent_data.get_one_of_inputs('language'))

        # 查询主机id
        ip_list = get_ip_by_regex(data.get_one_of_inputs('cc_host_ip'))
        host_result = cc_get_host_id_by_innerip(executor, biz_cc_id, ip_list)
        if not host_result['result']:
            data.set_outputs('ex_data', host_result['message'])
            return False

        cc_module_select = data.get_one_of_inputs('cc_module_select')
        cc_is_increment = data.get_one_of_inputs('cc_is_increment')

        cc_kwargs = {
            "bk_biz_id": biz_cc_id,
            "bk_host_id": [int(host_id) for host_id in host_result['data']],
            "bk_module_id": cc_module_select,
            "is_increment": cc_is_increment
        }
        cc_result = client.cc.transfer_host_module(cc_kwargs)
        if cc_result['result']:
            return True
        else:
            message = cc_handle_api_error('cc.transfer_host_module', cc_kwargs,
                                          cc_result['message'])
            data.set_outputs('ex_data', message)
            return False
コード例 #3
0
ファイル: cc.py プロジェクト: Q-skyworker/BK_project
    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)
        client.set_bk_api_ver('v2')
        if parent_data.get_one_of_inputs('language'):
            setattr(client, 'language',
                    parent_data.get_one_of_inputs('language'))
        # 查询主机id
        ip_list = get_ip_by_regex(data.get_one_of_inputs('cc_host_ip'))
        host_result = cc_get_host_id_by_innerip(executor, biz_cc_id, ip_list)
        if not host_result['result']:
            data.set_outputs('ex_data', host_result['message'])
            return False

        # 更新主机属性
        cc_host_property = data.get_one_of_inputs('cc_host_property')
        if cc_host_property == "bk_isp_name":
            bk_isp_name = cc_format_prop_data(
                executor, 'host', 'bk_isp_name',
                parent_data.get_one_of_inputs('language'))
            if not bk_isp_name['result']:
                data.set_outputs('ex_data', bk_isp_name['message'])
                return False

            cc_host_prop_value = bk_isp_name['data'].get(
                data.get_one_of_inputs('cc_host_prop_value'))
            if not cc_host_prop_value:
                data.set_outputs('ex_data', _(u'所属运营商校验失败,请重试并修改为正确的所属运营商'))
                return False

        elif cc_host_property == "bk_state_name":
            bk_state_name = cc_format_prop_data(
                executor, 'host', 'bk_state_name',
                parent_data.get_one_of_inputs('language'))
            if not bk_state_name['result']:
                data.set_outputs('ex_data', bk_state_name['message'])
                return False

            cc_host_prop_value = bk_state_name['data'].get(
                data.get_one_of_inputs('cc_host_prop_value'))
            if not cc_host_prop_value:
                data.set_outputs('ex_data', _(u'所在国家校验失败,请重试并修改为正确的所在国家'))
                return False
        elif cc_host_property == "bk_province_name":
            bk_province_name = cc_format_prop_data(
                executor, 'host', 'bk_province_name',
                parent_data.get_one_of_inputs('language'))
            if not bk_province_name['result']:
                data.set_outputs('ex_data', bk_province_name['message'])
                return False
            cc_host_prop_value = bk_province_name['data'].get(
                data.get_one_of_inputs('cc_host_prop_value'))
            if not cc_host_prop_value:
                data.set_outputs('ex_data', _(u'所在省份校验失败,请重试并修改为正确的所在省份'))
                return False
        else:
            cc_host_prop_value = data.get_one_of_inputs('cc_host_prop_value')

        cc_kwargs = {
            "bk_host_id": ",".join(host_result['data']),
            "data": {
                cc_host_property: cc_host_prop_value
            }
        }
        cc_result = client.cc.update_host(cc_kwargs)
        if cc_result['result']:
            return True
        else:
            message = cc_handle_api_error('cc.update_host', cc_kwargs,
                                          cc_result['message'])
            data.set_outputs('ex_data', message)
            return False