创建命令
更新时间:2026-07-28
描述
创建命令,支持保存、仅执行、执行并保存。
OpenAPI Explorer
去调试
您可以在 OpenAPI Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v{version}/ca/action
2Host: ca.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "execution": execution,
7 "action": {
8 "id": id,
9 "ref": ref,
10 "type": type,
11 "name": name,
12 "alias": alias,
13 "description": description,
14 "timeoutSecond": timeoutSecond,
15 "command": {
16 "type": type,
17 "content": content,
18 "scope": scope,
19 "enableParameter": enableParameter,
20 "parameters": [
21 {
22 "name": name,
23 "desc": desc,
24 "required": required,
25 "defaultValue": defaultValue
26 }
27 ],
28 "user": user,
29 "workDir": workDir,
30 "execParams": execParams,
31 "waitOnAgentMilli": waitOnAgentMilli
32 },
33 "fileUpload": {
34 "os": os,
35 "content": content,
36 "filename": filename,
37 "filepath": filepath,
38 "bosBucketName": bosBucketName,
39 "bosFilePath": bosFilePath,
40 "bosEtag": bosEtag,
41 "user": user,
42 "group": group,
43 "mode": mode,
44 "overwrite": overwrite
45 },
46 "supportedInstanceTypes": [supportedInstanceTypes],
47 "createdTimestamp": createdTimestamp,
48 "updatedTimestamp": updatedTimestamp
49 },
50 "parameters": parameters,
51 "targetSelectorType": targetSelectorType,
52 "targets": [
53 {
54 "instanceType": instanceType,
55 "instanceId": instanceId,
56 "instanceName": instanceName,
57 "internalIp": internalIp,
58 "externalIp": externalIp,
59 "bandwidth": bandwidth
60 }
61 ],
62 "targetSelector": {
63 "instanceType": instanceType,
64 "tags": [
65 {
66 "tagKey": tagKey,
67 "tagValue": tagValue
68 }
69 ],
70 "importInstances": {
71 "keywordType": keywordType,
72 "instances": [instances]
73 }
74 }
75}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号,当前取值为1 |
| execution | execution | 是 | RequestBody参数 | 执行动作。SAVE(仅保存),RUN(仅执行),SAVE_AND_RUN(保存并执行) |
| action | Action | 是 | RequestBody参数 | |
| parameters | Map<String,String> | 否 | RequestBody参数 | 执行命令时的参数值,仅在命令有参数时需要 |
| targetSelectorType | TargetSelectorType | 否 | RequestBody参数 | 实例选择器类型,仅在执行动作为执行或保存并执行时需要。默认值为INSTANCES_LIST。可选值:INSTANCES_LIST(实例列表),ALL_INSTANCES(全部实例),TAG_INSTANCES(实例标签选择),INSTANCES_IMPORT(实例列表导入) |
| targets | List<Target> | 否 | RequestBody参数 | 实例ID列表,仅在targetSelectorType为INSTANCES_LIST时需要 |
| targetSelector | TargetSelector | 否 | RequestBody参数 | 实例选择器 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| requestId | String | 请求id |
| code | String | 响应状态,成功为success |
| message | String | 错误信息 |
| success | Boolean | 请求是否处理成功 |
| result | ActionResult | 命令创建结果 |
请求示例
Plain Text
1POST /v1/ca/action
2Host: ca.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "execution" : "RUN",
7 "action" : {
8 "type" : "COMMAND",
9 "description" : "this is a test",
10 "timeoutSecond" : 300,
11 "command" : {
12 "type" : "SHELL",
13 "content" : "ls",
14 "scope" : "INDIVIDUAL",
15 "enableParameter" : false,
16 "user" : "root",
17 "workDir" : "/home"
18 }
19 },
20 "targets" : [ {
21 "instanceType" : "BCC",
22 "instanceId" : "i-p9L8X***"
23 } ]
24}
返回示例
Plain Text
1200 Success
2
3{
4 "requestId" : "83e831f9-8f27-4c1c-bde4-fdfb********",
5 "code" : "success",
6 "result" : {
7 "actionId" : "c-cVtZHfVRD8******",
8 "actionType" : "COMMAND",
9 "commandType" : "SHELL",
10 "version" : 0,
11 "runId" : "r-h5fTUn2sab******"
12 }
13}
评价此篇文章
