Class: AWS::AutoScaling::Group
- Inherits:
-
Core::Resource
- Object
- Core::Resource
- AWS::AutoScaling::Group
- Defined in:
- lib/aws/auto_scaling/group.rb
Instance Attribute Summary collapse
-
#availability_zone_names ⇒ Array<String>
readonly
The current value of availability_zone_names.
-
#created_time ⇒ Time
readonly
The current value of created_time.
-
#default_cooldown ⇒ Integer
readonly
The current value of default_cooldown.
-
#desired_capacity ⇒ Integer
readonly
The current value of desired_capacity.
-
#enabled_metrics ⇒ Array<Hash>
readonly
Returns a hash of enabled metric names (keys) and granularities (values).
-
#health_check_grace_period ⇒ Integer
readonly
The current value of health_check_grace_period.
-
#health_check_type ⇒ Symbol
readonly
Returns :ec2 or :vpc.
-
#launch_configuraiton_name ⇒ String
readonly
The current value of launch_configuraiton_name.
-
#load_balancer_names ⇒ Array<String>
readonly
The current value of load_balancer_names.
-
#max_size ⇒ Integer
readonly
The current value of max_size.
-
#min_size ⇒ Integer
readonly
The current value of min_size.
- #name ⇒ String readonly
-
#placement_group ⇒ String?
readonly
The current value of placement_group.
-
#suspended_processes ⇒ Hash
readonly
A hash of suspended process names (keys) and reasons (values).
Instance Method Summary collapse
- #activities ⇒ ActivityCollection
- #auto_scaling_instances ⇒ Array<AutoScaling::Instance>
- #availability_zones ⇒ Array<EC2::AvailabilityZone>
-
#delete(options = {}) ⇒ nil
Deletes the Auto Scaling group.
-
#delete! ⇒ nil
Deletes the Auto Scaling group along with all instances associated with the group, without waiting for all instances to be terminated.
-
#delete_all_tags ⇒ nil
Removes all tags from this Auto Scaling group.
-
#delete_tags(*tags) ⇒ nil
Deletes specific tags from this Auto Scaling group.
-
#disable_all_metrics_collection ⇒ nil
Disables all metrics collection for the Auto Scaling group.
- #disable_metrics_collection(*metrics) ⇒ nil
-
#ec2_instances ⇒ EC2::InstanceCollection
Returns a collection that represents the instances belonging to this Auto Scaling group.
-
#enable_all_metrics_collection ⇒ nil
Enables all metrics collection for the Auto Scaling group.
- #enable_metrics_collection(*metrics) ⇒ nil
- #exists? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Group
constructor
A new instance of Group.
- #launch_configuration ⇒ LaunchConfiguration
- #load_balancers ⇒ Array, <ELB::LoadBalancer>
- #notification_configurations ⇒ NotificationConfigurationCollection
-
#resume_all_processes ⇒ nil
Resumes all processes for this Auto Scaling group.
-
#resume_processes(*processes) ⇒ nil
Resumes processes for this Auto Scaling group.
- #scaling_policies ⇒ ScalingPolicyCollection
- #scheduled_actions ⇒ ScheduledActionCollection
-
#set_desired_capacity(capacity, options = {}) ⇒ nil
Adjusts the desired size of the Auto Scaling group by initiating scaling activities.
- #subnets ⇒ Array<EC2::Subnet>
-
#suspend_all_processes ⇒ nil
Suspends all processes for this Auto Scaling group.
-
#suspend_processes(*processes) ⇒ nil
Suspends processes for this Auto Scaling group.
- #tags ⇒ Tag
-
#update(options = {}) ⇒ nil
Update one or more attributes on the Auto Scaling group.
Constructor Details
#initialize(name, options = {}) ⇒ Group
Returns a new instance of Group.
51 52 53 54 |
# File 'lib/aws/auto_scaling/group.rb', line 51 def initialize name, = {} @name = name super end |
Instance Attribute Details
#availability_zone_names ⇒ Array<String> (readonly)
Returns the current value of availability_zone_names.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def availability_zone_names @availability_zone_names end |
#created_time ⇒ Time (readonly)
Returns the current value of created_time.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def created_time @created_time end |
#default_cooldown ⇒ Integer (readonly)
Returns the current value of default_cooldown.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def default_cooldown @default_cooldown end |
#desired_capacity ⇒ Integer (readonly)
Returns the current value of desired_capacity.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def desired_capacity @desired_capacity end |
#enabled_metrics ⇒ Array<Hash> (readonly)
Returns a hash of enabled metric names (keys) and granularities (values).
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def enabled_metrics @enabled_metrics end |
#health_check_grace_period ⇒ Integer (readonly)
Returns the current value of health_check_grace_period.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def health_check_grace_period @health_check_grace_period end |
#health_check_type ⇒ Symbol (readonly)
Returns :ec2 or :vpc.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def health_check_type @health_check_type end |
#launch_configuraiton_name ⇒ String (readonly)
Returns the current value of launch_configuraiton_name.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def launch_configuraiton_name @launch_configuraiton_name end |
#load_balancer_names ⇒ Array<String> (readonly)
Returns the current value of load_balancer_names.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def load_balancer_names @load_balancer_names end |
#max_size ⇒ Integer (readonly)
Returns the current value of max_size.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def max_size @max_size end |
#min_size ⇒ Integer (readonly)
Returns the current value of min_size.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def min_size @min_size end |
#name ⇒ String (readonly)
57 58 59 |
# File 'lib/aws/auto_scaling/group.rb', line 57 def name @name end |
#placement_group ⇒ String? (readonly)
Returns the current value of placement_group.
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def placement_group @placement_group end |
#suspended_processes ⇒ Hash (readonly)
A hash of suspended process names (keys) and reasons (values).
47 48 49 |
# File 'lib/aws/auto_scaling/group.rb', line 47 def suspended_processes @suspended_processes end |
Instance Method Details
#activities ⇒ ActivityCollection
146 147 148 |
# File 'lib/aws/auto_scaling/group.rb', line 146 def activities ActivityCollection.new(:group => self) end |
#auto_scaling_instances ⇒ Array<AutoScaling::Instance>
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/aws/auto_scaling/group.rb', line 151 def auto_scaling_instances instances.collect do |details| Instance.new_from( :describe_auto_scaling_groups, details, details.instance_id, :auto_scaling_group_name => name, # not provided by the response :config => config) end end |
#availability_zones ⇒ Array<EC2::AvailabilityZone>
187 188 189 190 191 |
# File 'lib/aws/auto_scaling/group.rb', line 187 def availability_zones availability_zone_names.collect do |az_name| EC2::AvailabilityZone.new(az_name, :config => config) end end |
#delete(options = {}) ⇒ nil
Deletes the Auto Scaling group. If you pass :force
as true then all the instances associated with this group will also be terminated.
383 384 385 386 387 388 389 |
# File 'lib/aws/auto_scaling/group.rb', line 383 def delete = {} client_opts = {} client_opts[:force_delete] = [:force] == true client_opts[:auto_scaling_group_name] = name client.delete_auto_scaling_group(client_opts) nil end |
#delete! ⇒ nil
Deletes the Auto Scaling group along with all instances associated with the group, without waiting for all instances to be terminated.
395 396 397 398 |
# File 'lib/aws/auto_scaling/group.rb', line 395 def delete! delete(:force => true) nil end |
#delete_all_tags ⇒ nil
Removes all tags from this Auto Scaling group.
364 365 366 367 |
# File 'lib/aws/auto_scaling/group.rb', line 364 def (self.) nil end |
#delete_tags(*tags) ⇒ nil
Deletes specific tags from this Auto Scaling group.
group.([
{ :key => 'role', :value => 'webserver' },
])
You may also pass Tag objects.
352 353 354 355 356 357 358 359 360 |
# File 'lib/aws/auto_scaling/group.rb', line 352 def * = .flatten.collect do |tag| tag.to_hash.merge( :resource_type => 'auto-scaling-group', :resource_id => name) end client.(:tags => ) nil end |
#disable_all_metrics_collection ⇒ nil
Disables all metrics collection for the Auto Scaling group.
299 300 301 |
# File 'lib/aws/auto_scaling/group.rb', line 299 def disable_all_metrics_collection disable_metrics_collection end |
#disable_metrics_collection(*metrics) ⇒ nil
289 290 291 292 293 294 295 |
# File 'lib/aws/auto_scaling/group.rb', line 289 def disable_metrics_collection *metrics client_opts = {} client_opts[:auto_scaling_group_name] = name client_opts[:metrics] = metrics.flatten client.disable_metrics_collection(client_opts) nil end |
#ec2_instances ⇒ EC2::InstanceCollection
Returns a collection that represents the instances belonging to this Auto Scaling group. You can use this collection to further refine the instances you are interested in:
group.ec2_instances.filter('availability-zone', 'us-east-1a').each do |i|
puts instance.id
end
174 175 176 177 |
# File 'lib/aws/auto_scaling/group.rb', line 174 def ec2_instances instances = EC2::InstanceCollection.new(:config => config) instances.tagged('aws:autoscaling:groupName').tagged_values(name) end |
#enable_all_metrics_collection ⇒ nil
Enables all metrics collection for the Auto Scaling group.
283 284 285 |
# File 'lib/aws/auto_scaling/group.rb', line 283 def enable_all_metrics_collection enable_metrics_collection end |
#enable_metrics_collection(*metrics) ⇒ nil
272 273 274 275 276 277 278 279 |
# File 'lib/aws/auto_scaling/group.rb', line 272 def enable_metrics_collection *metrics client_opts = {} client_opts[:auto_scaling_group_name] = name client_opts[:granularity] = '1Minute' client_opts[:metrics] = metrics.flatten client.enable_metrics_collection(client_opts) nil end |
#exists? ⇒ Boolean
401 402 403 404 405 406 |
# File 'lib/aws/auto_scaling/group.rb', line 401 def exists? client_opts = {} client_opts[:auto_scaling_group_names] = [name] resp = client.describe_auto_scaling_groups(client_opts) !resp.auto_scaling_groups.empty? end |
#launch_configuration ⇒ LaunchConfiguration
141 142 143 |
# File 'lib/aws/auto_scaling/group.rb', line 141 def launch_configuration LaunchConfiguration.new(launch_configuration_name, :config => config) end |
#load_balancers ⇒ Array, <ELB::LoadBalancer>
194 195 196 197 198 |
# File 'lib/aws/auto_scaling/group.rb', line 194 def load_balancers load_balancer_names.collect do |name| ELB::LoadBalancer.new(name, :config => config) end end |
#notification_configurations ⇒ NotificationConfigurationCollection
123 124 125 |
# File 'lib/aws/auto_scaling/group.rb', line 123 def notification_configurations NotificationConfigurationCollection.new(:group => self) end |
#resume_all_processes ⇒ nil
Resumes all processes for this Auto Scaling group.
266 267 268 |
# File 'lib/aws/auto_scaling/group.rb', line 266 def resume_all_processes resume_processes end |
#resume_processes(*processes) ⇒ nil
Resumes processes for this Auto Scaling group.
# resume two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'
256 257 258 259 260 261 262 |
# File 'lib/aws/auto_scaling/group.rb', line 256 def resume_processes *processes client_opts = {} client_opts[:auto_scaling_group_name] = name client_opts[:scaling_processes] = processes.flatten client.resume_processes(client_opts) nil end |
#scaling_policies ⇒ ScalingPolicyCollection
118 119 120 |
# File 'lib/aws/auto_scaling/group.rb', line 118 def scaling_policies ScalingPolicyCollection.new(self) end |
#scheduled_actions ⇒ ScheduledActionCollection
128 129 130 131 |
# File 'lib/aws/auto_scaling/group.rb', line 128 def scheduled_actions actions = ScheduledActionCollection.new(:config => config) actions.filter(:group => self) end |
#set_desired_capacity(capacity, options = {}) ⇒ nil
Adjusts the desired size of the Auto Scaling group by initiating scaling activities. When reducing the size of the group, it is not possible to define which Amazon EC2 instances will be terminated. This applies to any Auto Scaling decisions that might result in terminating instances.
215 216 217 218 219 220 221 222 |
# File 'lib/aws/auto_scaling/group.rb', line 215 def set_desired_capacity capacity, = {} client_opts = {} client_opts[:auto_scaling_group_name] = name client_opts[:desired_capacity] = capacity client_opts[:honor_cooldown] = [:honor_cooldown] == true client.set_desired_capacity(client_opts) nil end |
#subnets ⇒ Array<EC2::Subnet>
180 181 182 183 184 |
# File 'lib/aws/auto_scaling/group.rb', line 180 def subnets vpc_zone_identifier.to_s.split(/,/).collect do |subnet_id| EC2::Subnet.new(subnet_id, :config => config) end end |
#suspend_all_processes ⇒ nil
Suspends all processes for this Auto Scaling group.
243 244 245 |
# File 'lib/aws/auto_scaling/group.rb', line 243 def suspend_all_processes suspend_processes end |
#suspend_processes(*processes) ⇒ nil
Suspends processes for this Auto Scaling group.
# suspend two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'
233 234 235 236 237 238 239 |
# File 'lib/aws/auto_scaling/group.rb', line 233 def suspend_processes *processes client_opts = {} client_opts[:auto_scaling_group_name] = name client_opts[:scaling_processes] = processes.flatten client.suspend_processes(client_opts) nil end |
#tags ⇒ Tag
134 135 136 137 138 |
# File 'lib/aws/auto_scaling/group.rb', line 134 def tag_details.collect do |tag| Tag.new(tag.to_hash.merge(:config => config)) end end |
#update(options = {}) ⇒ nil
Update one or more attributes on the Auto Scaling group.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/aws/auto_scaling/group.rb', line 311 def update = {} group_opts = () # tags must be updated using a separate request from the # other attributes, *sigh* if = group_opts.delete(:tags) .map(&:to_hash).each do |tag| tag[:resource_type] = 'auto-scaling-group' tag[:resource_id] = name end client.(:tags => ) end unless group_opts.empty? client_opts = group_opts.merge(:auto_scaling_group_name => name) client.update_auto_scaling_group(client_opts) end nil end |