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, [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) for distributor in auto_distributors: distributor_id = distributor['id'] publish_call_request = CallRequest(repo_publish_manager.publish, [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
def DELETE(self, repo_id, importer_id, schedule_id): importer_manager = manager_factory.repo_importer_manager() schedule_list = importer_manager.list_sync_schedules(repo_id) if schedule_id not in schedule_list: raise exceptions.MissingResource(repo=repo_id, importer=importer_id, publish_schedule=schedule_id) schedule_manager = manager_factory.schedule_manager() resources = { dispatch_constants.RESOURCE_REPOSITORY_TYPE: { repo_id: dispatch_constants.RESOURCE_READ_OPERATION }, dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE: { importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION }, dispatch_constants.RESOURCE_SCHEDULE_TYPE: { schedule_id: dispatch_constants.RESOURCE_DELETE_OPERATION } } tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id), resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id), action_tag('delete_sync_schedule') ] call_request = CallRequest(schedule_manager.delete_sync_schedule, [repo_id, importer_id, schedule_id], resources=resources, tags=tags, archive=True) result = execution.execute(call_request) return self.ok(result)
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) consumer_ids = group_data.pop('consumer_ids', None) notes = group_data.pop('notes', None) if group_data: raise pulp_exceptions.InvalidValue(group_data.keys()) manager = managers_factory.consumer_group_manager() weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, group_id) ] call_request = CallRequest( manager.create_consumer_group, [group_id, display_name, description, consumer_ids, notes], weight=weight, tags=tags) call_request.creates_resource( dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, group_id) group = execution.execute_sync(call_request) group.update(serialization.link.child_link_obj(group['id'])) return self.created(group['_href'], group)
def POST(self): # Params params = self.params() role_id = params.get('role_id', None) 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))
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)
def test_args(self): call = Functor() args = ['fee', 'fie', 'foe', 'foo'] try: call_request = CallRequest(call, args) except Exception, e: self.fail(e.message)
def POST(self, repo_group_id): params = self.params() distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise MissingValue(['id']) publish_manager = managers_factory.repo_group_publish_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('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)
def POST(self): body = self.params() id = body.get('id') display_name = body.get('display_name') description = body.get('description') notes = body.get('notes') manager = managers.consumer_manager() args = [id, display_name, description, notes] weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id), action_tag('create') ] call_request = CallRequest(manager.register, args, weight=weight, tags=tags) call_request.creates_resource( dispatch_constants.RESOURCE_CONSUMER_TYPE, id) call_report = CallReport.from_call_request(call_request) call_report.serialize_result = False consumer = execution.execute_sync(call_request, call_report) consumer.update( {'_href': serialization.link.child_link_obj(consumer['id'])}) return self.created(consumer['_href'], consumer)
def POST(self, repo_id): params = self.params() criteria = params.get('criteria', None) if criteria is not None: try: criteria = UnitAssociationCriteria.from_client_input(criteria) except: _LOG.error('Error parsing unassociation criteria [%s]' % criteria) raise exceptions.PulpDataException(), None, sys.exc_info()[2] association_manager = manager_factory.repo_unit_association_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag('unassociate') ] call_request = CallRequest( association_manager.unassociate_by_criteria, [ repo_id, criteria, RepoContentUnit.OWNER_TYPE_USER, manager_factory.principal_manager().get_principal()['login'] ], tags=tags, archive=True) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) return execution.execute_async(self, call_request)
def DELETE(self, consumer_id, content_type): """ Delete an association between the specified consumer and profile. Designed to be idempotent. @param consumer_id: A consumer ID. @type consumer_id: str @param content_type: The content type ID. @type content_type: str @return: The deleted model object: {consumer_id:<str>, content_type:<str>, profile:<dict>} Or, None if bind does not exist. @rtype: dict """ manager = managers.consumer_profile_manager() args = [ consumer_id, content_type, ] tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id), ] call_request = CallRequest(manager.delete, args=args, tags=tags) call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) return self.ok(execution.execute(call_request))
def DELETE(self, consumer_id, schedule_id): consumer_manager = managers.consumer_manager() consumer_manager.get_consumer(consumer_id) 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('delete_unit_update_schedule') ] call_request = CallRequest( schedule_manager.delete_unit_update_schedule, [consumer_id, schedule_id], tags=tags, archive=True) call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_request.deletes_resource( dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id) result = execution.execute(call_request) return self.ok(result)
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)
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)
def PUT(self, consumer_id, content_type): """ Update the association of a profile with a consumer by content type ID. @param consumer_id: A consumer ID. @type consumer_id: str @param content_type: A content unit type ID. @type content_type: str @return: The updated model object: {consumer_id:<str>, content_type:<str>, profile:<dict>} @rtype: dict """ body = self.params() profile = body.get('profile') manager = managers.consumer_profile_manager() tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id), resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, content_type), action_tag('profile_update')] call_request = CallRequest(manager.update, [consumer_id, content_type], {'profile': profile}, tags=tags, weight=0, kwarg_blacklist=['profile']) call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_report = CallReport.from_call_request(call_request) call_report.serialize_result = False consumer = execution.execute_sync(call_request, call_report) link = serialization.link.child_link_obj(consumer_id, content_type) consumer.update(link) return self.ok(consumer)
def DELETE(self, repo_group_id, distributor_id): params = self.params() force = params.get('force', False) distributor_manager = managers_factory.repo_group_distributor_manager() resources = { dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE : {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE : {distributor_id : dispatch_constants.RESOURCE_DELETE_OPERATION}, } 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}, resources=resources, tags=tags, archive=True) execution.execute(call_request) return self.ok(None)
def POST(self, repo_id): # 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) execution.execute(call_request) return self.ok(None)
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() resources = { dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE : {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE : {distributor_id : dispatch_constants.RESOURCE_UPDATE_OPERATION}, } 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], resources=resources, tags=tags, archive=True) result = execution.execute(call_request) href = serialization.link.current_link_obj() result.update(href) return self.ok(result)
def POST(self, repo_id): # Params params = self.params() query = params.get('criteria', {}) options = params.get('options', {}) timeout = params.get('timeout', 60) try: criteria = UnitAssociationCriteria.from_client_input(query) except: _LOG.error('Error parsing association criteria [%s]' % query) raise exceptions.PulpDataException(), None, sys.exc_info()[2] try: timeout = int(timeout) except ValueError: raise exceptions.InvalidValue(['timeout']), None, sys.exc_info()[2] # Coordinator configuration tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag('resolve_dependencies') ] dependency_manager = manager_factory.dependency_manager() call_request = CallRequest( dependency_manager.resolve_dependencies_by_criteria, [repo_id, criteria, options], tags=tags, archive=True) call_request.reads_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) return execution.execute_sync_ok(self, call_request, timeout=timedelta(seconds=timeout))
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) 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]
def PUT(self, id): parameters = self.params() delta = parameters.get('delta', None) importer_config = parameters.get('importer_config', None) distributor_configs = parameters.get('distributor_configs', None) repo_manager = manager_factory.repo_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, id), action_tag('update') ] call_request = CallRequest( repo_manager.update_repo_and_plugins, [id, delta], { 'importer_config': importer_config, 'distributor_configs': distributor_configs }, tags=tags, archive=True, kwarg_blacklist=['importer_config', 'distributor_configs']) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, id) repo = execution.execute(call_request) repo.update(serialization.link.current_link_obj()) return self.ok(repo)
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]
def POST(self, repo_id): # Params (validation will occur in the manager) params = self.params() importer_type = params.get('importer_type_id', None) importer_config = params.get('importer_config', None) if importer_type is None: _LOG.error( 'Missing importer type adding importer to repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_type']) # Note: If an importer exists, it's removed, so no need to handle 409s. # Note: If the plugin raises an exception during initialization, let it # bubble up and be handled like any other 500. importer_manager = manager_factory.repo_importer_manager() weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag('add_importer') ] call_request = CallRequest(importer_manager.set_importer, [repo_id, importer_type], {'repo_plugin_config': importer_config}, weight=weight, tags=tags, kwarg_blacklist=['repo_plugin_config']) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) return execution.execute_sync_created(self, call_request, 'importer')
def test_kwargs(self): call = Functor() kwargs = {'one': 'foo', 'two': 'bar', 'three': 'baz'} try: call_request = CallRequest(call, kwargs=kwargs) except Exception, e: self.fail(e.message)
def PUT(self, repo_id, importer_id): # Params (validation will occur in the manager) params = self.params() importer_config = params.get('importer_config', None) if importer_config is None: _LOG.error( 'Missing configuration updating importer for repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_config']) importer_manager = manager_factory.repo_importer_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id), action_tag('update_importer') ] call_request = CallRequest(importer_manager.update_importer_config, [repo_id], {'importer_config': importer_config}, tags=tags, archive=True, kwarg_blacklist=['importer_config']) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id) result = execution.execute(call_request) return self.ok(result)
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() resources = { dispatch_constants.RESOURCE_ROLE_TYPE: { role_id: dispatch_constants.RESOURCE_CREATE_OPERATION } } 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, resources=resources, weight=weight, tags=tags) 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)
def DELETE(self, repo_id, distributor_id, schedule_id): distributor_manager = manager_factory.repo_distributor_manager() schedule_list = distributor_manager.list_publish_schedules( repo_id, distributor_id) if schedule_id not in schedule_list: raise exceptions.MissingResource(repo=repo_id, distributor=distributor_id, publish_schedule=schedule_id) schedule_manager = manager_factory.schedule_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag( dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id), resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id), action_tag('delete_publish_schedule') ] call_request = CallRequest(schedule_manager.delete_publish_schedule, [repo_id, distributor_id, schedule_id], tags=tags, archive=True) call_request.reads_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id) call_request.deletes_resource( dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id) result = execution.execute(call_request) return self.ok(result)
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))
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() resources = {dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE : { repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION }} 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], resources=resources, weight=weight, tags=tags) created = execution.execute(call_request) href = serialization.link.child_link_obj(created['id']) created.update(href) return self.created(href['_href'], created)
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)
def create_sync_schedule(self, repo_id, importer_id, sync_options, schedule_data): """ Create a new sync schedule for a given repository using the given importer. @param repo_id: @param importer_id: @param sync_options: @param schedule_data: @return: """ # validate the input self._validate_importer(repo_id, importer_id) schedule_utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the sync call request args = [repo_id] kwargs = {'overrides': sync_options['override_config']} call_request = CallRequest(sync_with_auto_publish_itinerary, args, kwargs, weight=0) # schedule the sync scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) importer_manager = managers_factory.repo_importer_manager() importer_manager.add_sync_schedule(repo_id, schedule_id) return schedule_id