更新时间:2024-06-28 GMT+08:00

创建任务

功能介绍

该接口用于创建工作流(任务),返回工作流详情。任务类型取决于模板名称和'input'参数。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/cms/workflow

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户从IAM申请到的projectid,一般为32位字符串。

最小长度:32

最大长度:32

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。

最小长度:1

最大长度:40960

Content-Type

String

指定类型为application/json。

最小长度:1

最大长度:32

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

工作流名称,需要满足中文、英文大小写、数字、中划线和下划线{1,64}。

最小长度:1

最大长度:64

type

String

工作流类型,可以为cron、manual

最小长度:1

最大长度:32

description

String

工作流描述信息。

最小长度:1

最大长度:128

tags

Object

标签键和值列表,标签键值对数量范围是0至20。

template_name

String

模板名称,示例:CMS::ECS::BulkyRunScript CMS::ECS::BulkyStartECSInstances CMS::ECS::BulkyCleanDisks

最小长度:1

最大长度:64

template_id

String

模板id。

最小长度:1

最大长度:64

input

Map<String,Object>

任务执行时需要的参数列表。

quote

Array of strings

引用,参数引用。

最小长度:1

最大长度:128

数组长度:1 - 128

job_name

String

作业名称。

最小长度:1

最大长度:64

job_id

String

作业id。

最小长度:1

最大长度:64

service_scenario

String

服务场景分类。

最小长度:1

最大长度:64

service_name

String

服务名称。

最小长度:1

最大长度:128

task_type

String

任务类型。package,script,job,cloud,standard,customize

最小长度:1

最大长度:32

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

id

String

工作流id,唯一标识,根据project_id和workflow_name生成。

最小长度:1

最大长度:64

name

String

工作流名称。

最小长度:1

最大长度:64

type

String

工作流类型,可以为cron、manual

最小长度:1

最大长度:16

description

String

工作流描述信息。

最小长度:1

最大长度:128

tags

Map<String,String>

标签键和值列表,标签键值对数量范围是0至20。

create_time

Long

工作流创建时间,为utc时间毫秒数。

最小值:0

最大值:9999999999999

create_by

String

工作流创人,从接口调用传入的token中获取。

最小长度:1

最大长度:64

update_time

Long

工作流更新时间,为utc时间毫秒数。

最小值:0

最大值:9999999999999

update_by

String

工作流更新人,从接口调用传入的token中获取。

最小长度:1

最大长度:64

template_name

String

模板名称。

最小长度:1

最大长度:64

template_id

String

模板id

最小长度:1

最大长度:64

input

Map<String,Object>

任务执行时需要的参数列表。

last_execution_id

String

最近一次执行id,也是工作流id

最小长度:1

最大长度:64

status

String

任务状态,包含success,fail,executing

最小长度:1

最大长度:16

citation_urns

Array of strings

工作流的引用。

最小长度:1

最大长度:256

数组长度:0 - 200

last_execution_end_time

Long

最近一次执行结束时间,为utc时间毫秒数

最小值:0

最大值:9999999999999

last_execution_start_time

Long

最近一次执行开始时间,为utc时间毫秒数

最小值:0

最大值:9999999999999

quote

Array of strings

引用,参数引用

最小长度:1

最大长度:256

数组长度:1 - 999

job_name

String

作业名称

最小长度:1

最大长度:64

job_id

String

作业id

最小长度:1

最大长度:64

service_scenario

String

服务场景分类

最小长度:1

最大长度:64

service_name

String

服务名称

最小长度:1

最大长度:64

task_type

String

任务类型

最小长度:1

最大长度:16

project_id

String

functiongraph返回的PROJECT_ID

最小长度:1

最大长度:32

workflow_id

String

functiongraph返回的WORKFLOW_ID

最小长度:1

最大长度:64

task_status

String

任务状态

最小长度:1

最大长度:32

nodes

Array of Node objects

任务节点

数组长度:1 - 20

edit_time

Long

编辑时间

最小值:0

最大值:9999999999999

execution_action_rules

Array of strings

执行动作细粒度权限

最小长度:1

最大长度:128

数组长度:0 - 200

execution_permission

Array of strings

云服务权限

最小长度:1

最大长度:128

数组长度:1 - 32

global_parameters

Array of Parameter objects

全局参数

数组长度:0 - 20

is_delete

Boolean

逻辑删除

steps

Array of Step objects

任务步骤

数组长度:1 - 10

output

String

任务输出

最小长度:1

最大长度:40960

trigger_id

String

触发器id

最小长度:1

最大长度:64

trigger_status

String

触发器状态

最小长度:1

最大长度:64

approve_id

String

审批id

最小长度:1

最大长度:64

template_i18n

WorkFlowModel object

任务国际化字段,包含中英文描述

enterprise_project_id

String

任务所属的企业项目

最小长度:1

最大长度:64

last_execute_by

String

