场景
当资源上有个标签键: 部门,标签值:零售,由于部门资源整合要把标签(键: 部门,值:零售)修改为标签(键: 部门,值:新零售),如何快速批量修改标签呢?
背景信息
运维编排服务OOS通过模板定义您需要编排的运维任务。模板内容支持YAML和JSON两种格式,模版分为公共模版和自定义模版两种类型。为了方便您快速使用OOS,OOS提供了公共模板供您直接使用和参考。。在使用模板前您需要仔细审查模板所要执行的运维任务,并优先在测试环境观察使用效果。
您也可以编写自定义模板来编写您所需要的运维任务。更多详情,请参见模板结构。本文中的TagResourcesFilterByTags是自定义模板
操作步骤
登录ECS管理控制台。
在左侧导航栏,选择 运维与监控 > 运维编排。
在顶部状态栏处,选择地域。
选择 我的模板 点击 创建模版
选择JSON
以下示例是针对ecs实例及redis实例进行标签值的更新
operateId : 操作ID,区分每次操作使用
tagKey:标签键,用来过滤资源
tagValue:标签值,用来过滤资源
tagKey:标签键,要修改目标标签键
newTagValue:新标签值,要修改后的标签值
-
{
-
"Description":
"根据标签查找资源并更新标签",
-
"FormatVersion":
"OOS-2019-06-01",
-
"Parameters": {
-
"operateId": {
-
"Description":
"操作ID,调用者自定义",
-
"Type":
"String",
-
"MinLength":
1,
-
"MaxLength":
64
-
},
-
"tagKey": {
-
"Description":
"当前key",
-
"Type":
"String",
-
"MinLength":
1,
-
"MaxLength":
64
-
},
-
"tagValue": {
-
"Description":
"当前value",
-
"Type":
"String",
-
"MinLength":
1,
-
"MaxLength":
64
-
},
-
"newTagValue": {
-
"Description":
"更新后value",
-
"Type":
"String",
-
"MinLength":
1,
-
"MaxLength":
64
-
}
-
},
-
"Tasks": [
-
{
-
"Name":
"DescribeInstances_ECS",
-
"Action":
"ACS::ExecuteAPI",
-
"Description": {
-
"zh-cn":
"通过标签过滤ECS实例",
-
"en":
"filter ecs instances by tags"
-
},
-
"Properties": {
-
"Service":
"ECS",
-
"API":
"DescribeInstances",
-
"AutoPaging":
true,
-
"Parameters": {
-
"Tags": [
-
{
-
"Key":
"{{ tagKey }}",
-
"Value":
"{{ tagValue }}"
-
}
-
]
-
}
-
},
-
"Outputs": {
-
"Instances": {
-
"Type":
"List",
-
"ValueSelector":
"Instances.Instance[].InstanceId"
-
}
-
}
-
},
-
{
-
"Name":
"TagResources_ECS_Instances",
-
"Action":
"ACS::ExecuteAPI",
-
"Description": {
-
"zh-cn":
"更新ECS实例标签",
-
"en":
"tag ecs instances"
-
},
-
"Properties": {
-
"Service":
"ECS",
-
"API":
"TagResources",
-
"Parameters": {
-
"Tags": [
-
{
-
"Key":
"{{ tagKey }}",
-
"Value":
"{{ newTagValue }}"
-
}
-
],
-
"ResourceType":
"Instance",
-
"ResourceIds": [
-
"{{ACS::TaskLoopItem}}"
-
]
-
}
-
},
-
"Loop": {
-
"MaxErrors":
"100%",
-
"Concurrency":
20,
-
"Items":
"{{DescribeInstances_ECS.Instances}}"
-
}
-
},
-
{
-
"OnError":
"ACS::NEXT",
-
"Name":
"DescribeInstances_REDIS",
-
"Action":
"ACS::ExecuteApi",
-
"Description": {
-
"zh-cn":
"通过标签过滤REDIS实例",
-
"en":
"filter redis(kvstore) instances by tags"
-
},
-
"Properties": {
-
"Service":
"R-kvstore",
-
"API":
"DescribeInstances",
-
"AutoPaging":
true,
-
"Parameters": {
-
"Tags": [
-
{
-
"Key":
"{{ tagKey }}",
-
"Value":
"{{ tagValue }}"
-
}
-
]
-
}
-
},
-
"Outputs": {
-
"Instances": {
-
"Type":
"List",
-
"ValueSelector":
"Instances.KVStoreInstance[].InstanceId"
-
}
-
}
-
},
-
{
-
"Name":
"TagResources_REDIS_Instances",
-
"Action":
"ACS::ExecuteAPI",
-
"Description": {
-
"zh-cn":
"更新REDIS实例标签",
-
"en":
"tag redis instances"
-
},
-
"Properties": {
-
"Service":
"R-kvstore",
-
"API":
"TagResources",
-
"Parameters": {
-
"Tags": [
-
{
-
"Key":
"{{ tagKey }}",
-
"Value":
"{{ newTagValue }}"
-
}
-
],
-
"ResourceType":
"Instance",
-
"ResourceIds": [
-
"{{ACS::TaskLoopItem}}"
-
]
-
}
-
},
-
"Loop": {
-
"MaxErrors":
"100%",
-
"Concurrency":
20,
-
"Items":
"{{DescribeInstances_REDIS.Instances}}"
-
}
-
}
-
],
-
"Outputs": {}
-
}
创建执行:
执行详情:
当执行状态显示成功,表示运维任务已完成。
当执行状态显示失败,您可以单击操作列下的详情查看执行日志,并根据日志信息分析和调整执行内容。
可以根据本文的代码修改为自己需要的cases。
原文链接
本文为云栖社区原创内容,未经允许不得转载。
转载:https://blog.csdn.net/yunqiinsight/article/details/103252162
查看评论