How to use the pulp.common.tags.action_tag function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulp / server / pulp / server / webservices / views / repositories.py View on Github external
:type  repo_id: str

        :raises exceptions.InvalidValue: if criteria params cannot be parsed
        :raises exceptions.OperationPostponed: dispatch a unassociate_by_criteria task
        """

        criteria_body = request.body_as_json.get('criteria', {})
        try:
            criteria = UnitAssociationCriteria.from_client_input(criteria_body)
        except exceptions.InvalidValue, e:
            invalid_criteria = exceptions.InvalidValue('criteria')
            invalid_criteria.add_child_exception(e)
            raise invalid_criteria

        task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
                     tags.action_tag('unassociate')]
        model.Repository.objects.get_repo_or_missing_resource(repo_id)
        async_result = unassociate_by_criteria.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE, repo_id,
            [repo_id, criteria.to_dict()], tags=task_tags)
        raise exceptions.OperationPostponed(async_result)
github pulp / pulp / bindings / pulp / bindings / tasks.py View on Github external
def get_repo_sync_tasks(self, repo_id):
        """
        Retrieves all incomplete sync tasks for the given repository.

        :param repo_id: identifies the repo
        :type  repo_id: str
        :return:        response with a list of Task objects; empty list for no matching tasks
        :rtype:         Response
        """
        repo_tag = tag_util.resource_tag(tag_util.RESOURCE_REPOSITORY_TYPE, repo_id)
        sync_tag = tag_util.action_tag(tag_util.ACTION_SYNC_TYPE)
        return self.get_all_tasks(tags=[repo_tag, sync_tag])
github pulp / pulp / client_lib / pulp / client / commands / repo / sync_publish.py View on Github external
of 'sync' or 'publish'.

    :param context: The CLI context from Okaara
    :type  context: pulp.client.extensions.core.ClientContext
    :param repo_id: The primary key of the repository you wish to limit the Task query to
    :type  repo_id: basestring
    :param action:  One of "sync" or "publish"
    :type  action:  basestring
    :return:        A list of Task objects
    :rtype:         list
    """
    repo_tag = tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id)
    if action == 'publish':
        action_tag = tags.action_tag(tags.ACTION_PUBLISH_TYPE)
    elif action == 'sync':
        action_tag = tags.action_tag(tags.ACTION_SYNC_TYPE)
    else:
        raise ValueError(
            '_get_repo_tasks() does not support %(action)s as an action.' % {'action': action})
    repo_search_criteria = {'filters': {'state': {'$nin': responses.COMPLETED_STATES},
                                        'tags': {'$all': [repo_tag, action_tag]}}}
    return context.server.tasks_search.search(**repo_search_criteria)
github pulp / pulpcore / client_lib / pulp / client / commands / consumer / bind.py View on Github external
def task_header(self, task):

        handlers = {
            tags.action_tag(tags.ACTION_BIND) : self._render_bind_header,
            tags.action_tag(tags.ACTION_AGENT_BIND) : self._render_agent_bind_header,
        }

        # There will be exactly 1 action tag for each task (multiple resource tags)
        action_tags = [t for t in task.tags if tags.is_action_tag(t)]
        action_tag = action_tags[0]

        handler = handlers[action_tag]
        handler()
github pulp / pulpcore / server / pulp / server / controllers / repository.py View on Github external
repo.save()
        else:
            raise pulp_exceptions.PulpCodedValidationException(
                error_code=error_codes.PLP1010, field='delta', field_type='dict', value=repo_delta)

    if importer_config is not None:
        importer_controller.update_importer_config(repo.repo_id, importer_config)

    additional_tasks = []
    if distributor_configs is not None:
        for dist_id, dist_config in distributor_configs.items():
            task_tags = [
                tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo.repo_id),
                tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                                  dist_id),
                tags.action_tag(tags.ACTION_UPDATE_DISTRIBUTOR)
            ]
            async_result = dist_controller.update.apply_async_with_reservation(
                tags.RESOURCE_REPOSITORY_TYPE, repo.repo_id,
                [repo.repo_id, dist_id, dist_config, None], tags=task_tags)
            additional_tasks.append(async_result)
    return TaskResult(repo, None, additional_tasks)
