Multi-DVS Support When Hypervisor is vCenter

This patcset supports multi DVS when network type is portgroup

Change-Id: Ic983182f5039ba67f12aa545ff670be7500ba6da
Partial-Bug:#1714428
This commit is contained in:
kvrshenoy 2018-09-14 22:41:43 -07:00 committed by Michal Kelner Mishali
parent f4ae18ea6c
commit 8177c8486e
3 changed files with 49 additions and 28 deletions

View File

@ -167,29 +167,49 @@ class DvsManager(VCManagerBase):
'vlan_tag': vlan_tag,
'dvs': dvs_moref.value})
def _get_portgroup(self, net_id):
"""Get the port group moref of the net_id."""
results = self._session.invoke_api(vim_util,
'get_objects',
self._session.vim,
'DistributedVirtualPortgroup',
100)
while results:
for pg in results.objects:
for prop in pg.propSet:
if net_id == prop.val:
vim_util.cancel_retrieval(self._session.vim, results)
return pg.obj
results = vim_util.continue_retrieval(self._session.vim, results)
raise exceptions.NetworkNotFound(net_id=net_id)
def _net_id_to_moref(self, dvs_moref, net_id):
"""Gets the moref for the specific neutron network."""
# NOTE(garyk): return this from a cache if not found then invoke
# code below.
port_groups = self._session.invoke_api(vim_util,
'get_object_properties',
self._session.vim,
dvs_moref,
['portgroup'])
if len(port_groups) and hasattr(port_groups[0], 'propSet'):
for prop in port_groups[0].propSet:
for val in prop.val[0]:
props = self._session.invoke_api(vim_util,
'get_object_properties',
self._session.vim,
val, ['name'])
if len(props) and hasattr(props[0], 'propSet'):
for prop in props[0].propSet:
# match name or mor id
if net_id == prop.val or net_id == val.value:
# NOTE(garyk): update cache
return val
raise exceptions.NetworkNotFound(net_id=net_id)
if dvs_moref:
port_groups = self._session.invoke_api(vim_util,
'get_object_properties',
self._session.vim,
dvs_moref,
['portgroup'])
if len(port_groups) and hasattr(port_groups[0], 'propSet'):
for prop in port_groups[0].propSet:
for val in prop.val[0]:
props = self._session.invoke_api(
vim_util,
'get_object_properties',
self._session.vim,
val, ['name'])
if len(props) and hasattr(props[0], 'propSet'):
for prop in props[0].propSet:
# match name or mor id
if net_id == prop.val or net_id == val.value:
# NOTE(garyk): update cache
return val
raise exceptions.NetworkNotFound(net_id=net_id)
else:
return self._get_portgroup(net_id)
def _is_vlan_network_by_moref(self, moref):
"""
@ -409,7 +429,7 @@ class DvsManager(VCManagerBase):
'get_object_properties_dict',
self._session.vim,
pg_moref, properties)
return pg_info
return pg_info, pg_moref
def _get_dvs_moref_from_teaming_data(self, teaming_data):
"""Get the moref dvs that belongs to the teaming data"""

View File

@ -188,6 +188,10 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
trunk_mode=trunk_mode)
return dvs_name
def _get_portgroup_info(self, net_id):
pg_info, dvpg_moref = self._dvs.dvs.get_port_group_info(None, net_id)
return pg_info, dvpg_moref
def _dvs_create_network(self, context, network):
net_data = network['network']
if net_data['admin_state_up'] is False:
@ -207,13 +211,12 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
net_id = dvs_name = None
if net_data.get(pnet.NETWORK_TYPE) == c_utils.NetworkTypes.PORTGROUP:
net_id = net_data.get(pnet.PHYSICAL_NETWORK)
pg_info = self._dvs.get_port_group_info(net_id)
pg_info, dvpg_moref = self._get_portgroup_info(net_id)
if pg_info.get('name') != net_data.get('name'):
err_msg = (_("Portgroup name %(dvpg)s must match network "
"name %(network)s") % {'dvpg': pg_info.get('name'),
'network': net_data.get('name')})
raise n_exc.InvalidInput(error_message=err_msg)
dvpg_moref = self._dvs.net_id_to_moref(net_id)
dvs_id = dvpg_moref.value
else:
dvs_id = self._dvs_get_id(net_data)

View File

@ -221,11 +221,10 @@ class NeutronSimpleDvsTest(NeutronSimpleDvsTestCase):
@mock.patch.object(dvs.DvsManager, 'get_port_group_info')
@mock.patch.object(dvs.DvsManager, '_net_id_to_moref')
def test_create_and_delete_dvs_network_portgroup(self, fake_get_moref,
def test_create_and_delete_dvs_network_portgroup(self, fake_moref,
fake_pg_info):
fake_pg_info.return_value = {'name': 'fake-name'}
fake_pg_info.return_value = {'name': 'fake-name'}, fake_moref
self._create_and_delete_dvs_network(network_type='portgroup')
self.assertTrue(fake_get_moref.call_count)
self.assertTrue(fake_pg_info.call_count)
@mock.patch.object(dvs.DvsManager, 'get_port_group_info')
@ -233,10 +232,9 @@ class NeutronSimpleDvsTest(NeutronSimpleDvsTestCase):
def test_create_and_delete_dvs_network_portgroup_vlan(self,
fake_get_moref,
fake_pg_info):
fake_pg_info.return_value = {'name': 'fake-name'}
fake_pg_info.return_value = {'name': 'fake-name'}, fake_get_moref
self._create_and_delete_dvs_network(network_type='portgroup',
vlan_tag=7)
self.assertTrue(fake_get_moref.call_count)
self.assertTrue(fake_pg_info.call_count)
def test_create_and_delete_dvs_port(self):
@ -333,7 +331,7 @@ class NeutronSimpleDvsTest(NeutronSimpleDvsTestCase):
def test_create_and_delete_portgroup_network_invalid_name(self,
fake_get_moref,
fake_pg_info):
fake_pg_info.return_value = {'name': 'fake-different-name'}
fake_pg_info.return_value = {'name': 'invalid-name'}, fake_get_moref
data = {'network': {'provider:network_type': 'portgroup',
'name': 'fake-name',
'admin_state_up': True}}