diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-02-06 01:00:30 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-02-06 01:00:30 +0000 |
| commit | bfd295daed4b22cd0716973bee33cffdaaeae931 (patch) | |
| tree | 31689400c872f4f26f7441b3d6e0fa84af215006 /nova/api | |
| parent | af235b22eccb81d815c79fd1f531734a140cfafb (diff) | |
| parent | 5d8868a4d58122dce6fdc81fa0ed17ae7fc55672 (diff) | |
| download | nova-bfd295daed4b22cd0716973bee33cffdaaeae931.tar.gz nova-bfd295daed4b22cd0716973bee33cffdaaeae931.tar.xz nova-bfd295daed4b22cd0716973bee33cffdaaeae931.zip | |
Merge "Refactor server password metadata to avoid direct db usage"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/metadata/password.py | 18 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/server_password.py | 5 |
2 files changed, 15 insertions, 8 deletions
diff --git a/nova/api/metadata/password.py b/nova/api/metadata/password.py index b2bb83b15..f3453e945 100644 --- a/nova/api/metadata/password.py +++ b/nova/api/metadata/password.py @@ -15,8 +15,9 @@ from webob import exc +from nova import conductor from nova import context -from nova import db +from nova import utils CHUNKS = 4 @@ -33,7 +34,7 @@ def extract_password(instance): return result or None -def set_password(context, instance_uuid, password): +def convert_password(context, password): """Stores password as system_metadata items. Password is stored with the keys 'password_0' -> 'password_3'. @@ -43,10 +44,7 @@ def set_password(context, instance_uuid, password): for i in xrange(CHUNKS): meta['password_%d' % i] = password[:CHUNK_LENGTH] password = password[CHUNK_LENGTH:] - db.instance_system_metadata_update(context, - instance_uuid, - meta, - False) + return meta def handle_password(req, meta_data): @@ -63,6 +61,12 @@ def handle_password(req, meta_data): if (req.content_length > MAX_SIZE or len(req.body) > MAX_SIZE): msg = _("Request is too large.") raise exc.HTTPBadRequest(explanation=msg) - set_password(ctxt, meta_data.uuid, req.body) + + conductor_api = conductor.API() + instance = conductor_api.instance_get_by_uuid(ctxt, meta_data.uuid) + sys_meta = utils.metadata_to_dict(instance['system_metadata']) + sys_meta.update(convert_password(ctxt, req.body)) + conductor_api.instance_update(ctxt, meta_data.uuid, + system_metadata=sys_meta) else: raise exc.HTTPBadRequest() diff --git a/nova/api/openstack/compute/contrib/server_password.py b/nova/api/openstack/compute/contrib/server_password.py index 0fd620fb8..9436d354f 100644 --- a/nova/api/openstack/compute/contrib/server_password.py +++ b/nova/api/openstack/compute/contrib/server_password.py @@ -24,6 +24,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute +from nova import db from nova import exception @@ -62,7 +63,9 @@ class ServerPasswordController(object): context = req.environ['nova.context'] authorize(context) instance = self._get_instance(context, server_id) - password.set_password(context, instance['uuid'], None) + meta = password.convert_password(context, None) + db.instance_system_metadata_update(context, instance['uuid'], + meta, False) class Server_password(extensions.ExtensionDescriptor): |
