How to use the pulp.server.dispatch.constants 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 / test / unit / test_dispatch_coordinator.py View on Github external
def test_task_records_insertion(self):
        task_id = 'my_task'
        repo_id = 'my_repo'
        content_unit_id = 'my_content_unit'
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {
                repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION,
            },
            dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE: {
                content_unit_id: [dispatch_constants.RESOURCE_READ_OPERATION],
            }
        }
        try:
            task_resources = coordinator.resource_dict_to_task_resources(resources)
            coordinator.set_task_id_on_task_resources(task_id, task_resources)
            self.collection.insert(task_resources, safe=True)
        except:
            self.fail(traceback.format_exc())
github pulp / pulp / platform / src / pulp / server / orchestration / distributor.py View on Github external
def delete(repo_id, distributor_id):

    call_requests = []

    # delete distributor
    manager = managers.repo_distributor_manager()
    resources = {
        dispatch_constants.RESOURCE_REPOSITORY_TYPE:
            {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION},
        dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE:
            {distributor_id: dispatch_constants.RESOURCE_DELETE_OPERATION}
    }
    tags = [
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
        action_tag('remove_distributor')
    ]

    delete_request = CallRequest(
        manager.remove_distributor,
        [repo_id, distributor_id],
        resources=resources,
        tags=tags,
        archive=True)

    call_requests.append(delete_request)
github pulp / pulp / platform / src / pulp / server / dispatch / coordinator.py View on Github external
def _run_task(self, task, timeout=None):
        """
        Run a task "synchronously".
        @param task: task to run
        @type  task: L{Task} instance
        @param timeout: how much time to wait for a synchronous task to start
                        None means indefinitely
        @type  timeout: None or datetime.timedelta
        """
        task_queue = dispatch_factory._task_queue()
        valid_states = [dispatch_constants.CALL_RUNNING_STATE]
        # it's perfectly legitimate for the call to complete before the first poll
        valid_states.extend(dispatch_constants.CALL_COMPLETE_STATES)

        try:
            wait_for_task(task, valid_states, poll_interval=self.task_state_poll_interval, timeout=timeout)

        except OperationTimedOut:
            task_queue.dequeue(task) # dequeue or cancel? really need timed out support
            raise

        else:
            wait_for_task(task, dispatch_constants.CALL_COMPLETE_STATES,
                          poll_interval=self.task_state_poll_interval)
github pulp / pulpcore / src / pulp / server / webservices / controllers / gc_contents.py View on Github external
def DELETE(self, content_type):
        orphan_manager = factory.content_orphan_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
        call_request = CallRequest(orphan_manager.delete_orphans_by_type, [content_type], tags=tags, archive=True)
        return execution.execute_async(self, call_request)
github pulp / pulpcore / server / pulp / server / itineraries / consumer.py View on Github external
"""
    Create an itinerary for consumer content installation.
    @param consumer_id: unique id of the consumer
    @type consumer_id: str
    @param units: units to install
    @type units: list or tuple
    @param options: options to pass to the install manager
    @type options: dict or None
    @return: list of call requests
    @rtype: list
    """
    manager = managers_factory.consumer_agent_manager()
    args = [consumer_id]
    kwargs = {'units': units, 'options': options}
    weight = pulp_config.config.getint('tasks', 'consumer_content_weight')
    tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
            action_tag('unit_install')]
    call_request = CallRequest(
        manager.install_content,
        args,
        kwargs,
        weight=weight,
        tags=tags,
        archive=True,
        asynchronous=True,
        kwarg_blacklist=['options'])
    call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, cancel_agent_request)
    call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
    return [call_request]
github pulp / pulp / src / pulp / server / webservices / controllers / gc_consumers.py View on Github external
    @auth_required(DELETE)
    def DELETE(self, id):

        manager = managers.consumer_manager()
        
        resources = {dispatch_constants.RESOURCE_CONSUMER_TYPE: {id: dispatch_constants.RESOURCE_DELETE_OPERATION}}
        tags = [id]
        call_request = CallRequest(manager.unregister,
                                   [id],
                                   resources=resources,
                                   tags=tags)
        return execution.execute_ok(self, call_request)
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / repo_groups.py View on Github external
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('publish')
        ]
        weight = pulp_config.config.getint('tasks', 'publish_weight')

        call_request = CallRequest(publish_manager.publish,
                                   args=[repo_group_id, distributor_id],
                                   kwargs={'publish_config_override' : overrides},
                                   tags=tags,
                                   weight=weight,
                                   archive=True)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id)
        call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, publish_manager.prep_publish)

        return execution.execute_async(self, call_request)
github pulp / pulp / platform / src / pulp / server / webservices / controllers / users.py View on Github external
    @auth_required(CREATE)
    def POST(self):

        # Pull all the user data
        user_data = self.params()
        login = user_data.get('login', None)
        password = user_data.get('password', None)
        name = user_data.get('name', None)

        # Creation
        manager = managers.user_manager()
        args = [login]
        kwargs = {'password': password,
                  'name': name}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_USER_TYPE, login),
                action_tag('create')]
        call_request = CallRequest(manager.create_user,
                                   args,
                                   kwargs,
                                   weight=weight,
                                   tags=tags,
                                   kwarg_blacklist=['password'])
        call_request.creates_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
        user = execution.execute_sync(call_request)
        user_link = serialization.link.child_link_obj(login)
        user.update(user_link)

        # Grant permissions
        permission_manager = managers.permission_manager()
        permission_manager.grant_automatic_permissions_for_resource(user_link['_href'])
github pulp / pulp / server / pulp / server / itineraries / repo.py View on Github external
def sync_with_auto_publish_itinerary(repo_id, overrides=None):
    """
    Create a call request list for the synchronization of a repository and the
    publishing of any distributors that are configured for auto publish.
    @param repo_id: id of the repository to create a sync call request list for
    @type repo_id: str
    @param overrides: dictionary of configuration overrides for this sync
    @type overrides: dict or None
    @return: list of call request instances
    @rtype: list
    """

    repo_sync_manager = manager_factory.repo_sync_manager()

    sync_weight = pulp_config.config.getint('tasks', 'sync_weight')
    sync_tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                 action_tag('sync')]

    sync_call_request = CallRequest(repo_sync_manager.sync, # rbarlow_converted
                                    [repo_id],
                                    {'sync_config_override': overrides},
                                    weight=sync_weight,
                                    tags=sync_tags,
                                    archive=True)
    sync_call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)

    call_requests = [sync_call_request]

    repo_publish_manager = manager_factory.repo_publish_manager()
    auto_publish_tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                         action_tag('auto_publish'), action_tag('publish')]
    auto_distributors = repo_publish_manager.auto_distributors(repo_id)
github pulp / pulpcore / platform / src / pulp / server / dispatch / task.py View on Github external
def _succeeded(self, result=None):
        """
        Mark the task completion as successful.
        @param result: result of the call
        @type  result: any
        """
        assert self.call_report.state is dispatch_constants.CALL_RUNNING_STATE

        self.call_report.result = result

        _LOG.info(_('SUCCESS: %(t)s') % {'t': str(self)})

        self.call_life_cycle_callbacks(dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK)
        self._complete(dispatch_constants.CALL_FINISHED_STATE)