def _get_cluster_templates_collection(self, marker, limit, sort_key, sort_dir, 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.ClusterTemplate.get_by_uuid( pecan.request.context, marker) cluster_templates = objects.ClusterTemplate.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ClusterTemplateCollection.convert_with_links(cluster_templates, limit, url=resource_url, sort_key=sort_key, sort_dir=sort_dir)
def _get_bays_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.Cluster.get_by_uuid(pecan.request.context, marker) bays = objects.Cluster.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return BayCollection.convert_with_links(bays, 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_containers_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None, bay_ident=None): context = pecan.request.context 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(context, marker) containers = pecan.request.rpcapi.container_list(context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir, bay_ident=bay_ident) 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 test_validate_sort_dir(self): sort_dir = utils.validate_sort_dir('asc') self.assertEqual('asc', sort_dir) # invalid sort_dir parameter self.assertRaises(wsme.exc.ClientSideError, utils.validate_sort_dir, 'fake-sort')
def _get_baymodels_collection(self, marker, limit, sort_key, sort_dir, 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, sort_key=sort_key, sort_dir=sort_dir)
def _get_nodegroup_collection(self, cluster_id, marker, limit, sort_key, sort_dir, filters, expand=True): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.NodeGroup.get(pecan.request.context, cluster_id, marker) nodegroups = objects.NodeGroup.list(pecan.request.context, cluster_id, limit=limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir, filters=filters) return NodeGroupCollection.convert(nodegroups, cluster_id, limit, 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) rcs = pecan.request.rpcapi.rc_list(pecan.request.context, bay_ident) return ReplicationControllerCollection.convert_with_links( rcs, 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) rcs = pecan.request.rpcapi.rc_list(pecan.request.context, bay_ident) 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, bay_ident, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) context = pecan.request.context services = pecan.request.rpcapi.service_list(context, bay_ident) return ServiceCollection.convert_with_links(services, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_clusters_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): context = pecan.request.context if context.is_admin: if expand: policy.enforce(context, "cluster:detail_all_projects", action="cluster:detail_all_projects") else: policy.enforce(context, "cluster:get_all_all_projects", action="cluster:get_all_all_projects") # TODO(flwang): Instead of asking an extra 'all_project's # parameter, currently the design is allowing admin user to list # all clusters from all projects. But the all_tenants is one of # the condition to do project filter in DB API. And it's also used # by periodic tasks. So the could be removed in the future and # a new parameter 'project_id' would be added so that admin user # can list clusters for a particular project. context.all_tenants = True limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Cluster.get_by_uuid(pecan.request.context, marker) clusters = objects.Cluster.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ClusterCollection.convert_with_links(clusters, 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, bay_ident=None): context = pecan.request.context limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) filters = None marker_obj = None if marker: marker_obj = objects.Container.get_by_uuid(context, marker) if bay_ident: bay_obj = api_utils.get_resource('Bay', bay_ident) filters = {'bay_uuid': bay_obj.uuid} containers = objects.Container.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) 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_federation_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.Federation.get_by_uuid(pecan.request.context, marker) federations = objects.Federation.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return FederationCollection.convert_with_links(federations, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_cluster_templates_collection(self, marker, limit, sort_key, sort_dir, 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.ClusterTemplate.get_by_uuid( pecan.request.context, marker) cluster_templates = objects.ClusterTemplate.list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ClusterTemplateCollection.convert_with_links(cluster_templates, limit, url=resource_url, sort_key=sort_key, sort_dir=sort_dir)
def _get_quota_collection(self, marker, limit, sort_key, sort_dir, filters): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Quota.get_by_id(pecan.request.context, marker) quotas = objects.Quota.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir, filters=filters) return QuotaCollection.convert(quotas, limit, sort_key=sort_key, sort_dir=sort_dir)
def _get_bays_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.Bay.get_by_uuid(pecan.request.context, marker) bays = pecan.request.rpcapi.bay_list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return BayCollection.convert_with_links(bays, 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_cluster_templates_collection(self, marker, limit, sort_key, sort_dir, resource_url=None): context = pecan.request.context if context.is_admin: if resource_url == '/'.join(['clustertemplates', 'detail']): policy.enforce(context, "clustertemplate:detail_all_projects", action="clustertemplate:detail_all_projects") else: policy.enforce(context, "clustertemplate:get_all_all_projects", action="clustertemplate:get_all_all_projects") # TODO(flwang): Instead of asking an extra 'all_project's # parameter, currently the design is allowing admin user to list # all clusters from all projects. But the all_tenants is one of # the condition to do project filter in DB API. And it's also used # by periodic tasks. So the could be removed in the future and # a new parameter 'project_id' would be added so that admin user # can list clusters for a particular project. context.all_tenants = True limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.ClusterTemplate.get_by_uuid( pecan.request.context, marker) cluster_templates = objects.ClusterTemplate.list( pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return ClusterTemplateCollection.convert_with_links(cluster_templates, limit, url=resource_url, sort_key=sort_key, sort_dir=sort_dir)