本文整理汇总了Python中pulp.server.dispatch.call.CallRequest类的典型用法代码示例。如果您正苦于以下问题:Python CallRequest类的具体用法?Python CallRequest怎么用?Python CallRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CallRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
def POST(self, repo_id):
# Params (validation will occur in the manager)
params = self.params()
distributor_type = params.get('distributor_type_id', None)
distributor_config = params.get('distributor_config', None)
distributor_id = params.get('distributor_id', None)
auto_publish = params.get('auto_publish', False)
# Update the repo
distributor_manager = manager_factory.repo_distributor_manager()
weight = pulp_config.config.getint('tasks', 'create_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
action_tag('add_distributor')]
if distributor_id is not None:
tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id))
call_request = CallRequest(distributor_manager.add_distributor,
[repo_id, distributor_type],
{'repo_plugin_config': distributor_config, 'auto_publish': auto_publish,
'distributor_id': distributor_id},
weight=weight,
tags=tags,
kwarg_blacklist=['repo_plugin_config'])
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
if distributor_id is not None:
call_request.creates_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
return execution.execute_created(self, call_request, distributor_id)
示例2: PUT
def PUT(self, repo_group_id, distributor_id):
params = self.params()
distributor_config = params.get('distributor_config', None)
if distributor_config is None:
raise pulp_exceptions.MissingValue(['distributor_config'])
distributor_manager = managers_factory.repo_group_distributor_manager()
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('update_distributor')
]
call_request = CallRequest(distributor_manager.update_distributor_config,
args=[repo_group_id, distributor_id, distributor_config],
tags=tags,
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)
result = execution.execute(call_request)
href = serialization.link.current_link_obj()
result.update(href)
return self.ok(result)
示例3: consumer_content_update_itinerary
def consumer_content_update_itinerary(consumer_id, units, options):
"""
Create an itinerary for consumer content update.
@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]
示例4: POST
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)
示例5: POST
def POST(self, repo_group_id):
# Params (validation will occur in the manager)
params = self.params()
distributor_type_id = params.get('distributor_type_id', None)
distributor_config = params.get('distributor_config', None)
distributor_id = params.get('distributor_id', None)
distributor_manager = managers_factory.repo_group_distributor_manager()
weight = pulp_config.config.getint('tasks', 'create_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
action_tag('add_distributor')]
if distributor_id is not None:
tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id))
call_request = CallRequest(distributor_manager.add_distributor,
[repo_group_id, distributor_type_id, distributor_config, distributor_id],
weight=weight,
tags=tags)
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
created = execution.execute(call_request)
href = serialization.link.child_link_obj(created['id'])
created.update(href)
return self.created(href['_href'], created)
示例6: POST
def POST(self, repo_id):
"""
Import an uploaded unit into the given repository.
:param repo_id: The id of the repository the upload should be imported into
:type repo_id: basestring
:return: A json serialized dictionary with two keys. 'success_flag' indexes a boolean
value that indicates whether the import was successful, and 'summary' will
contain the summary as reported by the Importer.
:rtype: basestring
"""
# Collect user input
params = self.params()
upload_id = params['upload_id']
unit_type_id = params['unit_type_id']
unit_key = params['unit_key']
unit_metadata = params.pop('unit_metadata', None)
# Coordinator configuration
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
action_tag('import_upload')]
upload_manager = manager_factory.content_upload_manager()
call_request = CallRequest(upload_manager.import_uploaded_unit,
[repo_id, unit_type_id, unit_key, unit_metadata, upload_id],
tags=tags, archive=True)
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
report = execution.execute(call_request)
return self.ok(report)
示例7: POST
def POST(self):
group_data = self.params()
group_id = group_data.pop('id', None)
if group_id is None:
raise pulp_exceptions.MissingValue(['id'])
display_name = group_data.pop('display_name', None)
description = group_data.pop('description', None)
repo_ids = group_data.pop('repo_ids', None)
notes = group_data.pop('notes', None)
distributors = group_data.pop('distributors', None)
if group_data:
raise pulp_exceptions.InvalidValue(group_data.keys())
# Create the repo group
manager = managers_factory.repo_group_manager()
args = [group_id, display_name, description, repo_ids, notes]
kwargs = {'distributor_list': distributors}
weight = pulp_config.config.getint('tasks', 'create_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, group_id)]
call_request = CallRequest(manager.create_and_configure_repo_group, args, kwargs, weight=weight,
tags=tags)
call_request.creates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, group_id)
group = execution.execute_sync(call_request)
group.update(serialization.link.child_link_obj(group['id']))
group['distributors'] = distributors or []
return self.created(group['_href'], group)
示例8: POST
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'])
return self.created(login, user)
示例9: POST
def POST(self):
# Params
params = self.params()
login = params.get('login', None)
resource = params.get('resource', None)
operation_names = params.get('operations', None)
_check_invalid_params({'login':login,
'resource':resource,
'operation_names':operation_names})
operations = _get_operations(operation_names)
# Grant permission synchronously
permission_manager = managers.permission_manager()
tags = [resource_tag(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource),
resource_tag(dispatch_constants.RESOURCE_USER_TYPE, login),
action_tag('grant_permission_to_user')]
call_request = CallRequest(permission_manager.grant,
[resource, login, operations],
tags=tags)
call_request.reads_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
call_request.updates_resource(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource)
return self.ok(execution.execute_sync(call_request))
示例10: publish_itinerary
def publish_itinerary(repo_id, distributor_id, overrides=None):
"""
Create an itinerary for repo publish.
@param repo_id: id of the repo to publish
@type repo_id: str
@param distributor_id: id of the distributor to use for the repo publish
@type distributor_id: str
@param overrides: dictionary of options to pass to the publish manager
@type overrides: dict or None
@return: list of call requests
@rtype: list
"""
repo_publish_manager = manager_factory.repo_publish_manager()
weight = pulp_config.config.getint('tasks', 'publish_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
action_tag('publish')]
call_request = CallRequest(repo_publish_manager.publish,
[repo_id, distributor_id],
{'publish_config_override': overrides},
weight=weight,
tags=tags,
archive=True)
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
return [call_request]
示例11: FailTests
class FailTests(base.PulpServerTests):
def setUp(self):
self.call_request = CallRequest(fail)
self.call_report = CallReport()
self.task = Task(self.call_request, self.call_report)
def tearDown(self):
self.call_request = None
self.call_report = None
self.task = None
def test_failed(self):
self.task._run()
self.assertTrue(self.call_report.state is dispatch_constants.CALL_ERROR_STATE,
self.call_report.state)
self.assertTrue(isinstance(self.call_report.exception, RuntimeError),
str(type(self.call_report.exception)))
self.assertTrue(isinstance(self.call_report.traceback, types.TracebackType))
def test_error_execution_hook(self):
hook = mock.Mock()
self.call_request.add_life_cycle_callback(dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook)
self.task._run()
self.assertTrue(hook.call_count == 1)
self.assertTrue(hook.call_args[0][0] is self.call_request)
self.assertTrue(hook.call_args[0][1] is self.call_report)
示例12: test_control_hooks
def test_control_hooks(self):
call_request = CallRequest(function)
for key in dispatch_constants.CALL_CONTROL_HOOKS:
self.assertTrue(call_request.control_hooks[key] is None)
for key in dispatch_constants.CALL_CONTROL_HOOKS:
call_request.add_control_hook(key, function)
self.assertTrue(call_request.control_hooks[key] is function)
示例13: PUT
def PUT(self, consumer_id, schedule_id):
consumer_manager = managers.consumer_manager()
consumer_manager.get_consumer(consumer_id)
schedule_data = self.params()
install_options = None
units = schedule_data.pop('units', None)
if 'options' in schedule_data:
install_options = {'options': schedule_data.pop('options')}
schedule_manager = managers.schedule_manager()
tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
action_tag('update_unit_uninstall_schedule')]
call_request = CallRequest(schedule_manager.update_unit_uninstall_schedule,
[consumer_id, schedule_id, units, install_options, schedule_data],
tags=tags,
archive=True)
call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)
execution.execute(call_request)
scheduler = dispatch_factory.scheduler()
scheduled_call = scheduler.get(schedule_id)
scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
scheduled_obj.update(serialization.link.current_link_obj())
return self.ok(scheduled_obj)
示例14: create_unit_install_schedule
def create_unit_install_schedule(self, consumer_id, units, install_options, schedule_data ):
"""
Create a schedule for installing content units on a consumer.
@param consumer_id: unique id for the consumer
@param units: list of unit type and unit key dicts
@param install_options: options to pass to the install manager
@param schedule_data: scheduling data
@return: schedule id
"""
self._validate_consumer(consumer_id)
self._validate_keys(install_options, _UNIT_INSTALL_OPTION_KEYS)
if 'schedule' not in schedule_data:
raise pulp_exceptions.MissingValue(['schedule'])
manager = managers_factory.consumer_agent_manager()
args = [consumer_id]
kwargs = {'units': units,
'options': install_options.get('options', {})}
weight = pulp_config.config.getint('tasks', 'consumer_content_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
action_tag('unit_install'), action_tag('scheduled_unit_install')]
call_request = CallRequest(manager.install_content, args, kwargs, weight=weight, tags=tags, archive=True)
call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
scheduler = dispatch_factory.scheduler()
schedule_id = scheduler.add(call_request, **schedule_data)
return schedule_id
示例15: POST
def POST(self, consumer_id):
consumer_manager = managers.consumer_manager()
consumer_manager.get_consumer(consumer_id)
schedule_data = self.params()
units = schedule_data.pop('units', None)
uninstall_options = {'options': schedule_data.pop('options', {})}
if not units:
raise MissingValue(['units'])
schedule_manager = managers.schedule_manager()
weight = pulp_config.config.getint('tasks', 'create_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
action_tag('create_unit_uninstall_schedule')]
call_request = CallRequest(schedule_manager.create_unit_uninstall_schedule,
[consumer_id, units, uninstall_options, schedule_data],
weight=weight,
tags=tags,
archive=True)
call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
schedule_id = execution.execute_sync(call_request)
scheduler = dispatch_factory.scheduler()
scheduled_call = scheduler.get(schedule_id)
scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
scheduled_obj.update(serialization.link.child_link_obj(schedule_id))
return self.created(scheduled_obj['_href'], scheduled_obj)