1 # Copyright (C) 2022 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 typing import List
17 from o2common.service.client.base_client import BaseClient
18 from o2ims.domain import stx_object as ocloudModel
19 from o2ims.domain.resource_type import ResourceTypeEnum
21 from o2common.helper import o2logging
22 logger = o2logging.get_logger(__name__)
25 class ComputeAggClient(BaseClient):
26 def __init__(self, driver=None):
28 self.driver = AggClientImp()
30 def _get(self, id) -> ocloudModel.StxGenericModel:
31 return self.driver.getComputeList(res_pool=self._pool_id)[0]
33 def _list(self, **filters):
34 return self.driver.getComputeList(res_pool=self._pool_id)
36 def _set_stx_client(self):
40 class NetworkAggClient(BaseClient):
41 def __init__(self, driver=None):
43 self.driver = AggClientImp()
45 def _get(self, id) -> ocloudModel.StxGenericModel:
46 return self.driver.getNetworkList(res_pool=self._pool_id)[0]
48 def _list(self, **filters):
49 return self.driver.getNetworkList(res_pool=self._pool_id)
51 def _set_stx_client(self):
55 class StorageAggClient(BaseClient):
56 def __init__(self, driver=None):
58 self.driver = AggClientImp()
60 def _get(self, id) -> ocloudModel.StxGenericModel:
61 return self.driver.getStorageList(res_pool=self._pool_id)[0]
63 def _list(self, **filters):
64 return self.driver.getStorageList(res_pool=self._pool_id)
66 def _set_stx_client(self):
70 class UndefinedAggClient(BaseClient):
71 def __init__(self, driver=None):
73 self.driver = AggClientImp()
75 def _get(self, id) -> ocloudModel.StxGenericModel:
76 return self.driver.getUndefinedList(res_pool=self._pool_id)[0]
78 def _list(self, **filters):
79 return self.driver.getUndefinedList(res_pool=self._pool_id)
81 def _set_stx_client(self):
85 class AggClientImp(object):
89 def getComputeList(self, **filters) -> List[ocloudModel.StxGenericModel]:
90 compute = ComputeAggregate(filters['res_pool'])
91 return [ocloudModel.StxGenericModel(
92 ResourceTypeEnum.COMPUTE_AGGREGATE, compute)]
94 def getNetworkList(self, **filters) -> List[ocloudModel.StxGenericModel]:
95 network = NetworkAggregate(filters['res_pool'])
96 return [ocloudModel.StxGenericModel(
97 ResourceTypeEnum.NETWORK_AGGREGATE, network)]
99 def getStorageList(self, **filters) -> List[ocloudModel.StxGenericModel]:
100 storage = StorageAggregate(filters['res_pool'])
101 return [ocloudModel.StxGenericModel(
102 ResourceTypeEnum.STORAGE_AGGREGATE, storage)]
104 def getUndefinedList(self, **filters) -> List[ocloudModel.StxGenericModel]:
105 undefined = UndefinedAggregate(filters['res_pool'])
106 return [ocloudModel.StxGenericModel(
107 ResourceTypeEnum.UNDEFINED_AGGREGATE, undefined)]
111 def __init__(self, res_pool_id: str, name: str) -> None:
113 setattr(self, 'name', self.name)
114 setattr(self, 'uuid',
115 uuid.uuid3(uuid.NAMESPACE_URL, res_pool_id + self.name))
116 setattr(self, 'updated_at', None)
117 setattr(self, 'created_at', None)
123 class ComputeAggregate(Aggregate):
124 def __init__(self, res_pool_id: str) -> None:
125 super().__init__(res_pool_id, 'compute_aggregate')
128 class NetworkAggregate(Aggregate):
129 def __init__(self, res_pool_id: str) -> None:
130 super().__init__(res_pool_id, 'network_aggregate')
133 class StorageAggregate(Aggregate):
134 def __init__(self, res_pool_id: str) -> None:
135 super().__init__(res_pool_id, 'storage_aggregate')
138 class UndefinedAggregate(Aggregate):
139 def __init__(self, res_pool_id: str) -> None:
140 super().__init__(res_pool_id, 'undefined_aggregate')