Implement watcher datamodel list in watcher-api
1. Add datamodel api and policy_enfoce file. 2. Add related unittest for data_model api and policy. Partially Implements:blueprint show-datamodel-api Change-Id: I1654685d8cf04db5dd132d43a8640ddf91893cad
This commit is contained in:
@@ -35,6 +35,7 @@ from watcher.api.controllers.v1 import action
|
||||
from watcher.api.controllers.v1 import action_plan
|
||||
from watcher.api.controllers.v1 import audit
|
||||
from watcher.api.controllers.v1 import audit_template
|
||||
from watcher.api.controllers.v1 import data_model
|
||||
from watcher.api.controllers.v1 import goal
|
||||
from watcher.api.controllers.v1 import scoring_engine
|
||||
from watcher.api.controllers.v1 import service
|
||||
@@ -114,6 +115,9 @@ class V1(APIBase):
|
||||
audits = [link.Link]
|
||||
"""Links to the audits resource"""
|
||||
|
||||
data_model = [link.Link]
|
||||
"""Links to the data model resource"""
|
||||
|
||||
actions = [link.Link]
|
||||
"""Links to the actions resource"""
|
||||
|
||||
@@ -158,6 +162,13 @@ class V1(APIBase):
|
||||
'audits', '',
|
||||
bookmark=True)
|
||||
]
|
||||
v1.data_model = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'data_model', ''),
|
||||
link.Link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'data_model', '',
|
||||
bookmark=True)
|
||||
]
|
||||
v1.actions = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'actions', ''),
|
||||
link.Link.make_link('bookmark',
|
||||
@@ -202,6 +213,7 @@ class Controller(rest.RestController):
|
||||
scoring_engines = scoring_engine.ScoringEngineController()
|
||||
services = service.ServicesController()
|
||||
strategies = strategy.StrategiesController()
|
||||
data_model = data_model.DataModelController()
|
||||
|
||||
@wsme_pecan.wsexpose(V1)
|
||||
def get(self):
|
||||
|
||||
68
watcher/api/controllers/v1/data_model.py
Normal file
68
watcher/api/controllers/v1/data_model.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2019 ZTE Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
An Interface for users and admin to List Data Model.
|
||||
"""
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
||||
from watcher.api.controllers.v1 import types
|
||||
from watcher.common import exception
|
||||
from watcher.common import policy
|
||||
from watcher.decision_engine import rpcapi
|
||||
|
||||
|
||||
class DataModelController(rest.RestController):
|
||||
"""REST controller for data model"""
|
||||
def __init__(self):
|
||||
super(DataModelController, self).__init__()
|
||||
|
||||
from_data_model = False
|
||||
"""A flag to indicate if the requests to this controller are coming
|
||||
from the top-level resource DataModel."""
|
||||
|
||||
@wsme_pecan.wsexpose(wtypes.text, wtypes.text, types.uuid)
|
||||
def get_all(self, data_model_type='compute', audit_uuid=None):
|
||||
"""Retrieve information about the given data model.
|
||||
|
||||
:param data_model_type: The type of data model user wants to list.
|
||||
Supported values: compute.
|
||||
Future support values: storage, baremetal.
|
||||
The default value is compute.
|
||||
:param audit_uuid: The UUID of the audit, used to filter data model
|
||||
by the scope in audit.
|
||||
"""
|
||||
if self.from_data_model:
|
||||
raise exception.OperationNotPermitted
|
||||
allowed_data_model_type = [
|
||||
'compute',
|
||||
]
|
||||
if data_model_type not in allowed_data_model_type:
|
||||
raise exception.DataModelTypeNotFound(
|
||||
data_model_type=data_model_type)
|
||||
context = pecan.request.context
|
||||
de_client = rpcapi.DecisionEngineAPI()
|
||||
policy.enforce(context, 'data_model:get_all',
|
||||
action='data_model:get_all')
|
||||
rpc_all_data_model = de_client.get_data_model_info(
|
||||
context,
|
||||
data_model_type,
|
||||
audit_uuid)
|
||||
return rpc_all_data_model
|
||||
Reference in New Issue
Block a user