Make it possible for DvsManager to manage its own DVS
For the nsxv plugin when using the dvs features, we should not repeat the dvs name information unless required, as the dvs moref may be set as part of the nsxv configuration. And if the dvs moref is set in the nsxv configuration then, we should use that to initialize DvsManager. Change-Id: Ibd81190aa91f255237c76f93e0fc15ab2659d6c7
This commit is contained in:
parent
d6e2f2f6b4
commit
5cbd2831fb
@ -635,7 +635,8 @@ def validate_nsxv_config_options():
|
||||
LOG.warning(_LW("dvs_id must be configured to support VLANs!"))
|
||||
if cfg.CONF.nsxv.vdn_scope_id is None:
|
||||
LOG.warning(_LW("vdn_scope_id must be configured to support VXLANs!"))
|
||||
if cfg.CONF.nsxv.use_dvs_features and not dvs_utils.dvs_is_enabled():
|
||||
if cfg.CONF.nsxv.use_dvs_features and not dvs_utils.dvs_is_enabled(
|
||||
dvs_id=cfg.CONF.nsxv.dvs_id):
|
||||
error = _("dvs host/vcenter credentials must be defined to use "
|
||||
"dvs features")
|
||||
raise nsx_exc.NsxPluginException(err_msg=error)
|
||||
|
@ -31,7 +31,7 @@ API_FIND_ALL_BY_UUID = 'FindAllByUuid'
|
||||
class DvsManager(object):
|
||||
"""Management class for dvs related tasks."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, dvs_id=None):
|
||||
"""Initializer.
|
||||
|
||||
A global session with the VC will be established. In addition to this
|
||||
@ -42,8 +42,12 @@ class DvsManager(object):
|
||||
"""
|
||||
self._session = dvs_utils.dvs_create_session()
|
||||
# In the future we may decide to support more than one DVS
|
||||
self._dvs_moref = self._get_dvs_moref(self._session,
|
||||
dvs_utils.dvs_name_get())
|
||||
if dvs_id is None:
|
||||
self._dvs_moref = self._get_dvs_moref(self._session,
|
||||
dvs_utils.dvs_name_get())
|
||||
else:
|
||||
self._dvs_moref = vim_util.get_moref(dvs_id,
|
||||
'VmwareDistributedVirtualSwitch')
|
||||
|
||||
def _get_dvs_moref(self, session, dvs_name):
|
||||
"""Get the moref of the configured DVS."""
|
||||
@ -97,7 +101,7 @@ class DvsManager(object):
|
||||
LOG.info(_LI("%(net_id)s with tag %(vlan_tag)s created on %(dvs)s."),
|
||||
{'net_id': net_id,
|
||||
'vlan_tag': vlan_tag,
|
||||
'dvs': dvs_utils.dvs_name_get()})
|
||||
'dvs': self._dvs_moref.value})
|
||||
|
||||
def _net_id_to_moref(self, net_id):
|
||||
"""Gets the moref for the specific neutron network."""
|
||||
@ -302,7 +306,7 @@ class DvsManager(object):
|
||||
net_id)
|
||||
LOG.info(_LI("%(net_id)s delete from %(dvs)s."),
|
||||
{'net_id': net_id,
|
||||
'dvs': dvs_utils.dvs_name_get()})
|
||||
'dvs': self._dvs_moref.value})
|
||||
|
||||
def get_vm_moref(self, instance_uuid):
|
||||
"""Get reference to the VM.
|
||||
|
@ -57,10 +57,10 @@ CONF = cfg.CONF
|
||||
CONF.register_opts(dvs_opts, 'dvs')
|
||||
|
||||
|
||||
def dvs_is_enabled():
|
||||
def dvs_is_enabled(dvs_id=None):
|
||||
"""Returns the configured DVS status."""
|
||||
return bool(CONF.dvs.host_ip and CONF.dvs.host_username and
|
||||
CONF.dvs.host_password and CONF.dvs.dvs_name)
|
||||
CONF.dvs.host_password and (dvs_id or CONF.dvs.dvs_name))
|
||||
|
||||
|
||||
def dvs_create_session():
|
||||
|
@ -211,7 +211,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
self._router_managers = managers.RouterTypeManager(self)
|
||||
|
||||
if cfg.CONF.nsxv.use_dvs_features:
|
||||
self._dvs = dvs.DvsManager()
|
||||
self._dvs = dvs.DvsManager(dvs_id=self.dvs_id)
|
||||
else:
|
||||
self._dvs = None
|
||||
|
||||
|
@ -50,12 +50,12 @@ class DvsTestCase(base.BaseTestCase):
|
||||
@mock.patch.object(dvs_utils, 'dvs_create_session',
|
||||
return_value=fake_session())
|
||||
@mock.patch.object(dvs.DvsManager, '_get_dvs_moref',
|
||||
return_value='dvs-moref')
|
||||
return_value=mock.MagicMock())
|
||||
def setUp(self, mock_moref, mock_session):
|
||||
super(DvsTestCase, self).setUp()
|
||||
cfg.CONF.set_override('dvs_name', 'fake_dvs', group='dvs')
|
||||
self._dvs = dvs.DvsManager()
|
||||
self.assertEqual('dvs-moref', self._dvs._dvs_moref)
|
||||
self.assertEqual(mock_moref.return_value, self._dvs._dvs_moref)
|
||||
mock_moref.assert_called_once_with(mock_session.return_value,
|
||||
'fake_dvs')
|
||||
|
||||
@ -141,7 +141,7 @@ class NeutronSimpleDvsTest(test_plugin.NeutronDbPluginV2TestCase):
|
||||
@mock.patch.object(dvs_utils, 'dvs_create_session',
|
||||
return_value=fake_session())
|
||||
@mock.patch.object(dvs.DvsManager, '_get_dvs_moref',
|
||||
return_value='dvs-moref')
|
||||
return_value=mock.MagicMock())
|
||||
def setUp(self, mock_moref, mock_session,
|
||||
plugin=PLUGIN_NAME,
|
||||
ext_mgr=None,
|
||||
|
Loading…
Reference in New Issue
Block a user