Class: Awscli::As::Groups
- Inherits:
-
Object
- Object
- Awscli::As::Groups
- Defined in:
- lib/awscli/as.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
- #delete(options) ⇒ Object
-
#initialize(connection) ⇒ Groups
constructor
A new instance of Groups.
- #list(options) ⇒ Object
- #resume_processes(options) ⇒ Object
- #set_desired_capacity(options) ⇒ Object
-
#suspend_processes(options) ⇒ Object
def update asg = @conn.groups.get(options) abort “Cannot find Auto Scaling Group with name: #:id” unless asg opts = Marshal.load(Marshal.dump(options)) opts.reject! { |k| k == ‘id’ } asg.update(opts) end.
Constructor Details
#initialize(connection) ⇒ Groups
Returns a new instance of Groups.
99 100 101 |
# File 'lib/awscli/as.rb', line 99 def initialize(connection) @conn = connection end |
Instance Method Details
#create(options) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/awscli/as.rb', line 112 def create() # => validate & parse options opts = Marshal.load(Marshal.dump()) #launch conf name abort "Launch configuration name not found: #{[:launch_configuration_name]}" unless @conn.configurations.get([:launch_configuration_name]) #remove required options from options hash opts.reject! { |k| k == 'id' } opts.reject! { |k| k == 'availability_zones' } opts.reject! { |k| k == 'launch_configuration_name' } opts.reject! { |k| k == 'max_size' } opts.reject! { |k| k == 'min_size' } if desired_capacity = opts.delete(:desired_capacity) opts.merge!('DesiredCapacity' => desired_capacity) end if default_cooldown = opts.delete(:default_cooldown) opts.merge!('DefaultCooldown' => default_cooldown) end if health_check_grace_period = opts.delete(:health_check_grace_period) opts.merge!('HealthCheckGracePeriod' => health_check_grace_period) end if health_check_type = opts.delete(:health_check_type) opts.merge!('HealthCheckType' => health_check_type) end if load_balancer_names = opts.delete(:load_balancer_names) opts.merge!('LoadBalancerNames' => load_balancer_names) end if placement_group = opts.delete(:placement_group) opts.merge!('PlacementGroup' => placement_group) end if = opts.delete(:tags) = Array.new .each do |t| abort "Invalid tags format, expecting 'key=value' format" unless t =~ /\S=\S/ end .each do |tag| parsed_tag = Hash.new key, value = tag.split("=") parsed_tag['Key'] = key parsed_tag['Value'] = value << parsed_tag end opts.merge!('Tags' => ) end if termination_policies = opts.delete(:termination_policies) opts.merge!('TerminationPolicies' => termination_policies) end if vpc_zone_identifiers = opts.delete(:vpc_zone_identifiers) opts.merge!('VPCZoneIdentifier' => vpc_zone_identifiers.join(',')) end begin @conn.create_auto_scaling_group( [:id], [:availability_zones], [:launch_configuration_name], [:max_size], [:min_size], opts ) puts "Created Auto Scaling Group with name: #{[:id]}" rescue Fog::AWS::AutoScaling::IdentifierTaken puts "A auto-scaling-group already exists with the name #{[:id]}" rescue Fog::AWS::AutoScaling::ValidationError puts "Validation Error: #{$!}" end end |
#delete(options) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/awscli/as.rb', line 223 def delete() begin if [:force] @conn.delete_auto_scaling_group( [:id], 'ForceDelete' => [:force] ) else @conn.delete_auto_scaling_group([:id]) end rescue Fog::AWS::AutoScaling::ResourceInUse puts 'You cannot delete an AutoScalingGroup while there are instances or pending Spot instance request(s) still in the group' puts 'Use -f option to force delete instances attached to the sacling group' exit 1 end puts "Deleted Auto scaling group #{[:id]}" end |
#list(options) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/awscli/as.rb', line 103 def list() if [:table] @conn.groups.table([:id, :launch_configuration_name, :desired_capacity, :min_size, :max_size, :vpc_zone_identifier, :termination_policies]) else #yaml dump puts @conn.describe_auto_scaling_groups.body['DescribeAutoScalingGroupsResult']['AutoScalingGroups'].to_yaml end end |
#resume_processes(options) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/awscli/as.rb', line 210 def resume_processes() if [:scaling_processes] @conn.resume_processes( [:id], 'ScalingProcesses' => [:scaling_processes] ) puts "Resuming processes #{[:scaling_processes]} for group: #{[:id]}" else @conn.resume_processes([:id]) puts "Resuming processes for group: #{[:id]}" end end |
#set_desired_capacity(options) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/awscli/as.rb', line 178 def set_desired_capacity() # => Sets the desired capacity of the auto sacling group asg = @conn.groups.get([:id]) abort "Cannot find Auto Scaling Group with name: #{[:id]}" unless asg min_size = asg.min_size max_size = asg.max_size abort "Desired capacity should fall in between auto scaling groups min-size: #{min_size} and max-size: #{max_size}" unless [:desired_capacity].between?(min_size, max_size) abort "Desired capacity is already #{asg.desired_capacity}" if [:desired_capacity] == asg.desired_capacity @conn.set_desired_capacity([:id], [:desired_capacity]) puts "Scaled Auto Scaling Group: #{[:id]} to a desired_capacity of #{[:desired_capacity]}" end |
#suspend_processes(options) ⇒ Object
def update
asg = @conn.groups.get([:id])
abort "Cannot find Auto Scaling Group with name: #{[:id]}" unless asg
opts = Marshal.load(Marshal.dump())
opts.reject! { |k| k == 'id' }
asg.update(opts)
end
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/awscli/as.rb', line 198 def suspend_processes() if [:scaling_processes] @conn.suspend_processes( [:id], 'ScalingProcesses' => [:scaling_processes]) puts "Suspending processes #{[:scaling_processes]} for group: #{[:id]}" else @conn.suspend_processes([:id]) puts "Suspending processes for group: #{[:id]}" end end |