Fix ocloudvirtualresource api typo
[pti/o2.git] / o2dms / views / nfdeployment_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 DmsLcmNfDeploymentDTO
20 from o2dms.views import dms_lcm_view, api_dms_lcm_v1
21 from o2common.service.messagebus import MessageBus
22
23 apibase = config.get_o2dms_api_base()
24
25
26 # LCM services #
27 @api_dms_lcm_v1\
28     .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
29            "NfDeployment")
30 @api_dms_lcm_v1\
31     .param('deploymentManagerID', 'ID of the deployment manager')
32 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
33 class DmsLcmNfDeploymentListRouter(Resource):
34
35     model = DmsLcmNfDeploymentDTO.NfDeployment_get
36
37     createdto = DmsLcmNfDeploymentDTO.NfDeployment_create
38     post_resp = DmsLcmNfDeploymentDTO.\
39         NfDeployment_create_post_resp
40
41     @api_dms_lcm_v1.doc('Get a list of NfDeployment')
42     @api_dms_lcm_v1.marshal_list_with(model)
43     def get(self, deploymentManagerID):
44         bus = MessageBus.get_instance()
45         return dms_lcm_view.lcm_nfdeployment_list(
46             deploymentManagerID, bus.uow)
47
48     @api_dms_lcm_v1.doc('Create a NfDeployment')
49     @api_dms_lcm_v1.expect(createdto)
50     @api_dms_lcm_v1.marshal_with(post_resp, code=201)
51     def post(self, deploymentManagerID):
52         bus = MessageBus.get_instance()
53         data = api_dms_lcm_v1.payload
54         id = dms_lcm_view.lcm_nfdeployment_create(
55             deploymentManagerID, data, bus.uow)
56         return {"id": id}, 201
57
58
59 @api_dms_lcm_v1\
60     .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
61            "NfDeployment/<nfDeploymentId>")
62 @api_dms_lcm_v1\
63     .param('deploymentManagerID', 'ID of the deployment manager')
64 @api_dms_lcm_v1.param('nfDeploymentId',
65                       'ID of the NfDeployment')
66 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
67 class DmsLcmNfDeploymentGetRouter(Resource):
68
69     model = DmsLcmNfDeploymentDTO.NfDeployment_get
70     updatedto = DmsLcmNfDeploymentDTO.\
71         NfDeployment_update
72
73     @api_dms_lcm_v1.doc('Get a NfDeploymentDescriptor')
74     @api_dms_lcm_v1.marshal_with(model)
75     def get(self, nfDeploymentId, deploymentManagerID):
76         bus = MessageBus.get_instance()
77         result = dms_lcm_view\
78             .lcm_nfdeployment_one(nfDeploymentId, bus.uow)
79         if result is not None:
80             return result
81         api_dms_lcm_v1.abort(
82             404, "NfDeploymentDescriptor {} doesn't exist".format(
83                 nfDeploymentId))
84
85     @api_dms_lcm_v1.doc('Update a NfDeployment')
86     @api_dms_lcm_v1.expect(updatedto)
87     def put(self, nfDeploymentId, deploymentManagerID):
88         bus = MessageBus.get_instance()
89         data = api_dms_lcm_v1.payload
90         dms_lcm_view.lcm_nfdeployment_update(
91             nfDeploymentId, data, bus.uow)
92         return {}, 201
93
94     @api_dms_lcm_v1.doc('Delete NfDeployment by ID')
95     @api_dms_lcm_v1.response(204, 'NfDeployment deleted')
96     def delete(self, nfDeploymentId, deploymentManagerID):
97         bus = MessageBus.get_instance()
98         with bus.uow:
99             bus.uow.nfdeployments.delete(nfDeploymentId)
100             bus.uow.commit()
101         return '', 204