add show resource and list resources

Implements: blueprint get-topology-api
Change-Id: Ib14664f1798041ee06cfc8a5105a8c3525b5811d
This commit is contained in:
Eyal 2016-01-20 15:41:50 +02:00
parent 0373cf684d
commit 50f0024ed0
3 changed files with 75 additions and 1 deletions

View File

@ -1,3 +1,5 @@
{
"get topology": "role:admin"
"get topology": "role:admin",
"get resource": "role:admin",
"list resources": "role:admin"
}

View File

@ -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()

View File

@ -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()