Code Review
/
pti
/
o2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add INF-320 support attribute-based filter
[pti/o2.git]
/
o2ims
/
views
/
ocloud_view.py
diff --git
a/o2ims/views/ocloud_view.py
b/o2ims/views/ocloud_view.py
index
83be178
..
e99279c
100644
(file)
--- a/
o2ims/views/ocloud_view.py
+++ b/
o2ims/views/ocloud_view.py
@@
-20,11
+20,14
@@
from datetime import datetime
import shutil
from o2common.service import unit_of_work
import shutil
from o2common.service import unit_of_work
+from o2common.config import config
+from o2common.views.pagination_view import Pagination
+from o2common.views.view import gen_filter
+from o2ims.domain import ocloud
from o2ims.views.ocloud_dto import SubscriptionDTO
from o2ims.domain.subscription_obj import Subscription
from o2common.helper import o2logging
from o2ims.views.ocloud_dto import SubscriptionDTO
from o2ims.domain.subscription_obj import Subscription
from o2common.helper import o2logging
-from o2common.config import config
logger = o2logging.get_logger(__name__)
logger = o2logging.get_logger(__name__)
@@
-40,10
+43,14
@@
def ocloud_one(ocloudid: str, uow: unit_of_work.AbstractUnitOfWork):
return first.serialize() if first is not None else None
return first.serialize() if first is not None else None
-def resource_types(uow: unit_of_work.AbstractUnitOfWork):
+def resource_types(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
+ pagination = Pagination(**kwargs)
+ filter_kwargs = pagination.get_filter()
+ args = gen_filter(ocloud.ResourceType,
+ kwargs['filter']) if 'filter' in kwargs else []
with uow:
with uow:
- li = uow.resource_types.list
(
)
- return
[r.serialize() for r in li]
+ li = uow.resource_types.list
_with_count(*args, **filter_kwargs
)
+ return
pagination.get_result(li)
def resource_type_one(resourceTypeId: str,
def resource_type_one(resourceTypeId: str,
@@
-53,10
+60,14
@@
def resource_type_one(resourceTypeId: str,
return first.serialize() if first is not None else None
return first.serialize() if first is not None else None
-def resource_pools(uow: unit_of_work.AbstractUnitOfWork):
+def resource_pools(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
+ pagination = Pagination(**kwargs)
+ filter_kwargs = pagination.get_filter()
+ args = gen_filter(ocloud.ResourcePool,
+ kwargs['filter']) if 'filter' in kwargs else []
with uow:
with uow:
- li = uow.resource_pools.list
(
)
- return
[r.serialize() for r in li]
+ li = uow.resource_pools.list
_with_count(*args, **filter_kwargs
)
+ return
pagination.get_result(li)
def resource_pool_one(resourcePoolId: str,
def resource_pool_one(resourcePoolId: str,
@@
-68,8
+79,9
@@
def resource_pool_one(resourcePoolId: str,
def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,
**kwargs):
def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,
**kwargs):
-
- filter_kwargs = {} # filter key should be the same with database name
+ pagination = Pagination(**kwargs)
+ # filter key should be the same with database name
+ filter_kwargs = pagination.get_filter()
if 'resourceTypeName' in kwargs:
resource_type_name = kwargs['resourceTypeName']
with uow:
if 'resourceTypeName' in kwargs:
resource_type_name = kwargs['resourceTypeName']
with uow:
@@
-81,15
+93,21
@@
def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,
res_type = uow.resource_types.get_by_name(resource_type_name)
restype_id = '' if res_type is None else res_type.resourceTypeId
filter_kwargs['resourceTypeId'] = restype_id
res_type = uow.resource_types.get_by_name(resource_type_name)
restype_id = '' if res_type is None else res_type.resourceTypeId
filter_kwargs['resourceTypeId'] = restype_id
+ args = gen_filter(
+ ocloud.Resource, kwargs['filter']) if 'filter' in kwargs else []
+ args.append(ocloud.Resource.resourcePoolId == resourcePoolId)
+ # args.append(ocloud.Resource.parentId == None)
- # li = uow.resources.list(resourcePoolId)
- # return [r.serialize() for r in li if r.resourceTypeId == restype_id]
if 'parentId' in kwargs:
filter_kwargs['parentId'] = kwargs['parentId']
if 'parentId' in kwargs:
filter_kwargs['parentId'] = kwargs['parentId']
+ if 'sort' in kwargs:
+ filter_kwargs['sort'] = kwargs['sort']
with uow:
with uow:
- li = uow.resources.list(resourcePoolId, **filter_kwargs)
- return [r.serialize() for r in li]
+ ret = uow.resources.list_with_count(
+ resourcePoolId, *args, **filter_kwargs)
+
+ return pagination.get_result(ret)
def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):
def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):
@@
-98,10
+116,14
@@
def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):
return first.serialize() if first is not None else None
return first.serialize() if first is not None else None
-def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):
+def deployment_managers(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
+ pagination = Pagination(**kwargs)
+ filter_kwargs = pagination.get_filter()
+ args = gen_filter(ocloud.DeploymentManager,
+ kwargs['filter']) if 'filter' in kwargs else []
with uow:
with uow:
- li = uow.deployment_managers.list
(
)
- return
[r.serialize() for r in li]
+ li = uow.deployment_managers.list
_with_count(*args, **filter_kwargs
)
+ return
pagination.get_result(li)
def deployment_manager_one(deploymentManagerId: str,
def deployment_manager_one(deploymentManagerId: str,
@@
-119,13
+141,13
@@
def deployment_manager_one(deploymentManagerId: str,
profile_data = result.pop("profile", None)
result['profileName'] = profile
profile_data = result.pop("profile", None)
result['profileName'] = profile
- if
"default"
== profile:
+ if
ocloud.DeploymentManagerProfileDefault
== profile:
pass
pass
- elif
"sol018"
== profile:
+ elif
ocloud.DeploymentManagerProfileSOL018
== profile:
result['deploymentManagementServiceEndpoint'] = \
profile_data['cluster_api_endpoint']
result['profileData'] = profile_data
result['deploymentManagementServiceEndpoint'] = \
profile_data['cluster_api_endpoint']
result['profileData'] = profile_data
- elif
"sol018_helmcli"
== profile:
+ elif
ocloud.DeploymentManagerProfileSOL018HelmCLI
== profile:
result['deploymentManagementServiceEndpoint'] = \
profile_data['cluster_api_endpoint']
result['deploymentManagementServiceEndpoint'] = \
profile_data['cluster_api_endpoint']
@@
-176,10
+198,14
@@
def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict:
return '/configs/'+kube_config_name
return '/configs/'+kube_config_name
-def subscriptions(uow: unit_of_work.AbstractUnitOfWork):
+def subscriptions(uow: unit_of_work.AbstractUnitOfWork, **kwargs):
+ pagination = Pagination(**kwargs)
+ filter_kwargs = pagination.get_filter()
+ args = gen_filter(ocloud.DeploymentManager,
+ kwargs['filter']) if 'filter' in kwargs else []
with uow:
with uow:
- li = uow.subscriptions.list
(
)
- return
[r.serialize() for r in li]
+ li = uow.subscriptions.list
_with_count(*args, **filter_kwargs
)
+ return
pagination.get_result(li)
def subscription_one(subscriptionId: str,
def subscription_one(subscriptionId: str,