Update O2app start with global ocloud ID
[pti/o2.git] / o2ims / views / provision_route.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from flask_restx import Resource
16
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
21
22
23 def configure_api_route():
24     # Set global bus for resource
25     global bus
26     bus = MessageBus.get_instance()
27
28
29 # ----------  SMO endpoint ---------- #
30 @api_provision_v1.route("/smo-endpoint")
31 class SmoEndpointListRouter(Resource):
32
33     model = SmoEndpointDTO.endpoint_get
34     expect = SmoEndpointDTO.endpoint
35     post_resp = SmoEndpointDTO.endpoint_post_resp
36
37     @api_provision_v1.doc('List SMO endpoints')
38     @api_provision_v1.marshal_list_with(model)
39     def get(self):
40         return provision_view.configurations(bus.uow)
41
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)
45     def post(self):
46         data = api_provision_v1.payload
47         result = provision_view.configuration_create(data, bus)
48         return result, 201
49
50
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):
56
57     model = SmoEndpointDTO.endpoint_get
58
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:
65             return result
66         api_provision_v1.abort(404,
67                                "SMO Endpoint configuration {} doesn't exist".
68                                format(configurationID))
69
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)
74         return result, 204