Example #1
0
def consumer_group_bind_itinerary(group_id, repo_id, distributor_id,
                                  notify_agent, binding_config, agent_options):
    """
    Bind the members of the specified consumer group.
    :param group_id: A consumer group ID.
    :type group_id: str
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor ID.
    :type distributor_id: str
    :param agent_options: Bind options passed to the agent handler.
    :type agent_options: dict
    :param notify_agent: indicates if the agent should be sent a message about the new binding
    :type  notify_agent: bool
    :param binding_config: configuration options to use when generating the payload for this binding
    :type binding_config: dict
    :return: A list of call_requests.
    :rtype list
    """
    call_requests = []
    manager = managers.consumer_group_query_manager()
    group = manager.get_group(group_id)
    for consumer_id in group['consumer_ids']:
        itinerary = bind_itinerary(consumer_id=consumer_id,
                                   repo_id=repo_id,
                                   distributor_id=distributor_id,
                                   notify_agent=notify_agent,
                                   binding_config=binding_config,
                                   agent_options=agent_options)
        call_requests.extend(itinerary)
    return call_requests
Example #2
0
def verify_group_resources(group_id, repo_id, distributor_id):
    """
    Confirm the group, repository, and distributor exist.

    :param group_id: The consumer group id to verify the existence of
    :type group_id: str
    :param repo_id: The repository id to confirm the existence of
    :type repo_id: str
    :param distributor_id: The distributor id to confirm the existence of on the repository
    :type distributor_id: str
    :return: A dictionary of the missing resources
    :rtype: dict
    """
    missing_resources = {}
    group_manager = factory.consumer_group_query_manager()
    repo_manager = factory.repo_query_manager()
    distributor_manager = factory.repo_distributor_manager()
    try:
        group_manager.get_group(group_id)
    except pulp_exceptions.MissingResource:
        missing_resources['group_id'] = group_id
    repo = repo_manager.find_by_id(repo_id)
    if repo is None:
        missing_resources['repo_id'] = repo_id
    try:
        distributor_manager.get_distributor(repo_id, distributor_id)
    except pulp_exceptions.MissingResource:
        missing_resources['distributor_id'] = distributor_id
    return missing_resources
Example #3
0
File: cud.py Project: nbetm/pulp
    def unbind(group_id, repo_id, distributor_id, options):
        """
        Unbind the members of the specified consumer group.
        :param group_id: A consumer group ID.
        :type group_id: str
        :param repo_id: A repository ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str
        :param options: Bind options passed to the agent handler.
        :type options: dict
        :return: TaskResult containing the ids of all the spawned tasks & bind errors
        :rtype: TaskResult
        """
        manager = manager_factory.consumer_group_query_manager()
        group = manager.get_group(group_id)

        bind_errors = []
        additional_tasks = []

        for consumer_id in group['consumer_ids']:
            try:
                report = unbind_task(consumer_id, repo_id, distributor_id, options)
                if report:
                    additional_tasks.extend(report.spawned_tasks)
            except PulpException, e:
                # Log a message so that we can debug but don't throw
                _logger.warn(e)
                bind_errors.append(e)
            except Exception, e:
                bind_errors.append(e)
Example #4
0
    def unbind(group_id, repo_id, distributor_id, options):
        """
        Unbind the members of the specified consumer group.
        :param group_id: A consumer group ID.
        :type group_id: str
        :param repo_id: A repository ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str
        :param options: Bind options passed to the agent handler.
        :type options: dict
        :return: TaskResult containing the ids of all the spawned tasks & bind errors
        :rtype: TaskResult
        """
        manager = manager_factory.consumer_group_query_manager()
        group = manager.get_group(group_id)

        bind_errors = []
        additional_tasks = []

        for consumer_id in group['consumer_ids']:
            try:
                report = unbind_task(consumer_id, repo_id, distributor_id,
                                     options)
                if report:
                    additional_tasks.extend(report.spawned_tasks)
            except PulpException, e:
                #Log a message so that we can debug but don't throw
                logger.warn(e.message)
                bind_errors.append(e)
            except Exception, e:
                bind_errors.append(e)
