From 32af3c94bd62c46713a44bf75f2e4989f8b98bc4 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Wed, 12 Dec 2012 07:14:12 +0000 Subject: Properly scope password options enable_instance_password is only used in api.openstack.compute.servers so move it there. password_length is passed as a parameter to every generate_password() call, so just move it into nova.utils and have generate_password() use it by default. Note: using a config option as the default value of a kwarg isn't a good idea because the option value is read when the function is defined which means you can't control its value during unit tests. Instead we use password=None as the default. blueprint: scope-config-opts Change-Id: I445174515fc2eacc56c7cccecadadd2a7e57d4f4 --- nova/api/openstack/compute/contrib/rescue.py | 3 +-- nova/api/openstack/compute/servers.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/rescue.py b/nova/api/openstack/compute/contrib/rescue.py index 8aff90c38..ce3dfaf97 100644 --- a/nova/api/openstack/compute/contrib/rescue.py +++ b/nova/api/openstack/compute/contrib/rescue.py @@ -28,7 +28,6 @@ from nova import utils CONF = cfg.CONF -CONF.import_opt('password_length', 'nova.config') LOG = logging.getLogger(__name__) authorize = exts.extension_authorizer('compute', 'rescue') @@ -55,7 +54,7 @@ class RescueController(wsgi.Controller): if body['rescue'] and 'adminPass' in body['rescue']: password = body['rescue']['adminPass'] else: - password = utils.generate_password(CONF.password_length) + password = utils.generate_password() instance = self._get_instance(context, id) try: diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 68c5372c3..a62740681 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -40,13 +40,19 @@ from nova.openstack.common import uuidutils from nova import utils -LOG = logging.getLogger(__name__) +server_opts = [ + cfg.BoolOpt('enable_instance_password', + default=True, + help='Allows use of instance password during ' + 'server creation'), +] CONF = cfg.CONF -CONF.import_opt('enable_instance_password', 'nova.config') +CONF.register_opts(server_opts) CONF.import_opt('network_api_class', 'nova.config') -CONF.import_opt('password_length', 'nova.config') CONF.import_opt('reclaim_instance_interval', 'nova.compute.manager') +LOG = logging.getLogger(__name__) + def make_fault(elem): fault = xmlutil.SubTemplateElement(elem, 'fault', selector='fault') @@ -1204,7 +1210,7 @@ class Controller(wsgi.Controller): try: password = body['adminPass'] except (KeyError, TypeError): - password = utils.generate_password(CONF.password_length) + password = utils.generate_password() context = req.environ['nova.context'] instance = self._get_server(context, req, id) @@ -1346,7 +1352,7 @@ class Controller(wsgi.Controller): password = server['adminPass'] self._validate_admin_password(password) except KeyError: - password = utils.generate_password(CONF.password_length) + password = utils.generate_password() except ValueError: raise exc.HTTPBadRequest(explanation=_("Invalid adminPass")) -- cgit