2013-05-30 23:19:08 +00:00
|
|
|
module AWS
|
|
|
|
class FakeAutoScaling
|
|
|
|
def initialize
|
|
|
|
end
|
2013-05-31 20:08:23 +00:00
|
|
|
|
|
|
|
def groups
|
|
|
|
@groups ||= GroupCollection.new
|
|
|
|
end
|
|
|
|
|
|
|
|
class GroupCollection
|
|
|
|
def initialize
|
|
|
|
@groups = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](name)
|
|
|
|
@groups[name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(name, options = {})
|
|
|
|
@groups[name] = Group.new name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Group
|
2013-06-04 02:31:10 +00:00
|
|
|
attr_reader :name, :max_size, :desired_capacity, :suspended_processes
|
2013-05-31 20:08:23 +00:00
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
2013-05-31 22:05:16 +00:00
|
|
|
@suspended_processes = {}
|
2013-05-31 22:16:41 +00:00
|
|
|
@max_size = 2
|
|
|
|
@desired_capacity = 1
|
2013-05-31 22:05:16 +00:00
|
|
|
end
|
|
|
|
|
2013-06-04 02:31:10 +00:00
|
|
|
def suspend_processes(processes)
|
2013-05-31 22:05:16 +00:00
|
|
|
processes.each do |process|
|
|
|
|
@suspended_processes[process] = 'test'
|
|
|
|
end
|
2013-05-31 20:08:23 +00:00
|
|
|
end
|
2013-05-31 22:16:41 +00:00
|
|
|
|
2013-06-04 01:07:10 +00:00
|
|
|
def resume_all_processes
|
|
|
|
@suspended_processes.clear
|
|
|
|
end
|
|
|
|
|
2013-05-31 22:16:41 +00:00
|
|
|
def update(options = {})
|
|
|
|
options.each do |key, value|
|
|
|
|
self.instance_variable_set "@#{key}", value
|
|
|
|
end
|
|
|
|
end
|
2013-06-03 23:19:03 +00:00
|
|
|
|
2013-06-04 22:39:56 +00:00
|
|
|
def auto_scaling_instances
|
|
|
|
@auto_scaling_instances ||= [AWS::FakeAutoScaling::Instance.new(self), AWS::FakeAutoScaling::Instance.new(self)]
|
2013-06-04 01:51:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_balancers
|
|
|
|
@load_balancers ||= AWS::FakeELB::LoadBalancerCollection.new
|
2013-06-03 23:19:03 +00:00
|
|
|
end
|
2013-06-05 01:20:34 +00:00
|
|
|
|
|
|
|
def ec2_instances
|
|
|
|
auto_scaling_instances.map(&:ec2_instance)
|
|
|
|
end
|
2013-05-31 20:08:23 +00:00
|
|
|
end
|
2013-06-04 22:39:56 +00:00
|
|
|
|
|
|
|
class Instance
|
|
|
|
def initialize(group)
|
|
|
|
@group = group
|
|
|
|
end
|
|
|
|
|
|
|
|
def terminate(decrement_desired_capacity)
|
|
|
|
@group.update(desired_capacity: @group.desired_capacity - 1) if decrement_desired_capacity
|
|
|
|
end
|
|
|
|
|
|
|
|
def id
|
|
|
|
'i-test'
|
|
|
|
end
|
2013-06-04 22:52:38 +00:00
|
|
|
|
|
|
|
def ec2_instance
|
2013-06-05 01:20:34 +00:00
|
|
|
AWS::FakeEC2::Instance.new(self.id)
|
2013-06-04 22:52:38 +00:00
|
|
|
end
|
2013-06-04 22:39:56 +00:00
|
|
|
end
|
2013-05-30 23:19:08 +00:00
|
|
|
end
|
|
|
|
end
|