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