创建运维模板
更新时间:2026-07-16
描述
您可以在模板中指定执行所需参数(参考请求示例1),也可以通过全局参数的形式在创建执行的时候再指定(参考请求实例2)。
OpenAPI Explorer
去调试
您可以在 OpenAPI Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v{version}/template
2Host: oos.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "name": name,
7 "description": description,
8 "tags": [
9 {
10 "key": key,
11 "value": value
12 }
13 ],
14 "linear": linear,
15 "parallelism": parallelism,
16 "operators": [
17 {
18 "name": name,
19 "description": description,
20 "tags": [
21 {
22 "key": key,
23 "value": value
24 }
25 ],
26 "operator": operator,
27 "label": label,
28 "retries": retries,
29 "retryInterval": retryInterval,
30 "timeout": timeout,
31 "parallelismRatio": parallelismRatio,
32 "parallelismCount": parallelismCount,
33 "parallelismControl": {
34 "ratio": ratio,
35 "count": count
36 },
37 "allowedFailureRatio": allowedFailureRatio,
38 "allowedFailureCount": allowedFailureCount,
39 "allowedFailureControl": {
40 "ratio": ratio,
41 "count": count
42 },
43 "manually": manually,
44 "scheduleDelayMilli": scheduleDelayMilli,
45 "waitOnAgentMilli": waitOnAgentMilli,
46 "pauseOnFailure": pauseOnFailure,
47 "condition": condition,
48 "breakpoints": [breakpoints],
49 "triggerRule": triggerRule,
50 "loopWindowType": loopWindowType,
51 "properties": properties,
52 "loops": [
53 {}
54 ]
55 }
56 ],
57 "links": [
58 {
59 "src": src,
60 "dst": dst
61 }
62 ],
63 "properties": [
64 {
65 "name": name,
66 "required": required,
67 "type": type,
68 "label": label,
69 "description": description,
70 "multiple": multiple,
71 "options": [options],
72 "selectOptions": [
73 {
74 "label": label,
75 "value": value
76 }
77 ],
78 "defaultValue": defaultValue
79 }
80 ]
81}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号,当前取值为2 |
| name | String | 是 | RequestBody参数 | 模板名称,不允许重复 |
| description | String | 否 | RequestBody参数 | 模板描述 |
| tags | List<KeyValuePair> | 否 | RequestBody参数 | 模板标签 |
| linear | Boolean | 是 | RequestBody参数 | 任务是否串行执行,默认false |
| parallelism | Integer | 否 | RequestBody参数 | 并发度,当linear=false的时候,可以控制Operator并发执行的数量 |
| operators | List<Operator> | 是 | RequestBody参数 | 模板任务步骤列表 |
| links | List<LinkModel> | 否 | RequestBody参数 | 描述 operator 之间的拓扑关系,linear=false 时必填 |
| properties | List<Property> | 否 | RequestBody参数 | 全局参数列表 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| success | Boolean | 请求是否成功 |
| msg | String | 失败时返回失败原因,成功时为空字符串 |
| code | Integer | 状态码 |
| result | Object | 运维模板信息 |
请求示例,1
Plain Text
1POST /v{version}/template
2Host: oos.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "namespace" : "default",
7 "name" : "Test",
8 "description" : "这是描述",
9 "operators" : [ {
10 "name" : "testCMD",
11 "description" : "exec cmd on agent",
12 "operator" : "BCE::Agent::ExecuteShell",
13 "inline" : false,
14 "retries" : 0,
15 "retryInterval" : 60000,
16 "timeout" : 300000,
17 "properties" : {
18 "execUser" : "root",
19 "workDir" : "/",
20 "__workerSelectors__" : {
21 "Ref" : "instanceList"
22 },
23 "content" : "echo 'hello world'"
24 }
25 } ],
26 "linear" : true,
27 "properties" : [ {
28 "name" : "instanceList",
29 "required" : true,
30 "type" : "bccInstance",
31 "description" : "instance list"
32 } ]
33}
请求示例,2
Plain Text
1POST /v{version}/template
2Host: oos.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "description" : "这是一段描述",
7 "name" : "test_oos_template2",
8 "operators" : [ {
9 "name" : "stop_bcc",
10 "description" : "停止BCC实例",
11 "operator" : "BCE::BCC::StopInstance",
12 "label" : "停止BCC实例",
13 "retryInterval" : 60000,
14 "timeout" : 3600000,
15 "properties" : {
16 "instanceId" : {
17 "Ref" : "instanceId1"
18 }
19 }
20 }, {
21 "name" : "start_bcc",
22 "description" : "启动BCC实例",
23 "operator" : "BCE::BCC::StartInstance",
24 "label" : "启动BCC实例",
25 "retryInterval" : 60000,
26 "timeout" : 3600000,
27 "properties" : {
28 "instanceId" : {
29 "Ref" : "instanceId2"
30 }
31 }
32 } ],
33 "properties" : [ {
34 "required" : true,
35 "type" : "bccInstance",
36 "name" : "instanceId1"
37 }, {
38 "required" : true,
39 "type" : "bccInstance",
40 "name" : "instanceId2"
41 } ],
42 "linear" : true
43}
返回示例
Plain Text
1200 Success
2
3{
4 "success" : true,
5 "msg" : "",
6 "code" : 200,
7 "result" : {
8 "id" : "tpl-******DK"
9 }
10}
评价此篇文章