任务最后一次执行人

最小长度:1

最大长度:64

表5 Node

参数

参数类型

描述

parent_node

String

父亲节点的名称。

最小长度:1

最大长度:64

category

String

节点类型。

最小长度:1

最大长度:32

description

String

节点描述。

最小长度:1

最大长度:1024

id

String

节点id

最小长度:1

最大长度:64

ignore_error

Boolean

是否忽略错误

metadata

Metadata object

元数据。

name

String

节点名称,比如是Node。

最小长度:1

最大长度:64

task_name

String

任务名称,节点上任务的名称。

最小长度:1

最大长度:64

表6 Metadata

参数

参数类型

描述

type

String

节点类型。

最小长度:1

最大长度:32

configuration

Map<String,Object>

配置信息。

表7 Parameter

参数

参数类型

描述

param_name

String

参数名称。

param_type

String

参数类型。

最小长度:1

最大长度:16

param_group

String

参数分组。

最小长度:1

最大长度:32

default_value

String

参数初始值。

最小长度:1

最大长度:40960

id

String

参数id。

最小长度:1

最大长度:64

encryption

Boolean

是否加密。

hint

String

参数提示。

最小长度:1

最大长度:1000

quote_param

Boolean

是否从参数库选择。

required

Boolean

是否为必填参数。

description

String

参数描述。

最小长度:1

最大长度:1000

表8 Step

参数

参数类型

描述

id

String

步骤id。

最小长度:1

最大长度:64

name

String

步骤名称。

最小长度:1

最大长度:32

type

String

步骤类型。

最小长度:1

最大长度:16

input

Map<String,String>

步骤参数。

ignore_error

Boolean

是否自动忽略错误。

description

String

步骤说明。

最小长度:1

最大长度:1000

表9 WorkFlowModel

参数

参数类型

描述

en-us

Map<String,String>

英文描述

zh-cn

Map<String,String>

中文描述

状态码: 400

表10 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:64

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

http返回码

最小值:0

最大值:999

状态码: 401

表11 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:64

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

http返回码

最小值:0

最大值:999

状态码: 500

表12 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:64

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

http返回码

最小值:0

最大值:999

