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 import jsonify
16 from flask_restx import Resource
18 from o2common.config import config
19 from o2dms.views.dms_dto import DmsDTO, DmsLcmNfDeploymentDescriptorDTO
20 from o2dms.views import dms_lcm_view
22 apibase = config.get_o2dms_api_base()
25 # ---------- DeploymentManagers ---------- #
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):
34 model = DmsDTO.dms_get
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:
43 api_dms.abort(404, "Deployment manager {} doesn't exist".format(
48 api_lcm_nfdeploymentDesc = DmsLcmNfDeploymentDescriptorDTO.api
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):
58 model = DmsLcmNfDeploymentDescriptorDTO.dmslcm_NfDeploymentDescriptor_get
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)
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):
76 model = DmsLcmNfDeploymentDescriptorDTO.dmslcm_NfDeploymentDescriptor_get
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:
86 api_dms.abort(404, "NfDeploymentDescriptor {} doesn't exist".format(
87 nfDeploymentDescriptorId))
90 def configure_namespace(app, bus):
91 app.add_namespace(api_dms, path=apibase)
92 app.add_namespace(api_lcm_nfdeploymentDesc, path=apibase)