diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-15 01:27:45 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-15 01:27:45 +0000 |
| commit | 0bc32cfef94dc2e45f86a0e526e3415ec5d4ca39 (patch) | |
| tree | ef33778221b5d9d9a71774ce903929d58406de2b /nova/api | |
| parent | 76267f4d6268b3a39e46dbace140e15d874dadc5 (diff) | |
| parent | 9af40c167879096a8f0f209bde4e6c5cc9295b86 (diff) | |
| download | nova-0bc32cfef94dc2e45f86a0e526e3415ec5d4ca39.tar.gz nova-0bc32cfef94dc2e45f86a0e526e3415ec5d4ca39.tar.xz nova-0bc32cfef94dc2e45f86a0e526e3415ec5d4ca39.zip | |
Merge "Implement network association in OS API"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/networks.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/networks.py b/nova/api/openstack/compute/contrib/networks.py index ece331fbb..fb1d3d77e 100644 --- a/nova/api/openstack/compute/contrib/networks.py +++ b/nova/api/openstack/compute/contrib/networks.py @@ -17,6 +17,7 @@ # under the License. +import webob from webob import exc from nova.api.openstack import extensions @@ -113,6 +114,31 @@ class NetworkController(object): def create(self, req, id, body=None): raise exc.HTTPNotImplemented() + def add(self, req, body): + context = req.environ['nova.context'] + authorize(context) + if not body: + raise exc.HTTPUnprocessableEntity() + + network_id = body.get('id', None) + project_id = context.project_id + LOG.debug(_("Associating network %(network)s" + " with project %(project)s") % + {"network": network_id or "", + "project": project_id}) + try: + self.network_api.add_network_to_project( + context, project_id, network_id) + except Exception as ex: + msg = (_("Cannot associate network %(network)s" + " with project %(project)s: %(message)s") % + {"network": network_id or "", + "project": project_id, + "message": getattr(ex, "value", str(ex))}) + raise exc.HTTPBadRequest(explanation=msg) + + return webob.Response(status_int=202) + class Networks(extensions.ExtensionDescriptor): """Admin-only Network Management Extension""" @@ -124,7 +150,10 @@ class Networks(extensions.ExtensionDescriptor): def get_resources(self): member_actions = {'action': 'POST'} - res = extensions.ResourceExtension('os-networks', - NetworkController(), - member_actions=member_actions) + collection_actions = {'add': 'POST'} + res = extensions.ResourceExtension( + 'os-networks', + NetworkController(), + member_actions=member_actions, + collection_actions=collection_actions) return [res] |
