コード例 #1
0
ファイル: test_network.py プロジェクト: anotherjesse/nova
 def test_public_network_association(self):
     """Makes sure that we can allocaate a public ip"""
     # TODO(vish): better way of adding floating ips
     self.context._project = self.projects[0]
     self.context.project_id = self.projects[0].id
     pubnet = IPy.IP(flags.FLAGS.floating_range)
     address = str(pubnet[0])
     try:
         db.floating_ip_get_by_address(context.get_admin_context(), address)
     except exception.NotFound:
         db.floating_ip_create(context.get_admin_context(),
                               {'address': address,
                                'host': FLAGS.host})
     float_addr = self.network.allocate_floating_ip(self.context,
                                                    self.projects[0].id)
     fix_addr = self._create_address(0)
     lease_ip(fix_addr)
     self.assertEqual(float_addr, str(pubnet[0]))
     self.network.associate_floating_ip(self.context, float_addr, fix_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, float_addr)
     self.network.disassociate_floating_ip(self.context, float_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, None)
     self.network.deallocate_floating_ip(self.context, float_addr)
     self.network.deallocate_fixed_ip(self.context, fix_addr)
     release_ip(fix_addr)
     db.floating_ip_destroy(context.get_admin_context(), float_addr)
コード例 #2
0
 def test_public_network_association(self):
     """Makes sure that we can allocaate a public ip"""
     # TODO(vish): better way of adding floating ips
     self.context._project = self.projects[0]
     self.context.project_id = self.projects[0].id
     pubnet = IPy.IP(flags.FLAGS.floating_range)
     address = str(pubnet[0])
     try:
         db.floating_ip_get_by_address(context.get_admin_context(), address)
     except exception.NotFound:
         db.floating_ip_create(context.get_admin_context(), {
             'address': address,
             'host': FLAGS.host
         })
     float_addr = self.network.allocate_floating_ip(self.context,
                                                    self.projects[0].id)
     fix_addr = self._create_address(0)
     lease_ip(fix_addr)
     self.assertEqual(float_addr, str(pubnet[0]))
     self.network.associate_floating_ip(self.context, float_addr, fix_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, float_addr)
     self.network.disassociate_floating_ip(self.context, float_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, None)
     self.network.deallocate_floating_ip(self.context, float_addr)
     self.network.deallocate_fixed_ip(self.context, fix_addr)
     release_ip(fix_addr)
     db.floating_ip_destroy(context.get_admin_context(), float_addr)
コード例 #3
0
ファイル: test_floating_ips.py プロジェクト: nicoleLiu/nova
 def test_translate_floating_ip_view(self):
     floating_ip_address = self._create_floating_ip()
     floating_ip = db.floating_ip_get_by_address(self.context, floating_ip_address)
     view = floating_ips._translate_floating_ip_view(floating_ip)
     self.assertTrue("floating_ip" in view)
     self.assertTrue(view["floating_ip"]["id"])
     self.assertEqual(view["floating_ip"]["ip"], self.address)
     self.assertEqual(view["floating_ip"]["fixed_ip"], None)
     self.assertEqual(view["floating_ip"]["instance_id"], None)
コード例 #4
0
 def test_translate_floating_ip_view(self):
     floating_ip_address = self._create_floating_ip()
     floating_ip = db.floating_ip_get_by_address(self.context,
                                                 floating_ip_address)
     view = _translate_floating_ip_view(floating_ip)
     self.assertTrue('floating_ip' in view)
     self.assertTrue(view['floating_ip']['id'])
     self.assertEqual(view['floating_ip']['ip'], self.address)
     self.assertEqual(view['floating_ip']['fixed_ip'], None)
     self.assertEqual(view['floating_ip']['instance_id'], None)
コード例 #5
0
ファイル: test_floating_ips.py プロジェクト: nicoleLiu/nova
 def test_translate_floating_ip_view(self):
     floating_ip_address = self._create_floating_ip()
     floating_ip = db.floating_ip_get_by_address(self.context,
                                                 floating_ip_address)
     view = floating_ips._translate_floating_ip_view(floating_ip)
     self.assertTrue('floating_ip' in view)
     self.assertTrue(view['floating_ip']['id'])
     self.assertEqual(view['floating_ip']['ip'], self.address)
     self.assertEqual(view['floating_ip']['fixed_ip'], None)
     self.assertEqual(view['floating_ip']['instance_id'], None)
