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
18 from o2common.views.flask_restx_fields import Json2Dict
23 ocloud = api_ims_inventory_v1.model(
26 'oCloudId': fields.String(required=True),
27 'globalcloudId': fields.String(attribute='globalCloudId'),
28 'name': fields.String,
29 'description': fields.String,
30 'serviceUri': fields.String(attribute='serviceUri'),
31 # 'infrastructureManagementServiceEndpoint': fields.String(
32 # attribute='serviceUri'),
33 # 'infrastructureMangementServiceEndPoint': fields.String(
34 # attribute='serviceUri'),
35 # 'resourceTypes': fields.String,
36 # 'resourcePools': fields.String,
37 # 'deploymentManagers': fields.String,
38 # 'smoRegistrationService': fields.String
39 'extensions': fields.String
41 mask='{oCloudId,globalcloudId,name,description,serviceUri}'
45 class ResourceTypeDTO:
46 alarm_dictionary = api_ims_inventory_v1.model(
50 'alarmDictionaryVersion': fields.String,
51 'alarmDictionarySchemVersion': fields.String,
52 'entityType': fields.String,
53 'vendor': fields.String,
54 'managementInterfaceId': fields.String,
55 'pkNotificationField': fields.String,
56 'alarmDefinition': fields.String,
60 resource_type_get = api_ims_inventory_v1.model(
63 'resourceTypeId': fields.String(required=True,
64 description='Resource type ID'),
65 'name': fields.String,
66 'description': fields.String,
67 'vendor': fields.String,
68 'model': fields.String,
69 'version': fields.String,
70 'alarmDictionary': fields.Nested(alarm_dictionary, False, True),
71 # 'resourceKind': fields.String,
72 # 'resourceClass': fields.String,
73 'extensions': fields.String
75 mask='{resourceTypeId,name,description,model,vendor,version}'
79 class ResourcePoolDTO:
81 resource_pool_get = api_ims_inventory_v1.model(
84 'resourcePoolId': fields.String(required=True,
85 description='Resource pool ID'),
86 'globalLocationId': fields.String,
87 'name': fields.String,
88 'description': fields.String,
89 'oCloudId': fields.String,
90 'location': fields.String,
91 # 'resources': fields.String,
92 'extensions': fields.String
94 mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
99 resource_list = api_ims_inventory_v1.model(
102 'resourceId': fields.String(required=True,
103 description='Resource ID'),
104 'resourceTypeId': fields.String,
105 'resourcePoolId': fields.String,
106 'globalAssetId': fields.String,
107 # 'name': fields.String,
108 'parentId': fields.String,
109 'description': fields.String,
110 # 'elements': fields.String,
111 # 'extensions': fields.String
112 'extensions': Json2Dict(attribute='extensions')
113 # 'extensions': fields.Raw(attribute='extensions')
115 mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
118 def recursive_resource_mapping(iteration_number=2):
119 resource_json_mapping = {
120 'resourceId': fields.String(required=True,
121 description='Resource ID'),
122 'resourceTypeId': fields.String,
123 'resourcePoolId': fields.String,
124 'globalAssetId': fields.String,
125 # 'name': fields.String,
126 'parentId': fields.String,
127 'description': fields.String,
128 # 'elements': fields.String,
129 # 'extensions': fields.String
130 'extensions': Json2Dict(attribute='extensions')
131 # 'extensions': fields.Raw(attribute='extensions')
134 resource_json_mapping['elements'] = fields.List(
135 fields.Nested(ResourceDTO.recursive_resource_mapping(
136 iteration_number-1)), attribute='children')
137 return api_ims_inventory_v1.model(
138 'ResourceGetDto' + str(iteration_number), resource_json_mapping,
139 mask='{resourceId,resourcePoolId,resourceTypeId,description,' +
143 class DeploymentManagerDTO:
145 deployment_manager_list = api_ims_inventory_v1.model(
146 "DeploymentManagerListDto",
148 'deploymentManagerId': fields.String(
150 description='Deployment manager ID'),
151 'name': fields.String,
152 'description': fields.String,
153 'oCloudId': fields.String,
154 'serviceUri': fields.String(attribute='serviceUri'),
155 # 'deploymentManagementServiceEndpoint': fields.String(
156 # attribute='serviceUri'),
157 # 'supportedLocations': fields.String,
158 # 'capabilities': fields.String,
159 # 'capacity': fields.String,
160 'profileSupportList': fields.List(
162 description='Profile support list, use default for the return \
164 'extensions': fields.String
166 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
167 'profileSupportList}'
170 profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
171 'cluster_api_endpoint': fields.String(
172 attribute='cluster_api_endpoint'),
173 'cluster_ca_cert': fields.String(attribute='cluster_ca_cert'),
174 'admin_user': fields.String(attribute='admin_user'),
175 'admin_client_cert': fields.String(attribute='admin_client_cert'),
176 'admin_client_key': fields.String(attribute='admin_client_key'),
177 # 'kube_config_file': fields.String(attribute='kube_config_file')
178 'helmcli_host_with_port': fields.String(
179 attribute='helmcli_host_with_port'),
180 'helmcli_username': fields.String(attribute='helmcli_username'),
181 'helmcli_password': fields.String(attribute='helmcli_password'),
182 'helmcli_kubeconfig': fields.String(attribute='helmcli_kubeconfig'),
185 extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
186 'profileName': fields.String,
187 'profileData': fields.Nested(profile, False, True),
190 deployment_manager_get = api_ims_inventory_v1.model(
191 "DeploymentManagerGetDto",
193 'deploymentManagerId': fields.String(
195 description='Deployment manager ID'),
196 'name': fields.String,
197 'description': fields.String,
198 'oCloudId': fields.String,
199 'serviceUri': fields.String(attribute='serviceUri'),
200 # 'deploymentManagementServiceEndpoint': fields.String(
201 # attribute='serviceUri'),
202 # 'supportedLocations': fields.String,
203 # 'capabilities': fields.String,
204 # 'capacity': fields.String,
205 'extensions': fields.Nested(extensions, True, True)
207 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
208 'extensions/profileName,extensions/profileData}'
212 class SubscriptionDTO:
214 subscription_get = api_ims_inventory_v1.model(
215 "SubscriptionGetDto",
217 'subscriptionId': fields.String(required=True,
218 description='Subscription ID'),
219 'callback': fields.String,
220 'consumerSubscriptionId': fields.String,
221 'filter': fields.String,
223 mask='{subscriptionId,callback}'
226 subscription_create = api_ims_inventory_v1.model(
227 "SubscriptionCreateDto",
229 'callback': fields.String(
230 required=True, description='Subscription callback address'),
231 'consumerSubscriptionId': fields.String,
232 'filter': fields.String,