Module: PoolParty::Ec2Wrapper::InstanceMethods
- Defined in:
- lib/modules/ec2_wrapper.rb
Instance Method Summary collapse
- #associate_address_with(ip, instance_id) ⇒ Object
-
#describe_instance(id) ⇒ Object
Instance description.
-
#ec2 ⇒ Object
EC2 connections.
-
#get_instance_by_id(id) ⇒ Object
Get instance by id.
-
#get_instances_description ⇒ Object
Get the s3 description for the response in a hash format.
-
#launch_new_instance! ⇒ Object
Run a new instance, with the user_data and the ami described in the config.
- #reset! ⇒ Object
-
#terminate_instance!(instance_id) ⇒ Object
Shutdown the instance by instance_id.
Instance Method Details
#associate_address_with(ip, instance_id) ⇒ Object
30 31 32 |
# File 'lib/modules/ec2_wrapper.rb', line 30 def associate_address_with(ip, instance_id) ec2.associate_address(:instance_id => instance_id, :public_ip => ip) end |
#describe_instance(id) ⇒ Object
Instance description
34 35 36 |
# File 'lib/modules/ec2_wrapper.rb', line 34 def describe_instance(id) EC2ResponseObject.get_hash_from_response(ec2.describe_instances(:instance_id => id)) end |
#ec2 ⇒ Object
EC2 connections
46 47 48 |
# File 'lib/modules/ec2_wrapper.rb', line 46 def ec2 @ec2 ||= EC2::Base.new(:access_key_id => Application.access_key, :secret_access_key => Application.secret_access_key) end |
#get_instance_by_id(id) ⇒ Object
Get instance by id
38 39 40 |
# File 'lib/modules/ec2_wrapper.rb', line 38 def get_instance_by_id(id) get_instances_description.select {|a| a.instance_id == id}[0] rescue nil end |
#get_instances_description ⇒ Object
Get the s3 description for the response in a hash format
42 43 44 |
# File 'lib/modules/ec2_wrapper.rb', line 42 def get_instances_description @cached_descriptions ||= EC2ResponseObject.get_descriptions(ec2.describe_instances) end |
#launch_new_instance! ⇒ Object
Run a new instance, with the user_data and the ami described in the config
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/modules/ec2_wrapper.rb', line 11 def launch_new_instance! instance = ec2.run_instances( :image_id => Application.ami, :user_data => "#{Application.launching_user_data}", :minCount => 1, :maxCount => 1, :key_name => "#{Application.keypair}", :availability_zone => nil, :size => "#{Application.size}") begin item = instance#.instancesSet.item EC2ResponseObject.get_hash_from_response(item) rescue Exception => e end end |
#reset! ⇒ Object
49 50 51 |
# File 'lib/modules/ec2_wrapper.rb', line 49 def reset! @cached_descriptions = nil end |
#terminate_instance!(instance_id) ⇒ Object
Shutdown the instance by instance_id
27 28 29 |
# File 'lib/modules/ec2_wrapper.rb', line 27 def terminate_instance!(instance_id) ec2.terminate_instances(:instance_id => instance_id) end |