Creating a Task
Function
This API is used to create a workflow (task). The workflow details will be returned. The task type depends on the template name and input parameter.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/cms/workflow
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID obtained from IAM. Generally, a project ID contains 32 characters. Minimum: 32 Maximum: 32 |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token obtained from IAM. Minimum: 1 Maximum: 40960 |
Content-Type |
Yes |
String |
Content type, which is application/json. Minimum: 1 Maximum: 32 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Workflow name, which can contain 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. Minimum: 1 Maximum: 64 |
type |
Yes |
String |
Workflow type. Options: cron and manual. Minimum: 1 Maximum: 32 |
description |
No |
String |
Workflow description. Minimum: 1 Maximum: 128 |
tags |
No |
Object |
List of tag keys and values. Maximum key-value pairs: 20. |
template_name |
No |
String |
Template name, for example, CMS::ECS::BulkyRunScript, CMS::ECS::BulkyStartECSInstances, or CMS::ECS::BulkyCleanDisks. Minimum: 1 Maximum: 64 |
template_id |
Yes |
String |
Template ID. Minimum: 1 Maximum: 64 |
input |
Yes |
Map<String,Object> |
List of parameters required for executing a task. |
quote |
No |
Array of strings |
Parameters that are referenced. Minimum: 1 Maximum: 128 Array Length: 1 - 128 |
job_name |
No |
String |
Job name. Minimum: 1 Maximum: 64 |
job_id |
No |
String |
Job ID. Minimum: 1 Maximum: 64 |
service_scenario |
No |
String |
Service scenario. Minimum: 1 Maximum: 64 |
service_name |
No |
String |
Service name. Minimum: 1 Maximum: 128 |
task_type |
Yes |
String |
Task type. Options: package, script, job, cloud, standard, and customize. Minimum: 1 Maximum: 32 |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
id |
String |
Workflow ID, which is unique and generated based on project_id and workflow_name. Minimum: 1 Maximum: 64 |
name |
String |
Workflow name. Minimum: 1 Maximum: 64 |
type |
String |
Workflow type. Options: cron and manual. Minimum: 1 Maximum: 16 |
description |
String |
Workflow description. Minimum: 1 Maximum: 128 |
tags |
Map<String,String> |
List of tag keys and values. Maximum key-value pairs: 20. |
create_time |
Long |
Time (UTC, in milliseconds) when a workflow was created. Minimum: 0 Maximum: 9999999999999 |
create_by |
String |
User who created the workflow. This parameter is obtained from the token transferred during API calling. Minimum: 1 Maximum: 64 |
update_time |
Long |
Time (UTC, in milliseconds) when a workflow was updated. Minimum: 0 Maximum: 9999999999999 |
update_by |
String |
User who updated the workflow. This parameter is obtained from the token transferred during API calling. Minimum: 1 Maximum: 64 |
template_name |
String |
Template name. Minimum: 1 Maximum: 64 |
template_id |
String |
Template ID. Minimum: 1 Maximum: 64 |
input |
Map<String,Object> |
List of parameters required for executing a task. |
last_execution_id |
String |
Latest execution ID, which is also the workflow ID. Minimum: 1 Maximum: 64 |
status |
String |
Task status. Options: success, fail, and executing. Minimum: 1 Maximum: 16 |
citation_urns |
Array of strings |
Reference of a workflow. Minimum: 1 Maximum: 256 Array Length: 0 - 200 |
last_execution_end_time |
Long |
End time (UTC, in milliseconds) of the last execution. Minimum: 0 Maximum: 9999999999999 |
last_execution_start_time |
Long |
Start time (UTC, in milliseconds) of the last execution. Minimum: 0 Maximum: 9999999999999 |
quote |
Array of strings |
Parameters that are referenced. Minimum: 1 Maximum: 256 Array Length: 1 - 999 |
job_name |
String |
Job name. Minimum: 1 Maximum: 64 |
job_id |
String |
Job ID. Minimum: 1 Maximum: 64 |
service_scenario |
String |
Service scenario. Minimum: 1 Maximum: 64 |
service_name |
String |
Service name. Minimum: 1 Maximum: 64 |
task_type |
String |
Task type. Minimum: 1 Maximum: 16 |
project_id |
String |
Project ID returned by FunctionGraph. Minimum: 1 Maximum: 32 |
workflow_id |
String |
Workflow ID returned by FunctionGraph. Minimum: 1 Maximum: 64 |
task_status |
String |
Task status. Minimum: 1 Maximum: 32 |
nodes |
Array of Node objects |
Task node. Array Length: 1 - 20 |
edit_time |
Long |
Edit time. Minimum: 0 Maximum: 9999999999999 |
execution_action_rules |
Array of strings |
Fine-grained permissions for executing actions. Minimum: 1 Maximum: 128 Array Length: 0 - 200 |
execution_permission |
Array of strings |
Cloud service permissions. Minimum: 1 Maximum: 128 Array Length: 1 - 32 |
global_parameters |
Array of Parameter objects |
Global parameters. Array Length: 0 - 20 |
is_delete |
Boolean |
Whether the object has been logically deleted. |
steps |
Array of Step objects |
Step. Array Length: 1 - 10 |
output |
String |
Task output. Minimum: 1 Maximum: 40960 |
trigger_id |
String |
Trigger ID. Minimum: 1 Maximum: 64 |
trigger_status |
String |
Trigger status. Minimum: 1 Maximum: 64 |
approve_id |
String |
Approval ID. Minimum: 1 Maximum: 64 |
template_i18n |
WorkFlowModel object |
Task internationalization field, including English description. |
enterprise_project_id |
String |
Enterprise project to which the task belongs. Minimum: 1 Maximum: 64 |
last_execute_by |
String |
Last task executor. Minimum: 1 Maximum: 64 |
Parameter |
Type |
Description |
---|---|---|
parent_node |
String |
Name of the parent node. Minimum: 1 Maximum: 64 |
category |
String |
Node type. Minimum: 1 Maximum: 32 |
description |
String |
Node description. Minimum: 1 Maximum: 1024 |
id |
String |
Node ID. Minimum: 1 Maximum: 64 |
ignore_error |
Boolean |
Whether to ignore the error. |
metadata |
Metadata object |
Metadata. |
name |
String |
Node name, for example, Node. Minimum: 1 Maximum: 64 |
task_name |
String |
Task name. Minimum: 1 Maximum: 64 |
Parameter |
Type |
Description |
---|---|---|
type |
String |
Node type. Minimum: 1 Maximum: 32 |
configuration |
Map<String,Object> |
Configuration information. |
Parameter |
Type |
Description |
---|---|---|
param_name |
String |
Parameter name. |
param_type |
String |
Parameter type. Minimum: 1 Maximum: 16 |
param_group |
String |
Parameter group. Minimum: 1 Maximum: 32 |
default_value |
String |
Initial value of a parameter. Minimum: 1 Maximum: 40960 |
id |
String |
Parameter ID. Minimum: 1 Maximum: 64 |
encryption |
Boolean |
Whether to encrypt the data. |
hint |
String |
Parameter prompt. Minimum: 1 Maximum: 1000 |
quote_param |
Boolean |
Whether to select a parameter from the parameter library. |
required |
Boolean |
Whether a parameter is mandatory. |
description |
String |
Parameter description. Minimum: 1 Maximum: 1000 |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Step ID. Minimum: 1 Maximum: 64 |
name |
String |
Step name. Minimum: 1 Maximum: 32 |
type |
String |
Step type. Minimum: 1 Maximum: 16 |
input |
Map<String,String> |
Step parameter. |
ignore_error |
Boolean |
Whether to automatically ignore errors. |
description |
String |
Step description. Minimum: 1 Maximum: 1000 |
Parameter |
Type |
Description |
---|---|---|
en-us |
Map<String,String> |
Description |
zh-cn |
Map<String,String> |
Description |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Response code. Minimum: 1 Maximum: 64 |
error_msg |
String |
Error message. Minimum: 1 Maximum: 1024 |
http_code |
Integer |
HTTP response code. Minimum: 0 Maximum: 999 |
Status code: 401
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Response code. Minimum: 1 Maximum: 64 |
error_msg |
String |
Error message. Minimum: 1 Maximum: 1024 |
http_code |
Integer |
HTTP response code. Minimum: 0 Maximum: 999 |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Response code. Minimum: 1 Maximum: 64 |
error_msg |
String |
Error message. Minimum: 1 Maximum: 1024 |
http_code |
Integer |
HTTP response code. Minimum: 0 Maximum: 999 |
Example Requests
-
Create an ECS startup task by using the name xxx, template "CMS::ECS::BulkyStartECSInstances", and input parameter "input".
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" }
-
Create a scheduled script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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" }
-
Create a script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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" }
-
Create an RDS instance restart task by using the name xxx, template "CMS::RDS::RestartRDSInstance", and input parameter "input".
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" }
-
Create a quick file distribution task by using the name xxx, template "CMS::ECS::Package", and input parameter "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" }
-
Create an ECS stop task by using the name xxx, template "CMS::ECS::BulkyStopECSInstances", and input parameter "input".
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" }
-
Create a disk clearance task by using the name xxx, template "CMS::ECS::BulkyCleanDisks", and input parameter "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" }
-
Create an ECS password change task by using the name xxx, template "CMS::ECS::BulkyChangeECSPassword", and input parameter "input".
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" }
-
Create a job task by using the name xxx, template "job_1", and input parameter "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" }
-
Create a workload restart task using the name xxx, template "CMS::CCE::RestartWorkloadInstance", and input parameter "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" }
Example Responses
Status code: 200
Success response: The workflow details are returned.
{ "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" : "Task 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" : "Starting ECS", "description" : "Starts a Huawei Cloud ECS." } }, "template_id" : "CMS::ECS::BulkyStartECSInstances", "template_name" : "CMS::ECS::BulkyStartECSInstances", "type" : "manual", "update_time" : 1670328823794 }
Status code: 400
Bad Request: Invalid request. The client should not repeat the request without modifications.
{ "error_code" : "AOM.31001302", "error_msg" : "Invalid input parameter.", "http_code" : 400 }
Status code: 401
Unauthorized: The authentication information is incorrect or invalid.
{ "error_code" : "AOM.31009003", "error_msg" : "auth failed.", "http_code" : 401 }
Status code: 500
Internal Server Error: The server is able to receive the request but unable to understand the request.
{ "error_code" : "AOM.31001305", "error_msg" : "workflow internal server error.", "http_code" : 500 }
SDK Sample Code
The SDK sample code is as follows.
Java
-
Create an ECS startup task by using the name xxx, template "CMS::ECS::BulkyStartECSInstances", and input parameter "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("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()); } } }
-
Create a scheduled script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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()); } } }
-
Create a script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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()); } } }
-
Create an RDS instance restart task by using the name xxx, template "CMS::RDS::RestartRDSInstance", and input parameter "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("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()); } } }
-
Create a quick file distribution task by using the name xxx, template "CMS::ECS::Package", and input parameter "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()); } } }
-
Create an ECS stop task by using the name xxx, template "CMS::ECS::BulkyStopECSInstances", and input parameter "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("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()); } } }
-
Create a disk clearance task by using the name xxx, template "CMS::ECS::BulkyCleanDisks", and input parameter "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()); } } }
-
Create an ECS password change task by using the name xxx, template "CMS::ECS::BulkyChangeECSPassword", and input parameter "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\":\"[\\"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()); } } }
-
Create a job task by using the name xxx, template "job_1", and input parameter "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()); } } }
-
Create a workload restart task using the name xxx, template "CMS::CCE::RestartWorkloadInstance", and input parameter "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()); } } }
Python
-
Create an ECS startup task by using the name xxx, template "CMS::ECS::BulkyStartECSInstances", and input parameter "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 = { "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)
-
Create a scheduled script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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)
-
Create a script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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)
-
Create an RDS instance restart task by using the name xxx, template "CMS::RDS::RestartRDSInstance", and input parameter "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 = { "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)
-
Create a quick file distribution task by using the name xxx, template "CMS::ECS::Package", and input parameter "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)
-
Create an ECS stop task by using the name xxx, template "CMS::ECS::BulkyStopECSInstances", and input parameter "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\"}", "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)
-
Create a disk clearance task by using the name xxx, template "CMS::ECS::BulkyCleanDisks", and input parameter "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)
-
Create an ECS password change task by using the name xxx, template "CMS::ECS::BulkyChangeECSPassword", and input parameter "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\":\"[\\"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)
-
Create a job task by using the name xxx, template "job_1", and input parameter "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)
-
Create a workload restart task using the name xxx, template "CMS::CCE::RestartWorkloadInstance", and input parameter "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)
Go
-
Create an ECS startup task by using the name xxx, template "CMS::ECS::BulkyStartECSInstances", and input parameter "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{}{ "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) } }
-
Create a scheduled script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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) } }
-
Create a script execution task by using the name xxx, template "CMS::ECS::BulkyRunScript", and input parameter "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) } }
-
Create an RDS instance restart task by using the name xxx, template "CMS::RDS::RestartRDSInstance", and input parameter "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{}{ "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) } }
-
Create a quick file distribution task by using the name xxx, template "CMS::ECS::Package", and input parameter "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) } }
-
Create an ECS stop task by using the name xxx, template "CMS::ECS::BulkyStopECSInstances", and input parameter "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\"}", "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) } }
-
Create a disk clearance task by using the name xxx, template "CMS::ECS::BulkyCleanDisks", and input parameter "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) } }
-
Create an ECS password change task by using the name xxx, template "CMS::ECS::BulkyChangeECSPassword", and input parameter "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\":\"[\\"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) } }
-
Create a job task by using the name xxx, template "job_1", and input parameter "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) } }
-
Create a workload restart task using the name xxx, template "CMS::CCE::RestartWorkloadInstance", and input parameter "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) } }
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
Success response: The workflow details are returned. |
400 |
Bad Request: Invalid request. The client should not repeat the request without modifications. |
401 |
Unauthorized: The authentication information is incorrect or invalid. |
500 |
Internal Server Error: The server is able to receive the request but unable to understand the request. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot