def distributor_removed(self, repo, config): """ Called when a distributor of this type is removed from a repository. This hook allows the distributor to clean up any files that may have been created during the actual publishing. The distributor may use the contents of the working directory in cleanup. It is not required that the contents of this directory be deleted by the distributor; Pulp will ensure it is wiped following this call. If this call raises an exception, the distributor will still be removed from the repository and the working directory contents will still be wiped by Pulp. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param config: plugin configuration :type config: pulp.plugins.config.PluginCallConfiguration """ # remove the directories that might have been created for this repo/distributor dir_list = [ repo.working_dir, configuration.get_master_publish_dir(repo, config, "v1"), configuration.get_master_publish_dir(repo, config, "v2"), configuration.get_web_publish_dir(repo, config, "v1"), configuration.get_web_publish_dir(repo, config, "v2") ] for repo_dir in dir_list: # in case repo_dir is None # ingore_errors set to True does not cover this. if repo_dir: shutil.rmtree(repo_dir, ignore_errors=True) # Remove the published app file & directory links dir_list = [ configuration.get_web_publish_dir(repo, config, "v1"), configuration.get_web_publish_dir(repo, config, "v2"), os.path.join(configuration.get_app_publish_dir(config, "v1"), configuration.get_redirect_file_name(repo)), os.path.join(configuration.get_app_publish_dir(config, "v2"), configuration.get_redirect_file_name(repo)) ] for repo_dir in dir_list: try: os.unlink(repo_dir) except OSError: # It's fine if this file doesn't exist pass
def __init__(self, repo, publish_conduit, config, repo_content_unit_q=None): """ :param repo: Pulp managed Yum repository :type repo: pulp.plugins.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration :param repo_content_unit_q: optional Q object that will be applied to the queries performed against RepoContentUnit model :type repo_content_unit_q: mongoengine.Q """ super(WebPublisher, self).__init__( step_type=constants.PUBLISH_STEP_WEB_PUBLISHER, repo=repo, publish_conduit=publish_conduit, config=config) docker_api_version = 'v1' publish_dir = configuration.get_web_publish_dir(repo, config, docker_api_version) app_file = configuration.get_redirect_file_name(repo) app_publish_location = os.path.join( configuration.get_app_publish_dir(config, docker_api_version), app_file) self.working_dir = os.path.join(self.get_working_dir(), docker_api_version) misc.mkdir(self.working_dir) self.web_working_dir = os.path.join(self.get_working_dir(), 'web') master_publish_dir = configuration.get_master_publish_dir(repo, config, docker_api_version) atomic_publish_step = AtomicDirectoryPublishStep(self.get_working_dir(), [('web', publish_dir), (app_file, app_publish_location)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) atomic_publish_step.description = _('Making v1 files available via web.') self.add_child(PublishImagesStep(repo_content_unit_q=repo_content_unit_q)) self.add_child(atomic_publish_step)
def __init__(self, repo, publish_conduit, config): """ :param repo: Pulp managed Yum repository. :type repo: pulp.server.db.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration """ super(WebPublisher, self).__init__(constants.PUBLISH_STEP_WEB_PUBLISHER, repo, publish_conduit, config) publish_dir = configuration.get_web_publish_dir(repo, config) app_file = configuration.get_redirect_file_name(repo) app_publish_location = os.path.join(configuration.get_app_publish_dir(config), app_file) self.web_working_dir = os.path.join(self.get_working_dir(), 'web') master_publish_dir = configuration.get_master_publish_dir(repo, config) atomic_publish_step = AtomicDirectoryPublishStep(self.get_working_dir(), [('web', publish_dir), (app_file, app_publish_location)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) atomic_publish_step.description = _('Making files available via web.') self.add_child(PublishImagesStep()) self.add_child(atomic_publish_step)
def __init__(self, repo, publish_conduit, config): """ :param repo: Pulp managed Yum repository :type repo: pulp.plugins.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration """ super(WebPublisher, self).__init__( step_type=constants.PUBLISH_STEP_WEB_PUBLISHER, repo=repo, publish_conduit=publish_conduit, config=config) docker_api_version = 'v1' publish_dir = configuration.get_web_publish_dir(repo, config, docker_api_version) app_file = configuration.get_redirect_file_name(repo) app_publish_location = os.path.join( configuration.get_app_publish_dir(config, docker_api_version), app_file) self.working_dir = os.path.join(self.get_working_dir(), docker_api_version) misc.mkdir(self.working_dir) self.web_working_dir = os.path.join(self.get_working_dir(), 'web') master_publish_dir = configuration.get_master_publish_dir(repo, config, docker_api_version) atomic_publish_step = AtomicDirectoryPublishStep(self.get_working_dir(), [('web', publish_dir), (app_file, app_publish_location)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) atomic_publish_step.description = _('Making v1 files available via web.') self.add_child(PublishImagesStep()) self.add_child(atomic_publish_step)
def __init__(self, repo, publish_conduit, config): """ Initialize the V2WebPublisher. :param repo: Pulp managed Yum repository :type repo: pulp.plugins.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration """ super(V2WebPublisher, self).__init__(constants.PUBLISH_STEP_WEB_PUBLISHER, repo, publish_conduit, config) # Map tags we've seen to the "newest" manifests that go with them self.tags = {} docker_api_version = 'v2' publish_dir = configuration.get_web_publish_dir(repo, config, docker_api_version) app_file = configuration.get_redirect_file_name(repo) app_publish_location = os.path.join( configuration.get_app_publish_dir(config, docker_api_version), app_file) self.working_dir = os.path.join(self.get_working_dir(), docker_api_version) misc.mkdir(self.working_dir) self.web_working_dir = os.path.join(self.get_working_dir(), 'web') master_publish_dir = configuration.get_master_publish_dir(repo, config, docker_api_version) atomic_publish_step = publish_step.AtomicDirectoryPublishStep( self.get_working_dir(), [('', publish_dir), (app_file, app_publish_location)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) atomic_publish_step.description = _('Making v2 files available via web.') self.add_child(PublishBlobsStep()) self.publish_manifests_step = PublishManifestsStep() self.add_child(self.publish_manifests_step) self.add_child(PublishTagsStep()) self.add_child(atomic_publish_step) self.add_child(RedirectFileStep(app_publish_location))
def distributor_removed(self, repo, config): """ Called when a distributor of this type is removed from a repository. This hook allows the distributor to clean up any files that may have been created during the actual publishing. The distributor may use the contents of the working directory in cleanup. It is not required that the contents of this directory be deleted by the distributor; Pulp will ensure it is wiped following this call. If this call raises an exception, the distributor will still be removed from the repository and the working directory contents will still be wiped by Pulp. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param config: plugin configuration :type config: pulp.plugins.config.PluginCallConfiguration """ # remove the directories that might have been created for this repo/distributor dir_list = [repo.working_dir, configuration.get_master_publish_dir(repo, config, "v1"), configuration.get_master_publish_dir(repo, config, "v2"), configuration.get_web_publish_dir(repo, config, "v1"), configuration.get_web_publish_dir(repo, config, "v2")] for repo_dir in dir_list: # in case repo_dir is None # ingore_errors set to True does not cover this. if repo_dir: shutil.rmtree(repo_dir, ignore_errors=True) # Remove the published app file & directory links dir_list = [configuration.get_web_publish_dir(repo, config, "v1"), configuration.get_web_publish_dir(repo, config, "v2"), os.path.join(configuration.get_app_publish_dir(config, "v1"), configuration.get_redirect_file_name(repo)), os.path.join(configuration.get_app_publish_dir(config, "v2"), configuration.get_redirect_file_name(repo))] for repo_dir in dir_list: try: os.unlink(repo_dir) except OSError: # It's fine if this file doesn't exist pass
def __init__(self, repo, publish_conduit, config, repo_content_unit_q=None): """ Initialize the V2WebPublisher. :param repo: Pulp managed Yum repository :type repo: pulp.plugins.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration :param repo_content_unit_q: optional Q object that will be applied to the queries performed against RepoContentUnit model :type repo_content_unit_q: mongoengine.Q """ super(V2WebPublisher, self).__init__(step_type=constants.PUBLISH_STEP_WEB_PUBLISHER, repo=repo, publish_conduit=publish_conduit, config=config) self.redirect_data = {1: set(), 2: set(), 'list': set(), 'amd64': {}} docker_api_version = 'v2' publish_dir = configuration.get_web_publish_dir( repo, config, docker_api_version) app_file = configuration.get_redirect_file_name(repo) app_publish_location = os.path.join( configuration.get_app_publish_dir(config, docker_api_version), app_file) self.working_dir = os.path.join(self.get_working_dir(), docker_api_version) misc.mkdir(self.working_dir) self.web_working_dir = os.path.join(self.get_working_dir(), 'web') master_publish_dir = configuration.get_master_publish_dir( repo, config, docker_api_version) atomic_publish_step = publish_step.AtomicDirectoryPublishStep( self.get_working_dir(), [('', publish_dir), (app_file, app_publish_location)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) atomic_publish_step.description = _( 'Making v2 files available via web.') self.add_child( PublishBlobsStep(repo_content_unit_q=repo_content_unit_q)) self.publish_manifests_step = PublishManifestsStep( self.redirect_data, repo_content_unit_q=repo_content_unit_q) self.add_child(self.publish_manifests_step) self.publish_manifest_lists_step = PublishManifestListsStep( self.redirect_data, repo_content_unit_q=repo_content_unit_q) self.add_child(self.publish_manifest_lists_step) self.add_child(PublishTagsStep(self.redirect_data)) self.add_child(atomic_publish_step) self.add_child( RedirectFileStep(app_publish_location, self.redirect_data))
def __init__(self, repo, publish_conduit, config, repo_content_unit_q=None): """ Initialize the V2WebPublisher. :param repo: Pulp managed Yum repository :type repo: pulp.plugins.model.Repository :param publish_conduit: Conduit providing access to relative Pulp functionality :type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: Pulp configuration for the distributor :type config: pulp.plugins.config.PluginCallConfiguration :param repo_content_unit_q: optional Q object that will be applied to the queries performed against RepoContentUnit model :type repo_content_unit_q: mongoengine.Q """ super(V2MultiWebPublisher, self).__init__(step_type=constants.PUBLISH_STEP_WEB_PUBLISHER, repo=repo, publish_conduit=publish_conduit, config=config) self.docker_api_version = 'v2' self.manifest_to_imgname_to_tags = {} # Needed when publishing tags and redirect files self.imgname_to_tags = {} # Needed when publishing redirect files self.imgname_to_mfid = {} # Needed when publishing blobs self.layer_to_manifests = {} # Will be set by PublishV2FileStep self.redirect_files = None self.add_child(V2MultiCollectTagsStep()) self.add_child(V2MultiPublishManifestsStep(repo_content_unit_q)) self.add_child( V2MultiPublishBlobsStep(repo_content_unit_q=repo_content_unit_q)) self.add_child(V2MultiPublishTagsStep()) self.add_child(V2MultiRedirectFilesStep()) self.add_child(V2MultiImageListingStep()) publish_dir = configuration.get_web_publish_dir( repo, config, self.docker_api_version) master_publish_dir = configuration.get_master_publish_dir( repo, config, self.docker_api_version) self.atomic_publish_step = publish_step.AtomicDirectoryPublishStep( self.get_working_dir(), [('', publish_dir)], master_publish_dir, step_type=constants.PUBLISH_STEP_OVER_HTTP) self.atomic_publish_step.description = _( 'Making v2 files available via web.') self.add_child(self.atomic_publish_step)
def test_get_web_publish_dir(self): directory = configuration.get_web_publish_dir(self.repo, self.config) self.assertEquals(directory, os.path.join(self.publish_dir, 'web', self.repo.id))
def test_get_web_publish_dir(self): directory = configuration.get_web_publish_dir(self.repo, self.config, 'v2') self.assertEquals(directory, os.path.join(self.publish_dir, 'v2', 'web', self.repo.id))