请求示例

  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStartECSInstances"、输入参数为"input"来创建启动ECS任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::ECS::BulkyStartECSInstances",
      "template_id" : "CMS::ECS::BulkyStartECSInstances",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"xxx\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "rate_control" : {
          "max" : "1",
          "timeDelay" : "10",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建定时执行脚本任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxxxxshced",
      "template_name" : "CMS::ECS::BulkyRunScript",
      "tags" : { },
      "input" : {
        "project_id" : "2xxx487fxxxxxbffc1cf",
        "region_id" : "cn-north-7",
        "trigger" : {
          "scheduled_time" : "00:04:05",
          "time_zone" : "Asia/Riyadh",
          "policy" : "periodic",
          "cron" : null,
          "period" : "[\"0\",\"3\",\"4\",\"5\",\"6\"]",
          "group" : "trigger"
        },
        "notice" : {
          "interval" : null,
          "before_notice" : null,
          "succeed_notice" : null,
          "fail_notice" : null,
          "group" : "notice",
          "before_topic_selected" : null,
          "success_topic_selected" : null,
          "fail_topic_selected" : null
        },
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"4bxxxxx-xxxx-4c92-xxxx-19469d40a51c\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "script_param" : {
          "name" : "zzy",
          "script_content" : "cd /xxx/xxx",
          "script_type" : "SHELL",
          "version_number" : "1.0",
          "cmd_user" : "xxxxx",
          "script_id" : "xxxx-7e9e-4eed-8xxf-5f1fxx6ebb7d",
          "scriptSelected" : "null",
          "script_args" : null,
          "sensitive_param" : false,
          "time_out" : "7200",
          "script_version_id" : "e005xxx4-1fcf-40xx-b1x6-8dxxxcae7b021",
          "sourceId" : "script",
          "group" : "script"
        }
      },
      "type" : "cron",
      "description" : "",
      "task_type" : "script",
      "template_id" : "CMS::ECS::BulkyRunScript"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建执行脚本任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "execute_task_demo",
      "template_name" : "CMS::ECS::BulkyRunScript",
      "template_id" : "CMS::ECS::BulkyRunScript",
      "tags" : { },
      "input" : {
        "script_param" : {
          "script_content" : "date",
          "script_type" : "SHELL",
          "version_number" : "1.0",
          "cmd_user" : "root",
          "script_id" : "6xxxx097-a4x4-4dxx-axa2-fef5xxxxdd55",
          "scriptSelected" : "null",
          "script_args" : "arg1 agr2",
          "sensitive_param" : "false",
          "time_out" : "7200",
          "script_version_id" : "47xxxd67-bxx5-45x9-860x-cb3d6xxxx745",
          "sourceId" : "script",
          "group" : "script"
        },
        "get_instances" : {
          "ecs_id_list" : "[\"4380xxx9-33xf-4xxe-axxx-7xxxxxx3fcd\"]",
          "type" : "manual",
          "group" : "ecs_instance",
          "vpc_id" : null,
          "subnet_id" : null
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "project_id" : "2xxxxxxca5xx8373xxx1bffxxcf",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "script"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::RDS::RestartRDSInstance、输入参数为"input"来创建重启RDS任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::RDS::RestartRDSInstance",
      "template_id" : "CMS::RDS::RestartRDSInstance",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "rds_instance",
          "rds_id_list" : "[\"xxx\"]",
          "rds_instance_tags" : null,
          "rds_instance_type" : null,
          "rds_instance_datastore_type" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::Package"、输入参数为"input"来创建快速分发文件任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::ECS::Package",
      "template_id" : "CMS::ECS::Package",
      "tags" : { },
      "input" : {
        "project_id" : "xxx",
        "region_id" : "cn-north-7",
        "package" : {
          "package_version_id" : "xxx",
          "package_basic_id" : "xxx",
          "cmd_user" : "xxxxx",
          "install_file_dir" : "/",
          "package_name" : "77779956",
          "version_number" : "110",
          "operate_type" : "install",
          "group" : "package",
          "software_list" : "[{x}]",
          "time_out" : "7200",
          "pre_install_script" : "",
          "install_script" : "ls",
          "un_install_script" : "",
          "plat_form" : "Linux"
        },
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"xxx\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        }
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "package"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStopECSInstances"、输入参数为"input"来创建关闭ECS任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::ECS::BulkyStopECSInstances",
      "template_id" : "CMS::ECS::BulkyStopECSInstances",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"xxx\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "stop_ecs_type" : {
          "group" : "stop_ecs_type",
          "stop_ecs_type" : "SOFT"
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyCleanDisks"、输入参数为"input"来创建清理磁盘任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::ECS::BulkyCleanDisks",
      "template_id" : "CMS::ECS::BulkyCleanDisks",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"xxx\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "clean_disk" : {
          "path" : "[{\"path\":\"/xxx/\",\"fileName\":\"xxxx.xx\",\"date\":\"1\"}]",
          "group" : "clean_disk",
          "platform" : "linux"
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxxxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyChangeECSPassword"、输入参数为"input"来创建修改ECS密码任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxxxx",
      "template_name" : "CMS::ECS::BulkyChangeECSPassword",
      "template_id" : "CMS::ECS::BulkyChangeECSPassword",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "ecs_instance",
          "ecs_id_list" : "[\"xxxxx\"]",
          "ecs_instance_status" : null,
          "ecs_instance_tags" : null,
          "ecs_instance_enterprise_project_id" : null,
          "vpc_id" : null,
          "subnet_id" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "user_password" : {
          "username" : "xxx",
          "password" : "xxxxx",
          "group" : "user_password"
        },
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxxxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }
  • 使用任务名称为"xxx"、模板名称为"job_1"、输入参数为"input"来创建作业任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "job_1",
      "template_id" : "xxx",
      "tags" : { },
      "input" : {
        "project_id" : "xxx",
        "region_id" : "cn-north-7",
        "isExist" : "false",
        "rate_control" : {
          "max" : "0",
          "timeDelay" : "0",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "reviewer_selected" : null,
          "group" : "approve"
        }
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "job"
    }
  • 使用任务名称为"xxx"、模板名称为"CMS::CCE::RestartWorkloadInstance"、输入参数为"input"来创建重启工作负载任务。

    https://{Endpoint}/v1/{project_id}/cms/workflow
    
    {
      "name" : "xxx",
      "template_name" : "CMS::CCE::RestartWorkloadInstance",
      "template_id" : "CMS::CCE::RestartWorkloadInstance",
      "tags" : { },
      "input" : {
        "get_instances" : {
          "type" : "manual",
          "group" : "cce_workload_instance",
          "cce_workload_id_list" : "[\"xxx\"]",
          "cce_workload_type" : "deployments",
          "cce_workload_cluster" : "xxx",
          "cce_workload_namespace" : null,
          "frontend_info" : null,
          "selectedData" : null
        },
        "cce_workload_restart_info" : {
          "group" : "cce_workload_restart_info",
          "time_interval" : "300"
        },
        "rate_control" : {
          "max" : "2",
          "timeDelay" : "2",
          "group" : "rate_control"
        },
        "approve" : {
          "need_approve" : "false",
          "topic_selected" : null,
          "group" : "approve"
        },
        "project_id" : "xxx",
        "region_id" : "cn-north-7"
      },
      "type" : "manual",
      "description" : "",
      "task_type" : "cloud"
    }

响应示例

状态码: 200

请求响应成功,返回工作流详情。

{
  "citation_urns" : [ ],
  "create_by" : "xxxx",
  "create_time" : 1670328762884,
  "description" : "",
  "edit_time" : 0,
  "enterprise_project_id" : "0",
  "execution_action_rules" : [ "ecs:cloudServers:start", "ecs:cloudServers:list" ],
  "execution_permission" : [ "CMS FullAccess", "ECS FullAccess", "AOM FullAccess" ],
  "id" : "c15a19ce-110b-4822-862a-a29677dbed6c",
  "input" : {
    "project_id" : "2axxxxa54xxx73bxxxbfxxcf",
    "approve" : {
      "need_approve" : "false",
      "group" : "approve"
    },
    "region_id" : "cn-north-7",
    "get_instances" : {
      "selectedData" : "",
      "frontend_info" : "{\"cmdbApplicationId\":\"xxxxx627611xxxd\"}",
      "type" : "cmdb_dynamic_node",
      "group" : "ecs_instance"
    },
    "rate_control" : {
      "max" : "1",
      "timeDelay" : "10",
      "group" : "rate_control"
    }
  },
  "is_delete" : false,
  "last_execute_by" : "xxx",
  "last_execution_end_time" : 1670328823670,
  "last_execution_id" : "adxxxxb-4894-4xxc-80xx-7xxx3de24b",
  "last_execution_start_time" : 1670328772402,
  "name" : "快速任务执行xxxx0123xx9",
  "nodes" : [ {
    "category" : "service",
    "description" : "Start the ECS instances",
    "id" : "start-ecs-instances",
    "ignore_error" : true,
    "metadata" : {
      "configuration" : {
        "func_urn" : "urn:fss:cn-north-7:xxxxxec14exxxx79b44xxxx57:function:CMS:CMS_DEFAULT_JAVA_FUN_NAME",
        "dataOutputPath" : "",
        "func_app" : "CMS",
        "dataInputPath" : "",
        "validator" : true,
        "func_version" : "latest",
        "dataResultsPath" : "",
        "parameters" : [ {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "2a47xxxx487f837xxxxxfc1cf",
          "isEditor" : false,
          "key" : "properties.project_id"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "cn-north-7",
          "isEditor" : false,
          "key" : "properties.region_id"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "",
          "isEditor" : false,
          "key" : "properties.selectedData"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "{\"cmdbApplicationId\":\"xxxxxxx96627xxxxxa3cd\"}",
          "isEditor" : false,
          "key" : "properties.frontend_info"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "cmdb_dynamic_node",
          "isEditor" : false,
          "key" : "properties.type"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "ecs_instance",
          "isEditor" : false,
          "key" : "properties.group"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "1",
          "isEditor" : false,
          "key" : "properties.max"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "10",
          "isEditor" : false,
          "key" : "properties.timeDelay"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "rate_control",
          "isEditor" : false,
          "key" : "properties.group"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "$.executionId",
          "isEditor" : false,
          "key" : "properties.executionId"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "xxxx9ce-xxxx-4822-xxxx-a296xxxxxc",
          "isEditor" : false,
          "key" : "properties.workflowId"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "CMS::ECS::StartECS",
          "isEditor" : false,
          "key" : "properties.cmsTaskName2Distribute"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "0.0.0.0",
          "isEditor" : false,
          "key" : "properties.cmsAccessPodLb"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "manual",
          "isEditor" : false,
          "key" : "properties.workflowType"
        }, {
          "default" : "",
          "showFormat" : false,
          "format" : "",
          "value" : "start-ecs-instances",
          "isEditor" : false,
          "key" : "properties.nodeId"
        } ]
      },
      "type" : "operation"
    },
    "name" : "startECSInstance",
    "task_name" : "CMS::ECS::StartECS"
  } ],
  "project_id" : "2axxxx5487f83xxxx891xxx1cf",
  "quote" : [ ],
  "status" : "success",
  "steps" : [ ],
  "tags" : { },
  "task_type" : "cloud",
  "template_i18n" : {
    "en-us" : {
      "name" : "Starting an ECS Instance",
      "description" : "Starting a HUAWEI CLOUD ECS Instance"
    },
    "zh-cn" : {
      "name" : "启动ECS实例",
      "description" : "启动华为云ECS实例"
    }
  },
  "template_id" : "CMS::ECS::BulkyStartECSInstances",
  "template_name" : "CMS::ECS::BulkyStartECSInstances",
  "type" : "manual",
  "update_time" : 1670328823794
}

状态码: 400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

{
  "error_code" : "AOM.31001302",
  "error_msg" : "Invalid input parameter.",
  "http_code" : 400
}

状态码: 401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

{
  "error_code" : "AOM.31009003",
  "error_msg" : "auth failed.",
  "http_code" : 401
}

状态码: 500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

{
  "error_code" : "AOM.31001305",
  "error_msg" : "workflow internal server error.",
  "http_code" : 500
}

SDK代码示例

SDK代码示例如下。

  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStartECSInstances"、输入参数为"input"来创建启动ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("rate_control", "{\"max\":\"1\",\"timeDelay\":\"10\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyStartECSInstances");
            body.withTemplateName("CMS::ECS::BulkyStartECSInstances");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建定时执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("project_id", "2xxx487fxxxxxbffc1cf");
            listbodyInput.put("region_id", "cn-north-7");
            listbodyInput.put("trigger", "{\"period\":\"[\\"0\\",\\"3\\",\\"4\\",\\"5\\",\\"6\\"]\",\"scheduled_time\":\"00:04:05\",\"time_zone\":\"Asia/Riyadh\",\"policy\":\"periodic\",\"group\":\"trigger\"}");
            listbodyInput.put("notice", "{\"group\":\"notice\"}");
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"4bxxxxx-xxxx-4c92-xxxx-19469d40a51c\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("script_param", "{\"sourceId\":\"script\",\"cmd_user\":\"xxxxx\",\"sensitive_param\":false,\"script_content\":\"cd /xxx/xxx\",\"name\":\"zzy\",\"version_number\":\"1.0\",\"script_id\":\"xxxx-7e9e-4eed-8xxf-5f1fxx6ebb7d\",\"script_type\":\"SHELL\",\"script_version_id\":\"e005xxx4-1fcf-40xx-b1x6-8dxxxcae7b021\",\"scriptSelected\":\"null\",\"time_out\":\"7200\",\"group\":\"script\"}");
            body.withTaskType("script");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyRunScript");
            body.withTemplateName("CMS::ECS::BulkyRunScript");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("cron");
            body.withName("xxxxxshced");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("script_param", "{\"sourceId\":\"script\",\"cmd_user\":\"root\",\"sensitive_param\":\"false\",\"script_content\":\"date\",\"version_number\":\"1.0\",\"script_id\":\"6xxxx097-a4x4-4dxx-axa2-fef5xxxxdd55\",\"script_type\":\"SHELL\",\"script_version_id\":\"47xxxd67-bxx5-45x9-860x-cb3d6xxxx745\",\"scriptSelected\":\"null\",\"script_args\":\"arg1 agr2\",\"time_out\":\"7200\",\"group\":\"script\"}");
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"4380xxx9-33xf-4xxe-axxx-7xxxxxx3fcd\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("project_id", "2xxxxxxca5xx8373xxx1bffxxcf");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("script");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyRunScript");
            body.withTemplateName("CMS::ECS::BulkyRunScript");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("execute_task_demo");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::RDS::RestartRDSInstance、输入参数为"input"来创建重启RDS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"rds_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"rds_instance\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::RDS::RestartRDSInstance");
            body.withTemplateName("CMS::RDS::RestartRDSInstance");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::Package"、输入参数为"input"来创建快速分发文件任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            listbodyInput.put("package", "{\"cmd_user\":\"xxxxx\",\"software_list\":\"[{x}]\",\"pre_install_script\":\"\",\"operate_type\":\"install\",\"un_install_script\":\"\",\"version_number\":\"110\",\"time_out\":\"7200\",\"install_script\":\"ls\",\"package_version_id\":\"xxx\",\"package_basic_id\":\"xxx\",\"package_name\":\"77779956\",\"install_file_dir\":\"/\",\"plat_form\":\"Linux\",\"group\":\"package\"}");
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            body.withTaskType("package");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::Package");
            body.withTemplateName("CMS::ECS::Package");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStopECSInstances"、输入参数为"input"来创建关闭ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("stop_ecs_type", "{\"stop_ecs_type\":\"SOFT\",\"group\":\"stop_ecs_type\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyStopECSInstances");
            body.withTemplateName("CMS::ECS::BulkyStopECSInstances");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyCleanDisks"、输入参数为"input"来创建清理磁盘任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("clean_disk", "{\"path\":\"[{\\"path\\":\\"/xxx/\\",\\"fileName\\":\\"xxxx.xx\\",\\"date\\":\\"1\\"}]\",\"platform\":\"linux\",\"group\":\"clean_disk\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxxxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyCleanDisks");
            body.withTemplateName("CMS::ECS::BulkyCleanDisks");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyChangeECSPassword"、输入参数为"input"来创建修改ECS密码任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"ecs_id_list\":\"[\\"xxxxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}");
            listbodyInput.put("user_password", "{\"password\":\"xxxxx\",\"username\":\"xxx\",\"group\":\"user_password\"}");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxxxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::ECS::BulkyChangeECSPassword");
            body.withTemplateName("CMS::ECS::BulkyChangeECSPassword");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxxxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"job_1"、输入参数为"input"来创建作业任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            listbodyInput.put("isExist", "false");
            listbodyInput.put("rate_control", "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            body.withTaskType("job");
            body.withInput(listbodyInput);
            body.withTemplateId("xxx");
            body.withTemplateName("job_1");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::CCE::RestartWorkloadInstance"、输入参数为"input"来创建重启工作负载任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.aom.v1.region.AomRegion;
    import com.huaweicloud.sdk.aom.v1.*;
    import com.huaweicloud.sdk.aom.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateWorkflowSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateWorkflowRequest request = new CreateWorkflowRequest();
            WorkflowRequestBody body = new WorkflowRequestBody();
            Map<String, Object> listbodyInput = new HashMap<>();
            listbodyInput.put("get_instances", "{\"cce_workload_id_list\":\"[\\"xxx\\"]\",\"cce_workload_cluster\":\"xxx\",\"type\":\"manual\",\"cce_workload_type\":\"deployments\",\"group\":\"cce_workload_instance\"}");
            listbodyInput.put("cce_workload_restart_info", "{\"time_interval\":\"300\",\"group\":\"cce_workload_restart_info\"}");
            listbodyInput.put("rate_control", "{\"max\":\"2\",\"timeDelay\":\"2\",\"group\":\"rate_control\"}");
            listbodyInput.put("approve", "{\"need_approve\":\"false\",\"group\":\"approve\"}");
            listbodyInput.put("project_id", "xxx");
            listbodyInput.put("region_id", "cn-north-7");
            body.withTaskType("cloud");
            body.withInput(listbodyInput);
            body.withTemplateId("CMS::CCE::RestartWorkloadInstance");
            body.withTemplateName("CMS::CCE::RestartWorkloadInstance");
            body.withTags(new Object());
            body.withDescription("");
            body.withType("manual");
            body.withName("xxx");
            request.withBody(body);
            try {
                CreateWorkflowResponse response = client.createWorkflow(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStartECSInstances"、输入参数为"input"来创建启动ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "rate_control": "{\"max\":\"1\",\"timeDelay\":\"10\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::ECS::BulkyStartECSInstances",
                template_name="CMS::ECS::BulkyStartECSInstances",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建定时执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "project_id": "2xxx487fxxxxxbffc1cf",
                "region_id": "cn-north-7",
                "trigger": "{\"period\":\"[\\"0\\",\\"3\\",\\"4\\",\\"5\\",\\"6\\"]\",\"scheduled_time\":\"00:04:05\",\"time_zone\":\"Asia/Riyadh\",\"policy\":\"periodic\",\"group\":\"trigger\"}",
                "notice": "{\"group\":\"notice\"}",
                "get_instances": "{\"ecs_id_list\":\"[\\"4bxxxxx-xxxx-4c92-xxxx-19469d40a51c\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "script_param": "{\"sourceId\":\"script\",\"cmd_user\":\"xxxxx\",\"sensitive_param\":false,\"script_content\":\"cd /xxx/xxx\",\"name\":\"zzy\",\"version_number\":\"1.0\",\"script_id\":\"xxxx-7e9e-4eed-8xxf-5f1fxx6ebb7d\",\"script_type\":\"SHELL\",\"script_version_id\":\"e005xxx4-1fcf-40xx-b1x6-8dxxxcae7b021\",\"scriptSelected\":\"null\",\"time_out\":\"7200\",\"group\":\"script\"}"
            }
            request.body = WorkflowRequestBody(
                task_type="script",
                input=listInputbody,
                template_id="CMS::ECS::BulkyRunScript",
                template_name="CMS::ECS::BulkyRunScript",
                tags={},
                description="",
                type="cron",
                name="xxxxxshced"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "script_param": "{\"sourceId\":\"script\",\"cmd_user\":\"root\",\"sensitive_param\":\"false\",\"script_content\":\"date\",\"version_number\":\"1.0\",\"script_id\":\"6xxxx097-a4x4-4dxx-axa2-fef5xxxxdd55\",\"script_type\":\"SHELL\",\"script_version_id\":\"47xxxd67-bxx5-45x9-860x-cb3d6xxxx745\",\"scriptSelected\":\"null\",\"script_args\":\"arg1 agr2\",\"time_out\":\"7200\",\"group\":\"script\"}",
                "get_instances": "{\"ecs_id_list\":\"[\\"4380xxx9-33xf-4xxe-axxx-7xxxxxx3fcd\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "project_id": "2xxxxxxca5xx8373xxx1bffxxcf",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="script",
                input=listInputbody,
                template_id="CMS::ECS::BulkyRunScript",
                template_name="CMS::ECS::BulkyRunScript",
                tags={},
                description="",
                type="manual",
                name="execute_task_demo"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::RDS::RestartRDSInstance、输入参数为"input"来创建重启RDS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"rds_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"rds_instance\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::RDS::RestartRDSInstance",
                template_name="CMS::RDS::RestartRDSInstance",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::Package"、输入参数为"input"来创建快速分发文件任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "project_id": "xxx",
                "region_id": "cn-north-7",
                "package": "{\"cmd_user\":\"xxxxx\",\"software_list\":\"[{x}]\",\"pre_install_script\":\"\",\"operate_type\":\"install\",\"un_install_script\":\"\",\"version_number\":\"110\",\"time_out\":\"7200\",\"install_script\":\"ls\",\"package_version_id\":\"xxx\",\"package_basic_id\":\"xxx\",\"package_name\":\"77779956\",\"install_file_dir\":\"/\",\"plat_form\":\"Linux\",\"group\":\"package\"}",
                "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}"
            }
            request.body = WorkflowRequestBody(
                task_type="package",
                input=listInputbody,
                template_id="CMS::ECS::Package",
                template_name="CMS::ECS::Package",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStopECSInstances"、输入参数为"input"来创建关闭ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "stop_ecs_type": "{\"stop_ecs_type\":\"SOFT\",\"group\":\"stop_ecs_type\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::ECS::BulkyStopECSInstances",
                template_name="CMS::ECS::BulkyStopECSInstances",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyCleanDisks"、输入参数为"input"来创建清理磁盘任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "clean_disk": "{\"path\":\"[{\\"path\\":\\"/xxx/\\",\\"fileName\\":\\"xxxx.xx\\",\\"date\\":\\"1\\"}]\",\"platform\":\"linux\",\"group\":\"clean_disk\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxxxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::ECS::BulkyCleanDisks",
                template_name="CMS::ECS::BulkyCleanDisks",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyChangeECSPassword"、输入参数为"input"来创建修改ECS密码任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"ecs_id_list\":\"[\\"xxxxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
                "user_password": "{\"password\":\"xxxxx\",\"username\":\"xxx\",\"group\":\"user_password\"}",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxxxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::ECS::BulkyChangeECSPassword",
                template_name="CMS::ECS::BulkyChangeECSPassword",
                tags={},
                description="",
                type="manual",
                name="xxxxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"job_1"、输入参数为"input"来创建作业任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "project_id": "xxx",
                "region_id": "cn-north-7",
                "isExist": "false",
                "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}"
            }
            request.body = WorkflowRequestBody(
                task_type="job",
                input=listInputbody,
                template_id="xxx",
                template_name="job_1",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::CCE::RestartWorkloadInstance"、输入参数为"input"来创建重启工作负载任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v1.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateWorkflowRequest()
            listInputbody = {
                "get_instances": "{\"cce_workload_id_list\":\"[\\"xxx\\"]\",\"cce_workload_cluster\":\"xxx\",\"type\":\"manual\",\"cce_workload_type\":\"deployments\",\"group\":\"cce_workload_instance\"}",
                "cce_workload_restart_info": "{\"time_interval\":\"300\",\"group\":\"cce_workload_restart_info\"}",
                "rate_control": "{\"max\":\"2\",\"timeDelay\":\"2\",\"group\":\"rate_control\"}",
                "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
                "project_id": "xxx",
                "region_id": "cn-north-7"
            }
            request.body = WorkflowRequestBody(
                task_type="cloud",
                input=listInputbody,
                template_id="CMS::CCE::RestartWorkloadInstance",
                template_name="CMS::CCE::RestartWorkloadInstance",
                tags={},
                description="",
                type="manual",
                name="xxx"
            )
            response = client.create_workflow(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStartECSInstances"、输入参数为"input"来创建启动ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "rate_control": "{\"max\":\"1\",\"timeDelay\":\"10\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyStartECSInstances"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyStartECSInstances",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建定时执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "project_id": "2xxx487fxxxxxbffc1cf",
            "region_id": "cn-north-7",
            "trigger": "{\"period\":\"[\\"0\\",\\"3\\",\\"4\\",\\"5\\",\\"6\\"]\",\"scheduled_time\":\"00:04:05\",\"time_zone\":\"Asia/Riyadh\",\"policy\":\"periodic\",\"group\":\"trigger\"}",
            "notice": "{\"group\":\"notice\"}",
            "get_instances": "{\"ecs_id_list\":\"[\\"4bxxxxx-xxxx-4c92-xxxx-19469d40a51c\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "script_param": "{\"sourceId\":\"script\",\"cmd_user\":\"xxxxx\",\"sensitive_param\":false,\"script_content\":\"cd /xxx/xxx\",\"name\":\"zzy\",\"version_number\":\"1.0\",\"script_id\":\"xxxx-7e9e-4eed-8xxf-5f1fxx6ebb7d\",\"script_type\":\"SHELL\",\"script_version_id\":\"e005xxx4-1fcf-40xx-b1x6-8dxxxcae7b021\",\"scriptSelected\":\"null\",\"time_out\":\"7200\",\"group\":\"script\"}",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyRunScript"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "script",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyRunScript",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "cron",
    		Name: "xxxxxshced",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyRunScript"、输入参数为"input"来创建执行脚本任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "script_param": "{\"sourceId\":\"script\",\"cmd_user\":\"root\",\"sensitive_param\":\"false\",\"script_content\":\"date\",\"version_number\":\"1.0\",\"script_id\":\"6xxxx097-a4x4-4dxx-axa2-fef5xxxxdd55\",\"script_type\":\"SHELL\",\"script_version_id\":\"47xxxd67-bxx5-45x9-860x-cb3d6xxxx745\",\"scriptSelected\":\"null\",\"script_args\":\"arg1 agr2\",\"time_out\":\"7200\",\"group\":\"script\"}",
            "get_instances": "{\"ecs_id_list\":\"[\\"4380xxx9-33xf-4xxe-axxx-7xxxxxx3fcd\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "project_id": "2xxxxxxca5xx8373xxx1bffxxcf",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyRunScript"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "script",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyRunScript",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "execute_task_demo",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::RDS::RestartRDSInstance、输入参数为"input"来创建重启RDS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"rds_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"rds_instance\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::RDS::RestartRDSInstance"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::RDS::RestartRDSInstance",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::Package"、输入参数为"input"来创建快速分发文件任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "project_id": "xxx",
            "region_id": "cn-north-7",
            "package": "{\"cmd_user\":\"xxxxx\",\"software_list\":\"[{x}]\",\"pre_install_script\":\"\",\"operate_type\":\"install\",\"un_install_script\":\"\",\"version_number\":\"110\",\"time_out\":\"7200\",\"install_script\":\"ls\",\"package_version_id\":\"xxx\",\"package_basic_id\":\"xxx\",\"package_name\":\"77779956\",\"install_file_dir\":\"/\",\"plat_form\":\"Linux\",\"group\":\"package\"}",
            "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::Package"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "package",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::Package",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyStopECSInstances"、输入参数为"input"来创建关闭ECS任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "stop_ecs_type": "{\"stop_ecs_type\":\"SOFT\",\"group\":\"stop_ecs_type\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyStopECSInstances"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyStopECSInstances",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyCleanDisks"、输入参数为"input"来创建清理磁盘任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"ecs_id_list\":\"[\\"xxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "clean_disk": "{\"path\":\"[{\\"path\\":\\"/xxx/\\",\\"fileName\\":\\"xxxx.xx\\",\\"date\\":\\"1\\"}]\",\"platform\":\"linux\",\"group\":\"clean_disk\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxxxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyCleanDisks"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyCleanDisks",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::ECS::BulkyChangeECSPassword"、输入参数为"input"来创建修改ECS密码任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"ecs_id_list\":\"[\\"xxxxx\\"]\",\"type\":\"manual\",\"group\":\"ecs_instance\"}",
            "user_password": "{\"password\":\"xxxxx\",\"username\":\"xxx\",\"group\":\"user_password\"}",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxxxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::ECS::BulkyChangeECSPassword"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::ECS::BulkyChangeECSPassword",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxxxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"job_1"、输入参数为"input"来创建作业任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "project_id": "xxx",
            "region_id": "cn-north-7",
            "isExist": "false",
            "rate_control": "{\"max\":\"0\",\"timeDelay\":\"0\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
        }
    	templateNameWorkflowRequestBody:= "job_1"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "job",
    		Input: listInputbody,
    		TemplateId: "xxx",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用任务名称为"xxx"、模板名称为"CMS::CCE::RestartWorkloadInstance"、输入参数为"input"来创建重启工作负载任务。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := aom.NewAomClient(
            aom.AomClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateWorkflowRequest{}
    	var listInputbody = map[string]interface{}{
            "get_instances": "{\"cce_workload_id_list\":\"[\\"xxx\\"]\",\"cce_workload_cluster\":\"xxx\",\"type\":\"manual\",\"cce_workload_type\":\"deployments\",\"group\":\"cce_workload_instance\"}",
            "cce_workload_restart_info": "{\"time_interval\":\"300\",\"group\":\"cce_workload_restart_info\"}",
            "rate_control": "{\"max\":\"2\",\"timeDelay\":\"2\",\"group\":\"rate_control\"}",
            "approve": "{\"need_approve\":\"false\",\"group\":\"approve\"}",
            "project_id": "xxx",
            "region_id": "cn-north-7",
        }
    	templateNameWorkflowRequestBody:= "CMS::CCE::RestartWorkloadInstance"
    	var tagsWorkflowRequestBody interface{} = make(map[string]string)
    	descriptionWorkflowRequestBody:= ""
    	request.Body = &model.WorkflowRequestBody{
    		TaskType: "cloud",
    		Input: listInputbody,
    		TemplateId: "CMS::CCE::RestartWorkloadInstance",
    		TemplateName: &templateNameWorkflowRequestBody,
    		Tags: &tagsWorkflowRequestBody,
    		Description: &descriptionWorkflowRequestBody,
    		Type: "manual",
    		Name: "xxx",
    	}
    	response, err := client.CreateWorkflow(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求响应成功,返回工作流详情。

400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

错误码

请参见错误码