From 8977826c949fb6d3e1de6aa4965122d01436ae5c Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 8 Nov 2011 14:32:44 -0500 Subject: Converting reboot to use instance objects Related to blueprint internal-uuids Change-Id: I50ebfdfd9c7193e732a3e2c2e1b1b3b32eb1bb57 --- nova/api/ec2/cloud.py | 5 ++++- nova/api/openstack/servers.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index b2aa120e6..735b72cef 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -1458,7 +1458,10 @@ class CloudController(object): def reboot_instances(self, context, instance_id, **kwargs): """instance_id is a list of instance ids""" LOG.audit(_("Reboot instance %r"), instance_id, context=context) - self._do_instances(self.compute_api.reboot, context, instance_id) + for ec2_id in instance_id: + _instance_id = ec2utils.ec2_id_to_id(ec2_id) + instance = self.compute_api.get(context, _instance_id) + self.compute_api.reboot(context, instance, 'HARD') return True def stop_instances(self, context, instance_id, **kwargs): diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index e11d8ceb0..2a1424e46 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -142,6 +142,13 @@ class Controller(object): limited_list = self._limit_items(instance_list, req) return self._build_list(req, limited_list, is_detail=is_detail) + def _get_server(self, context, instance_uuid): + """Utility function for looking up an instance by uuid""" + try: + return self.compute_api.get(context, instance_uuid) + except exception.NotFound: + raise exc.HTTPNotFound() + def _handle_quota_error(self, error): """ Reraise quota errors as api-specific http exceptions @@ -609,9 +616,12 @@ class Controller(object): msg = _("Missing argument 'type' for reboot") LOG.exception(msg) raise exc.HTTPBadRequest(explanation=msg) + + context = req.environ['nova.context'] + instance = self._get_server(context, id) + try: - self.compute_api.reboot(req.environ['nova.context'], id, - reboot_type) + self.compute_api.reboot(context, instance, reboot_type) except Exception, e: LOG.exception(_("Error in reboot %s"), e) raise exc.HTTPUnprocessableEntity() -- cgit