How to use the pulp.server.dispatch.call.CallRequest 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 / pulpcore / test / unit / test_dispatch_task.py View on Github external
def test_task_instantiation(self):
        call_request = CallRequest(mock.Mock())
        call_report = CallReport()
        try:
            Task(call_request)
            Task(call_request, call_report)
        except:
            self.fail(traceback.format_exc())
github pulp / pulp / test / unit / test_dispatch_call.py View on Github external
def test_execution_hooks(self):
        call_request = CallRequest(function)
        for key in dispatch_constants.CALL_LIFE_CYCLE_CALLBACKS:
            self.assertTrue(isinstance(call_request.execution_hooks[key], list))
            self.assertTrue(len(call_request.execution_hooks[key]) == 0)
            call_request.add_life_cycle_callback(key, function)
            self.assertTrue(isinstance(call_request.execution_hooks[key], list))
            self.assertTrue(len(call_request.execution_hooks[key]) == 1)
github pulp / pulpcore / test / unit / test_dispatch_call.py View on Github external
def test_serialize_deserialize_with_execution_hook(self):
        key = dispatch_constants.CALL_CANCEL_LIFE_CYCLE_CALLBACK
        call_request = CallRequest(function)
        call_request.add_life_cycle_callback(key, function)
        data = call_request.serialize()
        self.assertTrue(isinstance(data, dict))
        call_request_2 = CallRequest.deserialize(data)
        self.assertTrue(isinstance(call_request_2, CallRequest))
        self.assertTrue(call_request_2.execution_hooks[key][0] == function)
github pulp / pulp / platform / src / pulp / server / webservices / controllers / permissions.py View on Github external
resource = params.get('resource', None)
        operation_names = params.get('operations', None)
        
        _check_invalid_params({'role_id':role_id,
                               'resource':resource,
                               'operation_names':operation_names})

        operations = _get_operations(operation_names)
        
        # Grant permission synchronously
        role_manager = managers.role_manager()
        
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('remove_permission_from_role')]

        call_request = CallRequest(role_manager.remove_permissions_from_role,
                                   [role_id, resource, operations],
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_ROLE_TYPE, role_id)
        
        return self.ok(execution.execute_sync(call_request))
github pulp / pulpcore / platform / src / pulp / server / itineraries / consumer.py View on Github external
    @param consumer_id: unique id of the consumer
    @type consumer_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
    """
    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_uninstall')]
    call_request = CallRequest(manager.uninstall_content, args, kwargs, weight=weight, tags=tags, archive=True, asynchronous=True)
    call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
    return [call_request]
github pulp / pulpcore / platform / src / pulp / server / dispatch / task.py View on Github external
def __init__(self, call_request, call_report=None):

        assert isinstance(call_request, call.CallRequest)
        assert isinstance(call_report, (types.NoneType, call.CallReport))

        self.call_request = call_request
        self.call_report = call_report or call.CallReport.from_call_request(call_request)
        self.call_report.state = dispatch_constants.CALL_WAITING_STATE

        self.call_request_exit_state = None
        self.queued_call_id = None
        self.complete_callback = None
github pulp / pulpcore / src / pulp / server / webservices / controllers / gc_contents.py View on Github external
def POST(self):
        orphans = self.params()
        orphan_manager = factory.content_orphan_manager()
        tags = [action_tag('delete_orphans'),
                resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
        call_request = CallRequest(orphan_manager.delete_orphans_by_id, [orphans], tags=tags, archive=True)
        return execution.execute_async(self, call_request)
github pulp / pulp / server / pulp / server / itineraries / repo.py View on Github external
{'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)

    for distributor in auto_distributors:
        distributor_id = distributor['id']
        publish_call_request = CallRequest(repo_publish_manager.publish, # rbarlow_converted
                                           [repo_id, distributor_id],
                                           tags=auto_publish_tags,
                                           archive=True)
        publish_call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        publish_call_request.depends_on(sync_call_request.id,
                                        [dispatch_constants.CALL_FINISHED_STATE])

        call_requests.append(publish_call_request)

    return call_requests
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / consumer_groups.py View on Github external
def DELETE(self, consumer_group_id):
        manager = managers_factory.consumer_group_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)]
        call_request = CallRequest(manager.delete_consumer_group,
                                   [consumer_group_id],
                                   tags=tags)
        call_request.deletes_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
        result = execution.execute(call_request)
        return self.ok(result)
github pulp / pulp / server / pulp / server / itineraries / consumer.py View on Github external
    @param consumer_id: unique id of the consumer
    @type consumer_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
    """
    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_update')]
    call_request = CallRequest(
        manager.update_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]