summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/escalator/api/v1/clusters.py123
-rw-r--r--api/escalator/api/v1/controller.py13
-rw-r--r--api/escalator/api/v1/router.py7
-rw-r--r--api/escalator/installer/__init__.py0
-rw-r--r--api/escalator/installer/daisy/__init__.py0
-rw-r--r--api/escalator/installer/daisy/api.py14
6 files changed, 157 insertions, 0 deletions
diff --git a/api/escalator/api/v1/clusters.py b/api/escalator/api/v1/clusters.py
new file mode 100644
index 0000000..c37dda1
--- /dev/null
+++ b/api/escalator/api/v1/clusters.py
@@ -0,0 +1,123 @@
+# Copyright 2013 OpenStack Foundation
+# 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.
+
+"""
+/clusters list for Escalator v1 API
+"""
+from oslo_log import log as logging
+from webob.exc import HTTPBadRequest
+from webob.exc import HTTPForbidden
+
+from escalator.api import policy
+from escalator.api.v1 import controller
+from escalator.common import exception
+from escalator.common import utils
+from escalator.common import wsgi
+from escalator import i18n
+from escalator import notifier
+import escalator.installer.daisy.api as daisy_api
+
+LOG = logging.getLogger(__name__)
+_ = i18n._
+_LE = i18n._LE
+_LI = i18n._LI
+_LW = i18n._LW
+
+
+class Controller(controller.BaseController):
+ """
+ WSGI controller for clusters resource in Escalaotr v1 API
+
+ The clusters resource API is a RESTful web service for cluster data.
+ The API is as follows::
+
+ GET /clusters -- Returns a set of brief metadata about clusters
+ GET /clusters -- Returns a set of detailed metadata about
+ clusters
+ """
+ def __init__(self):
+ self.notifier = notifier.Notifier()
+ self.policy = policy.Enforcer()
+
+ def _enforce(self, req, action, target=None):
+ """Authorize an action against our policies"""
+ if target is None:
+ target = {}
+ try:
+ self.policy.enforce(req.context, action, target)
+ except exception.Forbidden:
+ raise HTTPForbidden()
+
+ def detail(self, req):
+ """
+ Returns detailed information for all available clusters
+
+ :param req: The WSGI/Webob Request object
+ :retval The response body is a mapping of the following form::
+
+ {'clusters': [
+ {'id': <ID>,
+ 'name': <NAME>,
+ 'nodes': <NODES>,
+ 'networks': <NETWORKS>,
+ 'description': <DESCRIPTION>,
+ 'created_at': <TIMESTAMP>,
+ 'updated_at': <TIMESTAMP>,
+ 'deleted_at': <TIMESTAMP>|<NONE>,}, ...
+ ]}
+ """
+ self._enforce(req, 'get_clusters')
+ try:
+ clusters = daisy_api.cluster_list(req.context)
+ clusters_list = list()
+ while True:
+ try:
+ cluster_new = next(clusters)
+ clusters_list.append(cluster_new)
+ except StopIteration:
+ break
+ except exception.Invalid as e:
+ raise HTTPBadRequest(explanation=e.msg, request=req)
+ return dict(clusters=clusters_list)
+
+
+class ProjectDeserializer(wsgi.JSONRequestDeserializer):
+ """Handles deserialization of specific controller method requests."""
+
+ def _deserialize(self, request):
+ result = {}
+ result["cluster_meta"] = utils.get_cluster_meta(request)
+ return result
+
+
+class ProjectSerializer(wsgi.JSONResponseSerializer):
+ """Handles serialization of specific controller method responses."""
+
+ def __init__(self):
+ self.notifier = notifier.Notifier()
+
+ def get_cluster(self, response, result):
+ cluster_meta = result['cluster_meta']
+ response.status = 201
+ response.headers['Content-Type'] = 'application/json'
+ response.body = self.to_json(dict(cluster=cluster_meta))
+ return response
+
+
+def create_resource():
+ """Projects resource factory method"""
+ deserializer = ProjectDeserializer()
+ serializer = ProjectSerializer()
+ return wsgi.Resource(Controller(), deserializer, serializer)
diff --git a/api/escalator/api/v1/controller.py b/api/escalator/api/v1/controller.py
new file mode 100644
index 0000000..ad0b9d7
--- /dev/null
+++ b/api/escalator/api/v1/controller.py
@@ -0,0 +1,13 @@
+class BaseController(object):
+
+ def get_cluster_meta_or_404(self, request, cluster_id):
+ """
+ Grabs the cluster metadata for an cluster with a supplied
+ identifier or raises an HTTPNotFound (404) response
+
+ :param request: The WSGI/Webob Request object
+ :param cluster_id: The opaque cluster identifier
+
+ :raises HTTPNotFound if cluster does not exist
+ """
+ pass
diff --git a/api/escalator/api/v1/router.py b/api/escalator/api/v1/router.py
index e1709ca..5942cb1 100644
--- a/api/escalator/api/v1/router.py
+++ b/api/escalator/api/v1/router.py
@@ -14,6 +14,7 @@
# under the License.
from escalator.common import wsgi
from escalator.api.v1 import versions
+from escalator.api.v1 import clusters
class API(wsgi.Router):
@@ -24,6 +25,12 @@ class API(wsgi.Router):
wsgi.Resource(wsgi.RejectMethodController())
versions_resource = versions.create_resource()
+ clusters_resource = clusters.create_resource()
+
+ mapper.connect("/clusters",
+ controller=clusters_resource,
+ action='detail',
+ conditions={'method': ['GET']})
mapper.connect("/versions",
controller=versions_resource,
diff --git a/api/escalator/installer/__init__.py b/api/escalator/installer/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/escalator/installer/__init__.py
diff --git a/api/escalator/installer/daisy/__init__.py b/api/escalator/installer/daisy/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/escalator/installer/daisy/__init__.py
diff --git a/api/escalator/installer/daisy/api.py b/api/escalator/installer/daisy/api.py
new file mode 100644
index 0000000..661d0d5
--- /dev/null
+++ b/api/escalator/installer/daisy/api.py
@@ -0,0 +1,14 @@
+from daisyclient.v1 import client as daisy_client
+
+
+def daisyclient(request):
+ DAISY_ENDPOINT_URL = "http://127.0.0.1:19292"
+ return daisy_client.Client(version=1, endpoint=DAISY_ENDPOINT_URL)
+
+
+def cluster_list(request):
+ return daisyclient(request).clusters.list()
+
+
+def cluster_get(request, cluster_id):
+ return daisyclient(request).clusters.get(cluster_id)