From 50f0024ed0284a4ef11da766091645e9c875215a Mon Sep 17 00:00:00 2001 From: Eyal Date: Wed, 20 Jan 2016 15:41:50 +0200 Subject: [PATCH] add show resource and list resources Implements: blueprint get-topology-api Change-Id: Ib14664f1798041ee06cfc8a5105a8c3525b5811d --- etc/vitrage/policy.json | 4 +- vitrage/api/controllers/v1/resource.py | 70 ++++++++++++++++++++++++++ vitrage/api/controllers/v1/root.py | 2 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 vitrage/api/controllers/v1/resource.py diff --git a/etc/vitrage/policy.json b/etc/vitrage/policy.json index 3ed8c0304..b1e99372a 100644 --- a/etc/vitrage/policy.json +++ b/etc/vitrage/policy.json @@ -1,3 +1,5 @@ { - "get topology": "role:admin" + "get topology": "role:admin", + "get resource": "role:admin", + "list resources": "role:admin" } \ No newline at end of file diff --git a/vitrage/api/controllers/v1/resource.py b/vitrage/api/controllers/v1/resource.py new file mode 100644 index 000000000..fdf36cb10 --- /dev/null +++ b/vitrage/api/controllers/v1/resource.py @@ -0,0 +1,70 @@ +# 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 pecan + +from oslo_log import log +from pecan.core import abort +from pecan import rest +from vitrage.api.policy import enforce +# noinspection PyProtectedMember +from vitrage.i18n import _LI + + +LOG = log.getLogger(__name__) + + +class ResourcesController(rest.RestController): + + @pecan.expose() + def _lookup(self, id_, *remainder): + LOG.info(_LI('got lookup %s') % id_) + return ResourceController(id_), remainder + + @pecan.expose('json') + def index(self, resource_type=None): + enforce("list resources", pecan.request.headers, + pecan.request.enforcer, {}) + + LOG.info(_LI('received list resources with filter %s') % resource_type) + + try: + return self.get_resources(resource_type) + except Exception as e: + LOG.exception("failed to get resources %s", e) + abort(404, str(e)) + + @staticmethod + def get_resources(resource_type): + return dict() + + +class ResourceController(rest.RestController): + + def __init__(self, id_): + self.id = id_ + + @pecan.expose('json') + def get(self): + enforce("get resource", pecan.request.headers, + pecan.request.enforcer, {}) + + LOG.info(_LI('received get resource with id %s') % self.id) + try: + return self.get_resource(self.id) + except Exception as e: + LOG.exception("failed to get resource %s", e) + abort(404, str(e)) + + @staticmethod + def get_resource(id_): + return dict() diff --git a/vitrage/api/controllers/v1/root.py b/vitrage/api/controllers/v1/root.py index b66b27529..d73e8ee4b 100644 --- a/vitrage/api/controllers/v1/root.py +++ b/vitrage/api/controllers/v1/root.py @@ -10,8 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +from vitrage.api.controllers.v1 import resource from vitrage.api.controllers.v1 import topology class V1Controller(object): topology = topology.TopologyController() + resources = resource.ResourcesController()