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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Group

Returns a new instance of Group.



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

def initialize(attributes={})
  attributes['DefaultCooldown'] ||= 300
  attributes['DesiredCapacity'] ||= 0
  attributes['EnabledMetrics'] ||= []
  attributes['HealthCheckGracePeriod'] ||= 0
  attributes['HealthCheckType'] ||= 'EC2'
  attributes['Instances'] ||= []
  attributes['LoadBalancerNames'] ||= []
  attributes['MaxSize'] ||= 0
  attributes['MinSize'] ||= 0
  attributes['SuspendedProcesses'] ||= []
  attributes['Tags'] ||= []
  attributes['TerminationPolicies'] ||= ['Default']
  super
end

Instance Method Details

#activitiesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 43

def activities
  requires :id
  data = []
  next_token = nil
  loop do
    result = service.describe_scaling_activities('AutoScalingGroupName' => id, 'NextToken' => next_token).body['DescribeScalingActivitiesResult']
    data += result['Activities']
    next_token = result['NextToken']
    break if next_token.nil?
  end
  Fog::AWS::AutoScaling::Activities.new({
    :data => data,
    :service => service,
    #:load_balancer => self
  })
end

#configurationObject



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

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

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

def reload

super
self

end



123
124
125
126
127
128
129
130
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 123

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

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

  service.delete_auto_scaling_group(id, opts)
end

#disable_metrics_collection(metrics = {}) ⇒ Object



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

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

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



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

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

#filtered_options(method) ⇒ Object



138
139
140
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 138

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

#instancesObject



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

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

#instances_in_serviceObject



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

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

#instances_out_serviceObject



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

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

#optionsObject



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

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)


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

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

#resume_processes(processes = []) ⇒ Object



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

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

#saveObject



108
109
110
111
112
113
114
115
116
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 108

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



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

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

#updateObject



132
133
134
135
136
# File 'lib/fog/aws/models/auto_scaling/group.rb', line 132

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