diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-12-22 12:59:00 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-12-22 12:59:00 +0000 |
| commit | 5bcaecdc7d42b8a4aa2f16e96c064869438d6a12 (patch) | |
| tree | 85cde1b8379e320621a949240d767dfd07e0b17e /nova/api | |
| parent | b2f36879b0d5f264ae2a9dd49fb893c6fbe25068 (diff) | |
| parent | adcfd491308a98107e82b9f0595e0bf2f37b5a54 (diff) | |
Merge "Allow accessIPv4 and accessIPv6 on rebuild action"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/v2/servers.py | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/nova/api/openstack/v2/servers.py b/nova/api/openstack/v2/servers.py index 51ccaadde..cb0ece1f0 100644 --- a/nova/api/openstack/v2/servers.py +++ b/nova/api/openstack/v2/servers.py @@ -16,10 +16,10 @@ import base64 import os +from xml.dom import minidom from webob import exc import webob -from xml.dom import minidom from nova.api.openstack import common from nova.api.openstack.v2 import ips @@ -731,46 +731,68 @@ class Controller(wsgi.Controller): return self._resize(req, id, flavor_ref) def _action_rebuild(self, info, request, instance_id): - context = request.environ['nova.context'] - instance = self._get_server(context, instance_id) + """Rebuild an instance with the given attributes""" + try: + body = info['rebuild'] + except (KeyError, TypeError): + raise exc.HTTPBadRequest(_("Invalid request body")) try: - image_href = info["rebuild"]["imageRef"] + image_href = body["imageRef"] except (KeyError, TypeError): msg = _("Could not parse imageRef from request.") - LOG.debug(msg) raise exc.HTTPBadRequest(explanation=msg) - personality = info["rebuild"].get("personality", []) - injected_files = [] - if personality: - injected_files = self._get_injected_files(personality) + try: + password = body['adminPass'] + except (KeyError, TypeError): + password = utils.generate_password(FLAGS.password_length) - metadata = info["rebuild"].get("metadata") - name = info["rebuild"].get("name") + context = request.environ['nova.context'] + instance = self._get_server(context, instance_id) + + attr_map = { + 'personality': 'files_to_inject', + 'name': 'display_name', + 'accessIPv4': 'access_ip_v4', + 'accessIPv6': 'access_ip_v6', + 'metadata': 'metadata', + } - if metadata: - self._validate_metadata(metadata) + kwargs = {} - if 'rebuild' in info and 'adminPass' in info['rebuild']: - password = info['rebuild']['adminPass'] - else: - password = utils.generate_password(FLAGS.password_length) + for request_attribute, instance_attribute in attr_map.items(): + try: + kwargs[instance_attribute] = body[request_attribute] + except (KeyError, TypeError): + pass + + self._validate_metadata(kwargs.get('metadata', {})) + + if 'files_to_inject' in kwargs: + personality = kwargs['files_to_inject'] + kwargs['files_to_inject'] = self._get_injected_files(personality) try: - self.compute_api.rebuild(context, instance, image_href, - password, name=name, metadata=metadata, - files_to_inject=injected_files) + self.compute_api.rebuild(context, + instance, + image_href, + password, + **kwargs) + except exception.RebuildRequiresActiveInstance: - msg = _("Instance %s must be active to rebuild.") % instance_id + msg = _("Instance must be active to rebuild.") raise exc.HTTPConflict(explanation=msg) except exception.InstanceNotFound: - msg = _("Instance %s could not be found") % instance_id + msg = _("Instance could not be found") raise exc.HTTPNotFound(explanation=msg) instance = self._get_server(context, instance_id) + self._add_instance_faults(context, [instance]) view = self._view_builder.show(request, instance) + + # Add on the adminPass attribute since the view doesn't do it view['server']['adminPass'] = password return view |
