Class: EC2ResponseObject
- Defined in:
- lib/poolparty/net/remote_bases/ec2.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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/poolparty/net/remote_bases/ec2.rb', line 98 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/poolparty/net/remote_bases/ec2.rb', line 131 def self.get_hash_from_response(resp) begin { :instance_id => resp.instanceId, :name => resp.instanceId, :ip => resp.dnsName || "not-assigned", :status => resp.instanceState.name, :launching_time => resp.launchTime, :keypair => resp.keyName } rescue Exception => e nil end end |
.get_response_from(resp) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/poolparty/net/remote_bases/ec2.rb', line 121 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 |