Class: Opsicle::ManageableStack

Inherits:
Object
  • Object
show all
Defined in:
lib/opsicle/manageable_stack.rb

Constant Summary collapse

STOPPABLE_STATES =
%w(start_failed stop_failed online running_setup setup_failed booting rebooting)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack_id, opsworks_adapter, cli = nil) ⇒ ManageableStack

Returns a new instance of ManageableStack.



7
8
9
10
11
12
13
# File 'lib/opsicle/manageable_stack.rb', line 7

def initialize(stack_id, opsworks_adapter, cli=nil)
  self.id = stack_id
  self.opsworks_adapter = opsworks_adapter
  self.cli = cli
  self.stack = @opsworks_adapter.stack(id)
  self.vpc_id = self.stack.vpc_id
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def cli
  @cli
end

#eipsObject

Returns the value of attribute eips.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def eips
  @eips
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def id
  @id
end

#opsworks_adapterObject

Returns the value of attribute opsworks_adapter.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def opsworks_adapter
  @opsworks_adapter
end

#stackObject

Returns the value of attribute stack.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def stack
  @stack
end

#vpc_idObject

Returns the value of attribute vpc_id.



3
4
5
# File 'lib/opsicle/manageable_stack.rb', line 3

def vpc_id
  @vpc_id
end

Instance Method Details

#deleteable_instances(layer) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/opsicle/manageable_stack.rb', line 41

def deleteable_instances(layer)
  instances.select do |instance|
    instance.auto_scaling_type.nil? &&
    instance.status == "stopped" &&
    instance.layer_ids.include?(layer.layer_id)
  end
end

#instancesObject



37
38
39
# File 'lib/opsicle/manageable_stack.rb', line 37

def instances
  @opsworks_adapter.instances_by_stack(id)
end

#stoppable_instances(layer) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/opsicle/manageable_stack.rb', line 49

def stoppable_instances(layer)
  instances.select do |instance|
    instance.elastic_ip.nil? &&
    STOPPABLE_STATES.include?(instance.status) &&
    instance.layer_ids.include?(layer.layer_id)
  end
end

#transfer_eip(moveable_eip, target_instance_id) ⇒ Object



33
34
35
# File 'lib/opsicle/manageable_stack.rb', line 33

def transfer_eip(moveable_eip, target_instance_id)
  @opsworks_adapter.associate_elastic_ip(moveable_eip[:ip_address], target_instance_id)
end