X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fdomain%2Focloud.py;h=1323134b3c1749afe7a9901651f2bf592a0d9f67;hb=refs%2Fchanges%2F24%2F7524%2F1;hp=49b25508c8ad492eddf6e0e5e750a45eb688193b;hpb=5c501cb5e57a1ac3e0e7d38e22a3759e7958777a;p=pti%2Fo2.git diff --git a/o2ims/domain/ocloud.py b/o2ims/domain/ocloud.py index 49b2550..1323134 100644 --- a/o2ims/domain/ocloud.py +++ b/o2ims/domain/ocloud.py @@ -13,8 +13,9 @@ # limitations under the License. from __future__ import annotations +import json -from o2ims.domain.base import AgRoot +from o2common.domain.base import AgRoot, Serializer # from dataclasses import dataclass # from datetime import date # from typing import Optional, List, Set @@ -22,21 +23,14 @@ from .resource_type import ResourceTypeEnum # from uuid import UUID -class Subscription(AgRoot): - def __init__(self, id: str, callback: str, consumersubid: str = '', - filter: str = '') -> None: - self.subscriptionId = id - self.callback = callback - self.consumerSubscriptionId = consumersubid - self.filter = filter - - -class DeploymentManager: +class DeploymentManager(AgRoot, Serializer): def __init__(self, id: str, name: str, ocloudid: str, dmsendpoint: str, description: str = '', supportedLocations: str = '', capabilities: str = '', capacity: str = '') -> None: + super().__init__() self.deploymentManagerId = id + self.version_number = 0 self.oCloudId = ocloudid self.name = name self.description = description @@ -47,11 +41,13 @@ class DeploymentManager: self.extensions = [] -class ResourcePool(AgRoot): +class ResourcePool(AgRoot, Serializer): def __init__(self, id: str, name: str, location: str, ocloudid: str, gLocationId: str = '', description: str = '') -> None: + super().__init__() self.resourcePoolId = id + self.version_number = 0 self.oCloudId = ocloudid self.globalLocationId = gLocationId self.name = name @@ -60,14 +56,16 @@ class ResourcePool(AgRoot): self.extensions = [] -class ResourceType(AgRoot): +class ResourceType(AgRoot, Serializer): def __init__(self, typeid: str, name: str, typeEnum: ResourceTypeEnum, ocloudid: str, vender: str = '', model: str = '', version: str = '', description: str = '') -> None: + super().__init__() self.resourceTypeId = typeid + self.version_number = 0 self.oCloudId = ocloudid - self.resourceTypeEnum = typeEnum.value + self.resourceTypeEnum = typeEnum self.name = name self.vender = vender self.model = model @@ -76,22 +74,44 @@ class ResourceType(AgRoot): self.extensions = [] -class Resource(AgRoot): +class Resource(AgRoot, Serializer): def __init__(self, resourceId: str, resourceTypeId: str, - resourcePoolId: str, oCloudId: str = '', - parentId: str = '', elements: list = [], + resourcePoolId: str, name: str, parentId: str = '', + gAssetId: str = '', elements: str = '', description: str = '') -> None: + super().__init__() self.resourceId = resourceId - self.oCloudId = oCloudId + self.version_number = 0 self.resourceTypeId = resourceTypeId self.resourcePoolId = resourcePoolId + self.name = name + self.globalAssetId = gAssetId self.parentId = parentId self.elements = elements self.description = description + self.children = [] self.extensions = [] + def set_children(self, children: list): + self.children = children -class Ocloud(AgRoot): + def serialize(self): + d = Serializer.serialize(self) + + if 'elements' in d and d['elements'] != '': + d['elements'] = json.loads(d['elements']) + + if not hasattr(self, 'children') or len(self.children) == 0: + return d + else: + d['children'] = [] + + for child in self.children: + d['children'].append(child.serialize()) + return d + + +class Ocloud(AgRoot, Serializer): def __init__(self, ocloudid: str, name: str, imsendpoint: str, globalcloudId: str = '', description: str = '', version_number: int = 0) -> None: @@ -106,16 +126,15 @@ class Ocloud(AgRoot): self.deploymentManagers = [] self.resourceTypes = [] self.extensions = [] - # self.events = [] - - def addDeploymentManager(self, - deploymentManager: DeploymentManager): - - deploymentManager.oCloudId = self.oCloudId - old = filter( - lambda x: x.deploymentManagerId == - deploymentManager.deploymentManagerId, - self.deploymentManagers) - for o in old or []: - self.deploymentManagers.remove(o) - self.deploymentManagers.append(deploymentManager) + + # def addDeploymentManager(self, + # deploymentManager: DeploymentManager): + + # deploymentManager.oCloudId = self.oCloudId + # old = filter( + # lambda x: x.deploymentManagerId == + # deploymentManager.deploymentManagerId, + # self.deploymentManagers) + # for o in old or []: + # self.deploymentManagers.remove(o) + # self.deploymentManagers.append(deploymentManager)