Class: Opsicle::AddTags
- Inherits:
-
Object
- Object
- Opsicle::AddTags
- Defined in:
- lib/opsicle/commands/add_tags.rb
Instance Method Summary collapse
- #add_tags_to_instances(instances) ⇒ Object
- #execute(options = {}) ⇒ Object
-
#initialize(environment) ⇒ AddTags
constructor
A new instance of AddTags.
- #select_instances(instances) ⇒ Object
- #select_layer ⇒ Object
Constructor Details
#initialize(environment) ⇒ AddTags
Returns a new instance of AddTags.
12 13 14 15 16 17 18 19 |
# File 'lib/opsicle/commands/add_tags.rb', line 12 def initialize(environment) @client = Client.new(environment) @ec2_adapter = Ec2Adapter.new(@client) @opsworks_adapter = OpsworksAdapter.new(@client) stack_id = @client.config.opsworks_config[:stack_id] @stack = ManageableStack.new(stack_id, @opsworks_adapter) @cli = HighLine.new end |
Instance Method Details
#add_tags_to_instances(instances) ⇒ Object
29 30 31 |
# File 'lib/opsicle/commands/add_tags.rb', line 29 def (instances) instances.each { |instance| instance.({add_tags_mode: true}) } end |
#execute(options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/opsicle/commands/add_tags.rb', line 21 def execute(={}) puts "Stack ID = #{@stack.id}" layer = select_layer all_instances = layer.get_cloneable_instances = select_instances(all_instances) () end |
#select_instances(instances) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/opsicle/commands/add_tags.rb', line 47 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
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/opsicle/commands/add_tags.rb', line 33 def select_layer puts "\nLayers:\n" ops_layers = @opsworks_adapter.layers(@stack.id) layers = [] ops_layers.each do |layer| layers << ManageableLayer.new(layer.name, layer.layer_id, @stack, @opsworks_adapter.client, @ec2_adapter.client, @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 |