diff options
| author | Dan Smith <danms@us.ibm.com> | 2013-02-04 12:12:43 -0500 |
|---|---|---|
| committer | Dan Smith <danms@us.ibm.com> | 2013-02-05 14:00:51 -0500 |
| commit | 5d8868a4d58122dce6fdc81fa0ed17ae7fc55672 (patch) | |
| tree | 534e767c153b7cdf9530c4c343c9011a043e0c94 /nova/api | |
| parent | 139d15a40557066a39a1c2ba48c81711a9dd3730 (diff) | |
| download | nova-5d8868a4d58122dce6fdc81fa0ed17ae7fc55672.tar.gz nova-5d8868a4d58122dce6fdc81fa0ed17ae7fc55672.tar.xz nova-5d8868a4d58122dce6fdc81fa0ed17ae7fc55672.zip | |
Refactor server password metadata to avoid direct db usage
This refactors the set_password() method in the server_password
API extension to merely format the metadata and return it, leaving
the job of updating the database to the caller. In the API extension
case, the update can be done immediately against the database as
before. In the case of the metadata API handler and the xenapi virt
driver making the call, conductor can be used to update the instance's
system_metadata, thereby avoiding a direct database access.
Related to blueprint no-db-compute
Change-Id: I0563feaa97d768a96f950c148b1dbf51c356c4ac
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): |