コード例 #6
0
ファイル: test_floating_ips.py プロジェクト: isyippee/nova
 def test_translate_floating_ip_view(self):
     floating_ip_address = self.floating_ip
     floating_ip = db.floating_ip_get_by_address(self.context, floating_ip_address)
     # NOTE(vish): network_get uses the id not the address
     floating_ip = db.floating_ip_get(self.context, floating_ip["id"])
     view = self.floating_ips._translate_floating_ip_view(floating_ip)
     self.assertIn("floating_ip", view)
     self.assertTrue(view["floating_ip"]["id"])
     self.assertEqual(view["floating_ip"]["ip"], self.floating_ip)
     self.assertIsNone(view["floating_ip"]["fixed_ip"])
     self.assertIsNone(view["floating_ip"]["instance_id"])
コード例 #7
0
 def test_translate_floating_ip_view(self):
     floating_ip_address = self.floating_ip
     floating_ip = db.floating_ip_get_by_address(self.context,
                                                 floating_ip_address)
     # NOTE(vish): network_get uses the id not the address
     floating_ip = db.floating_ip_get(self.context, floating_ip['id'])
     view = self.floating_ips._translate_floating_ip_view(floating_ip)
     self.assertIn('floating_ip', view)
     self.assertTrue(view['floating_ip']['id'])
     self.assertEqual(view['floating_ip']['ip'], self.floating_ip)
     self.assertIsNone(view['floating_ip']['fixed_ip'])
     self.assertIsNone(view['floating_ip']['instance_id'])
コード例 #8
0
 def test_translate_floating_ip_view(self):
     floating_ip_address = self.floating_ip
     floating_ip = db.floating_ip_get_by_address(self.context,
                                                 floating_ip_address)
     floating_ip['fixed_ip'] = None
     floating_ip['instance'] = None
     view = floating_ips_search._translate_floating_ip_view(floating_ip)
     self.assertTrue('floating_ip' in view)
     self.assertTrue(view['floating_ip']['id'])
     self.assertEqual(view['floating_ip']['ip'], self.floating_ip)
     self.assertEqual(view['floating_ip']['fixed_ip'], None)
     self.assertEqual(view['floating_ip']['instance_id'], None)
コード例 #9
0
ファイル: test_floating_ips.py プロジェクト: AnyBucket/nova
 def test_translate_floating_ip_view(self):
     floating_ip_address = self.floating_ip
     floating_ip = db.floating_ip_get_by_address(self.context,
                                                 floating_ip_address)
     # NOTE(vish): network_get uses the id not the address
     floating_ip = db.floating_ip_get(self.context, floating_ip['id'])
     self.controller._normalize_ip(floating_ip)
     view = floating_ips._translate_floating_ip_view(floating_ip)
     self.assertTrue('floating_ip' in view)
     self.assertTrue(view['floating_ip']['id'])
     self.assertEqual(view['floating_ip']['ip'], self.floating_ip)
     self.assertEqual(view['floating_ip']['fixed_ip'], None)
     self.assertEqual(view['floating_ip']['instance_id'], None)
コード例 #10
0
    def test_translate_floating_ip_view(self):
        floating_ip_address = self.floating_ip
        floating_ip = db.floating_ip_get_by_address(self.context,
                                                    floating_ip_address)
        # NOTE(vish): network_get uses the id not the address
        floating_ip = db.floating_ip_get(self.context, floating_ip['id'])
        floating_obj = objects.FloatingIP()
        objects.FloatingIP._from_db_object(self.context, floating_obj,
                                           floating_ip)

        view = self.floating_ips._translate_floating_ip_view(floating_obj)

        self.assertIn('floating_ip', view)
        self.assertTrue(view['floating_ip']['id'])
        self.assertEqual(view['floating_ip']['ip'], floating_obj.address)
        self.assertIsNone(view['floating_ip']['fixed_ip'])
        self.assertIsNone(view['floating_ip']['instance_id'])
コード例 #11
0
 def get_by_address(cls, context, address):
     db_floatingip = db.floating_ip_get_by_address(context, str(address))
     return cls._from_db_object(context, cls(context), db_floatingip)
コード例 #12
0
ファイル: floating_ip.py プロジェクト: EliseCheng/nova
 def get_by_address(cls, context, address):
     db_floatingip = db.floating_ip_get_by_address(context, str(address))
     return cls._from_db_object(context, cls(context), db_floatingip)
コード例 #13
0
    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