def inputs_format(self): return [ self.InputItem( name=_("填参方式"), key="cc_transfer_select_method_method", type="string", schema=StringItemSchema(description=_("填参方式")), ), self.InputItem( name=_("更新主机所属业务模块详情"), key="cc_host_transfer_detail", type="array", schema=ArrayItemSchema( description=_("更新主机所属业务模块详情"), item_schema=ObjectItemSchema(description=_("业务模块属性修改对象"), property_schemas={}), ), ), self.InputItem( name=_("自动扩展分隔符"), key="cc_transfer_host_template_break_line", type="string", schema=StringItemSchema(description=_("在自动填参时使用的扩展分割符")), ), self.InputItem( name=_("更新方式"), key="is_append", type="boolean", schema=BooleanItemSchema(description=_("更新方式")), ), ]
def inputs_format(self): return [ self.InputItem( name=_("业务 ID"), key="biz_cc_id", type="string", schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("主机替换信息"), key="cc_host_replace_detail", type="object", schema=ArrayItemSchema( description=_("主机替换信息"), item_schema=ObjectItemSchema( description=_("替换机与被替换机信息"), property_schemas={ "cc_fault_ip": StringItemSchema(description=_("故障机 内网IP")), "cc_new_ip": StringItemSchema(description=_("替换机 内网IP")), }, ), ), ), self.InputItem( name=_("复制故障机属性"), key="copy_attributes", type="bool", schema=BooleanItemSchema(description=_("复制故障机属性")), ), ]
def inputs_format(self): return [ self.InputItem( name=_("是否允许跨业务"), key="job_across_biz", type="bool", schema=BooleanItemSchema(description=_("是否允许跨业务,如果允许,源文件IP格式需为【云区域ID:IP】")), ), self.InputItem( name=_("源文件"), key="job_source_files", type="array", schema=ArrayItemSchema( description=_("待分发文件列表"), item_schema=ObjectItemSchema( description=_("待分发文件信息"), property_schemas={ "ip": StringItemSchema(description=_("机器 IP")), "files": StringItemSchema(description=_("文件路径")), "account": StringItemSchema(description=_("执行账户")), }, ), ), ), self.InputItem( name=_("上传限速"), key="upload_speed_limit", type="string", schema=StringItemSchema(description=_("MB/s")), ), self.InputItem( name=_("下载限速"), key="download_speed_limit", type="string", schema=StringItemSchema(description=_("MB/s")), ), self.InputItem( name=_("目标 IP"), key="job_ip_list", type="string", schema=StringItemSchema(description=_("文件分发目标机器 IP,多个用英文逗号 `,` 分隔")), ), self.InputItem( name=_("目标账户"), key="job_account", type="string", schema=StringItemSchema(description=_("文件分发目标机器账户")), ), self.InputItem( name=_("目标路径"), key="job_target_path", type="string", schema=StringItemSchema(description=_("文件分发目标路径")), ), self.InputItem( name=_("超时时间"), key="job_timeout", type="string", schema=StringItemSchema(description=_("超时时间")) ), ]
class Service(object): __metaclass__ = ABCMeta schedule_result_attr = '__schedule_finish__' schedule_determine_attr = '__need_schedule__' InputItem = InputItem OutputItem = OutputItem interval = None _result_output = OutputItem( name=_(u"执行结果"), key='_result', type='bool', schema=BooleanItemSchema(description=_(u"是否执行成功"))) def __init__(self, name=None): self.name = name self.interval = deepcopy(self.interval) @abstractmethod def execute(self, data, parent_data): # get params from data pass def outputs_format(self): return [] def inputs_format(self): return [] def inputs(self): return self.inputs_format() def outputs(self): custom_format = self.outputs_format() assert isinstance(custom_format, list) custom_format.append(self._result_output) return custom_format def need_schedule(self): return getattr(self, Service.schedule_determine_attr, False) def schedule(self, data, parent_data, callback_data=None): return True def finish_schedule(self): setattr(self, self.schedule_result_attr, True) def is_schedule_finished(self): return getattr(self, self.schedule_result_attr, False) def __getstate__(self): if 'logger' in self.__dict__: del self.__dict__['logger'] return self.__dict__ def clean_status(self): setattr(self, self.schedule_result_attr, False)
def inputs_format(self): return super().inputs_format() + [ self.InputItem( name=_("IP Tag 分组"), key="is_tagged_ip", type="boolean", schema=BooleanItemSchema(description=_("是否对 IP 进行 Tag 分组")), ), ]
def inputs_format(self): return [ self.InputItem( name=_("业务 ID"), key="biz_cc_id", type="string", schema=StringItemSchema(description=_("通知人员所属的 CMDB 业务 ID")), ), self.InputItem( name=_("通知方式"), key="bk_notify_type", type="array", schema=ArrayItemSchema( description=_("需要使用的通知方式,从 API 网关自动获取已实现的通知渠道"), item_schema=StringItemSchema(description=_("通知方式"))), ), self.InputItem( name=_("固定分组"), key="bk_receiver_group", type="array", required=False, schema=ArrayItemSchema( description=_("需要进行通知的业务人员分组"), enum=["Maintainers", "ProductPm", "Developer", "Tester"], item_schema=StringItemSchema(description=_("通知分组")), ), ), self.InputItem( name=_("项目人员分组"), key="bk_staff_group", type="array", required=False, schema=ArrayItemSchema( description=_("需要进行通知的项目人员分组ID列表"), item_schema=IntItemSchema(description=_("项目人员分组ID"))), ), self.InputItem( name=_("额外通知人"), key="bk_more_receiver", type="string", schema=StringItemSchema( description=_("除了通知分组外需要额外通知的人员,多个用英文逗号 `,` 分隔")), ), self.InputItem(name=_("通知标题"), key="bk_notify_title", type="string", schema=StringItemSchema(description=_("通知的标题"))), self.InputItem(name=_("通知内容"), key="bk_notify_content", type="string", schema=StringItemSchema(description=_("通知的内容"))), self.InputItem(name=_("通知执行人"), key="notify", type="boolean", schema=BooleanItemSchema(description=_("通知执行人名字"))), ]
def inputs_format(self): return [ self.InputItem( name=_("生成文件名[后缀]"), key="local_name", type="string", schema=StringItemSchema(description=_("生成文件名")), ), self.InputItem( name=_("文本内容"), key="local_content", type="string", schema=StringItemSchema(description=_("文本内容")), ), self.InputItem( name=_("目标IP"), key="job_ip_list", type="string", schema=StringItemSchema( description=_("IP必须填写【云区域ID:IP】或者【IP】格式之一,多个用换行分隔;【IP】格式需要保证所填写的内网IP在配置平台(CMDB)的该业务中是唯一的") ), ), self.InputItem( name=_("目标账户"), key="file_account", type="string", schema=StringItemSchema(description=_("请输入在蓝鲸作业平台上注册的账户名")), ), self.InputItem( name=_("目标路径"), key="file_path", type="string", schema=StringItemSchema(description=_("目标路径")), ), self.InputItem( name=_("是否允许跨业务"), key="job_across_biz", type="boolean", schema=BooleanItemSchema(description=_("是否允许跨业务,如果允许,源文件IP格式需为【云区域ID:IP】")), ), ]
def inputs_format(self): return [ self.InputItem( name=_("业务 ID"), key="biz_cc_id", type="string", schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("作业模板 ID"), key="job_task_id", type="string", schema=StringItemSchema(description=_("需要执行的 JOB 作业模板 ID")), ), self.InputItem( name=_("全局变量"), key="job_global_var", type="array", schema=ArrayItemSchema( description=_("作业模板执行所需的全局变量列表"), item_schema=ObjectItemSchema( description=_("全局变量"), property_schemas={ "category": IntItemSchema(description=_("变量类型,云参(1) 上下文参数(2) IP(3)")), "name": StringItemSchema(description=_("变量名")), "value": StringItemSchema(description=_("变量值")), }, ), ), ), self.InputItem( name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), ), ]
def inputs_format(self): return [ self.InputItem( name=_("业务 ID"), key="biz_cc_id", type="string", schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("脚本来源"), key="job_script_source", type="string", schema=StringItemSchema( description=_( "待执行的脚本来源,手动(manual),业务脚本(general),公共脚本(public)"), enum=["manual", "general", "public"], ), ), self.InputItem( name=_("脚本类型"), key="job_script_type", type="string", schema=StringItemSchema( description=_( "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), enum=["1", "2", "3", "4", "5"], ), ), self.InputItem( name=_("脚本内容"), key="job_content", type="string", schema=StringItemSchema( description=_("待执行的脚本内容,仅在脚本来源为手动时生效")), ), self.InputItem( name=_("公共脚本"), key="job_script_list_public", type="string", schema=StringItemSchema( description=_("待执行的公共脚本 ID,仅在脚本来源为公共脚本时生效")), ), self.InputItem( name=_("业务脚本"), key="job_script_list_general", type="string", schema=StringItemSchema( description=_("待执行的业务脚本 ID,仅在脚本来源为业务脚本时生效")), ), self.InputItem( name=_("脚本执行参数"), key="job_script_param", type="string", schema=StringItemSchema(description=_("脚本执行参数")), ), self.InputItem( name=_("是否允许跨业务"), key="job_across_biz", type="bool", schema=BooleanItemSchema(description=_( "是否允许跨业务(跨业务需在作业平台添加白名单),允许时,源文件IP格式需为【云区域ID:IP】")), ), self.InputItem( name=_("目标 IP"), key="job_ip_list", type="string", schema=StringItemSchema( description=_("执行脚本的目标机器 IP,多个用英文逗号 `,` 分隔")), ), self.InputItem( name=_("目标账户"), key="job_account", type="string", schema=StringItemSchema(description=_("执行脚本的目标机器账户")), ), self.InputItem( name=_("IP 存在性校验"), key="ip_is_exist", type="string", schema=BooleanItemSchema(description=_( "是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), ), self.InputItem( name=_("自定义任务名"), key="custom_task_name", type="string", schema=BooleanItemSchema( description=_("用户自定义任务名称。不填的话,作业平台会自动生成任务名称")), ), ]
def test_type(self): self.assertEqual('int', IntItemSchema._type()) self.assertEqual('string', StringItemSchema._type()) self.assertEqual('float', FloatItemSchema._type()) self.assertEqual('boolean', BooleanItemSchema._type())