895bfcb3cf3994f973bc724bbd5012b98ca5a22f
[pti/o2.git] / o2dms / views / dms_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 import jsonify
16 from flask_restx import Resource
17
18 from o2common.config import config
19 from o2dms.views.dms_dto import DmsDTO, DmsLcmNfDeploymentDescriptorDTO
20 from o2dms.views import dms_lcm_view
21
22 apibase = config.get_o2dms_api_base()
23
24
25 # ----------  DeploymentManagers ---------- #
26 api_dms = DmsDTO.api
27
28
29 @api_dms.route("/<deploymentManagerID>")
30 @api_dms.param('deploymentManagerID', 'ID of the deployment manager')
31 @api_dms.response(404, 'Deployment manager not found')
32 class DmsGetRouter(Resource):
33
34     model = DmsDTO.dms_get
35
36     @api_dms.doc('Get deployment manager')
37     @api_dms.marshal_with(model)
38     def get(self, deploymentManagerID):
39         result = dms_lcm_view.deployment_manager_one(
40             deploymentManagerID, uow)
41         if result is not None:
42             return result
43         api_dms.abort(404, "Deployment manager {} doesn't exist".format(
44             deploymentManagerID))
45
46
47 # LCM services #
48 api_lcm_nfdeploymentDesc = DmsLcmNfDeploymentDescriptorDTO.api
49
50
51 @api_lcm_nfdeploymentDesc\
52     .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle")
53 @api_lcm_nfdeploymentDesc\
54     .param('deploymentManagerID', 'ID of the deployment manager')
55 @api_lcm_nfdeploymentDesc.response(404, 'DMS LCM not found')
56 class DmsLcmNfDeploymentDescListRouter(Resource):
57
58     model = DmsLcmNfDeploymentDescriptorDTO.dmslcm_NfDeploymentDescriptor_get
59
60     @api_lcm_nfdeploymentDesc.doc('Get a list of NfDeploymentDescriptor')
61     @api_lcm_nfdeploymentDesc.marshal_list_with(model)
62     def get(self, deploymentManagerID):
63         return dms_lcm_view.lcm_nfdeploymentdesc_list(deploymentManagerID, uow)
64
65
66 @api_lcm_nfdeploymentDesc\
67     .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
68            "<nfDeploymentDescriptorId>")
69 @api_lcm_nfdeploymentDesc\
70     .param('deploymentManagerID', 'ID of the deployment manager')
71 @api_lcm_nfdeploymentDesc.param('nfDeploymentDescriptorId',
72                                 'ID of the NfDeploymentDescriptor')
73 @api_lcm_nfdeploymentDesc.response(404, 'DMS LCM not found')
74 class DmsLcmNfDeploymentDescGetRouter(Resource):
75
76     model = DmsLcmNfDeploymentDescriptorDTO.dmslcm_NfDeploymentDescriptor_get
77
78     @api_lcm_nfdeploymentDesc.doc('Get a NfDeploymentDescriptor')
79     @api_lcm_nfdeploymentDesc.marshal_with(model)
80     def get(self, nfDeploymentDescriptorId, deploymentManagerID):
81         result = dms_lcm_view\
82             .lcm_nfdeploymentdesc_one(nfDeploymentDescriptorId,
83                                       deploymentManagerID, uow)
84         if result is not None:
85             return result
86         api_dms.abort(404, "NfDeploymentDescriptor {} doesn't exist".format(
87             nfDeploymentDescriptorId))
88
89
90 def configure_namespace(app, bus):
91     app.add_namespace(api_dms, path=apibase)
92     app.add_namespace(api_lcm_nfdeploymentDesc, path=apibase)
93
94     # Set global uow
95     global uow
96     uow = bus.uow