summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2013-02-05 20:10:53 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-02-05 23:38:04 +0900
commita99c33c6db7e54473383b980641e7b59c872f805 (patch)
tree187fd993ae074d51277bbffc497351af4af4a753
parentffed73fbe6096176f38c1302a3946317373d7638 (diff)
rest/quantum: quantum iface REST API
Quantum teach ryu the relation iface-id and network_id Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/app/rest_quantum.py127
1 files changed, 127 insertions, 0 deletions
diff --git a/ryu/app/rest_quantum.py b/ryu/app/rest_quantum.py
new file mode 100644
index 00000000..da75701d
--- /dev/null
+++ b/ryu/app/rest_quantum.py
@@ -0,0 +1,127 @@
+# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2012 Isaku Yamahata <yamahata at private email ne jp>
+#
+# 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 json
+from webob import Response
+
+from ryu.base import app_manager
+from ryu.app.wsgi import (ControllerBase,
+ WSGIApplication)
+from ryu.lib import quantum_ifaces
+
+# REST API for openstack quantum
+# get the list of iface-ids
+# GET /v1.0/quantum/ports/
+#
+# register the iface_id
+# POST /v1.0/quantum/ports/{iface_id}
+#
+# unregister iface_id
+# DELETE /v1.0/quantum/ports/{iface_id}
+#
+# associate netowrk_id with iface_id
+# GET /v1.0/quantum/ports/{iface_id}/network_id
+#
+# associate netowrk_id with iface_id
+# POST /v1.0/quantum/ports/{iface_id}/network_id/{network_id}
+#
+# update netowrk_id with iface_id
+# PUT /v1.0/quantum/ports/{iface_id}/network_id/{network_id}
+
+
+class QuantumController(ControllerBase):
+ def __init__(self, req, link, data, **config):
+ super(QuantumController, self).__init__(req, link, data, **config)
+ self.ifaces = data
+
+ def list_ifaces(self, _req, **_kwargs):
+ body = json.dumps(self.ifaces.keys())
+ return Response(content_type='application/json', body=body)
+
+ def delete_iface(self, _req, iface_id, **_kwargs):
+ self.ifaces.unregister(iface_id)
+ return Response(status=200)
+
+ def list_keys(self, _req, iface_id, **_kwargs):
+ try:
+ keys = self.ifaces.list_keys(iface_id)
+ except KeyError:
+ return Response(status=404)
+ body = json.dumps(keys)
+ return Response(content_type='application/json', body=body)
+
+ def get_key(self, _req, iface_id, key, **_kwargs):
+ try:
+ value = self.ifaces.get_key(iface_id, key)
+ except KeyError:
+ return Response(status=404)
+ body = json.dumps(value)
+ return Response(content_type='application/json', body=body)
+
+ def create_value(self, _req, iface_id, key, value, **_kwargs):
+ try:
+ self.ifaces.set_key(iface_id, key, value)
+ except ValueError:
+ return Response(status=404)
+ return Response(status=200)
+
+ def update_value(self, _req, iface_id, key, value, **_kwargs):
+ try:
+ self.ifaces.update_key(iface_id, key, value)
+ except ValueError:
+ return Response(status=404)
+ return Response(status=200)
+
+
+class QuantumIfaceAPI(app_manager.RyuApp):
+ _CONTEXTS = {
+ 'quantum_ifaces': quantum_ifaces.QuantumIfaces,
+ 'wsgi': WSGIApplication,
+ }
+
+ def __init__(self, *args, **kwargs):
+ super(QuantumIfaceAPI, self).__init__(*args, **kwargs)
+ self.ifaces = kwargs['quantum_ifaces']
+ wsgi = kwargs['wsgi']
+ mapper = wsgi.mapper
+
+ controller = QuantumController
+ wsgi.registory[controller.__name__] = self.ifaces
+ route_name = 'quantum_ifaces'
+ uri = '/v1.0/quantum'
+
+ ports_uri = uri + '/ports'
+ s = mapper.submapper(controller=controller)
+ s.connect(route_name, ports_uri, action='list_ifaces',
+ conditions=dict(method=['GET', 'HEAD']))
+
+ iface_uri = ports_uri + '/{iface_id}'
+ s.connect(route_name, iface_uri, action='delete_iface',
+ conditions=dict(method=['DELETE']))
+
+ keys_uri = iface_uri + '/keys'
+ s.connect(route_name, keys_uri, action='list_keys',
+ conditions=dict(method=['GET', 'HEAD']))
+
+ key_uri = keys_uri + '/{key}'
+ s.connect(route_name, key_uri, action='get_key',
+ conditions=dict(method=['GET', 'HEAD']))
+
+ value_uri = keys_uri + '/{key}/{value}'
+ s.connect(route_name, value_uri, action='create_value',
+ conditions=dict(method=['POST']))
+ s.connect(route_name, value_uri, action='update_value',
+ conditions=dict(method=['PUT']))