def _get_shares(self, req, is_detail): """Returns a list of shares, transformed through view builder. """ context = req.environ["manila.context"] search_opts = {} search_opts.update(req.GET) # NOTE(rushiagr): v2 API allows name instead of display_name if "name" in search_opts: search_opts["display_name"] = search_opts["name"] del search_opts["name"] common.remove_invalid_options(context, search_opts, self._get_share_search_options()) shares = self.share_api.get_all(context, search_opts=search_opts) limited_list = common.limited(shares, req) if is_detail: shares = self._view_builder.detail_list(req, limited_list) else: shares = self._view_builder.summary_list(req, limited_list) return shares
def test_remove_invalid_options_admin(self): ctx = context.RequestContext('fakeuser', 'fakeproject', is_admin=True) search_opts = {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'} expected_opts = {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'} allowed_opts = ['a', 'c'] common.remove_invalid_options(ctx, search_opts, allowed_opts) self.assertEqual(search_opts, expected_opts)
def _get_snapshots(self, req, is_detail): """Returns a list of snapshots.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs search_opts.pop('limit', None) search_opts.pop('offset', None) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') common.remove_invalid_options(context, search_opts, self._get_snapshots_search_options()) snapshots = self.share_api.get_all_snapshots( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir, ) limited_list = common.limited(snapshots, req) if is_detail: snapshots = self._view_builder.detail_list(req, limited_list) else: snapshots = self._view_builder.summary_list(req, limited_list) return snapshots
def _get_access_group_entries(self, req, is_detail): """Returns a list of access_group_entries.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') access_group_id = search_opts.pop('access_group_id', None) common.remove_invalid_options(context, search_opts, self._get_access_entries_search_options()) access_group_entries = self.access_group_api.get_all_access_group_entries( context, access_group_id = access_group_id, sort_key=sort_key, sort_dir=sort_dir, ) print("NMH 222222 api/v2/access_group_entries.py access_group_entries is",access_group_entries) limited_list = common.limited(access_group_entries, req) if is_detail: access_group_entries = self._view_builder.detail_list(req, limited_list) else: access_group_entries = self._view_builder.summary_list(req, limited_list) return access_group_entries
def index(self, req): # pylint: disable=E0102 context = req.environ['manila.context'] filters = {} filters.update(req.GET) common.remove_invalid_options( context, filters, ('export_location_id', 'export_location_path')) instances = db.share_instances_get_all(context, filters) return self._view_builder.detail_list(req, instances)
def _get_security_services(self, req, is_detail): """Returns a transformed list of security services. The list gets transformed through view builder. """ context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # NOTE(vponomaryov): remove 'status' from search opts # since it was removed from security service model. search_opts.pop('status', None) if 'share_network_id' in search_opts: share_nw = db.share_network_get(context, search_opts['share_network_id']) security_services = share_nw['security_services'] del search_opts['share_network_id'] else: if 'all_tenants' in search_opts and context.is_admin: policy.check_policy(context, RESOURCE_NAME, 'get_all_security_services') security_services = db.security_service_get_all(context) else: security_services = db.security_service_get_all_by_project( context, context.project_id) search_opts.pop('all_tenants', None) common.remove_invalid_options( context, search_opts, self._get_security_services_search_options()) if search_opts: results = [] not_found = object() for ss in security_services: if all(ss.get(opt, not_found) == value for opt, value in search_opts.items()): results.append(ss) security_services = results limited_list = common.limited(security_services, req) if is_detail: security_services = self._view_builder.detail_list( req, limited_list) for ss in security_services['security_services']: share_networks = db.share_network_get_all_by_security_service( context, ss['id']) ss['share_networks'] = [sn['id'] for sn in share_networks] else: security_services = self._view_builder.summary_list( req, limited_list) return security_services
def _get_snapshots(self, req, is_detail): """Returns a list of snapshots.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs search_opts.pop('limit', None) search_opts.pop('offset', None) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') if 'description' in search_opts: search_opts['display_description'] = search_opts.pop( 'description') # like filter for key, db_key in (('name~', 'display_name~'), ('description~', 'display_description~')): if key in search_opts: search_opts[db_key] = search_opts.pop(key) common.remove_invalid_options(context, search_opts, self._get_snapshots_search_options()) snapshots = self.share_api.get_all_snapshots( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir, ) # Snapshots with no instances are filtered out. snapshots = list(filter(lambda x: x.get('status') is not None, snapshots)) limited_list = common.limited(snapshots, req) if is_detail: snapshots = self._view_builder.detail_list(req, limited_list) else: snapshots = self._view_builder.summary_list(req, limited_list) return snapshots
def _get_security_services(self, req, is_detail): """Returns a transformed list of security services. The list gets transformed through view builder. """ context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'get_all_security_services') search_opts = {} search_opts.update(req.GET) if 'share_network_id' in search_opts: share_nw = db.share_network_get(context, search_opts['share_network_id']) security_services = share_nw['security_services'] else: common.remove_invalid_options( context, search_opts, self._get_security_services_search_options()) if 'all_tenants' in search_opts: security_services = db.security_service_get_all(context) del search_opts['all_tenants'] else: security_services = db.security_service_get_all_by_project( context, context.project_id) if search_opts: results = [] not_found = object() for service in security_services: for opt, value in six.iteritems(search_opts): if service.get(opt, not_found) != value: break else: results.append(service) security_services = results limited_list = common.limited(security_services, req) if is_detail: security_services = self._view_builder.detail_list( req, limited_list) else: security_services = self._view_builder.summary_list( req, limited_list) return security_services
def _get_shares(self, req, is_detail): """Returns a list of shares, transformed through view builder.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs search_opts.pop('limit', None) search_opts.pop('offset', None) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') # Deserialize dicts if 'metadata' in search_opts: search_opts['metadata'] = ast.literal_eval(search_opts['metadata']) if 'extra_specs' in search_opts: search_opts['extra_specs'] = ast.literal_eval( search_opts['extra_specs']) # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') if sort_key == 'name': sort_key = 'display_name' common.remove_invalid_options( context, search_opts, self._get_share_search_options()) shares = self.share_api.get_all( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir) limited_list = common.limited(shares, req) if is_detail: shares = self._view_builder.detail_list(req, limited_list) else: shares = self._view_builder.summary_list(req, limited_list) return shares
def _get_snapshots(self, req, is_detail): """Returns a list of snapshots.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # NOTE(rushiagr): v2 API allows name instead of display_name if 'name' in search_opts: search_opts['display_name'] = search_opts['name'] del search_opts['name'] common.remove_invalid_options(context, search_opts, self._get_snapshots_search_options()) snapshots = self.share_api.get_all_snapshots(context, search_opts=search_opts) limited_list = common.limited(snapshots, req) if is_detail: snapshots = self._view_builder.detail_list(req, limited_list) else: snapshots = self._view_builder.summary_list(req, limited_list) return snapshots
def _get_shares(self, req, is_detail): """Returns a list of shares, transformed through view builder.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs search_opts.pop('limit', None) search_opts.pop('offset', None) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') show_count = False if 'with_count' in search_opts: show_count = utils.get_bool_from_api_params( 'with_count', search_opts) search_opts.pop('with_count') # Deserialize dicts if 'metadata' in search_opts: search_opts['metadata'] = ast.literal_eval(search_opts['metadata']) if 'extra_specs' in search_opts: search_opts['extra_specs'] = ast.literal_eval( search_opts['extra_specs']) # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') if 'description' in search_opts: search_opts['display_description'] = search_opts.pop( 'description') # like filter for key, db_key in (('name~', 'display_name~'), ('description~', 'display_description~')): if key in search_opts: search_opts[db_key] = search_opts.pop(key) if sort_key == 'name': sort_key = 'display_name' common.remove_invalid_options( context, search_opts, self._get_share_search_options()) shares = self.share_api.get_all( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir) total_count = None if show_count: total_count = len(shares) limited_list = common.limited(shares, req) if is_detail: shares = self._view_builder.detail_list(req, limited_list, total_count) else: shares = self._view_builder.summary_list(req, limited_list, total_count) return shares