使用OOS实现自动删除创建于7天前的镜像

OOS简介
Operation Orchestration Service,简称OOS,是全面、免费的云上自动化运维平台,提供运维任务的管理和执行。典型使用场景包括:事件驱动运维,批量操作运维,定时运维任务,跨地域运维等,OOS为重要运维场景提供审批,通知等功能。OOS帮您实现标准化运维任务,从而实践运维即代码(Operations as Code)的先进理念。关于OOS更详细的介绍请参见什么是运维编排服务


场景介绍
基于OOS实现自动删除创建于7天前的镜像。


操作步骤
1.登陆OOS控制台,找到我的模板,点击创建模板
使用OOS实现自动删除创建于7天前的镜像
2.选择空白模版
使用OOS实现自动删除创建于7天前的镜像


3.复制下文提供的模板到YAML栏中,输入模板名称(Delete-ExpiredImage),点击创建模板
使用OOS实现自动删除创建于7天前的镜像


模板(Delete-ExpiredImage)内容:


FormatVersion: OOS-2019-06-01
Description: ''
Parameters:
regionId:
Type: String
Description:
  en: The id of region.
  zh-cn: 地域ID。
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'

force:

Description:
  en: Specifies whether to forcibly delete the image.
  zh-cn: 是否强制删除镜像。
Type: Boolean
Default: false

expiredDays:

Description:
  en: The expired days of image.
  zh-cn: 镜像过期天数。
Type: Number
Default: 7

rateControl:

Description:
  en: Concurrency ratio of task execution.
  zh-cn: 任务执行的并发比率。
Type: Json
AssociationProperty: RateControl
Default:
  Mode: Concurrency
  MaxErrors: 100%
  Concurrency: 10

Tasks:

Name: describeImages

Action: 'ACS::ExecuteAPI'
Description: ''
Properties:
  Service: ECS
  API: DescribeImages
  Parameters:
    RegionId: '{{ regionId }}'
    ImageOwnerAlias: self
    Filter:

Key: CreationEndTime
Value:

'Fn::FormatUTCTime':

'Fn::AddHour':

'{{ ACS::CurrentUTCTime }}'

"Fn::Eval":

'-{{ expiredDays }}*24''%Y-%m-%dT00:00Z'
Outputs:
imageIds:

Type: List
ValueSelector: '.Images.Image[].ImageId'

Name: deleteImages

Action: 'ACS::ExecuteAPI'
Description:
  en: Delete the expired images.
  zh-cn: 删除过期镜像。
Properties:
  Service: ECS
  API: DeleteImage
  Parameters:
    RegionId: '{{ regionId }}'
    ImageId: '{{ ACS::TaskLoopItem }}'
    Force: '{{ force }}'
Loop:
  Items: '{{ describeImages.imageIds }}'
  RateControl: '{{ rateControl }}'

Outputs:

deletedImageIds:

Type: List
Value: '{{ describeImages.imageIds }}'</code></pre>

定时执行模版
1.找到定时运维,点击创建,选择周期性重复执行,设置定时执行的规则。
截图所示规则:截止规则结束时间,每天0点0分定时执行制指定模板
使用OOS实现自动删除创建于7天前的镜像


2.模板选择,选择上文创建的模板。参数设置,选择目标地域,点击确认风险并执行。
使用OOS实现自动删除创建于7天前的镜像


3.在执行详情页中可以查看定时执行列表和所操作的资源。
使用OOS实现自动删除创建于7天前的镜像

上一篇:ECS-buy 镜像选择页功能更新


下一篇:什么是云存储