diff options
| author | Ryu Ishimoto <ryu@midokura.jp> | 2011-07-11 05:21:06 +0900 |
|---|---|---|
| committer | Ryu Ishimoto <ryu@midokura.jp> | 2011-07-11 05:21:06 +0900 |
| commit | dea12df6165c3417efb0a3959462b9080be1bbca (patch) | |
| tree | 0d8c190b137d808210af6c80f1a5c2aa0dcbb0f2 | |
| parent | 1da51f7b07f0080c44063a355c84fafd1fdf02bc (diff) | |
Added vif OS API extension to get started on it
| -rw-r--r-- | nova/api/openstack/contrib/vifs.py | 86 | ||||
| -rw-r--r-- | nova/network/api.py | 4 |
2 files changed, 90 insertions, 0 deletions
diff --git a/nova/api/openstack/contrib/vifs.py b/nova/api/openstack/contrib/vifs.py new file mode 100644 index 000000000..5c8492aa3 --- /dev/null +++ b/nova/api/openstack/contrib/vifs.py @@ -0,0 +1,86 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2011 Midokura KK +# +# 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 +from webob import exc + +from nova import exception +from nova import network +from nova.api.openstack import extensions + + +def _translate_vif_view(vif): + result = {'id': vif['id'], + 'mac': vif['address'], + 'network_id': vif['network_id']} + return {'vif': result} + + +def _translate_vifs_view(vifs): + return {'vifs': [_translate_vif_view(vif) for vif in vifs]} + + +class ServerVIFController(object): + """The controller for VIFs attached to servers. + + A child resource of the server. + """ + + _serialization_metadata = { + 'application/xml': { + "attributes": { + "vif": [ + "id", + "mac", + "network_id", + ]}}} + + def __init__(self): + self.network_api = network.API() + super(ServerVIFController, self).__init__() + + def index(self, req, server_id): + """Return data about the vifs of the server.""" + context = req.environ['nova.context'] + + vifs = self.network_api.get_vifs_by_instance(context, server_id) + + return _translate_vifs_view(vifs) + + + +class VIFs(extensions.ExtensionDescriptor): + def get_name(self): + return "VIFs" + + def get_alias(self): + return "os-vifs" + + def get_description(self): + return "VIF support" + + def get_namespace(self): + return "http://docs.openstack.org/ext/vifs/api/v1.1" + + def get_updated(self): + return "2011-07-11T00:00:00+00:00" + + def get_resources(self): + resources = [] + + res = extensions.ResourceExtension('os-server_vifs', + ServerVIFController()) + resources.append(res) + + return resources diff --git a/nova/network/api.py b/nova/network/api.py index b2b96082b..e1bd0f845 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -46,6 +46,10 @@ class API(base.Base): context.project_id) return ips + def get_vifs_by_instance(self, context, instance_id): + vifs = self.db.virtual_interface_get_by_instance(context, instance_id) + return vifs + def allocate_floating_ip(self, context): """Adds a floating ip to a project.""" # NOTE(vish): We don't know which network host should get the ip |
