Module: Builderator::Control::Clean
- Defined in:
- lib/builderator/control/clean.rb
Overview
Control logic for cleanup tasks
Class Method Summary collapse
- .aborted? ⇒ Boolean
- .commit? ⇒ Boolean
- .configs! ⇒ Object
- .exceptions ⇒ Object
- .images! ⇒ Object
- .limit? ⇒ Boolean
- .options(arg = nil) ⇒ Object
- .snapshots! ⇒ Object
- .volumes! ⇒ Object
Class Method Details
.aborted? ⇒ Boolean
108 109 110 |
# File 'lib/builderator/control/clean.rb', line 108 def aborted? @commit && @abort end |
.commit? ⇒ Boolean
100 101 102 |
# File 'lib/builderator/control/clean.rb', line 100 def commit? @commit && !@abort end |
.configs! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/builderator/control/clean.rb', line 24 def configs! resources = Model.launch_configs.unused() limit!(Model::LaunchConfigs, 'Cleanup Launch Configurations', resources, &Proc.new) aborted!(&Proc.new) resources.each do |l, _| yield :remove, "Launch Configuration #{ l }", :red Model.launch_configs.resources.delete(l) next unless commit? # puts "delete_launch_configuration(:launch_configuration_name => #{l})" Util.asg.delete_launch_configuration(:launch_configuration_name => l) end rescue Aws::AutoScaling::Errors::ServiceError => e exceptions << Util::AwsException.new('Cleanup Launch Configurations', e) yield(*exceptions.last.status) end |
.exceptions ⇒ Object
112 113 114 |
# File 'lib/builderator/control/clean.rb', line 112 def exceptions @exceptions ||= [] end |
.images! ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/builderator/control/clean.rb', line 43 def images! resources = Model.images.unused() limit!(Model::Images, 'Cleanup Images', resources, &Proc.new) aborted!(&Proc.new) resources.each do |i, image| yield :remove, "Image #{ i } (#{ image[:properties]['name'] })", :red Model.images.resources.delete(i) next unless commit? puts "deregister_image(:image_id => #{i})" # Util.ec2.deregister_image(:image_id => i) end rescue Aws::EC2::Errors::ServiceError => e exceptions << Util::AwsException.new('Cleanup Images', e) yield(*exceptions.last.status) end |
.limit? ⇒ Boolean
104 105 106 |
# File 'lib/builderator/control/clean.rb', line 104 def limit? @limit end |
.options(arg = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/builderator/control/clean.rb', line 12 def (arg = nil) return @options unless arg.is_a?(Hash) @options = arg.clone Util.region(@options.delete('region')) @commit = @options.delete('commit') { false } @limit = @options.delete('limit') { true } @options end |
.snapshots! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/builderator/control/clean.rb', line 62 def snapshots! resources = Model.snapshots.unused limit!(Model::Snapshots, 'Cleanup Snapshots', resources, &Proc.new) aborted!(&Proc.new) resources.each do |s, _| yield :remove, "Snapshot #{ s }", :red Model.snapshots.resources.delete(s) next unless commit? puts "delete_snapshot(:snapshot_id => #{s})" # Util.ec2.delete_snapshot(:snapshot_id => s) end rescue Aws::EC2::Errors::ServiceError => e exceptions << Util::AwsException.new('Cleanup Snapshots', e) yield(*exceptions.last.status) end |
.volumes! ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/builderator/control/clean.rb', line 81 def volumes! resources = Model.volumes.unused limit!(Model::Volumes, 'Cleanup Volumes', resources, &Proc.new) aborted!(&Proc.new) resources.each do |v, _| yield :remove, "Volume #{ v }", :red Model.volumes.resources.delete(v) next unless commit? puts "delete_volume(:volume_id => #{v})" # Util.ec2.delete_volume(:volume_id => v) end rescue Aws::EC2::Errors::ServiceError => e exceptions << Util::AwsException.new('Cleanup Volumes', e) yield(*exceptions.last.status) end |