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, #connection

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #to_json, #wait_for

Methods included from Fog::Attributes::ClassMethods

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

Methods included from Fog::Attributes::InstanceMethods

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

Constructor Details

#initialize(attributes = {}) ⇒ Group

Returns a new instance of Group.



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

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

Instance Method Details

#activitiesObject



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

def activities
  requires :id
  data = []
  next_token = nil
  loop do
    result = connection.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,
    :connection => connection,
    #:load_balancer => self
  })
end

#configurationObject



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

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

#destroyObject

def reload

super
self

end



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

def destroy
  requires :id
  connection.delete_auto_scaling_group(id)
end

#disable_metrics_collection(metrics = {}) ⇒ Object



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

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

#enable_metrics_collection(metrics = {}) ⇒ Object



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

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

#instancesObject



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

def instances
  Fog::AWS::AutoScaling::Instances.new({
    :data => attributes['Instances'],
    :connection => connection
  })
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

#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
  connection.resume_processes(id, 'ScalingProcesses' => processes)
  reload
end

#saveObject



108
109
110
111
112
113
114
115
116
117
# 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

  connection.create_auto_scaling_group(id, availability_zones, launch_configuration_name, max_size, min_size)
  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
  connection.suspend_processes(id, 'ScalingProcesses' => processes)
  reload
end