1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from flask_restx import Resource
17 from o2common.service.messagebus import MessageBus
18 from o2ims.views import provision_view
19 from o2ims.views.api_ns import api_provision_v1
20 from o2ims.views.provision_dto import SmoEndpointDTO
23 def configure_api_route():
24 # Set global bus for resource
26 bus = MessageBus.get_instance()
29 # ---------- SMO endpoint ---------- #
30 @api_provision_v1.route("/smo-endpoint")
31 class SmoEndpointListRouter(Resource):
33 model = SmoEndpointDTO.endpoint_get
34 expect = SmoEndpointDTO.endpoint
35 post_resp = SmoEndpointDTO.endpoint_post_resp
37 @api_provision_v1.doc('List SMO endpoints')
38 @api_provision_v1.marshal_list_with(model)
40 return provision_view.configurations(bus.uow)
42 @api_provision_v1.doc('Create a SMO endpoint')
43 @api_provision_v1.expect(expect)
44 @api_provision_v1.marshal_with(post_resp, code=201)
46 data = api_provision_v1.payload
47 result = provision_view.configuration_create(data, bus)
51 @api_provision_v1.route("/smo-endpoint/<configurationID>")
52 @api_provision_v1.param('configurationID',
53 'ID of the SMO endpoint configuration')
54 @api_provision_v1.response(404, 'SMO Endpoint configuration not found')
55 class SmoEndpointGetDelRouter(Resource):
57 model = SmoEndpointDTO.endpoint_get
59 @api_provision_v1.doc('Get configuration by ID')
60 @api_provision_v1.marshal_with(model)
61 def get(self, configurationID):
62 result = provision_view.configuration_one(
63 configurationID, bus.uow)
64 if result is not None:
66 api_provision_v1.abort(404,
67 "SMO Endpoint configuration {} doesn't exist".
68 format(configurationID))
70 @api_provision_v1.doc('Delete configuration by ID')
71 @api_provision_v1.response(204, 'Configuration deleted')
72 def delete(self, configurationID):
73 result = provision_view.configuration_delete(configurationID, bus.uow)