Example #5
0
def verify_group_resources(group_id, repo_id, distributor_id):
    """
    Confirm the group, repository, and distributor exist.

    :param group_id: The consumer group id to verify the existence of
    :type group_id: str
    :param repo_id: The repository id to confirm the existence of
    :type repo_id: str
    :param distributor_id: The distributor id to confirm the existence of on the repository
    :type distributor_id: str
    :return: A dictionary of the missing resources
    :rtype: dict
    """
    missing_resources = {}
    group_manager = factory.consumer_group_query_manager()
    repo_manager = factory.repo_query_manager()
    distributor_manager = factory.repo_distributor_manager()
    try:
        group_manager.get_group(group_id)
    except pulp_exceptions.MissingResource:
        missing_resources['group_id'] = group_id
    repo = repo_manager.find_by_id(repo_id)
    if repo is None:
        missing_resources['repo_id'] = repo_id
    try:
        distributor_manager.get_distributor(repo_id, distributor_id)
    except pulp_exceptions.MissingResource:
        missing_resources['distributor_id'] = distributor_id
    return missing_resources
Example #6
0
def consumer_group_bind_itinerary(group_id, repo_id, distributor_id, notify_agent, binding_config, agent_options):
    """
    Bind the members of the specified consumer group.
    :param group_id: A consumer group ID.
    :type group_id: str
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor ID.
    :type distributor_id: str
    :param agent_options: Bind options passed to the agent handler.
    :type agent_options: dict
    :param notify_agent: indicates if the agent should be sent a message about the new binding
    :type  notify_agent: bool
    :param binding_config: configuration options to use when generating the payload for this binding
    :type binding_config: dict
    :return: A list of call_requests.
    :rtype list
    """
    call_requests = []
    manager = managers.consumer_group_query_manager()
    group = manager.get_group(group_id)
    for consumer_id in group["consumer_ids"]:
        itinerary = bind_itinerary(
            consumer_id=consumer_id,
            repo_id=repo_id,
            distributor_id=distributor_id,
            notify_agent=notify_agent,
            binding_config=binding_config,
            agent_options=agent_options,
        )
        call_requests.extend(itinerary)
    return call_requests
