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_restx import fields
17 from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
22 ocloud = api_ims_inventory_v1.model(
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
40 mask='{oCloudId,globalcloudId,name,description,serviceUri}'
44 class ResourceTypeDTO:
45 alarm_dictionary = api_ims_inventory_v1.model(
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,
59 resource_type_get = api_ims_inventory_v1.model(
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
74 mask='{resourceTypeId,name,description,model,vendor,version}'
78 class ResourcePoolDTO:
80 resource_pool_get = api_ims_inventory_v1.model(
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
93 mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
98 resource_list = api_ims_inventory_v1.model(
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
112 mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
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
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,' +
138 class DeploymentManagerDTO:
140 deployment_manager_list = api_ims_inventory_v1.model(
141 "DeploymentManagerListDto",
143 'deploymentManagerId': fields.String(
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(
157 description='Profile support list, use default for the return \
159 'extensions': fields.String
161 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
162 'profileSupportList}'
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'),
180 extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
181 'profileName': fields.String,
182 'profileData': fields.Nested(profile, False, True),
185 deployment_manager_get = api_ims_inventory_v1.model(
186 "DeploymentManagerGetDto",
188 'deploymentManagerId': fields.String(
190 description='Deployment manager ID'),
191 'name': fields.String,
192 'description': fields.String,
193 'oCloudId': fields.String,
194 'serviceUri': fields.String(attribute='serviceUri'),
195 # 'deploymentManagementServiceEndpoint': fields.String(
196 # attribute='serviceUri'),
197 # 'supportedLocations': fields.String,
198 # 'capabilities': fields.String,
199 # 'capacity': fields.String,
200 'extensions': fields.Nested(extensions, True, True)
202 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
203 'extensions/profileName,extensions/profileData}'
207 class SubscriptionDTO:
209 subscription_get = api_ims_inventory_v1.model(
210 "SubscriptionGetDto",
212 'subscriptionId': fields.String(required=True,
213 description='Subscription ID'),
214 'callback': fields.String,
215 'consumerSubscriptionId': fields.String,
216 'filter': fields.String,
218 mask='{subscriptionId,callback}'
221 subscription_create = api_ims_inventory_v1.model(
222 "SubscriptionCreateDto",
224 'callback': fields.String(
225 required=True, description='Subscription callback address'),
226 'consumerSubscriptionId': fields.String,
227 'filter': fields.String,