def list_vms(host=None): """ make a list of vms and expand out their fixed_ip and floating ips sensibly """ flags.parse_args([]) my_instances = [] if host is None: instances = db.instance_get_all(context.get_admin_context()) else: instances = db.instance_get_all_by_host( context.get_admin_context(), host) for instance in instances: my_inst = {} my_inst = dict(instance).copy() for (k,v) in my_inst.items(): try: json.encoder(v) except TypeError, e: v = str(v) my_inst[k] = v ec2_id = db.get_ec2_instance_id_by_uuid(context.get_admin_context(), instance.uuid) ec2_id = 'i-' + hex(int(ec2_id)).replace('0x', '').zfill(8) my_inst['ec2_id'] = ec2_id try: fixed_ips = db.fixed_ip_get_by_instance(context.get_admin_context(), instance.uuid) except: pass my_inst['fixed_ips'] = [ ip.address for ip in fixed_ips ] my_inst['floating_ips'] = [] for ip in fixed_ips: my_inst['floating_ips'].extend([ f_ip.address for f_ip in db.floating_ip_get_by_fixed_address(context.get_admin_context(), ip.address)]) my_instances.append(my_inst)
def list_vms(host=None): """ make a list of vms and expand out their fixed_ip and floating ips sensibly """ flags.parse_args([]) my_instances = [] if host is None: instances = db.instance_get_all(context.get_admin_context()) else: instances = db.instance_get_all_by_host(context.get_admin_context(), host) for instance in instances: my_inst = {} my_inst = dict(instance).copy() for (k, v) in my_inst.items(): try: json.encoder(v) except TypeError, e: v = str(v) my_inst[k] = v ec2_id = db.get_ec2_instance_id_by_uuid(context.get_admin_context(), instance.uuid) ec2_id = 'i-' + hex(int(ec2_id)).replace('0x', '').zfill(8) my_inst['ec2_id'] = ec2_id try: fixed_ips = db.fixed_ip_get_by_instance( context.get_admin_context(), instance.uuid) except: pass my_inst['fixed_ips'] = [ip.address for ip in fixed_ips] my_inst['floating_ips'] = [] for ip in fixed_ips: my_inst['floating_ips'].extend([ f_ip.address for f_ip in db.floating_ip_get_by_fixed_address( context.get_admin_context(), ip.address) ]) my_instances.append(my_inst)
def get_floating_ips_by_fixed_address(self, context, fixed_address): return db.floating_ip_get_by_fixed_address(context, fixed_address)
def get_by_fixed_address(cls, context, fixed_address): db_floatingips = db.floating_ip_get_by_fixed_address( context, str(fixed_address)) return obj_base.obj_make_list(context, cls(context), objects.FloatingIP, db_floatingips)
def get_floating_ips_by_fixed_address(self, context, fixed_address): return db.floating_ip_get_by_fixed_address(context, fixed_address)
def get_by_fixed_address(cls, context, fixed_address): db_floatingips = db.floating_ip_get_by_fixed_address( context, str(fixed_address)) return obj_base.obj_make_list(context, cls(context), objects.FloatingIP, db_floatingips)