Example #7
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     manager.unassociate(consumer_group_id, criteria)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Example #8
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get(
         'criteria', {}))
     manager = managers_factory.consumer_group_manager()
     manager.unassociate(consumer_group_id, criteria)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Example #9
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id),
             action_tag('consumer_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [consumer_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
     execution.execute(call_request)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Example #10
0
def uninstall_content(consumer_group_id, units, options):
    """
    Create an itinerary for consumer group content uninstallation.
    :param consumer_group_id: unique id of the consumer group
    :type consumer_group_id: str
    :param units: units to uninstall
    :type units: list or tuple
    :param options: options to pass to the uninstall manager
    :type options: dict or None
    :return: Details of the subtasks that were executed
    :rtype: TaskResult
    """
    consumer_group = managers.consumer_group_query_manager().get_group(consumer_group_id)
    agent_manager = managers.consumer_agent_manager()

    return _process_group(consumer_group, PLP0022, {'group_id': consumer_group_id},
                          agent_manager.uninstall_content, units, options)
Example #11
0
    def uninstall_content(consumer_group_id, units, options):
        """
        Create an itinerary for consumer group content uninstallation.
        :param consumer_group_id: unique id of the consumer group
        :type consumer_group_id: str
        :param units: units to uninstall
        :type units: list or tuple
        :param options: options to pass to the uninstall manager
        :type options: dict or None
        :return: Details of the subtasks that were executed
        :rtype: TaskResult
        """
        consumer_group = manager_factory.consumer_group_query_manager().get_group(consumer_group_id)
        agent_manager = manager_factory.consumer_agent_manager()

        return ConsumerGroupManager.process_group(consumer_group, error_codes.PLP0022,
                                                  {'group_id': consumer_group_id},
                                                  agent_manager.uninstall_content, units, options)
Example #12
0
    def post(self, request, consumer_group_id):
        """
        Associate a consumer to the group.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_group_id: id for the requested group
        :type consumer_group_id: str
        :return: Response containing consumers bound to the group
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json
        criteria = Criteria.from_client_input(params.get('criteria', {}))
        manager = factory.consumer_group_manager()
        manager.associate(consumer_group_id, criteria)
        query_manager = factory.consumer_group_query_manager()
        group = query_manager.get_group(consumer_group_id)
        return generate_json_response_with_pulp_encoder(group['consumer_ids'])
Example #13
0
File: cud.py Project: nbetm/pulp
    def update_content(consumer_group_id, units, options):
        """
        Create an itinerary for consumer group content update.
        :param consumer_group_id: unique id of the consumer group
        :type consumer_group_id: str
        :param units: units to update
        :type units: list or tuple
        :param options: options to pass to the update manager
        :type options: dict or None
        :return: Details of the subtasks that were executed
        :rtype: TaskResult
        """
        consumer_group = manager_factory.consumer_group_query_manager().get_group(consumer_group_id)
        agent_manager = manager_factory.consumer_agent_manager()

        return ConsumerGroupManager.process_group(consumer_group, error_codes.PLP0021,
                                                  {'group_id': consumer_group_id},
                                                  agent_manager.update_content, units, options)
Example #14
0
    def post(self, request, consumer_group_id):
        """
        Unassociate a consumer from the group.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_group_id: id for the requested group
        :type consumer_group_id: str
        :return: Response containing consumers bound to the group
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json
        criteria = Criteria.from_client_input(params.get('criteria', {}))
        manager = factory.consumer_group_manager()
        manager.unassociate(consumer_group_id, criteria)
        query_manager = factory.consumer_group_query_manager()
        group = query_manager.get_group(consumer_group_id)
        return generate_json_response_with_pulp_encoder(group['consumer_ids'])
Example #15
0
def consumer_group_content_uninstall_itinerary(consumer_group_id, units, options):
    """
    Create an itinerary for consumer group content uninstallation.
    :param consumer_group_id: unique id of the consumer group
    :type consumer_group_id: str
    :param units: units to uninstall
    :type units: list or tuple
    :param options: options to pass to the uninstall manager
    :type options: dict or None
    :return: list of call requests
    :rtype: list
    """
    consumer_group = managers.consumer_group_query_manager().get_group(consumer_group_id)
    consumer_group_call_requests_list = []
    for consumer_id in consumer_group['consumer_ids']:
        consumer_call_requests = consumer_content_uninstall_itinerary(consumer_id, units, options)
        consumer_group_call_requests_list.extend(consumer_call_requests)
 
    return consumer_group_call_requests_list
Example #16
0
def update_content(consumer_group_id, units, options):
    """
    Create an itinerary for consumer group content update.
    :param consumer_group_id: unique id of the consumer group
    :type consumer_group_id: str
    :param units: units to update
    :type units: list or tuple
    :param options: options to pass to the update manager
    :type options: dict or None
    :return: Details of the subtasks that were executed
    :rtype: TaskResult
    """
    consumer_group = managers.consumer_group_query_manager().get_group(
        consumer_group_id)
    agent_manager = managers.consumer_agent_manager()

    return _process_group(consumer_group, PLP0021,
                          {'group_id': consumer_group_id},
                          agent_manager.update_content, units, options)
Example #17
0
    def bind(group_id, repo_id, distributor_id, notify_agent, binding_config,
             agent_options):
        """
        Bind the members of the specified consumer group.

        :param group_id:       A consumer group ID.
        :type group_id:        str
        :param repo_id:        A repository ID.
        :type repo_id:         str
        :param distributor_id: A distributor ID.
        :type distributor_id:  str
        :param agent_options:  Bind options passed to the agent handler.
        :type agent_options:   dict
        :param notify_agent:   indicates if the agent should be sent a message about the new binding
        :type  notify_agent:   bool
        :param binding_config: configuration options to use when generating the payload for this
                               binding
        :type binding_config:  dict
        :return:               Details of the subtasks that were executed
        :rtype:                TaskResult
        """
        manager = manager_factory.consumer_group_query_manager()
        group = manager.get_group(group_id)

        bind_errors = []
        additional_tasks = []

        for consumer_id in group['consumer_ids']:
            try:
                report = bind_task(consumer_id, repo_id, distributor_id,
                                   notify_agent, binding_config, agent_options)
                if report.spawned_tasks:
                    additional_tasks.extend(report.spawned_tasks)
            except PulpException, e:
                # Log a message so that we can debug but don't throw
                _logger.debug(e)
                bind_errors.append(e)
            except Exception, e:
                _logger.exception(e)
                # Don't do anything else since we still want to process all the other consumers
                bind_errors.append(e)
Example #18
0
def consumer_group_unbind_itinerary(group_id, repo_id, distributor_id, options):
    """
    Unbind the members of the specified consumer group.
    :param group_id: A consumer group ID.
    :type group_id: str
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor ID.
    :type distributor_id: str
    :param options: Bind options passed to the agent handler.
    :type options: dict
    :return: A list of call_requests.
    :rtype list
    """
    call_requests = []
    manager = managers.consumer_group_query_manager()
    group = manager.get_group(group_id)
    for consumer_id in group["consumer_ids"]:
        itinerary = unbind_itinerary(consumer_id, repo_id, distributor_id, options)
        call_requests.extend(itinerary)
    return call_requests
Example #19
0
def consumer_group_content_update_itinerary(consumer_group_id, units, options):
    """
    Create an itinerary for consumer group content update.
    :param consumer_group_id: unique id of the consumer group
    :type consumer_group_id: str
    :param units: units to update
    :type units: list or tuple
    :param options: options to pass to the update manager
    :type options: dict or None
    :return: list of call requests
    :rtype: list
    """
    consumer_group = managers.consumer_group_query_manager().get_group(
        consumer_group_id)
    consumer_group_call_requests_list = []
    for consumer_id in consumer_group['consumer_ids']:
        consumer_call_requests = consumer_content_update_itinerary(
            consumer_id, units, options)
        consumer_group_call_requests_list.extend(consumer_call_requests)

    return consumer_group_call_requests_list
Example #20
0
File: cud.py Project: nbetm/pulp
    def bind(group_id, repo_id, distributor_id, notify_agent, binding_config, agent_options):
        """
        Bind the members of the specified consumer group.

        :param group_id:       A consumer group ID.
        :type group_id:        str
        :param repo_id:        A repository ID.
        :type repo_id:         str
        :param distributor_id: A distributor ID.
        :type distributor_id:  str
        :param agent_options:  Bind options passed to the agent handler.
        :type agent_options:   dict
        :param notify_agent:   indicates if the agent should be sent a message about the new binding
        :type  notify_agent:   bool
        :param binding_config: configuration options to use when generating the payload for this
                               binding
        :type binding_config:  dict
        :return:               Details of the subtasks that were executed
        :rtype:                TaskResult
        """
        manager = manager_factory.consumer_group_query_manager()
        group = manager.get_group(group_id)

        bind_errors = []
        additional_tasks = []

        for consumer_id in group['consumer_ids']:
            try:
                report = bind_task(consumer_id, repo_id, distributor_id, notify_agent,
                                   binding_config, agent_options)
                if report.spawned_tasks:
                    additional_tasks.extend(report.spawned_tasks)
            except PulpException, e:
                # Log a message so that we can debug but don't throw
                _logger.debug(e)
                bind_errors.append(e)
            except Exception, e:
                _logger.exception(e)
                # Don't do anything else since we still want to process all the other consumers
                bind_errors.append(e)
Example #21
0
def consumer_group_unbind_itinerary(group_id, repo_id, distributor_id,
                                    options):
    """
    Unbind the members of the specified consumer group.
    :param group_id: A consumer group ID.
    :type group_id: str
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor ID.
    :type distributor_id: str
    :param options: Bind options passed to the agent handler.
    :type options: dict
    :return: A list of call_requests.
    :rtype list
    """
    call_requests = []
    manager = managers.consumer_group_query_manager()
    group = manager.get_group(group_id)
    for consumer_id in group['consumer_ids']:
        itinerary = unbind_itinerary(consumer_id, repo_id, distributor_id,
                                     options)
        call_requests.extend(itinerary)
    return call_requests
Example #22
0
 def __init__(self):
     super(ConsumerGroupSearch, self).__init__(
         managers_factory.consumer_group_query_manager().find_by_criteria)
Example #23
0
 def __init__(self):
     super(ConsumerGroupSearch, self).__init__(
         managers_factory.consumer_group_query_manager().find_by_criteria)