Class: PoolParty::EC2ResponseObject
- Defined in:
- lib/modules/ec2_wrapper.rb
Overview
Provides a simple class to wrap around the amazon responses
Class Method Summary collapse
- .get_descriptions(resp) ⇒ Object
- .get_hash_from_response(resp) ⇒ Object
- .get_response_from(resp) ⇒ Object
Class Method Details
.get_descriptions(resp) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/modules/ec2_wrapper.rb', line 61 def self.get_descriptions(resp) rs = get_response_from(resp) # puts rs.methods.sort - rs.ancestors.methods out = begin if rs.respond_to?(:instancesSet) [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)] else rs.collect {|r| if r.instancesSet.item.class == Array r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)} else [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)] end }.flatten.reject {|a| a.nil? } end rescue Exception => e # Really weird bug with amazon's ec2 gem rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue [] end out end |
.get_hash_from_response(resp) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/modules/ec2_wrapper.rb', line 94 def self.get_hash_from_response(resp) begin { :instance_id => resp.instanceId, :ip => resp.dnsName, :status => resp.instanceState.name, :launching_time => resp.launchTime, :keypair => resp.keyName } rescue Exception => e nil end end |
.get_response_from(resp) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/modules/ec2_wrapper.rb', line 84 def self.get_response_from(resp) begin rs = resp.reservationSet.item unless resp.reservationSet.nil? rs ||= resp.DescribeInstancesResponse.reservationSet.item rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs rs.reject! {|a| a.nil? || a.empty? } rescue Exception => e end rs end |