Add nsx-manager config option to nsx.ini

Until now, we assigned the NSX manager's IP to nsx_controllers
config option in nsx.ini. This change removes that ambiguity
and adds a new nsx_manager string option to nsx.ini.

DocImpact
Change-Id: I4aebfe775039d62821c7db4f955fa350c1872324
This commit is contained in:
Akash Gangil 2015-07-24 07:49:44 -07:00
parent c3746389a1
commit 23fa220a03
5 changed files with 28 additions and 18 deletions

View File

@ -101,6 +101,11 @@ function neutron_plugin_configure_service {
else
die $LINENO "The VMware NSX plugin needs at least an NSX controller."
fi
if [[ "$NSX_MANAGER" != "" ]]; then
iniset /$Q_PLUGIN_CONF_FILE nsx_v3 nsx_manager $NSX_MANAGER
else
die $LINENO "The VMware NSX plugin needs a NSX manager."
fi
if [[ "$NSX_USER" != "" ]]; then
iniset /$Q_PLUGIN_CONF_FILE nsx_v3 nsx_user $NSX_USER
fi

View File

@ -160,11 +160,13 @@ cluster_opts = [
nsx_v3_opts = [
cfg.StrOpt('nsx_user',
default='admin',
help=_('User name for NSX controllers in this cluster')),
help=_('User name for the NSX manager')),
cfg.StrOpt('nsx_password',
default='default',
secret=True,
help=_('Password for NSX controllers in this cluster')),
help=_('Password for the NSX manager')),
cfg.StrOpt('nsx_manager',
help=_('IP address of the NSX manager')),
cfg.StrOpt('default_edge_cluster_uuid',
help=_("Default edge cluster identifier"))]

View File

@ -25,14 +25,17 @@ from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
LOG = log.getLogger(__name__)
def _get_controller_endpoint():
# For now only work with one controller
# NOTE: The same options defined for 'old' NSX controller connection can be
# reused for connecting to next-gen NSX controllers
controller = cfg.CONF.nsx_controllers[0]
def _get_manager_endpoint():
manager = _get_manager_ip()
username = cfg.CONF.nsx_v3.nsx_user
password = cfg.CONF.nsx_v3.nsx_password
return "https://%s" % controller, username, password
return "https://%s" % manager, username, password
def _get_manager_ip():
# NOTE: In future this may return the IP address from a pool
manager = cfg.CONF.nsx_v3.nsx_manager
return manager
def _validate_result(result, expected, operation):
@ -48,8 +51,8 @@ def _validate_result(result, expected, operation):
def get_resource(resource):
controller, user, password = _get_controller_endpoint()
url = controller + "/api/v1/%s" % resource
manager, user, password = _get_manager_endpoint()
url = manager + "/api/v1/%s" % resource
headers = {'Accept': 'application/json'}
result = requests.get(url, auth=auth.HTTPBasicAuth(user, password),
verify=False, headers=headers)
@ -59,8 +62,8 @@ def get_resource(resource):
def create_resource(resource, data):
controller, user, password = _get_controller_endpoint()
url = controller + "/api/v1/%s" % resource
manager, user, password = _get_manager_endpoint()
url = manager + "/api/v1/%s" % resource
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
result = requests.post(url, auth=auth.HTTPBasicAuth(user, password),
@ -72,8 +75,8 @@ def create_resource(resource, data):
def update_resource(resource, data):
controller, user, password = _get_controller_endpoint()
url = controller + "/api/v1/%s" % resource
manager, user, password = _get_manager_endpoint()
url = manager + "/api/v1/%s" % resource
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
result = requests.put(url, auth=auth.HTTPBasicAuth(user, password),
@ -85,8 +88,8 @@ def update_resource(resource, data):
def delete_resource(resource):
controller, user, password = _get_controller_endpoint()
url = controller + "/api/v1/%s" % resource
manager, user, password = _get_manager_endpoint()
url = manager + "/api/v1/%s" % resource
result = requests.delete(url, auth=auth.HTTPBasicAuth(user, password),
verify=False)
_validate_result(result, [requests.codes.ok, requests.codes.not_found],

View File

@ -20,6 +20,6 @@ import unittest
class NsxLibTestCase(unittest.TestCase):
def setUp(self):
cfg.CONF.set_override('nsx_controllers', ['1.2.3.4'])
cfg.CONF.set_override('nsx_user', 'admin')
cfg.CONF.set_override('nsx_password', 'default')
cfg.CONF.set_override('nsx_manager', '1.2.3.4', 'nsx_v3')

View File

@ -32,7 +32,7 @@ class NsxPluginV3TestCase(test_plugin.NeutronDbPluginV2TestCase):
service_plugins=None):
super(NsxPluginV3TestCase, self).setUp(plugin=plugin,
ext_mgr=ext_mgr)
cfg.CONF.set_override('nsx_controllers', ["1.1.1.1"])
cfg.CONF.set_override('nsx_manager', '1.2.3.4', 'nsx_v3')
# Mock entire nsxlib methods as this is the best approach to perform
# white-box testing on the plugin class
# TODO(salv-orlando): supply unit tests for nsxlib.v3