4f0adfdf3ac2a924f19cdc038b52ad054846e3c0
[pti/o2.git] / o2dms / views / ocloud_vresource_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 DmsLcmNfOCloudVResourceDTO
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/<nfDeploymentId>/NfOCloudVirtualResource")
30 @api_dms_lcm_v1\
31     .param('deploymentManagerID', 'ID of the Deployment Manager')
32 @api_dms_lcm_v1.param('nfDeploymentId',
33                       'ID of the NfDeployment')
34 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
35 class DmsLcmNfOCloudVResListRouter(Resource):
36
37     model = DmsLcmNfOCloudVResourceDTO.NfOCloudVResource_get
38
39     @api_dms_lcm_v1.doc('Get a list of NfOCloudVirtualResource')
40     @api_dms_lcm_v1.marshal_list_with(model)
41     def get(self, nfDeploymentId, deploymentManagerID):
42         bus = MessageBus.get_instance()
43         return dms_lcm_view.lcm_nfocloudvresource_list(
44             nfDeploymentId, bus.uow)
45
46
47 @api_dms_lcm_v1\
48     .route("/<deploymentManagerID>/O2dms_DeploymentLifecycle/"
49            "NfDeployment/<nfDeploymentId>/"
50            "NfOCloudVirtualResource/<nfOCloudVirtualResourceId>")
51 @api_dms_lcm_v1\
52     .param('deploymentManagerID', 'ID of the deployment manager')
53 @api_dms_lcm_v1.param('nfDeploymentId',
54                       'ID of the NfDeployment')
55 @api_dms_lcm_v1.param('nfOCloudVirtualResourceId',
56                       'ID of the NfOCloudVirtualResource')
57 @api_dms_lcm_v1.response(404, 'DMS LCM not found')
58 class DmsLcmNfOCloudVResGetRouter(Resource):
59
60     model = DmsLcmNfOCloudVResourceDTO.NfOCloudVResource_get
61
62     @api_dms_lcm_v1.doc('Get a NfOCloudVirtualResource')
63     @api_dms_lcm_v1.marshal_with(model)
64     def get(self, nfOCloudVirtualResourceId,
65             nfDeploymentId, deploymentManagerID):
66         bus = MessageBus.get_instance()
67         result = dms_lcm_view\
68             .lcm_nfocloudvresource_one(nfOCloudVirtualResourceId, bus.uow)
69         if result is not None:
70             return result
71         api_dms_lcm_v1.abort(
72             404, "NfOCloudVirtualResource {} doesn't exist".format(
73                 nfOCloudVirtualResourceId))