github pulp / pulp / client_lib / pulp / client / commands / repo / sync_publish.py View on Github external
:param context: The CLI context from Okaara
    :type  context: pulp.client.extensions.core.ClientContext
    :param repo_id: The primary key of the repository you wish to limit the Task query to
    :type  repo_id: basestring
    :param action:  One of "sync" or "publish"
    :type  action:  basestring
    :return:        A list of Task objects
    :rtype:         list
    """
    repo_tag = tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id)
    if action == 'publish':
        action_tag = tags.action_tag(tags.ACTION_PUBLISH_TYPE)
    elif action == 'sync':
        action_tag = tags.action_tag(tags.ACTION_SYNC_TYPE)
    elif action == 'download':
        action_tag = tags.action_tag(tags.ACTION_DOWNLOAD_TYPE)
    else:
        raise ValueError(
            '_get_repo_tasks() does not support %(action)s as an action.' % {'action': action})
    repo_search_criteria = {'filters': {'state': {'$nin': responses.COMPLETED_STATES},
                                        'tags': {'$all': [repo_tag, action_tag]}}}
    return context.server.tasks_search.search(**repo_search_criteria)
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / roles.py View on Github external
def POST(self):

        # Pull all the roles data
        role_data = self.params()
        role_id = role_data.get('role_id', None)
        display_name = role_data.get('display_name', None)
        description = role_data.get('description', None)

        # Creation
        manager = managers.role_manager()
        args = [role_id, display_name, description]
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('create')]
        call_request = CallRequest(manager.create_role,
                                   args,
                                   weight=weight,
                                   tags=tags)
        call_request.creates_resource(dispatch_constants.RESOURCE_ROLE_TYPE, role_id)

        role = execution.execute_sync(call_request)
        role_link = serialization.link.child_link_obj(role_id)
        role.update(role_link)
        
        return self.created(role_id, role)
github pulp / pulp_rpm / extensions_admin / pulp_rpm / extensions / admin / export.py View on Github external
def _get_publish_tasks(resource_id, context):
    """
    Get the list of currently running publish tasks for the given repo_group id.

    :param resource_id:     The id of the resource to retrieve the task id for. This should be a
                            repo or group id
    :type  resource_id:     str
    :param context:         The client context is used when fetching existing task ids
    :type  context:         pulp.client.extensions.core.ClientContext

    :return: The Task, if it exists. If it does not, this will return None
    :rtype:  list of pulp.bindings.responses.Task
    """
    tags = [tag_utils.resource_tag(tag_utils.RESOURCE_REPOSITORY_GROUP_TYPE, resource_id),
            tag_utils.action_tag(tag_utils.ACTION_PUBLISH_TYPE)]
    criteria = {'filters': {'state': {'$nin': responses.COMPLETED_STATES}, 'tags': {'$all': tags}}}
    return context.server.tasks_search.search(**criteria)
github pulp / pulpcore / server / pulp / server / controllers / repository.py View on Github external
:param repo_id: id of the repo to publish
    :type  repo_id: str
    :param distributor_id: publish the repo with this distributor
    :type  distributor_id: str
    :param overrides: dictionary of options to pass to the publish task
    :type  overrides: dict or None
    :param scheduled_call_id: id of scheduled call that dispatched this task
    :type  scheduled_call_id: str

    :return: task result object
    :rtype: pulp.server.async.tasks.TaskResult
    """
    kwargs = {'repo_id': repo_id, 'dist_id': distributor_id, 'publish_config_override': overrides,
              'scheduled_call_id': scheduled_call_id}
    tags = [resource_tag(RESOURCE_REPOSITORY_TYPE, repo_id),
            action_tag('publish')]
    return publish.apply_async_with_reservation(RESOURCE_REPOSITORY_TYPE, repo_id, tags=tags,
                                                kwargs=kwargs)
github pulp / pulp / server / pulp / server / itineraries / repository.py View on Github external
:type  delta:           dict

    :return: A list of call_requests known as an itinerary.
    :rtype: list
    """

    call_requests = []

    # update the distributor

    manager = managers.repo_distributor_manager()

    tags = [
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
        action_tag('update_distributor')
    ]

    # Retrieve configuration options from the delta
    auto_publish = None
    if delta is not None:
        auto_publish = delta.get('auto_publish')

    update_request = CallRequest(manager.update_distributor_config, [repo_id, distributor_id],
                                 {'distributor_config': config, 'auto_publish': auto_publish}, tags=tags,
                                 archive=True, kwarg_blacklist=['distributor_config', 'auto_publish'])

    update_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
    update_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)

    call_requests.append(update_request)