def _extract_instance_info(instances):
 ret = {}
 for instance in instances:
  if isinstance(instance['instancesSet']['item'], list):
   for item in instance['instancesSet']['item']:
    name = _extract_name_tag(item)
    ret[name] = item
    ret[name]['name'] = name
    ret[name].update(dict(id=item['instanceId'], image=item['imageId'], size=item['instanceType'], state=item['instanceState']['name'], private_ips=item.get('privateIpAddress', []), public_ips=item.get('ipAddress', [])))
  else:
   item = instance['instancesSet']['item']
   name = _extract_name_tag(item)
   ret[name] = item
   ret[name]['name'] = name
   ret[name].update(dict(id=item['instanceId'], image=item['imageId'], size=item['instanceType'], state=item['instanceState']['name'], private_ips=item.get('privateIpAddress', []), public_ips=item.get('ipAddress', [])))
 return ret

def _extract_instance_info ( instances ) : ret = { } for instance in instances : if isinstance ( instance [ 'instancesSet' ] [ 'item' ] , list ) : for item in instance [ 'instancesSet' ] [ 'item' ] : name = _extract_name_tag ( item ) ret [ name ] = item ret [ name ] [ 'name' ] = name ret [ name ] . update ( dict ( id = item [ 'instanceId' ] , image = item [ 'imageId' ] , size = item [ 'instanceType' ] , state = item [ 'instanceState' ] [ 'name' ] , private_ips = item . get ( 'privateIpAddress' , [ ] ) , public_ips = item . get ( 'ipAddress' , [ ] ) ) ) else : item = instance [ 'instancesSet' ] [ 'item' ] name = _extract_name_tag ( item ) ret [ name ] = item ret [ name ] [ 'name' ] = name ret [ name ] . update ( dict ( id = item [ 'instanceId' ] , image = item [ 'imageId' ] , size = item [ 'instanceType' ] , state = item [ 'instanceState' ] [ 'name' ] , private_ips = item . get ( 'privateIpAddress' , [ ] ) , public_ips = item . get ( 'ipAddress' , [ ] ) ) ) return ret
given an instance query .