def _create_download_requests(content_units): """ Make a list of Nectar DownloadRequests for the given content units using the lazy catalog. :param content_units: The content units to build a list of DownloadRequests for. :type content_units: list of pulp.server.db.model.FileContentUnit :return: A list of DownloadRequests; each request includes a ``data`` instance variable which is a dict containing the FileContentUnit, the list of files in the unit, and the downloaded file's storage path. :rtype: list of nectar.request.DownloadRequest """ requests = [] working_dir = get_working_directory() signing_key = Key.load(pulp_conf.get('authentication', 'rsa_key')) for content_unit in content_units: # All files in the unit; every request for a unit has a reference to this dict. unit_files = {} unit_working_dir = os.path.join(working_dir, content_unit.id) for file_path in content_unit.list_files(): qs = LazyCatalogEntry.objects.filter( unit_id=content_unit.id, unit_type_id=content_unit.type_id, path=file_path ) catalog_entry = qs.order_by('revision').first() if catalog_entry is None: continue signed_url = _get_streamer_url(catalog_entry, signing_key) temporary_destination = os.path.join( unit_working_dir, os.path.basename(catalog_entry.path) ) mkdir(unit_working_dir) unit_files[temporary_destination] = { CATALOG_ENTRY: catalog_entry, PATH_DOWNLOADED: None, } request = DownloadRequest(signed_url, temporary_destination) # For memory reasons, only hold onto the id and type_id so we can reload the unit # once it's successfully downloaded. request.data = { TYPE_ID: content_unit.type_id, UNIT_ID: content_unit.id, UNIT_FILES: unit_files, } requests.append(request) return requests
def __init__(self, **kwargs): super(ContentView, self).__init__(**kwargs) self.key = Key.load(pulp_conf.get('authentication', 'rsa_key')) # Make sure all requested paths fall under these sub-directories, otherwise # we might find ourselves serving private keys to all and sundry. local_storage = pulp_conf.get('server', 'storage_dir') self.safe_serving_paths = [os.path.realpath(os.path.join(local_storage, subdir)) for subdir in SAFE_STORAGE_SUBDIRS] logger.debug(_("Serving Pulp content from {paths}; ensure " "Apache's mod_xsendfile is configured to serve from " "these paths as well").format(paths=str(self.safe_serving_paths)))
def _create_download_requests(content_units): """ Make a list of Nectar DownloadRequests for the given content units using the lazy catalog. :param content_units: The content units to build a list of DownloadRequests for. :type content_units: list of pulp.server.db.model.FileContentUnit :return: A list of DownloadRequests; each request includes a ``data`` instance variable which is a dict containing the FileContentUnit, the list of files in the unit, and the downloaded file's storage path. :rtype: list of nectar.request.DownloadRequest """ requests = [] working_dir = get_working_directory() signing_key = Key.load(pulp_conf.get('authentication', 'rsa_key')) for content_unit in content_units: # All files in the unit; every request for a unit has a reference to this dict. unit_files = {} unit_working_dir = os.path.join(working_dir, content_unit.id) for file_path in content_unit.list_files(): qs = LazyCatalogEntry.objects.filter( unit_id=content_unit.id, unit_type_id=content_unit.type_id, path=file_path) catalog_entry = qs.order_by('revision').first() if catalog_entry is None: continue signed_url = _get_streamer_url(catalog_entry, signing_key) temporary_destination = os.path.join( unit_working_dir, os.path.basename(catalog_entry.path)) mkdir(unit_working_dir) unit_files[temporary_destination] = { CATALOG_ENTRY: catalog_entry, PATH_DOWNLOADED: None, } request = DownloadRequest(signed_url, temporary_destination) # For memory reasons, only hold onto the id and type_id so we can reload the unit # once it's successfully downloaded. request.data = { TYPE_ID: content_unit.type_id, UNIT_ID: content_unit.id, UNIT_FILES: unit_files, } requests.append(request) return requests
def __init__(self, **kwargs): super(ContentView, self).__init__(**kwargs) self.key = Key.load(pulp_conf.get('authentication', 'rsa_key')) # Make sure all requested paths fall under these sub-directories, otherwise # we might find ourselves serving private keys to all and sundry. local_storage = pulp_conf.get('server', 'storage_dir') self.safe_serving_paths = [ os.path.realpath(os.path.join(local_storage, subdir)) for subdir in SAFE_STORAGE_SUBDIRS ] logger.debug( _("Serving Pulp content from {paths}; ensure " "Apache's mod_xsendfile is configured to serve from " "these paths as well").format( paths=str(self.safe_serving_paths)))
def __init__(self, **kwargs): super(ContentView, self).__init__(**kwargs) self.key = Key.load(pulp_conf.get('authentication', 'rsa_key'))