def get_distributor(repo_group_id, distributor_id): """ Returns an individual distributor on the given repo group, raising an exception if one does not exist at the given ID. @param repo_group_id: identifies the repo group @type repo_group_id: str @param distributor_id: identifies the distributor @type distributor_id: str @return: SON representation of the distributor @rtype: dict @raise MissingResource: if either there is no distributor for the given group ID/distributor ID pair or the group itself does not exist """ # Check the group's existence for the exception contract first manager_factory.repo_group_query_manager().get_group(repo_group_id) # Check for the distributor if we know the group exists spec = { 'repo_group_id': repo_group_id, 'id': distributor_id, } distributor = RepoGroupDistributor.get_collection().find_one(spec) if distributor is None: raise MissingResource(repo_group=repo_group_id, distributor=distributor_id) return distributor
def get_distributor(self, repo_group_id, distributor_id): """ Returns an individual distributor on the given repo group, raising an exception if one does not exist at the given ID. @param repo_group_id: identifies the repo group @type repo_group_id: str @param distributor_id: identifies the distributor @type distributor_id: str @return: SON representation of the distributor @rtype: dict @raise MissingResource: if either there is no distributor for the given group ID/distributor ID pair or the group itself does not exist """ # Check the group's existence for the exception contract first manager_factory.repo_group_query_manager().get_group(repo_group_id) # Check for the distributor if we know the group exists spec = { 'repo_group_id' : repo_group_id, 'id' : distributor_id, } distributor = RepoGroupDistributor.get_collection().find_one(spec) if distributor is None: raise MissingResource(repo_group=repo_group_id, distributor=distributor_id) return distributor
def post(self, request, repo_group_id): """ Dispatch a task to publish content from the repo group using the distributor specified by the params. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_group_id: repo group to publish :type repo_group_id: str :raises pulp_exceptions.MissingValue if 'id' is not passed in the body :raises pulp_exceptions.OperationPosponed: dispatch a task """ params = request.body_as_json distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise pulp_exceptions.MissingValue(['id']) # If a repo group does not exist, get_group raises a MissingResource exception manager = managers_factory.repo_group_query_manager() manager.get_group(repo_group_id) task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), tags.action_tag('publish') ] async_result = repo_group_publish.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id, args=[repo_group_id, distributor_id], kwargs={'publish_config_override': overrides}, tags=task_tags ) raise pulp_exceptions.OperationPostponed(async_result)
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)
def post(self, request, repo_group_id): """ Dispatch a task to publish content from the repo group using the distributor specified by the params. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_group_id: repo group to publish :type repo_group_id: str :raises pulp_exceptions.MissingValue if 'id' is not passed in the body :raises pulp_exceptions.OperationPosponed: dispatch a task """ params = request.body_as_json distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise pulp_exceptions.MissingValue(['id']) # If a repo group does not exist, get_group raises a MissingResource exception manager = managers_factory.repo_group_query_manager() manager.get_group(repo_group_id) task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), tags.action_tag('publish') ] async_result = repo_group_publish.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id, args=[repo_group_id, distributor_id], kwargs={'publish_config_override': overrides}, tags=task_tags) raise pulp_exceptions.OperationPostponed(async_result)
def POST(self, repo_group_id): params = self.params() distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise MissingValue(['id']) # If a repo group does not exist, get_group raises a MissingResource exception manager = managers_factory.repo_group_query_manager() manager.get_group(repo_group_id) task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), tags.action_tag('publish') ] async_result = publish.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id, args=[repo_group_id, distributor_id], kwargs={'publish_config_override': overrides}, tags=task_tags) raise OperationPostponed(async_result)
def related_groups(distributor_type_id, omit_group_id=None): """ Loads and converts into plugin transfer objects all groups that have a distributor of the given ID. @param omit_group_id: if specified, the given group won't be included, used when retrieving related groups in an update call @type omit_group_id: str @return: list of transfer objects to pass to the plugin @rtype: list """ query_manager = manager_factory.repo_group_query_manager() related_groups = query_manager.find_with_distributor_type( distributor_type_id) transfer_groups = [] for g in related_groups: if omit_group_id and g['id'] == omit_group_id: continue all_configs = [d['config'] for d in g['distributors']] trg = common_utils.to_related_repo_group(g, all_configs) transfer_groups.append(trg) return transfer_groups
def related_groups(distributor_type_id, omit_group_id=None): """ Loads and converts into plugin transfer objects all groups that have a distributor of the given ID. @param omit_group_id: if specified, the given group won't be included, used when retrieving related groups in an update call @type omit_group_id: str @return: list of transfer objects to pass to the plugin @rtype: list """ query_manager = manager_factory.repo_group_query_manager() related_groups = query_manager.find_with_distributor_type(distributor_type_id) transfer_groups = [] for g in related_groups: if omit_group_id and g['id'] == omit_group_id: continue all_configs = [d['config'] for d in g['distributors']] trg = common_utils.to_related_repo_group(g, all_configs) transfer_groups.append(trg) return transfer_groups
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]
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)
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]
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]
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)
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)
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)
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)
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)
def POST(self, repo_group_id): params = self.params() distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise MissingValue(['id']) # If a repo group does not exist, get_group raises a MissingResource exception manager = managers_factory.repo_group_query_manager() manager.get_group(repo_group_id) task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), tags.action_tag('publish')] async_result = publish.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id, args=[repo_group_id, distributor_id], kwargs={'publish_config_override' : overrides}, tags=task_tags) raise OperationPostponed(async_result)
def __init__(self): super(RepoGroupSearch, self).__init__( managers_factory.repo_group_query_manager().find_by_criteria)
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]
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]