Class: Fog::AWS::AutoScaling::Group

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/auto_scaling/group.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Group

Returns a new instance of Group.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 25

def initialize(attributes={})
  self.instances = []
  self.default_cooldown = 300
  self.desired_capacity = 0
  self.enabled_metrics = []
  self.health_check_grace_period = 0
  self.health_check_type = 'EC2'
  self.load_balancer_names = []
  self.max_size = 0
  self.min_size = 0
  self.suspended_processes = []
  self.tags = {}
  self.termination_policies = ['Default']
  super
end

Instance Method Details

#activitiesObject



41
42
43
44
45
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 41

def activities
  requires :id

  activities = Fog::AWS::AutoScaling::Activities.new(:service => service, :filters => {'AutoScalingGroupName' => id})
end

#attach_instances(*instance_ids) ⇒ Object



70
71
72
73
74
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 70

def attach_instances(*instance_ids)
  requires :id
  service.attach_instances(id, 'InstanceIds' => instance_ids)
  reload
end

#attach_load_balancers(*load_balancer_names) ⇒ Object



47
48
49
50
51
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 47

def attach_load_balancers(*load_balancer_names)
  requires :id
  service.attach_load_balancers(id, 'LoadBalancerNames' => load_balancer_names)
  reload
end

#configurationObject



53
54
55
56
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 53

def configuration
  requires :launch_configuration_name
  service.configurations.get(launch_configuration_name)
end

#destroy(options = { :force => false }) ⇒ Object

def reload

super
self

end



134
135
136
137
138
139
140
141
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 134

def destroy(options = { :force => false })
  requires :id

  opts = {}
  opts.merge!({'ForceDelete' => true}) if options[:force]

  service.delete_auto_scaling_group(id, opts)
end

#detach_instances(*instance_ids) ⇒ Object



64
65
66
67
68
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 64

def detach_instances(*instance_ids)
  requires :id
  service.detach_instances(id, 'InstanceIds' => instance_ids)
  reload
end

#detach_load_balancers(*load_balancer_names) ⇒ Object



58
59
60
61
62
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 58

def detach_load_balancers(*load_balancer_names)
  requires :id
  service.detach_load_balancers(id, 'LoadBalancerNames' => load_balancer_names)
  reload
end

#disable_metrics_collection(metrics = {}) ⇒ Object



76
77
78
79
80
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 76

def disable_metrics_collection(metrics = {})
  requires :id
  service.disable_metrics_collection(id, 'Metrics' => metrics)
  reload
end

#enable_metrics_collection(granularity = '1Minute', metrics = {}) ⇒ Object



82
83
84
85
86
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 82

def enable_metrics_collection(granularity = '1Minute', metrics = {})
  requires :id
  service.enable_metrics_collection(id, granularity, 'Metrics' => metrics)
  reload
end

#filtered_options(method) ⇒ Object



149
150
151
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 149

def filtered_options(method)
  Hash[options.select{|k,_| ExpectedOptions[method].include?(k)}]
end

#instancesObject



88
89
90
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 88

def instances
  Fog::AWS::AutoScaling::Instances.new(:service => service).load(attributes[:instances])
end

#instances_in_serviceObject



92
93
94
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 92

def instances_in_service
  attributes[:instances].select {|hash| hash['LifecycleState'] == 'InService'}.map {|hash| hash['InstanceId']}
end

#instances_out_serviceObject



96
97
98
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 96

def instances_out_service
  attributes[:instances].select {|hash| hash['LifecycleState'] == 'OutOfService'}.map {|hash| hash['InstanceId']}
end

#optionsObject



153
154
155
156
157
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 153

def options
  ret = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
  ret.delete_if { |key, value| value.nil? }
  ret
end

#ready?Boolean

Returns:

  • (Boolean)


112
113
114
115
116
117
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 112

def ready?
  # Is this useful?
  #instances_in_service.length == desired_capacity
  #instances_in_service.length >= min_size
  true
end

#resume_processes(processes = []) ⇒ Object



100
101
102
103
104
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 100

def resume_processes(processes = [])
  requires :id
  service.resume_processes(id, 'ScalingProcesses' => processes)
  reload
end

#saveObject



119
120
121
122
123
124
125
126
127
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 119

def save
  requires :id
  requires :availability_zones
  requires :launch_configuration_name
  requires :max_size
  requires :min_size
  service.create_auto_scaling_group(id, availability_zones, launch_configuration_name, max_size, min_size, filtered_options(:create_auto_scaling_group))
  reload
end

#suspend_processes(processes = []) ⇒ Object



106
107
108
109
110
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 106

def suspend_processes(processes = [])
  requires :id
  service.suspend_processes(id, 'ScalingProcesses' => processes)
  reload
end

#updateObject



143
144
145
146
147
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 143

def update
  requires :id
  service.update_auto_scaling_group(id, filtered_options(:update_auto_scaling_group) )
  reload
end