Class: BaseMethods
- Inherits:
-
Object
- Object
- BaseMethods
- Defined in:
- lib/base_methods.rb
Class Method Summary collapse
-
.describe_instance_by_region(region) ⇒ Object
Returns array of instances in specific region.
-
.describe_regions ⇒ Object
Returns array of regions.
- .instance_action(instance_id, action, region) ⇒ Object
- .start_over(region) ⇒ Object
Class Method Details
.describe_instance_by_region(region) ⇒ Object
Returns array of instances in specific region
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/base_methods.rb', line 18 def self.describe_instance_by_region(region) StartingConfiguration.config # TODO Refactor @instances = [] client = AWS::EC2::Client.new(:region => region) instances = client.describe_instances instances[:reservation_set].each do | instance | @tags = [] instance[:instances_set].first[:tag_set].each do |tag| @tags << {tag[:key] => tag[:value]} if tag[:key] == "Name" @name = tag[:value] end end hash = { :instance_id => instance[:instances_set].first[:instance_id], :ip_address => instance[:instances_set].first[:ip_address], :instance_state => instance[:instances_set].first[:instance_state][:name], :launch_time => instance[:instances_set].first[:launch_time], :name => @name, :keypair => instance[:instances_set].first[:key_name] } @tags.each do |tag| hash.merge!(tag) end @instances << hash end return @instances end |
.describe_regions ⇒ Object
Returns array of regions
11 12 13 14 15 |
# File 'lib/base_methods.rb', line 11 def self.describe_regions regions = AWS::Core::RegionCollection.new @array = [] regions.each { |region| @array << region.name } end |
.instance_action(instance_id, action, region) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/base_methods.rb', line 50 def self.instance_action(instance_id, action, region) ec2 = AWS::EC2.new(:region => region) i = ec2.instances[instance_id] if action == "start" i.start elsif action == "stop" i.stop elsif action == "terminate" i.terminate else end end |
.start_over(region) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/base_methods.rb', line 63 def self.start_over(region) question = Questions.new # Start Process if region == "none" # Select a region @region = question.region else @region = region end # Select an Instance @selected_instance = question.select_instance(@region) # Select the action @instance = question.instance_action(@selected_instance) end |