Class: Opsicle::CloneInstance
- Inherits:
-
Object
- Object
- Opsicle::CloneInstance
- Defined in:
- lib/opsicle/commands/clone_instance.rb
Instance Method Summary collapse
- #execute(options = {}) ⇒ Object
-
#initialize(environment) ⇒ CloneInstance
constructor
A new instance of CloneInstance.
- #select_instances(instances) ⇒ Object
- #select_layer ⇒ Object
Constructor Details
#initialize(environment) ⇒ CloneInstance
Returns a new instance of CloneInstance.
10 11 12 13 14 15 16 |
# File 'lib/opsicle/commands/clone_instance.rb', line 10 def initialize(environment) @client = Client.new(environment) @opsworks = @client.opsworks stack_id = @client.config.opsworks_config[:stack_id] @stack = CloneableStack.new(@client.config.opsworks_config[:stack_id], @opsworks) @cli = HighLine.new end |
Instance Method Details
#execute(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/opsicle/commands/clone_instance.rb', line 18 def execute(={}) puts "Stack ID = #{@stack.id}" layer = select_layer all_instances = layer.get_cloneable_instances instances_to_clone = select_instances(all_instances) instances_to_clone.each do |instance| instance.clone() end end |
#select_instances(instances) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opsicle/commands/clone_instance.rb', line 43 def select_instances(instances) puts "\nInstances:\n" instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" } instance_indices_string = @cli.ask("Instances? (enter as a comma separated list)\n", String) instance_indices_list = instance_indices_string.split(/,\s*/) instance_indices_list.map! { |instance_index| instance_index.to_i - 1 } return_array = [] instance_indices_list.each do |index| return_array << instances[index] end return_array end |
#select_layer ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/opsicle/commands/clone_instance.rb', line 29 def select_layer puts "\nLayers:\n" ops_layers = @opsworks.describe_layers({ :stack_id => @stack.id }).layers layers = [] ops_layers.each do |layer| layers << CloneableLayer.new(layer.name, layer.layer_id, @opsworks, @cli) end layers.each_with_index { |layer, index| puts "#{index.to_i + 1}) #{layer.name}"} layer_index = @cli.ask("Layer?\n", Integer) { |q| q.in = 1..layers.length.to_i } - 1 layers[layer_index] end |