From 0bf27df376ae45a0dd23d37f099afe57ec05ad86 Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Mon, 12 Nov 2012 13:04:38 +1030 Subject: Add vpn ip/port setting support for CloudPipe This extends the cloudpipe REST API to allow the setting of the IP and port for the VPN for each network in the project /v2/{tenant_id/os-cloudpipe/configure-project # POST ip/port This forms part of the work to provide APIs for functionality currently implemented by nova-manage that needs direct db access so nova-manage can eventually be removed DocImpact Implements: blueprint apis-for-nova-manage Change-Id: I416c0bfbe1c88470638f1c2004d1dcaeb51a6c41 --- .../openstack/compute/contrib/cloudpipe_update.py | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 nova/api/openstack/compute/contrib/cloudpipe_update.py (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/cloudpipe_update.py b/nova/api/openstack/compute/contrib/cloudpipe_update.py new file mode 100644 index 000000000..e4a200c81 --- /dev/null +++ b/nova/api/openstack/compute/contrib/cloudpipe_update.py @@ -0,0 +1,78 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 IBM +# All Rights Reserved. +# +# 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.exc + +from nova.api.openstack.compute.contrib import cloudpipe +from nova.api.openstack import extensions +from nova.api.openstack import wsgi +from nova import db +from nova import exception +from nova.openstack.common import log as logging + +LOG = logging.getLogger(__name__) +authorize = extensions.extension_authorizer('compute', 'cloudpipe_update') + + +class CloudpipeUpdateController(wsgi.Controller): + """Handle updating the vpn ip/port for cloudpipe instances.""" + + def __init__(self): + super(CloudpipeUpdateController, self).__init__() + + @wsgi.action("update") + def update(self, req, id, body): + """Configure cloudpipe parameters for the project""" + + context = req.environ['nova.context'] + authorize(context) + + if id != "configure-project": + msg = _("Unknown action %s") % id + raise webob.exc.HTTPBadRequest(explanation=msg) + + project_id = context.project_id + + try: + params = body['configure_project'] + vpn_ip = params['vpn_ip'] + vpn_port = params['vpn_port'] + except (TypeError, KeyError): + raise webob.exc.HTTPUnprocessableEntity() + + networks = db.project_get_networks(context, project_id) + for network in networks: + db.network_update(context, network['id'], + {'vpn_public_address': vpn_ip, + 'vpn_public_port': int(vpn_port)}) + return webob.exc.HTTPAccepted() + + +class Cloudpipe_update(extensions.ExtensionDescriptor): + """Adds the ability to set the vpn ip/port for cloudpipe instances.""" + + name = "CloudpipeUpdate" + alias = "os-cloudpipe-update" + namespace = "http://docs.openstack.org/compute/ext/cloudpipe-update/api/v2" + updated = "2012-11-14T00:00:00+00:00" + + def get_controller_extensions(self): + controller = CloudpipeUpdateController() + extension = extensions.ControllerExtension(self, 'os-cloudpipe', + controller) + return [extension] -- cgit