Fix api_versions request failed issue, Add oCloudId in the DMS query
[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     )
41
42
43 class ResourceTypeDTO:
44     alarm_dictionary = api_ims_inventory_v1.model(
45         "AlarmDictionaryDto",
46         {
47             'id': fields.String,
48             'alarmDictionaryVersion': fields.String,
49             'alarmDictionarySchemVersion': fields.String,
50             'entityType': fields.String,
51             'vendor': fields.String,
52             'managementInterfaceId': fields.String,
53             'pkNotificationField': fields.String,
54             'alarmDefinition': fields.String,
55         }
56     )
57
58     resource_type_get = api_ims_inventory_v1.model(
59         "ResourceTypeGetDto",
60         {
61             'resourceTypeId': fields.String(required=True,
62                                             description='Resource type ID'),
63             'name': fields.String,
64             'description': fields.String,
65             'vendor': fields.String,
66             'model': fields.String,
67             'version': fields.String,
68             'alarmDictionary': fields.Nested(alarm_dictionary, False, True),
69             # 'resourceKind': fields.String,
70             # 'resourceClass': fields.String,
71             'extensions': fields.String
72         }
73     )
74
75
76 class ResourcePoolDTO:
77
78     resource_pool_get = api_ims_inventory_v1.model(
79         "ResourcePoolGetDto",
80         {
81             'resourcePoolId': fields.String(required=True,
82                                             description='Resource pool ID'),
83             'globalLocationId': fields.String,
84             'name': fields.String,
85             'description': fields.String,
86             'oCloudId': fields.String,
87             'location': fields.String,
88             # 'resources': fields.String,
89             'extensions': fields.String
90         }
91     )
92
93
94 class ResourceDTO:
95     resource_list = api_ims_inventory_v1.model(
96         "ResourceListDto",
97         {
98             'resourceId': fields.String(required=True,
99                                         description='Resource ID'),
100             'resourceTypeId': fields.String,
101             'resourcePoolId': fields.String,
102             'globalAssetId': fields.String,
103             # 'name': fields.String,
104             'parentId': fields.String,
105             'description': fields.String,
106             # 'elements': fields.String,
107             'extensions': fields.String
108         }
109     )
110
111     def recursive_resource_mapping(iteration_number=2):
112         resource_json_mapping = {
113             'resourceId': fields.String(required=True,
114                                         description='Resource ID'),
115             'resourceTypeId': fields.String,
116             'resourcePoolId': fields.String,
117             'globalAssetId': fields.String,
118             # 'name': fields.String,
119             'parentId': fields.String,
120             'description': fields.String,
121             # 'elements': fields.String,
122             'extensions': fields.String
123         }
124         if iteration_number:
125             resource_json_mapping['elements'] = fields.List(
126                 fields.Nested(ResourceDTO.recursive_resource_mapping(
127                     iteration_number-1)), attribute='children')
128         return api_ims_inventory_v1.model(
129             'ResourceGetDto' + str(iteration_number), resource_json_mapping)
130
131
132 class DeploymentManagerDTO:
133
134     deployment_manager_list = api_ims_inventory_v1.model(
135         "DeploymentManagerListDto",
136         {
137             'deploymentManagerId': fields.String(
138                 required=True,
139                 description='Deployment manager ID'),
140             'name': fields.String,
141             'description': fields.String,
142             'oCloudId': fields.String,
143             'serviceUri': fields.String(attribute='serviceUri'),
144             # 'deploymentManagementServiceEndpoint': fields.String(
145             # attribute='serviceUri'),
146             # 'supportedLocations': fields.String,
147             # 'capabilities': fields.String,
148             # 'capacity': fields.String,
149             'profileSupportList': fields.List(
150                 fields.String,
151                 description='Profile support list, use default for the return \
152                      endpoint'),
153             'extensions': fields.String
154         }
155     )
156
157     profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
158         'cluster_api_endpoint': fields.String(
159             attribute='cluster_api_endpoint'),
160         'cluster_ca_cert': fields.String(attribute='cluster_ca_cert'),
161         'admin_user': fields.String(attribute='admin_user'),
162         'admin_client_cert': fields.String(attribute='admin_client_cert'),
163         'admin_client_key': fields.String(attribute='admin_client_key'),
164         # 'kube_config_file': fields.String(attribute='kube_config_file')
165         'helmcli_host_with_port': fields.String(
166             attribute='helmcli_host_with_port'),
167         'helmcli_username': fields.String(attribute='helmcli_username'),
168         'helmcli_password': fields.String(attribute='helmcli_password'),
169         'helmcli_kubeconfig': fields.String(attribute='helmcli_kubeconfig'),
170     })
171
172     deployment_manager_get = api_ims_inventory_v1.model(
173         "DeploymentManagerGetDto",
174         {
175             'deploymentManagerId': fields.String(
176                 required=True,
177                 description='Deployment manager ID'),
178             'name': fields.String,
179             'description': fields.String,
180             'oCloudId': fields.String,
181             'serviceUri': fields.String(attribute='serviceUri'),
182             # 'deploymentManagementServiceEndpoint': fields.String(
183             # attribute='serviceUri'),
184             # 'supportedLocations': fields.String,
185             # 'capabilities': fields.String,
186             # 'capacity': fields.String,
187             'profileName': fields.String,
188             'profileData': fields.Nested(profile, False, True),
189             'extensions': fields.String
190         }
191     )
192
193
194 class SubscriptionDTO:
195
196     subscription_get = api_ims_inventory_v1.model(
197         "SubscriptionGetDto",
198         {
199             'subscriptionId': fields.String(required=True,
200                                             description='Subscription ID'),
201             'callback': fields.String,
202             'consumerSubscriptionId': fields.String,
203             'filter': fields.String,
204         }
205     )
206
207     subscription = api_ims_inventory_v1.model(
208         "SubscriptionCreateDto",
209         {
210             'callback': fields.String(
211                 required=True, description='Subscription callback address'),
212             'consumerSubscriptionId': fields.String,
213             'filter': fields.String,
214         }
215     )
216
217     subscription_post_resp = api_ims_inventory_v1.model(
218         "SubscriptionCreatedRespDto",
219         {
220             'subscriptionId': fields.String(required=True,
221                                             description='Subscription ID'),
222         }
223     )