summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-12-12 07:14:12 +0000
committerMark McLoughlin <markmc@redhat.com>2012-12-12 08:26:59 +0000
commit32af3c94bd62c46713a44bf75f2e4989f8b98bc4 (patch)
tree6855a1fe7940cc706f07f90c36c5f7e32f356f83 /nova/api
parentac658aa7d0671fb9b5a0a2c504f4b73dff514da9 (diff)
downloadnova-32af3c94bd62c46713a44bf75f2e4989f8b98bc4.tar.gz
nova-32af3c94bd62c46713a44bf75f2e4989f8b98bc4.tar.xz
nova-32af3c94bd62c46713a44bf75f2e4989f8b98bc4.zip
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
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/rescue.py3
-rw-r--r--nova/api/openstack/compute/servers.py16
2 files changed, 12 insertions, 7 deletions
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"))