def test_validate_limit(self): limit = utils.validate_limit(10) self.assertEqual(10, 10) # max limit limit = utils.validate_limit(999999999) self.assertEqual(CONF.api.max_limit, limit) # negative self.assertRaises(wsme.exc.ClientSideError, utils.validate_limit, -1) # zero self.assertRaises(wsme.exc.ClientSideError, utils.validate_limit, 0)
def _get_services_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Service.get_by_uuid(pecan.request.context, marker) services = pecan.request.rpcapi.service_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ServiceCollection.convert_with_links(services, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_baymodels_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.BayModel.get_by_uuid(pecan.request.context, marker) baymodels = objects.BayModel.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return BayModelCollection.convert_with_links(baymodels, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_pods_collection(self, marker, limit, sort_key, sort_dir, bay_ident, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Pod.get_by_uuid(pecan.request.context, marker) pods = pecan.request.rpcapi.pod_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return PodCollection.convert_with_links(pods, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_containers_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Container.get_by_uuid(pecan.request.context, marker) containers = objects.Container.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) for i, c in enumerate(containers): try: containers[i] = pecan.request.rpcapi.container_show(c.uuid) except Exception as e: LOG.exception(_LE("Error while list container %(uuid)s: " "%(e)s."), {'uuid': c.uuid, 'e': e}) containers[i].status = fields.ContainerStatus.UNKNOWN return ContainerCollection.convert_with_links(containers, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_x509keypairs_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.X509KeyPair.get_by_uuid( pecan.request.context, marker) x509keypairs = pecan.request.rpcapi.x509keypair_list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return X509KeyPairCollection.convert_with_links(x509keypairs, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_rcs_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.ReplicationController.get_by_uuid( pecan.request.context, marker) rcs = pecan.request.rpcapi.rc_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ReplicationControllerCollection.convert_with_links( rcs, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_containers_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Container.get_by_uuid(pecan.request.context, marker) containers = objects.Container.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) containers = [ pecan.request.rpcapi.container_show(c.uuid) for c in containers ] return ContainerCollection.convert_with_links(containers, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_rcs_collection(self, marker, limit, sort_key, sort_dir, bay_ident, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.ReplicationController.get_by_uuid( pecan.request.context, marker) rcs = pecan.request.rpcapi.rc_list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ReplicationControllerCollection.convert_with_links( rcs, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_services_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Service.get_by_uuid(pecan.request.context, marker) services = pecan.request.rpcapi.service_list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir ) return ServiceCollection.convert_with_links( services, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir )
def _get_containers_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Container.get_by_uuid(pecan.request.context, marker) containers = objects.Container.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ContainerCollection.convert_with_links(containers, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_x509keypairs_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.X509KeyPair.get_by_uuid(pecan.request.context, marker) x509keypairs = pecan.request.rpcapi.x509keypair_list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return X509KeyPairCollection.convert_with_links(x509keypairs, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)