Class: Opsicle::CloneInstance
- Inherits:
-
Object
- Object
- Opsicle::CloneInstance
- Defined in:
- lib/opsicle/commands/clone_instance.rb
Instance Method Summary collapse
- #clone_instances(instances, options) ⇒ Object
- #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.
11 12 13 14 15 16 17 |
# File 'lib/opsicle/commands/clone_instance.rb', line 11 def initialize(environment) @client = Client.new(environment) @opsworks_adapter = OpsworksAdapter.new(@client) stack_id = @client.config.opsworks_config[:stack_id] @stack = ManageableStack.new(stack_id, @opsworks_adapter.client) @cli = HighLine.new end |
Instance Method Details
#clone_instances(instances, options) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/opsicle/commands/clone_instance.rb', line 29 def clone_instances(instances, ) if [:'with-defaults'] instances.each { |instance| instance.clone_with_defaults() } else instances.each { |instance| instance.clone() } end end |
#execute(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/opsicle/commands/clone_instance.rb', line 19 def execute(={}) puts "Stack ID = #{@stack.id}" layer = select_layer all_instances = layer.get_cloneable_instances instance_to_clone = select_instances(all_instances) clone_instances(instance_to_clone, ) layer.ami_id = nil layer.agent_version = nil end |
#select_instances(instances) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/opsicle/commands/clone_instance.rb', line 51 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
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/opsicle/commands/clone_instance.rb', line 37 def select_layer puts "\nLayers:\n" ops_layers = @opsworks_adapter.get_layers(@stack.id) layers = [] ops_layers.each do |layer| layers << ManageableLayer.new(layer.name, layer.layer_id, @stack, @opsworks_adapter.client, @client.ec2, @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 |