Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@return: The deleted bind model object:
{consumer_group_id:, repo_id:, distributor_id:}
Or, None if bind does not exist.
@rtype: dict
"""
manager = managers_factory.consumer_group_manager()
args = [
consumer_group_id,
repo_id,
distributor_id,
]
tags = [
resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE,
consumer_group_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
action_tag('unbind')
]
call_request = CallRequest(manager.unbind,
args=args,
tags=tags)
call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_group_id)
call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
return self.ok(execution.execute(call_request))
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)
def post(self, request):
"""
Dispatch a delete_orphan_by_id task.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:raises: OperationPostponed when an async operation is performed
"""
all_orphans = request.body_as_json
task_tags = [tags.action_tag('delete_orphans'),
tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
async_task = content_orphan.delete_orphans_by_id.apply_async([all_orphans], tags=task_tags)
raise OperationPostponed(async_task)
@auth_required(authorization.DELETE)
def DELETE(self, repo_group_id, distributor_id):
params = self.params()
force = params.get('force', False)
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('remove_distributor')
]
call_request = CallRequest(distributor_manager.remove_distributor,
args=[repo_group_id, distributor_id],
kwargs={'force' : force},
tags=tags,
archive=True)
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
call_request.deletes_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id)
execution.execute(call_request)
return self.ok(None)
:type repo_group_id: str
:raises pulp_exceptions.MissingValue if 'id' is not passed in the body
:raises pulp_exceptions.OperationPosponed: dispatch a task
"""
params = request.body_as_json
distributor_id = params.get('id', None)
overrides = params.get('override_config', None)
if distributor_id is None:
raise pulp_exceptions.MissingValue(['id'])
# If a repo group does not exist, get_group raises a MissingResource exception
manager = managers_factory.repo_group_query_manager()
manager.get_group(repo_group_id)
task_tags = [
tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
tags.action_tag('publish')
]
async_result = repo_group_publish.apply_async_with_reservation(
tags.RESOURCE_REPOSITORY_GROUP_TYPE,
repo_group_id,
args=[repo_group_id, distributor_id],
kwargs={'publish_config_override': overrides},
tags=task_tags
)
raise pulp_exceptions.OperationPostponed(async_result)
@param binding_config: configuration options to use when generating the payload for this binding
@return: A list of call_requests.
@rtype list
"""
call_requests = []
bind_manager = managers.consumer_bind_manager()
agent_manager = managers.consumer_agent_manager()
# bind
tags = [
resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
action_tag(ACTION_BIND)
]
args = [
consumer_id,
repo_id,
distributor_id,
notify_agent,
binding_config,
]
bind_request = CallRequest(
bind_manager.bind,
args,
weight=0,
tags=tags)
: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)
@return:
"""
# validate the input
self._validate_distributor(repo_id, distributor_id)
schedule_utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS)
if 'schedule' not in schedule_data:
raise pulp_exceptions.MissingValue(['schedule'])
# build the publish call
publish_manager = managers_factory.repo_publish_manager()
args = [repo_id, distributor_id]
kwargs = {'publish_config_override': publish_options['override_config']}
weight = pulp_config.config.getint('tasks', 'publish_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)]
call_request = CallRequest(publish_manager.publish, args, kwargs, weight=weight, tags=tags, archive=True)
call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, publish_manager.prep_publish)
# schedule the publish
scheduler = dispatch_factory.scheduler()
schedule_id = scheduler.add(call_request, **schedule_data)
distributor_manager = managers_factory.repo_distributor_manager()
distributor_manager.add_publish_schedule(repo_id, distributor_id, schedule_id)
return schedule_id
def _get_repo_tasks(context, repo_id, action):
"""
Retrieve a list of incomplete Task objects for the given repo_id and action. action must be one
of 'sync', 'download', 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)
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)
@auth_required(UPDATE)
def POST(self, role_id):
# Params (validation will occur in the manager)
params = self.params()
login = params.get('login', None)
if login is None:
raise exceptions.InvalidValue(login)
role_manager = managers.role_manager()
tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
action_tag('add_user_to_role')]
call_request = CallRequest(role_manager.add_user_to_role,
[role_id, login],
tags=tags)
call_request.updates_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
return self.ok(execution.execute_sync(call_request))