运维模板(Template)接口
更新时间:2024-08-16
创建运维模板
接口描述
您可以在模板中指定执行所需参数(参考请求示例1),也可以通过全局参数的形式在创建执行的时候再指定(参考请求实例2)
请求结构
- method:POST
- URL:/api/logic/oos/v2/template
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
请求示例 1
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseTemplateRequest request = new BaseTemplateRequest();
13request.setName("test_oos_template4");
14request.setLinear(true);
15Operator stopBcc = new Operator();
16stopBcc.setName("stop_bcc");
17stopBcc.setOperator("BCE::BCC::StopInstance");
18stopBcc.setRetries(0);
19stopBcc.setRetryInterval(60000);
20stopBcc.setTimeout(3600000);
21
22Map<String, Object> properties = new HashMap();
23properties.put("instances", Collections.singletonList(
24 Collections.singletonMap("instanceId", "i-******Pi") // 待关机的实例 Id
25));
26stopBcc.setProperties(properties);
27List<Operator> operators = new ArrayList();
28operators.add(stopBcc);
29request.setOperators(operators);
30// call
31BaseTemplateResponse template = oosClient.createTemplate(request);
响应示例 1
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******DK"
7 }
8}
9
请求示例 2
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseTemplateRequest request = new BaseTemplateRequest();
13request.setName("test_oos_template_param");
14request.setLinear(true);
15Operator stopBcc = new Operator();
16stopBcc.setName("stop_bcc");
17stopBcc.setOperator("BCE::BCC::StopInstance");
18stopBcc.setRetries(0);
19stopBcc.setRetryInterval(60000);
20stopBcc.setTimeout(3600000);
21
22Map<String, Object> properties = new HashMap();
23// 引用全局参数
24properties.put("instances", Collections.singletonList(
25 Collections.singletonMap("Ref", "instanceId")
26));
27stopBcc.setProperties(properties);
28List<Operator> operators = new ArrayList();
29operators.add(stopBcc);
30request.setOperators(operators);
31// 设置全局参数
32Property instanceId = new Property();
33instanceId.setName("instanceId");
34instanceId.setRequired(true);
35instanceId.setType("bccInstance");
36request.setProperties(Collections.singletonList(instanceId));
37// call
38BaseTemplateResponse template = oosClient.createTemplate(request);
响应示例 2
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******DK"
7 }
8}
9
校验运维模板
接口描述
用于校验模板是否符合规则
请求结构
- method:POST
- URL:/api/logic/oos/v2/template/check
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
请求示例
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseTemplateRequest request = new BaseTemplateRequest();
13request.setName("test_oos_template_param");
14request.setLinear(true);
15Operator stopBcc = new Operator();
16stopBcc.setName("stop_bcc");
17stopBcc.setOperator("BCE::BCC::StopInstance");
18stopBcc.setRetries(0);
19stopBcc.setRetryInterval(60000);
20stopBcc.setTimeout(3600000);
21
22Map<String, Object> properties = new HashMap();
23properties.put("instances", Collections.singletonList(
24 Collections.singletonMap("Ref", "instanceId")
25));
26stopBcc.setProperties(properties);
27List<Operator> operators = new ArrayList();
28operators.add(stopBcc);
29request.setOperators(operators);
30Property instanceId = new Property();
31instanceId.setName("instanceId");
32instanceId.setRequired(true);
33instanceId.setType("bccInstance");
34request.setProperties(Collections.singletonList(instanceId));
35
36// call
37CheckTemplateResponse checkTemplateResponse = oosClient.checkTemplate(request);
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200
5}
6
更新运维模板
接口描述
用于更新运维模板,注意改接口只能够全量更新
请求结构
- method:PUT
- URL:/api/logic/oos/v2/template
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
Template | Template | 运维模板 | 是 | RequestBody参数 |
id | String | 运维模板ID | 是 | RequestBody参数 |
请求示例
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseTemplateRequest request = new BaseTemplateRequest();
13request.setName("test_oos_template_param");
14request.setLinear(true);
15Operator stopBcc = new Operator();
16stopBcc.setName("stop_bcc_update");
17stopBcc.setOperator("BCE::BCC::StopInstance");
18stopBcc.setRetries(0);
19stopBcc.setRetryInterval(60000);
20stopBcc.setTimeout(3600000);
21
22Map<String, Object> properties = new HashMap();
23properties.put("instances", Collections.singletonList(
24 Collections.singletonMap("Ref", "instanceId")
25));
26stopBcc.setProperties(properties);
27List<Operator> operators = new ArrayList();
28operators.add(stopBcc);
29request.setOperators(operators);
30Property instanceId = new Property();
31instanceId.setName("instanceId");
32instanceId.setRequired(true);
33instanceId.setType("bccInstance");
34request.setProperties(Collections.singletonList(instanceId));
35
36request.setId("tpl-******wE");
37// call
38BaseTemplateResponse baseTemplateResponse = oosClient.updateTemplate(request);
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200
5}
6
删除运维模板
接口描述
用于删除运维模板
请求结构
- method:DELETE
- URL:/api/logic/oos/v2/template?{Query参数}
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
id | String | 运维模板ID | 是 | Query参数 |
请求示例
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12String templateId = "tpl-******wE";
13// call
14BaseTemplateResponse baseTemplateResponse = oosClient.deleteTemplate(templateId);
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200
5}
6
查看运维模板
接口描述
用于查看运维模板详情
请求结构
- method:GET
- URL:/api/logic/oos/v2/template?{Query参数}
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
name | String | 运维模板名称 | 是 | Query参数 |
type | String | 运维模板类型,包括GLOBAL(系统)、INDIVIDUAL(个人) | 是 | Query参数 |
请求示例
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12String templateName = "test_oos_template4";
13TemplateType templateType = TemplateType.INDIVIDUAL;
14// call
15BaseTemplateResponse baseTemplateResponse = oosClient.getTemplateDetail(templateName, templateType);
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "tpl-******nP",
7 "name": "test_oos_template4",
8 "description": "",
9 "linear": true,
10 "operators": [
11 {
12 "name": "stop_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-******Pi"
33 }
34 ]
35 },
36 "initContext": {}
37 }
38 ]
39 }
40}
41
查看运维模板列表
接口描述
用于查看运维模板列表
请求结构
- method:POST
- URL:/api/logic/oos/v2/template/list
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
sort | String | 排序字段,默认为创建时间 | 否 | RequestBody参数 |
ascending | boolean | 是否升序,默认false | 否 | RequestBody参数 |
pageNo | int | 页数,从1开始计数 | 是 | RequestBody参数 |
pageSize | int | 每页展示数量,最大值:100 | 是 | RequestBody参数 |
请求示例
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12TemplateListRequest request = new TemplateListRequest();
13request.setSort("createTime");
14request.setAscending(false);
15request.setPageNo(1);
16request.setPageSize(10);
17// call
18TemplateListResponse templateList = oosClient.getTemplateList(request);
响应示例
JSON
1{
2 "success": true,
3 "msg": "",
4 "result": {
5 "templates": [
6 {
7 "id": "tpl-******nP",
8 "name": "test_oos_template4",
9 "type": "INDIVIDUAL",
10 "description": "",
11 "linear": true,
12 "operators": [
13 {
14 "name": "stop_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}
51