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.dms_dto import DmsLcmNfDeploymentDTO
21 from o2dms.views.dms_dto import DmsLcmNfOCloudVResourceDTO
22 from o2dms.views import dms_lcm_view, api_dms_lcm_v1
24 apibase = config.get_o2dms_api_base()
27 # ---------- DeploymentManagers ---------- #
28 @api_dms_lcm_v1.route("/<deploymentManagerID>")
29 @api_dms_lcm_v1.param('deploymentManagerID', 'ID of the deployment manager')
30 @api_dms_lcm_v1.response(404, 'Deployment manager not found')
31 class DmsGetRouter(Resource):
33 model = DmsDTO.dms_get
35 @api_dms_lcm_v1.doc('Get deployment manager')
36 @api_dms_lcm_v1.marshal_with(model)
37 def get(self, deploymentManagerID):
38 result = dms_lcm_view.deployment_manager_one(
39 deploymentManagerID, bus.uow)
40 if result is not None:
42 api_dms_lcm_v1.abort(404, "Deployment manager {} doesn't exist".format(
48 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
49 "NfDeploymentDescriptor")
51 .param('deploymentManagerID', 'ID of the deployment manager')
52 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
53 class DmsLcmNfDeploymentDescListRouter(Resource):
55 model = DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_get
57 createdto = DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_create
58 post_resp = DmsLcmNfDeploymentDescriptorDTO.\
59 NfDeploymentDescriptor_create_post_resp
61 @api_dms_lcm_v1.doc('Get a list of NfDeploymentDescriptor')
62 @api_dms_lcm_v1.marshal_list_with(model)
63 def get(self, deploymentManagerID):
64 return dms_lcm_view.lcm_nfdeploymentdesc_list(
65 deploymentManagerID, bus.uow)
67 @api_dms_lcm_v1.doc('Create a NfDeploymentDescriptor')
68 @api_dms_lcm_v1.expect(createdto)
69 @api_dms_lcm_v1.marshal_with(post_resp, code=201)
70 def post(self, deploymentManagerID):
71 data = api_dms_lcm_v1.payload
72 id = dms_lcm_view.lcm_nfdeploymentdesc_create(
73 deploymentManagerID, data, bus.uow)
74 return {"id": id}, 201
78 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
79 "NfDeploymentDescriptor/<nfDeploymentDescriptorId>")
81 .param('deploymentManagerID', 'ID of the deployment manager')
82 @api_dms_lcm_v1.param('nfDeploymentDescriptorId',
83 'ID of the NfDeploymentDescriptor')
84 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
85 class DmsLcmNfDeploymentDescGetRouter(Resource):
87 model = DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_get
88 updatedto = DmsLcmNfDeploymentDescriptorDTO.\
89 NfDeploymentDescriptor_update
91 @api_dms_lcm_v1.doc('Get a NfDeploymentDescriptor')
92 @api_dms_lcm_v1.marshal_with(model)
93 def get(self, nfDeploymentDescriptorId, deploymentManagerID):
94 result = dms_lcm_view\
95 .lcm_nfdeploymentdesc_one(nfDeploymentDescriptorId, bus.uow)
96 if result is not None:
99 404, "NfDeploymentDescriptor {} doesn't exist".format(
100 nfDeploymentDescriptorId))
102 @api_dms_lcm_v1.doc('Update a NfDeploymentDescriptor')
103 @api_dms_lcm_v1.expect(updatedto)
104 def put(self, nfDeploymentDescriptorId, deploymentManagerID):
105 data = api_dms_lcm_v1.payload
106 dms_lcm_view.lcm_nfdeploymentdesc_update(
107 nfDeploymentDescriptorId, data, bus.uow)
110 @api_dms_lcm_v1.doc('Delete NfDeploymentDescriptor by ID')
111 @api_dms_lcm_v1.response(204, 'NfDeploymentDescriptor deleted')
112 def delete(self, nfDeploymentDescriptorId, deploymentManagerID):
114 bus.uow.nfdeployment_descs.delete(nfDeploymentDescriptorId)
121 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
124 .param('deploymentManagerID', 'ID of the deployment manager')
125 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
126 class DmsLcmNfDeploymentListRouter(Resource):
128 model = DmsLcmNfDeploymentDTO.NfDeployment_get
130 createdto = DmsLcmNfDeploymentDTO.NfDeployment_create
131 post_resp = DmsLcmNfDeploymentDTO.\
132 NfDeployment_create_post_resp
134 @api_dms_lcm_v1.doc('Get a list of NfDeployment')
135 @api_dms_lcm_v1.marshal_list_with(model)
136 def get(self, deploymentManagerID):
137 return dms_lcm_view.lcm_nfdeployment_list(
138 deploymentManagerID, bus.uow)
140 @api_dms_lcm_v1.doc('Create a NfDeployment')
141 @api_dms_lcm_v1.expect(createdto)
142 @api_dms_lcm_v1.marshal_with(post_resp, code=201)
143 def post(self, deploymentManagerID):
144 data = api_dms_lcm_v1.payload
145 id = dms_lcm_view.lcm_nfdeployment_create(
146 deploymentManagerID, data, bus.uow)
147 return {"id": id}, 201
151 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
152 "NfDeployment/<nfDeploymentId>")
154 .param('deploymentManagerID', 'ID of the deployment manager')
155 @api_dms_lcm_v1.param('nfDeploymentId',
156 'ID of the NfDeployment')
157 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
158 class DmsLcmNfDeploymentGetRouter(Resource):
160 model = DmsLcmNfDeploymentDTO.NfDeployment_get
161 updatedto = DmsLcmNfDeploymentDTO.\
164 @api_dms_lcm_v1.doc('Get a NfDeploymentDescriptor')
165 @api_dms_lcm_v1.marshal_with(model)
166 def get(self, nfDeploymentId, deploymentManagerID):
167 result = dms_lcm_view\
168 .lcm_nfdeployment_one(nfDeploymentId, bus.uow)
169 if result is not None:
171 api_dms_lcm_v1.abort(
172 404, "NfDeploymentDescriptor {} doesn't exist".format(
175 @api_dms_lcm_v1.doc('Update a NfDeployment')
176 @api_dms_lcm_v1.expect(updatedto)
177 def put(self, nfDeploymentId, deploymentManagerID):
178 data = api_dms_lcm_v1.payload
179 dms_lcm_view.lcm_nfdeployment_update(
180 nfDeploymentId, data, bus.uow)
183 @api_dms_lcm_v1.doc('Delete NfDeployment by ID')
184 @api_dms_lcm_v1.response(204, 'NfDeployment deleted')
185 def delete(self, nfDeploymentId, deploymentManagerID):
187 bus.uow.nfdeployments.delete(nfDeploymentId)
194 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
195 "NfDeployment/<nfDeploymentId>/NfOCloudVirtualResource")
197 .param('deploymentManagerID', 'ID of the Deployment Manager')
198 @api_dms_lcm_v1.param('nfDeploymentId',
199 'ID of the NfDeployment')
200 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
201 class DmsLcmNfOCloudVResListRouter(Resource):
203 model = DmsLcmNfOCloudVResourceDTO.NfOCloudVResource_get
205 @api_dms_lcm_v1.doc('Get a list of NfOCloudVirtualResource')
206 @api_dms_lcm_v1.marshal_list_with(model)
207 def get(self, nfDeploymentId, deploymentManagerID):
208 return dms_lcm_view.lcm_nfocloudvresource_list(
209 nfDeploymentId, bus.uow)
213 .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
214 "NfDeployment/<nfDeploymentId>"
215 "NfOCloudVirtualResource/<nfOCloudVirtualResourceId>")
217 .param('deploymentManagerID', 'ID of the deployment manager')
218 @api_dms_lcm_v1.param('nfDeploymentId',
219 'ID of the NfDeployment')
220 @api_dms_lcm_v1.param('nfOCloudVirtualResourceId',
221 'ID of the NfOCloudVirtualResource')
222 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
223 class DmsLcmNfOCloudVResGetRouter(Resource):
225 model = DmsLcmNfOCloudVResourceDTO.NfOCloudVResource_get
227 @api_dms_lcm_v1.doc('Get a NfOCloudVirtualResource')
228 @api_dms_lcm_v1.marshal_with(model)
229 def get(self, nfOCloudVirtualResourceId,
230 nfDeploymentId, deploymentManagerID):
231 result = dms_lcm_view\
232 .lcm_nfocloudvresource_one(nfOCloudVirtualResourceId, bus.uow)
233 if result is not None:
235 api_dms_lcm_v1.abort(
236 404, "NfOCloudVirtualResource {} doesn't exist".format(
237 nfOCloudVirtualResourceId))
240 def configure_namespace(app, bus_new):
241 app.add_namespace(api_dms_lcm_v1, path=apibase)