X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fviews%2Focloud_view.py;h=52161259ad741ed75cc77c1a3cddf548ae608d4f;hb=refs%2Ftags%2F2.0.0-rc3;hp=bc1109774834fd74f7a1ef2d9211f77e9757e063;hpb=56d70321199385deedfe2d1c438c14a22dbb50d6;p=pti%2Fo2.git diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index bc11097..5216125 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -77,11 +77,16 @@ def resource_pool_one(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork): with uow: first = uow.resource_pools.get(resourcePoolId) - return first.serialize() if first is not None else None + return first.serialize() if first else None def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, **kwargs): + with uow: + first = uow.resource_pools.get(resourcePoolId) + if first is None: + raise NotFoundException("ResourcePool {} doesn't exist".format( + resourcePoolId)) pagination = Pagination(**kwargs) # filter key should be the same with database name query_kwargs = pagination.get_pagination() @@ -98,8 +103,6 @@ def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, query_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) if 'parentId' in kwargs: query_kwargs['parentId'] = kwargs['parentId'] @@ -113,10 +116,19 @@ def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, 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, resourcePoolId: str): with uow: - first = uow.resources.get(resourceId) - return first.serialize() if first is not None else None + resoucePool = uow.resource_pools.get(resourcePoolId) + if resoucePool is None: + raise NotFoundException("ResourcePool {} doesn't exist".format( + resourcePoolId)) + + first = uow.resources.get(resourceId) + if first is None: + raise NotFoundException("Resource {} doesn't exist".format( + resourceId)) + return first.serialize() def deployment_managers(uow: unit_of_work.AbstractUnitOfWork, **kwargs):