Beispiel #1
0
    def publish(group_id, distributor_id, publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        :param group_id:                identifies the repo group
        :type  group_id:                str
        :param distributor_id:          identifies the group's distributor
        :type  distributor_id:          str
        :param publish_config_override: values to pass the plugin for this publish call alone
        :type  publish_config_override: dict
        """
        distributor_manager = manager_factory.repo_group_distributor_manager()
        distributor = distributor_manager.get_distributor(group_id, distributor_id)
        distributor_type_id = distributor["distributor_type_id"]
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(distributor_type_id)

        group_query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor_type_id = distributor["distributor_type_id"]

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor)

        call_config = PluginCallConfiguration(plugin_config, distributor["config"], publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(distributor_type_id, group_id)

        # TODO: Add events for group publish start/complete
        RepoGroupPublishManager._do_publish(transfer_group, distributor_id, distributor_instance, conduit, call_config)
Beispiel #2
0
    def update_distributor_config(self, repo_group_id, distributor_id,
                                  distributor_config):
        """
        Attempts to update the saved configuration for the given distributor.
        The distributor will be asked if the new configuration is valid. If
        not, this method will raise an error and the existing configuration
        will remain unchanged.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @param distributor_id: identifies the distributor on the group
        @type  distributor_id: str

        @param distributor_config: new configuration values to use
        @type  distributor_config: dict

        @return: the updated distributor
        @rtype:  dict

        @raise MissingResource: if the given group or distributor do not exist
        @raise PulpDataException: if the plugin indicates the new configuration
               is invalid
        """

        # Validation - calls will raise MissingResource
        group_manager = manager_factory.repo_group_query_manager()
        group = group_manager.get_group(repo_group_id)
        distributor = self.get_distributor(repo_group_id, distributor_id)

        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        # Resolve the requested changes into the existing config
        merged_config = process_update_config(distributor['config'],
                                              distributor_config)

        # Request the distributor validate the new configuration
        call_config = PluginCallConfiguration(plugin_config, merged_config)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(
            distributor_type_id, repo_group_id)
        transfer_related_groups = related_groups(distributor_type_id,
                                                 omit_group_id=repo_group_id)

        # Request the plugin validate the configuration
        try:
            is_valid, message = distributor_instance.validate_config(
                transfer_group, call_config, transfer_related_groups)

            if not is_valid:
                raise PulpDataException(message)
        except Exception, e:
            _LOG.exception(
                'Exception received from distributor [%s] while validating config'
                % distributor_type_id)
            raise PulpDataException(e.args), None, sys.exc_info()[2]
Beispiel #3
0
    def update_distributor_config(repo_group_id, distributor_id,
                                  distributor_config):
        """
        Attempts to update the saved configuration for the given distributor.
        The distributor will be asked if the new configuration is valid. If
        not, this method will raise an error and the existing configuration
        will remain unchanged.

        :param repo_group_id:      identifies the group
        :type  repo_group_id:      str
        :param distributor_id:     identifies the distributor on the group
        :type  distributor_id:     str
        :param distributor_config: new configuration values to use
        :type  distributor_config: dict
        :return:                   the updated distributor
        :rtype:                    dict
        :raise MissingResource:    if the given group or distributor do not exist
        :raise PulpDataException:  if the plugin indicates the new configuration is invalid
        """

        # Validation - calls will raise MissingResource
        group_manager = manager_factory.repo_group_query_manager()
        group = group_manager.get_group(repo_group_id)
        distributor = RepoGroupDistributorManager.get_distributor(
            repo_group_id, distributor_id)

        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        # Resolve the requested changes into the existing config
        merged_config = process_update_config(distributor['config'],
                                              distributor_config)

        # Request the distributor validate the new configuration
        call_config = PluginCallConfiguration(plugin_config, merged_config)
        transfer_group = common_utils.to_transfer_repo_group(group)
        config_conduit = RepoConfigConduit(distributor_type_id)

        # Request the plugin validate the configuration
        try:
            is_valid, message = distributor_instance.validate_config(
                transfer_group, call_config, config_conduit)

            if not is_valid:
                raise PulpDataException(message)
        except Exception, e:
            msg = _(
                'Exception received from distributor [%(d)s] while validating config'
            )
            msg = msg % {'d': distributor_type_id}
            _logger.exception(msg)
            raise PulpDataException(e.args), None, sys.exc_info()[2]
Beispiel #4
0
    def publish(self,
                group_id,
                distributor_id,
                distributor=None,
                distributor_instance=None,
                plugin_config=None,
                publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        @param group_id: identifies the repo group
        @type  group_id: str

        @param distributor_id: identifies the group's distributor
        @type  distributor_id: str

        @param distributor: distributor metadata as associate with the repo group
        @type distributor: dict

        @param distributor_instance: instance of group's distributor to be used
                                     for publishing
        @type distributor_instance: GroupDistributor

        @param plugin_config: general configuration for the distributor instance
        @type plugin_config: dict or None

        @param publish_config_override: values to pass the plugin for this
               publish call alone
        @type  publish_config_override: dict
        """
        if None in (distributor, distributor_instance):
            raise MissingResource(repo_group=group_id,
                                  group_distributor=distributor_id)

        group_query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor_type_id = distributor['distributor_type_id']

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor_id)

        call_config = PluginCallConfiguration(plugin_config,
                                              distributor['config'],
                                              publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(
            distributor_type_id, group_id)

        # TODO: Add events for group publish start/complete
        self._do_publish(transfer_group, distributor_id, distributor_instance,
                         conduit, call_config)
Beispiel #5
0
    def update_distributor_config(self, repo_group_id, distributor_id, distributor_config):
        """
        Attempts to update the saved configuration for the given distributor.
        The distributor will be asked if the new configuration is valid. If
        not, this method will raise an error and the existing configuration
        will remain unchanged.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @param distributor_id: identifies the distributor on the group
        @type  distributor_id: str

        @param distributor_config: new configuration values to use
        @type  distributor_config: dict

        @return: the updated distributor
        @rtype:  dict

        @raise MissingResource: if the given group or distributor do not exist
        @raise PulpDataException: if the plugin indicates the new configuration
               is invalid
        """

        # Validation - calls will raise MissingResource
        group_manager = manager_factory.repo_group_query_manager()
        group = group_manager.get_group(repo_group_id)
        distributor = self.get_distributor(repo_group_id, distributor_id)

        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(distributor_type_id)

        # Resolve the requested changes into the existing config
        merged_config = process_update_config(distributor['config'], distributor_config)

        # Request the distributor validate the new configuration
        call_config = PluginCallConfiguration(plugin_config, merged_config)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(distributor_type_id, repo_group_id)
        config_conduit = RepoConfigConduit(distributor_type_id)

        # Request the plugin validate the configuration
        try:
            is_valid, message = distributor_instance.validate_config(transfer_group, call_config,
                                                                     config_conduit)

            if not is_valid:
                raise PulpDataException(message)
        except Exception, e:
            _LOG.exception('Exception received from distributor [%s] while validating config' % distributor_type_id)
            raise PulpDataException(e.args), None, sys.exc_info()[2]
Beispiel #6
0
    def remove_distributor(repo_group_id, distributor_id, force=False):
        """
        Removes a distributor from a group.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @param distributor_id: identifies the distributor on the group
        @type  distributor_id: str

        @param force: if true, the distributor will be removed from the database
               regardless of whether or not the plugin's clean up method raises
               an exception

        @raise MissingResource: if there is no group or distributor with the
               given ID
        @raise PulpExecutionException: if the distributor raises an error on cleanup
        """
        distributor_coll = RepoGroupDistributor.get_collection()

        # Validation - calls will raise MissingResource
        group = manager_factory.repo_group_query_manager().get_group(
            repo_group_id)
        distributor = RepoGroupDistributorManager.get_distributor(
            repo_group_id, distributor_id)

        # Call the distributor's cleanup method
        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        call_config = PluginCallConfiguration(plugin_config,
                                              distributor['config'])
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.distributor_working_dir(
            distributor_type_id, repo_group_id)

        try:
            distributor_instance.distributor_removed(transfer_group,
                                                     call_config)
        except Exception:
            _logger.exception(
                'Exception cleaning up distributor [%s] on group [%s]' %
                (distributor_id, repo_group_id))

            if not force:
                raise PulpExecutionException(), None, sys.exc_info()[2]

        # Clean up the database
        distributor_coll.remove(distributor, safe=True)
Beispiel #7
0
    def publish(self,
                group_id,
                distributor_id,
                distributor=None,
                distributor_instance=None,
                plugin_config=None,
                publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        @param group_id: identifies the repo group
        @type  group_id: str

        @param distributor_id: identifies the group's distributor
        @type  distributor_id: str

        @param distributor: distributor metadata as associate with the repo group
        @type distributor: dict

        @param distributor_instance: instance of group's distributor to be used
                                     for publishing
        @type distributor_instance: GroupDistributor

        @param plugin_config: general configuration for the distributor instance
        @type plugin_config: dict or None

        @param publish_config_override: values to pass the plugin for this
               publish call alone
        @type  publish_config_override: dict
        """
        if None in (distributor, distributor_instance):
            raise MissingResource(repo_group=group_id, group_distributor=distributor_id)

        group_query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor_type_id = distributor['distributor_type_id']

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor_id)

        call_config = PluginCallConfiguration(plugin_config, distributor['config'], publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(distributor_type_id, group_id)

        # TODO: Add events for group publish start/complete
        self._do_publish(transfer_group, distributor_id, distributor_instance, conduit, call_config)
Beispiel #8
0
    def remove_distributor(repo_group_id, distributor_id, force=False):
        """
        Removes a distributor from a group.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @param distributor_id: identifies the distributor on the group
        @type  distributor_id: str

        @param force: if true, the distributor will be removed from the database
               regardless of whether or not the plugin's clean up method raises
               an exception

        @raise MissingResource: if there is no group or distributor with the
               given ID
        @raise PulpExecutionException: if the distributor raises an error on cleanup
        """
        distributor_coll = RepoGroupDistributor.get_collection()

        # Validation - calls will raise MissingResource
        group = manager_factory.repo_group_query_manager().get_group(repo_group_id)
        distributor = RepoGroupDistributorManager.get_distributor(repo_group_id, distributor_id)

        # Call the distributor's cleanup method
        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        call_config = PluginCallConfiguration(plugin_config, distributor['config'])
        transfer_group = common_utils.to_transfer_repo_group(group)

        try:
            distributor_instance.distributor_removed(transfer_group, call_config)
        except Exception:
            _logger.exception('Exception cleaning up distributor [%s] on group [%s]' % (
                distributor_id, repo_group_id))

            if not force:
                raise PulpExecutionException(), None, sys.exc_info()[2]

        # Clean up the database
        distributor_coll.remove(distributor, safe=True)
Beispiel #9
0
    def publish(group_id, distributor_id, publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        :param group_id:                identifies the repo group
        :type  group_id:                str
        :param distributor_id:          identifies the group's distributor
        :type  distributor_id:          str
        :param publish_config_override: values to pass the plugin for this publish call alone
        :type  publish_config_override: dict
        """
        distributor_manager = manager_factory.repo_group_distributor_manager()
        distributor = distributor_manager.get_distributor(
            group_id, distributor_id)
        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        group_query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor_type_id = distributor['distributor_type_id']

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor)

        call_config = PluginCallConfiguration(plugin_config,
                                              distributor['config'],
                                              publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(
            distributor_type_id, group_id)

        # TODO: Add events for group publish start/complete
        RepoGroupPublishManager._do_publish(transfer_group, distributor_id,
                                            distributor_instance, conduit,
                                            call_config)
Beispiel #10
0
    def publish(self, group_id, distributor_id, publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        @param group_id: identifies the repo group
        @type  group_id: str

        @param distributor_id: identifies the group's distributor
        @type  distributor_id: str

        @param publish_config_override: values to pass the plugin for this
               publish call alone
        @type  publish_config_override: dict
        """

        group_query_manager = manager_factory.repo_group_query_manager()
        distributor_manager = manager_factory.repo_group_distributor_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor = distributor_manager.get_distributor(group_id, distributor_id)
        distributor_type_id = distributor['distributor_type_id']

        try:
            distributor_instance, plugin_config =\
                plugin_api.get_group_distributor_by_id(distributor_type_id)
        except plugin_exceptions.PluginNotFound:
            raise MissingResource(distributor_type=distributor_type_id), None, sys.exc_info()[2]

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor_id)

        call_config = PluginCallConfiguration(plugin_config, distributor['config'], publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.group_distributor_working_dir(distributor_type_id, group_id)

        # TODO: Add events for group publish start/complete
        self._do_publish(transfer_group, distributor_id, distributor_instance, conduit, call_config)
Beispiel #11
0
    def add_distributor(repo_group_id,
                        distributor_type_id,
                        group_plugin_config,
                        distributor_id=None):
        """
        Adds an association from the given repository group to a distributor.
        The assocation will be tracked through the distributor_id; each
        distributor on a given group must have a unique ID. If this is not
        specified, one will be generated. If a distributor already exists on the
        group with a given ID, the existing one will be removed and replaced
        with the newly configured one.

        @param repo_group_id: identifies the repo group
        @type  repo_group_id: str

        @param distributor_type_id: type of distributor being added; must reference
               one of the installed group distributors
        @type  distributor_type_id: str

        @param group_plugin_config: config to use for the distributor for this group alone
        @type  group_plugin_config: dict

        @param distributor_id: if specified, the newly added distributor will be
               referenced by this value and the group id; if omitted one will
               be generated
        @type  distributor_id: str

        @return: database representation of the added distributor
        @rtype:  dict

        @raise MissingResource: if the group doesn't exist
        @raise InvalidValue: if a distributor ID is provided and is not valid
        @raise PulpDataException: if the plugin indicates the config is invalid
        @raise PulpExecutionException: if the plugin raises an exception while
               initializing the newly added distributor
        """
        distributor_coll = RepoGroupDistributor.get_collection()

        query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = query_manager.get_group(
            repo_group_id)  # will raise MissingResource

        if not plugin_api.is_valid_group_distributor(distributor_type_id):
            raise InvalidValue(['distributor_type_id'])

        # Determine the ID for the distributor on this repo
        if distributor_id is None:
            distributor_id = str(uuid.uuid4())
        else:
            # Validate if one was passed in
            if not is_distributor_id_valid(distributor_id):
                raise InvalidValue(['distributor_id'])

        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        # Convention is that a value of None means unset. Remove any keys that
        # are explicitly set to None so the plugin will default them.
        clean_config = None
        if group_plugin_config is not None:
            clean_config = dict([(k, v)
                                 for k, v in group_plugin_config.items()
                                 if v is not None])

        # Let the plugin validate the configuration
        call_config = PluginCallConfiguration(plugin_config, clean_config)
        transfer_group = common_utils.to_transfer_repo_group(group)

        config_conduit = RepoConfigConduit(distributor_type_id)

        # Request the plugin validate the configuration
        try:
            is_valid, message = distributor_instance.validate_config(
                transfer_group, call_config, config_conduit)

            if not is_valid:
                raise PulpDataException(message)
        except Exception, e:
            msg = _(
                'Exception received from distributor [%(d)s] while validating config'
            )
            msg = msg % {'d': distributor_type_id}
            _logger.exception(msg)
            raise PulpDataException(e.args), None, sys.exc_info()[2]
Beispiel #12
0
    def add_distributor(self, repo_group_id, distributor_type_id, group_plugin_config,
                        distributor_id=None):
        """
        Adds an association from the given repository group to a distributor.
        The assocation will be tracked through the distributor_id; each
        distributor on a given group must have a unique ID. If this is not
        specified, one will be generated. If a distributor already exists on the
        group with a given ID, the existing one will be removed and replaced
        with the newly configured one.

        @param repo_group_id: identifies the repo group
        @type  repo_group_id: str

        @param distributor_type_id: type of distributor being added; must reference
               one of the installed group distributors
        @type  distributor_type_id: str

        @param group_plugin_config: config to use for the distributor for this group alone
        @type  group_plugin_config: dict

        @param distributor_id: if specified, the newly added distributor will be
               referenced by this value and the group id; if omitted one will
               be generated
        @type  distributor_id: str

        @return: database representation of the added distributor
        @rtype:  dict

        @raise MissingResource: if the group doesn't exist
        @raise InvalidValue: if a distributor ID is provided and is not valid
        @raise PulpDataException: if the plugin indicates the config is invalid
        @raise PulpExecutionException: if the plugin raises an exception while
               initializing the newly added distributor
        """
        distributor_coll = RepoGroupDistributor.get_collection()

        query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = query_manager.get_group(repo_group_id) # will raise MissingResource

        if not plugin_api.is_valid_group_distributor(distributor_type_id):
            raise InvalidValue(['distributor_type_id'])

        # Determine the ID for the distributor on this repo
        if distributor_id is None:
            distributor_id = str(uuid.uuid4())
        else:
            # Validate if one was passed in
            if not is_distributor_id_valid(distributor_id):
                raise InvalidValue(['distributor_id'])

        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(distributor_type_id)

        # Convention is that a value of None means unset. Remove any keys that
        # are explicitly set to None so the plugin will default them.
        clean_config = None
        if group_plugin_config is not None:
            clean_config = dict([(k, v) for k, v in group_plugin_config.items() if v is not None])

        # Let the plugin validate the configuration
        call_config = PluginCallConfiguration(plugin_config, clean_config)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.distributor_working_dir(distributor_type_id, repo_group_id)

        # Load the related groups which is needed for the validation
        transfer_related_groups = related_groups(distributor_type_id)

        # Request the plugin validate the configuration
        try:
            is_valid, message = distributor_instance.validate_config(transfer_group, call_config, transfer_related_groups)

            if not is_valid:
                raise PulpDataException(message)
        except Exception, e:
            _LOG.exception('Exception received from distributor [%s] while validating config' % distributor_type_id)
            raise PulpDataException(e.args), None, sys.exc_info()[2]