190: def list_as_hash(state=nil, inst_ids=[], &each_inst)
191: state &&= state.to_sym
192: state = nil if state == :any
193: raise "Unknown state: #{state}" if state && !Instances.known_state?(state)
194: state = 'shutting-down''shutting-down' if state == :shutting_down
195:
196:
197:
198: inst_ids = objects_to_instance_ids(inst_ids)
199:
200: response = Rudy::AWS::EC2.execute_request({}) {
201: @@ec2.describe_instances(:instance_id => inst_ids)
202: }
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213: return nil unless response['reservationSet'].is_a?(Hash)
214:
215: resids = []
216: instances = {}
217: response['reservationSet']['item'].each do |res|
218: resids << res['reservationId']
219: groups = res['groupSet']['item'].collect { |g| g['groupId'] }
220:
221: next unless res['instancesSet'].is_a?(Hash)
222: res['instancesSet']['item'].each do |props|
223: inst = Instances.from_hash(props)
224: next if state && inst.state != state.to_s
225: inst.groups = groups
226:
227: instances[inst.awsid] = inst
228: end
229: end
230:
231: instances.each_value { |inst| each_inst.call(inst) } if each_inst
232:
233: instances = nil if instances.empty?
234: instances
235: end