diff options
| author | Tomoe Sugihara <tomoe@midokura.com> | 2012-01-24 18:14:47 +0900 |
|---|---|---|
| committer | Tomoe Sugihara <tomoe@midokura.com> | 2012-01-25 11:10:13 +0900 |
| commit | 2594e480b2d90490a92865afbeecda35b29320d6 (patch) | |
| tree | ed2e704f19e42f75392b24e9bae18a1421ecdbf4 /nova/api | |
| parent | a99f429591b5efcbcc21a618190e4bef7d9fba38 (diff) | |
| download | nova-2594e480b2d90490a92865afbeecda35b29320d6.tar.gz nova-2594e480b2d90490a92865afbeecda35b29320d6.tar.xz nova-2594e480b2d90490a92865afbeecda35b29320d6.zip | |
Add os-start/os-stop server actions to OSAPI
Implements blueprint start-stop-methods-support-in-os-servers-xapi
Change-Id: I7aa241ffdd2ec3a7c9800411268f4adc47960be8
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/server_start_stop.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/server_start_stop.py b/nova/api/openstack/compute/contrib/server_start_stop.py new file mode 100644 index 000000000..e5317f051 --- /dev/null +++ b/nova/api/openstack/compute/contrib/server_start_stop.py @@ -0,0 +1,76 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 Midokura Japan K.K. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License + +import webob + +from nova.api.openstack import extensions +from nova.api.openstack import wsgi +from nova import compute +from nova import exception +from nova import log as logging + + +LOG = logging.getLogger('nova.api.openstack.compute.contrib.server_start_stop') + + +class ServerStartStopActionController(wsgi.Controller): + def __init__(self, *args, **kwargs): + super(ServerStartStopActionController, self).__init__(*args, **kwargs) + self.compute_api = compute.API() + + @wsgi.action('os-start') + def _start_server(self, req, id, body): + """Start an instance. """ + context = req.environ['nova.context'] + + try: + LOG.debug(_("start instance %r"), id) + instance = self.compute_api.get(context, id) + self.compute_api.start(context, instance) + except exception.ApiError, e: + raise webob.exc.HTTPBadRequest(explanation=e.message) + except exception.NotAuthorized, e: + raise webob.exc.HTTPUnauthorized() + return webob.Response(status_int=202) + + @wsgi.action('os-stop') + def _stop_server(self, req, id, body): + """Stop an instance.""" + context = req.environ['nova.context'] + + try: + LOG.debug(_("stop instance %r"), id) + instance = self.compute_api.get(context, id) + self.compute_api.stop(context, instance) + except exception.ApiError, e: + raise webob.exc.HTTPBadRequest(explanation=e.message) + except exception.NotAuthorized, e: + raise webob.exc.HTTPUnauthorized() + + return webob.Response(status_int=202) + + +class Server_start_stop(extensions.ExtensionDescriptor): + """Start/Stop instance compute API support""" + + name = "ServerStartStop" + namespace = "http://docs.openstack.org/compute/ext/servers/api/v1.1" + updated = "2012-01-23:00:00+00:00" + + def get_controller_extensions(self): + controller = ServerStartStopActionController() + extension = extensions.ControllerExtension(self, 'servers', controller) + return [extension] |
