Update error handling; update selector; change delete response code to 200
[pti/o2.git] / o2ims / views / ocloud_dto.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_restx import fields
16
17 from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
18
19
20 class OcloudDTO:
21
22     ocloud = api_ims_inventory_v1.model(
23         "OcloudDto",
24         {
25             'oCloudId': fields.String(required=True),
26             'globalcloudId': fields.String(attribute='globalCloudId'),
27             'name': fields.String,
28             'description': fields.String,
29             'serviceUri': fields.String(attribute='serviceUri'),
30             # 'infrastructureManagementServiceEndpoint': fields.String(
31             # attribute='serviceUri'),
32             # 'infrastructureMangementServiceEndPoint': fields.String(
33             # attribute='serviceUri'),
34             # 'resourceTypes': fields.String,
35             # 'resourcePools': fields.String,
36             # 'deploymentManagers': fields.String,
37             # 'smoRegistrationService': fields.String
38             'extensions': fields.String
39         },
40         mask='{oCloudId,globalcloudId,name,description,serviceUri}'
41     )
42
43
44 class ResourceTypeDTO:
45     alarm_dictionary = api_ims_inventory_v1.model(
46         "AlarmDictionaryDto",
47         {
48             'id': fields.String,
49             'alarmDictionaryVersion': fields.String,
50             'alarmDictionarySchemVersion': fields.String,
51             'entityType': fields.String,
52             'vendor': fields.String,
53             'managementInterfaceId': fields.String,
54             'pkNotificationField': fields.String,
55             'alarmDefinition': fields.String,
56         }
57     )
58
59     resource_type_get = api_ims_inventory_v1.model(
60         "ResourceTypeGetDto",
61         {
62             'resourceTypeId': fields.String(required=True,
63                                             description='Resource type ID'),
64             'name': fields.String,
65             'description': fields.String,
66             'vendor': fields.String,
67             'model': fields.String,
68             'version': fields.String,
69             'alarmDictionary': fields.Nested(alarm_dictionary, False, True),
70             # 'resourceKind': fields.String,
71             # 'resourceClass': fields.String,
72             'extensions': fields.String
73         },
74         mask='{resourceTypeId,name,description,model,vendor,version}'
75     )
76
77
78 class ResourcePoolDTO:
79
80     resource_pool_get = api_ims_inventory_v1.model(
81         "ResourcePoolGetDto",
82         {
83             'resourcePoolId': fields.String(required=True,
84                                             description='Resource pool ID'),
85             'globalLocationId': fields.String,
86             'name': fields.String,
87             'description': fields.String,
88             'oCloudId': fields.String,
89             'location': fields.String,
90             # 'resources': fields.String,
91             'extensions': fields.String
92         },
93         mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
94     )
95
96
97 class ResourceDTO:
98     resource_list = api_ims_inventory_v1.model(
99         "ResourceListDto",
100         {
101             'resourceId': fields.String(required=True,
102                                         description='Resource ID'),
103             'resourceTypeId': fields.String,
104             'resourcePoolId': fields.String,
105             'globalAssetId': fields.String,
106             # 'name': fields.String,
107             'parentId': fields.String,
108             'description': fields.String,
109             # 'elements': fields.String,
110             'extensions': fields.String
111         },
112         mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
113     )
114
115     def recursive_resource_mapping(iteration_number=2):
116         resource_json_mapping = {
117             'resourceId': fields.String(required=True,
118                                         description='Resource ID'),
119             'resourceTypeId': fields.String,
120             'resourcePoolId': fields.String,
121             'globalAssetId': fields.String,
122             # 'name': fields.String,
123             'parentId': fields.String,
124             'description': fields.String,
125             # 'elements': fields.String,
126             'extensions': fields.String
127         }
128         if iteration_number:
129             resource_json_mapping['elements'] = fields.List(
130                 fields.Nested(ResourceDTO.recursive_resource_mapping(
131                     iteration_number-1)), attribute='children')
132         return api_ims_inventory_v1.model(
133             'ResourceGetDto' + str(iteration_number), resource_json_mapping,
134             mask='{resourceId,resourcePoolId,resourceTypeId,description,' +
135             'parentId}')
136
137
138 class DeploymentManagerDTO:
139
140     deployment_manager_list = api_ims_inventory_v1.model(
141         "DeploymentManagerListDto",
142         {
143             'deploymentManagerId': fields.String(
144                 required=True,
145                 description='Deployment manager ID'),
146             'name': fields.String,
147             'description': fields.String,
148             'oCloudId': fields.String,
149             'serviceUri': fields.String(attribute='serviceUri'),
150             # 'deploymentManagementServiceEndpoint': fields.String(
151             # attribute='serviceUri'),
152             # 'supportedLocations': fields.String,
153             # 'capabilities': fields.String,
154             # 'capacity': fields.String,
155             'profileSupportList': fields.List(
156                 fields.String,
157                 description='Profile support list, use default for the return \
158                      endpoint'),
159             'extensions': fields.String
160         },
161         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
162         'profileSupportList}'
163     )
164
165     profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
166         'cluster_api_endpoint': fields.String(
167             attribute='cluster_api_endpoint'),
168         'cluster_ca_cert': fields.String(attribute='cluster_ca_cert'),
169         'admin_user': fields.String(attribute='admin_user'),
170         'admin_client_cert': fields.String(attribute='admin_client_cert'),
171         'admin_client_key': fields.String(attribute='admin_client_key'),
172         # 'kube_config_file': fields.String(attribute='kube_config_file')
173         'helmcli_host_with_port': fields.String(
174             attribute='helmcli_host_with_port'),
175         'helmcli_username': fields.String(attribute='helmcli_username'),
176         'helmcli_password': fields.String(attribute='helmcli_password'),
177         'helmcli_kubeconfig': fields.String(attribute='helmcli_kubeconfig'),
178     })
179
180     deployment_manager_get = api_ims_inventory_v1.model(
181         "DeploymentManagerGetDto",
182         {
183             'deploymentManagerId': fields.String(
184                 required=True,
185                 description='Deployment manager ID'),
186             'name': fields.String,
187             'description': fields.String,
188             'oCloudId': fields.String,
189             'serviceUri': fields.String(attribute='serviceUri'),
190             # 'deploymentManagementServiceEndpoint': fields.String(
191             # attribute='serviceUri'),
192             # 'supportedLocations': fields.String,
193             # 'capabilities': fields.String,
194             # 'capacity': fields.String,
195             'profileName': fields.String,
196             'profileData': fields.Nested(profile, False, True),
197             'extensions': fields.String
198         },
199         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
200         'profileName,profileData}'
201     )
202
203
204 class SubscriptionDTO:
205
206     subscription_get = api_ims_inventory_v1.model(
207         "SubscriptionGetDto",
208         {
209             'subscriptionId': fields.String(required=True,
210                                             description='Subscription ID'),
211             'callback': fields.String,
212             'consumerSubscriptionId': fields.String,
213             'filter': fields.String,
214         },
215         mask='{subscriptionId,callback}'
216     )
217
218     subscription = api_ims_inventory_v1.model(
219         "SubscriptionCreateDto",
220         {
221             'callback': fields.String(
222                 required=True, description='Subscription callback address'),
223             'consumerSubscriptionId': fields.String,
224             'filter': fields.String,
225         }
226     )
227
228     subscription_post_resp = api_ims_inventory_v1.model(
229         "SubscriptionCreatedRespDto",
230         {
231             'subscriptionId': fields.String(required=True,
232                                             description='Subscription ID'),
233         }
234     )