def _check_vifs(self, expect_num_vifs): ctx = context.RequestContext('user1', "").elevated() self.assertEqual(len(db.virtual_interface_get_all(ctx)), expect_num_vifs)
def index(self, req): """Return all flavors in brief.""" #flavors = self._get_flavors(req) #return self._view_builder.index(req, flavors) project_id=str(req.environ['HTTP_X_TENANT_ID']) context = req.environ['nova.context'] context = context.elevated() networks = db.network_get_all(context) nets=[dict(network.iteritems()) for network in networks] virtual_interfaces = db.virtual_interface_get_all(context) vifs=[dict(vif.iteritems()) for vif in virtual_interfaces] #make a dict of relationships between Network_IDs and Instance_IDs {1:[1,2],...} net_vm_dict = {} for vif in vifs: net_id=int(vif['network_id']) vm_id=int(vif['instance_id']) if net_id in net_vm_dict: net_vm_dict[net_id].append(vm_id) else: net_vm_dict[net_id] = [vm_id] print net_vm_dict #Go through the dict , filter by this project and get detailed infos #instance_get(context, instance_id) net_list = [] for netID in net_vm_dict: networks= db.network_get(context, netID) net = dict(networks.iteritems()) print str(net['project_id']) if net['project_id']==None or net['project_id']==project_id: print "my precious~~" net_info = {} net_info['id']=str(net['uuid']) net_info['name']=str(net['label']) net_info['cidr']=str(net['cidr']) net_info['vm']=[] net_list.append(net_info) for vmID in net_vm_dict[netID]: vms = db.instance_get(context, vmID) vm = dict(vms.iteritems()) if vm['project_id']==project_id: print "My VM" vm_info = {} #Get vm infos for each VM vm_info['name']=str(vm['hostname']) vm_info['id']=str(vm['uuid']) vm_info['vm_state']=str(vm['vm_state']) #Get fixed_ips for each VM fixed_ips = db.fixed_ip_get_by_instance(context, vmID) fixed_ip_info = [] for ip in fixed_ips: fixed_ip_info.append(str(dict(ip.iteritems())['address'])) vm_info['fixed_ips'] = fixed_ip_info #Get Floating_ips for each VM floating_ip_info = [] for fixed_ip in fixed_ip_info: try: floating_ips = db.floating_ip_get_by_address(context, fixed_ip) except exception.FloatingIpNotFoundForAddress: print "floating not found" continue if floating_ips != None: for floating_ip in floating_ips: floating_ip_info.append(str(dict(ip.floating_ip.iteritems()['address']))) vm_info['floating_ips']=floating_ip_info net_info['vm'].append(vm_info) ret_net_list={} ret_net_list['networks']=net_list print ret_net_list return ret_net_list
def _check_vifs(self, expect_num_vifs): ctx = context.RequestContext('user1', "").elevated() self.assertEqual(len(db.virtual_interface_get_all(ctx)), expect_num_vifs)
def get_all(cls, context): db_vifs = db.virtual_interface_get_all(context) return base.obj_make_list(context, cls(context), objects.VirtualInterface, db_vifs)
def get_all(cls, context): db_vifs = db.virtual_interface_get_all(context) return base.obj_make_list(context, cls(context), objects.VirtualInterface, db_vifs)