运维模板(Template)接口
更新时间:2024-08-16
创建运维模板
接口描述
您可以在模板中指定执行所需参数(参考请求示例1),也可以通过全局参数的形式在创建执行的时候再指定(参考请求实例2)
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
响应参数
名称 | 类型 | 描述 |
---|---|---|
id | String | 模板ID,全局唯一 |
请求示例 1
Go
1 req := &model.Template{
2 Name: "test_go_sdk",
3 Description: "des",
4 Tags: nil,
5 Operators: []*model.Operator{
6 {
7 Name: "start_bcc",
8 Description: "启动BCC实例",
9 Operator: "BCE::BCC::StartInstance",
10 Properties: map[string]interface{}{
11 "instances": []map[string]string{
12 {
13 "instanceId": "i-xxxxxx",
14 "name": "instance-xxxxx",
15 },
16 },
17 },
18 },
19 },
20 Properties: []*model.Property{
21 {
22 Name: "test_param",
23 Type: "string",
24 Required: false,
25 },
26 },
27 Linear: true,
28 }
29 result, err := oosClient.CreateTemplate(req)
响应示例 1
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******DK"
7 }
8}
请求示例 2
Go
1 req := &model.Template{
2 Name: "test_go_sdk_2",
3 Description: "des",
4 Tags: nil,
5 Operators: []*model.Operator{
6 {
7 Name: "start_bcc",
8 Description: "启动BCC实例",
9 Operator: "BCE::BCC::StartInstance",
10 Properties: map[string]interface{}{
11 "instances": []map[string]string{
12 {
13 "Ref":"test_param",
14 },
15 },
16 },
17 },
18 },
19 Properties: []*model.Property{
20 {
21 Name: "test_param",
22 Type: "bccInstance",
23 Required: true,
24 DefaultValue: map[string]interface{}{
25 "instanceId": "i-xxxxx",
26 },
27 },
28 },
29 Linear: true,
30 }
31 result, err := oosClient.CreateTemplate(req)
响应示例 2
Go
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******"
7 }
8}
校验运维模板
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
请求示例
Go
1 req := &model.Template{
2 Name: "test_go_sdk",
3 Description: "des",
4 Tags: nil,
5 Operators: []*model.Operator{
6 {
7 Name: "start_bcc",
8 Description: "启动BCC实例",
9 Operator: "BCE::BCC::StartInstance",
10 Properties: map[string]interface{}{
11 "instances": []map[string]string{
12 {
13 "instanceId": "i-xxxxxx",
14 "name": "instance-xxxxx",
15 },
16 },
17 },
18 },
19 },
20 Properties: []*model.Property{
21 {
22 Name: "test_param",
23 Type: "string",
24 Required: false,
25 },
26 },
27 Linear: true,
28 }
29 result, err := oosClient.CheckTemplate(req)
响应示例
成功响应示例
无
失败响应示例
JSON
1[Code: InvalidRequest; Message: template is invalid: op name is required; RequestId: eb******]
更新运维模板
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
请求示例
Go
1 req := &model.Template{
2 ID: "tpl-26ENudO2",
3 Name: "test_go_sdk_2",
4 Description: "des",
5 Tags: nil,
6 Operators: []*model.Operator{
7 {
8 Name: "start_bcc",
9 Description: "启动BCC实例",
10 Operator: "BCE::BCC::StartInstance",
11 Properties: map[string]interface{}{
12 "instances": []map[string]string{
13 {
14 "Ref": "test_param",
15 },
16 {
17 "instanceId": "i-lQwXU07Z",
18 "name": "instance-3nd0wnlr",
19 },
20 },
21 },
22 },
23 },
24 Properties: []*model.Property{
25 {
26 Name: "test_param",
27 Type: "bccInstance",
28 Required: true,
29 DefaultValue: map[string]interface{}{
30 "instanceId": "i-lQwXU07Z",
31 },
32 },
33 },
34 Linear: true,
35 }
36 result, err := oosClient.UpdateTemplate(req)
删除运维模板
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
id | String | 运维模板ID | 是 | Query参数 |
请求示例
Go
1 result, err := oosClient.DeleteTemplate("tpl-6UUp6jpj")
查看运维模板
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
name | String | 运维模板名称 | 是 | Query参数 |
templateType | String | 运维模板类型:GLOBAL-全局模板;INDIVIDUAL-个人模板 | 是 | Query参数 |
请求示例
Go
1 result, err := oosClient.GetTemplateDetail("test_go_sdk", string(model.TemplateTypeIndividual))
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******",
7 "name": "test_go_sdk",
8 "description": "",
9 "linear": true,
10 "operators": [
11 {
12 "name": "start_bcc",
13 "description": "",
14 "operator": "BCE::BCC::StopInstance",
15 "retries": 0,
16 "retryInterval": 60000,
17 "timeout": 3600000,
18 "parallelismControl": {
19 "ratio": 0.0,
20 "count": 0
21 },
22 "allowedFailureControl": {
23 "ratio": 0.0,
24 "count": 0
25 },
26 "manually": false,
27 "scheduleDelayMilli": 0,
28 "pauseOnFailure": false,
29 "properties": {
30 "instances": [
31 {
32 "instanceId": "i-******"
33 }
34 ]
35 },
36 "initContext": {}
37 }
38 ]
39 }
40}
41
42}
查看运维模板列表
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
sort | String | 排序字段,默认为创建时间 | 否 | RequestBody参数 |
ascending | boolean | 是否升序,默认false | 否 | RequestBody参数 |
pageNo | int | 页数,从1开始计数 | 是 | RequestBody参数 |
pageSize | int | 每页展示数量,最大值:100 | 是 | RequestBody参数 |
请求示例
Go
1 req := &model.GetTemplateListRequest{
2 BasePageRequest: model.BasePageRequest{
3 Ascending: false,
4 PageNo: 1,
5 PageSize: 100,
6 },
7 }
8 result, err := oosClient.GetTemplateList(req)
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "result": {
5 "templates": [
6 {
7 "id": "tpl-******",
8 "name": "test_go_sdk",
9 "type": "INDIVIDUAL",
10 "description": "",
11 "linear": true,
12 "operators": [
13 {
14 "name": "start_bcc",
15 "description": "",
16 "operator": "BCE::BCC::StopInstance",
17 "retries": 0,
18 "retryInterval": 60000,
19 "timeout": 3600000,
20 "parallelismControl": {
21 "ratio": 0.0,
22 "count": 0
23 },
24 "allowedFailureControl": {
25 "ratio": 0.0,
26 "count": 0
27 },
28 "manually": false,
29 "scheduleDelayMilli": 0,
30 "pauseOnFailure": false,
31 "properties": {
32 "instances": [
33 {
34 "instanceId": "i-******Pi"
35 }
36 ]
37 },
38 "initContext": {}
39 }
40 ]
41 }
42 //省略剩余的
43 ],
44 "orderBy": "createTime",
45 "order": "desc",
46 "pageNo": 1,
47 "pageSize": 10,
48 "totalCount": 126
49 }
50}