def get(self, request): """Get a list of packages. The listing result is an object with property "packages". Example GET: http://localhost/api/app-catalog/packages?sort_dir=desc #flake8: noqa The following get parameters may be passed in the GET request: :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen package. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). Any additional request parameters will be passed through the API as filters. """ filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) packages, has_more_data = api.packages.package_list( request, filters=filters, **kwargs) return { 'packages': [p.to_dict() for p in packages], 'has_more_data': has_more_data, }
def get(self, request, environment, component): """Get a metadata object for a component in a given environment Example GET: http://localhost/api/app-catalog/environments/123/components/456/metadata The following get parameters may be passed in the GET request: :param environment: identifier of the environment :param component: identifier of the component Any additionally a "session" parameter should be passed through the API as a keyword. """ filters, keywords = rest_utils.parse_filters_kwargs(request, ['session']) session = keywords.get('session') if not session: session = env_api.Session.get_or_create_or_delete(request, environment) component = api.muranoclient(request).services.get( environment, '/' + component, session) if component: return component.to_dict()['?'].get('metadata', {}) return {}
def post(self, request, environment, component): """Set a metadata object for a component in a given environment Example POST: http://localhost/api/app-catalog/environments/123/components/456/metadata The following get parameters may be passed in the GET request: :param environment: identifier of the environment :param component: identifier of the component Any additionally a "session" parameter should be passed through the API as a keyword. Request body should contain 'updated' keyword, contain all the updated metadata attributes. If it is empty, the metadata is considered to be deleted. """ client = api.muranoclient(request) filters, keywords = rest_utils.parse_filters_kwargs(request, ['session']) session = keywords.get('session') if not session: session = env_api.Session.get_or_create_or_delete(request, environment) updated = request.DATA.get('updated', {}) path = '/{0}/%3F/metadata'.format(component) if updated: client.services.put(environment, path, updated, session) else: client.services.delete(environment, path, session)
def get(self, request): """Get a list of packages. The listing result is an object with property "packages". Example GET: http://localhost/api/murano/packages?sort_dir=desc #flake8: noqa The following get parameters may be passed in the GET request: :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen package. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). Any additional request parameters will be passed through the API as filters. """ filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) packages, has_more_data = api.packages.package_list( request, filters=filters, **kwargs) return { 'packages': [p.to_dict() for p in packages], 'has_more_data': has_more_data, }
def post(self, request, environment): """Set a metadata object for a given environment Example POST: http://localhost/api/app-catalog/environments/123/metadata The following get parameters may be passed in the GET request: :param environment: identifier of the environment Any additionally a "session" parameter should be passed through the API as a keyword. Request body should contain 'updated' keyword, contain all the updated metadata attributes. If it is empty, the metadata is considered to be deleted. """ client = api.muranoclient(request) filters, keywords = rest_utils.parse_filters_kwargs(request, ['session']) session = keywords.get('session') if not session: session = env_api.Session.get_or_create_or_delete(request, environment) updated = request.DATA.get('updated', {}) patch = { "op": "replace", "path": "/?/metadata", "value": updated } client.environments.update_model(environment, [patch], session)
def get(self, request): """Get a list of images. The listing result is an object with property "items". Each item is an image. Example GET: http://localhost/api/glance/images?sort_dir=desc&sort_key=name&name=cirros-0.3.2-x86_64-uec #flake8: noqa The following get parameters may be passed in the GET request: :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen image. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). :param sort_key: The field to sort on (for example, 'created_at'). Default is created_at. Any additional request parameters will be passed through the API as filters. There are v1/v2 complications which are being addressed as a separate work stream: https://review.openstack.org/#/c/150084/ """ filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) images, has_more_data, has_prev_data = api.glance.image_list_detailed(request, filters=filters, **kwargs) return {"items": [i.to_dict() for i in images], "has_more_data": has_more_data, "has_prev_data": has_prev_data}
def get(self, request): """Get a list of metadata definition namespaces. The listing result is an object with property "items". Each item is a namespace. Example GET: http://localhost/api/glance/metadefs/namespaces?resource_types=OS::Nova::Flavor&sort_dir=desc&marker=OS::Compute::Watchdog&paginate=False&sort_key=namespace #flake8: noqa The following get parameters may be passed in the GET request: :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen namespace. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). :param sort_key: The field to sort on (for example, 'created_at'). Default is namespace. The way base namespaces are loaded into glance typically at first deployment is done in a single transaction giving them a potentially unpredictable sort result when using create_at. Any additional request parameters will be passed through the API as filters. """ filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) namespaces, has_more, has_prev = api.glance.metadefs_namespace_list(request, filters=filters, **kwargs) return {"items": [n.to_dict() for n in namespaces], "has_more_data": has_more, "has_prev_data": has_prev}
def get(self, request): """Get a list of projects. By default a listing of all projects for the current domain are returned. You may specify GET parameters for domain_id (string), user_id (string) and admin (boolean) to change that listing's context. Additionally, paginate (boolean) and marker may be used to get paginated listings. The listing result is an object with properties: items The list of project objects. has_more Boolean indicating there are more results when pagination is used. """ filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] if len(filters) == 0: filters = None result, has_more = api.keystone.tenant_list( request, paginate=request.GET.get('paginate', False), marker=request.GET.get('marker'), domain=request.GET.get('domain_id'), user=request.GET.get('user_id'), admin=request.GET.get('admin', True), filters=filters) # return (list of results, has_more_data) return dict(has_more=has_more, items=[d.to_dict() for d in result])
def get(self, request): """Get a list of projects. By default a listing of all projects for the current domain are returned. You may specify GET parameters for domain_id (string), user_id (string) and admin (boolean) to change that listing's context. Additionally, paginate (boolean) and marker may be used to get paginated listings. The listing result is an object with properties: items The list of project objects. has_more Boolean indicating there are more results when pagination is used. """ filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] if len(filters) == 0: filters = None result, has_more = api.keystone.tenant_list( request, paginate=request.GET.get('paginate', False), marker=request.GET.get('marker'), domain=request.GET.get('domain_id'), user=request.GET.get('user_id'), admin=request.GET.get('admin', True), filters=filters ) # return (list of results, has_more_data) return dict(has_more=has_more, items=[d.to_dict() for d in result])
def get(self, request): """Get a list of volume snapshots associated with the current project. The listing result is an object with property "items". """ result = api.cinder.volume_snapshot_list( request, search_opts=rest_utils.parse_filters_kwargs(request)[0]) return {'items': [u.to_dict() for u in result]}
def get(self, request): """Get a list of volume snapshots associated with the current project. The listing result is an object with property "items". """ result = api.cinder.volume_snapshot_list( request, search_opts=rest_utils.parse_filters_kwargs(request)[0] ) return {'items': [u.to_dict() for u in result]}
def test_parse_filters_keywords(self): kwargs = { 'sort_dir': '1', 'sort_key': '2', } filters = { 'filter1': '1', 'filter2': '2', } # Combined request_params = dict(kwargs) request_params.update(filters) request = self.mock_rest_request(**{'GET': dict(request_params)}) output_filters, output_kwargs = utils.parse_filters_kwargs( request, kwargs) self.assertDictEqual(kwargs, output_kwargs) self.assertDictEqual(filters, output_filters) # Empty Filters request = self.mock_rest_request(**{'GET': dict(kwargs)}) output_filters, output_kwargs = utils.parse_filters_kwargs( request, kwargs) self.assertDictEqual(kwargs, output_kwargs) self.assertDictEqual({}, output_filters) # Empty keywords request = self.mock_rest_request(**{'GET': dict(filters)}) output_filters, output_kwargs = utils.parse_filters_kwargs( request) self.assertDictEqual({}, output_kwargs) self.assertDictEqual(filters, output_filters) # Empty both request = self.mock_rest_request(**{'GET': dict()}) output_filters, output_kwargs = utils.parse_filters_kwargs( request) self.assertDictEqual({}, output_kwargs) self.assertDictEqual({}, output_filters)
def get(self, request): """Get a list of policies.""" filters, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) policies, has_more_data, has_prev_data = senlin.policy_list( request, filters=filters, **kwargs) return { 'items': [p.to_dict() for p in policies], 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Get a list of receivers.""" filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) receivers, has_more_data, has_prev_data = senlin.receiver_list( request, filters=filters, **kwargs) return { 'items': [r.to_dict() for r in receivers], 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Get a list of profiles.""" filters, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS) profiles, has_more_data, has_prev_data = senlin.profile_list( request, filters=filters, **kwargs) return { 'items': [p.to_dict() for p in profiles], 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Get a list of clusters.""" filters, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) clusters, has_more_data, has_prev_data = senlin.cluster_list( request, filters=filters, **kwargs) return { 'items': [c.to_dict() for c in clusters], 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Get a list of images. The listing result is an object with property "items". Each item is an image. Example GET: http://localhost/api/glance/images?sort_dir=desc&sort_key=name&name=cirros-0.3.2-x86_64-uec The following get parameters may be passed in the GET request: :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen image. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). :param sort_key: The field to sort on (for example, 'created_at'). Default is created_at. Any additional request parameters will be passed through the API as filters. There are v1/v2 complications which are being addressed as a separate work stream: https://review.opendev.org/#/c/150084/ """ filters, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) images, has_more_data, has_prev_data = api.glance.image_list_detailed( request, filters=filters, **kwargs) fix_images = [] for image in images: if ("Plesk" not in image.name): fix_images.append(image) return { 'items': [i for i in fix_images], 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Provides a list with the user's servers Example GET: http://localhost/api/extension/servers """ try: instances, _more = server_list( request, search_opts=rest_utils.parse_filters_kwargs(request)[0]) except Exception as e: raise rest_utils.AjaxError(400, 'Unable to retrieve instances. ' "'%s'" % e.args[0]) all_servers = [u.to_dict() for u in instances] return { 'items': all_servers }
def get(self, request): """Get a list of metadata definition namespaces. The listing result is an object with property "items". Each item is a namespace. Example GET: http://localhost/api/glance/metadefs/namespaces?resource_types=OS::Nova::Flavor&sort_dir=desc&marker=OS::Compute::Watchdog&paginate=False&sort_key=namespace The following get parameters may be passed in the GET request: :param resource_type: Namespace resource type. If specified returned namespace properties will have prefixes proper for selected resource type. :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen namespace. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). :param sort_key: The field to sort on (for example, 'created_at'). Default is namespace. The way base namespaces are loaded into glance typically at first deployment is done in a single transaction giving them a potentially unpredictable sort result when using create_at. Any additional request parameters will be passed through the API as filters. """ filters, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) names = ('items', 'has_more_data', 'has_prev_data') return dict( izip( names, api.glance.metadefs_namespace_full_list(request, filters=filters, **kwargs)))
def get(self, request): """Get a detailed list of volumes associated with the current user's project. Example GET: http://localhost/api/cinder/volumes?paginate=true&sort_dir=asc If invoked as an admin, you may set the GET parameter "all_projects" to 'true' to return details for all projects. The following get parameters may be passed in the GET :param search_opts: includes options such as name, status, bootable :param paginate: If true will perform pagination based on settings. :param marker: Specifies the namespace of the last-seen image. The typical pattern of limit and marker is to make an initial limited request and then to use the last namespace from the response as the marker parameter in a subsequent limited request. With paginate, limit is automatically set. :param sort_dir: The sort direction ('asc' or 'desc'). The listing result is an object with property "items". """ if request.GET.get('all_projects') == 'true': result, has_more, has_prev = api.cinder.volume_list_paged( request, {'all_tenants': 1} ) else: search_opts, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) result, has_more, has_prev = api.cinder.volume_list_paged( request, search_opts=search_opts, **kwargs ) return { 'items': [u.to_dict() for u in result], 'has_more_data': has_more, 'has_prev_data': has_prev }
def get(self, request): """Get a list of receivers.""" filters, kwargs = rest_utils.parse_filters_kwargs( request, CLIENT_KEYWORDS) receivers, has_more_data, has_prev_data = senlin.receiver_list( request, filters=filters, **kwargs) receivers_dict = [] for r in receivers: r = r.to_dict() r["params"] = api_utils.convert_to_yaml(r["params"]) r["channel"] = api_utils.convert_to_yaml(r["channel"]) receivers_dict.append(r) return { 'items': receivers_dict, 'has_more_data': has_more_data, 'has_prev_data': has_prev_data, }
def get(self, request): """Get a list of users. By default, a listing of all users for the current domain are returned. You may specify GET parameters for project_id, domain_id and group_id to change that listing's context. The listing result is an object with property "items". """ domain_context = request.session.get("domain_context") filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] if len(filters) == 0: filters = None result = api.keystone.user_list( request, project=request.GET.get("project_id"), domain=request.GET.get("domain_id", domain_context), group=request.GET.get("group_id"), filters=filters, ) return {"items": [u.to_dict() for u in result]}
def get(self, request): """Get a list of users. By default, a listing of all users for the current domain are returned. You may specify GET parameters for project_id, domain_id and group_id to change that listing's context. The listing result is an object with property "items". """ domain_context = request.session.get('domain_context') filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] if not filters: filters = None result = api.keystone.user_list(request, project=request.GET.get('project_id'), domain=request.GET.get( 'domain_id', domain_context), group=request.GET.get('group_id'), filters=filters) return {'items': [u.to_dict() for u in result]}
def get(self, request): """Get a detailed list of volumes associated with the current user's project. If invoked as an admin, you may set the GET parameter "all_projects" to 'true'. The following get parameters may be passed in the GET :param search_opts includes options such as name, status, bootable The listing result is an object with property "items". """ # TODO(clu_): when v2 pagination stuff in Cinder API merges # (https://review.openstack.org/#/c/118450), handle here accordingly if request.GET.get('all_projects') == 'true': result = api.cinder.volume_list(request, {'all_tenants': 1}) else: result = api.cinder.volume_list( request, search_opts=rest_utils.parse_filters_kwargs(request)[0]) return {'items': [u.to_dict() for u in result]}
def get(self, request): """Get a detailed list of volumes associated with the current user's project. If invoked as an admin, you may set the GET parameter "all_projects" to 'true'. The following get parameters may be passed in the GET :param search_opts includes options such as name, status, bootable The listing result is an object with property "items". """ # TODO(clu_): when v2 pagination stuff in Cinder API merges # (https://review.openstack.org/#/c/118450), handle here accordingly if request.GET.get('all_projects') == 'true': result = api.cinder.volume_list(request, {'all_tenants': 1}) else: result = api.cinder.volume_list( request, search_opts=rest_utils.parse_filters_kwargs(request)[0] ) return {'items': [u.to_dict() for u in result]}
def get(self, request, plan_id): search_opts, kwargs = rest_utils.parse_filters_kwargs( request, ['availability_zone_map']) az_map = json.loads(kwargs['availability_zone_map']) return {'topo': api.build_resources_topo(request, plan_id, az_map)}
def get(self, request, resource_type): search_opts, kwargs = rest_utils.parse_filters_kwargs(request) res = api.resource_list(request, resource_type, search_opts=search_opts) return {'items': [r.__dict__.get('_info') for r in res]}
def get(self, request): search_opts, kwargs = rest_utils.parse_filters_kwargs(request) plans, _, _ = api.plan_list(request, search_opts=search_opts) return {'items': [p.to_dict() for p in plans]}