def POST(self, repo_id): # TODO: Add timeout support # Params params = self.params() overrides = params.get("override_config", None) # Execute the sync asynchronously 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) sync_call_request.add_life_cycle_callback( dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, repo_sync_manager.prep_sync ) 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.add_life_cycle_callback( dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, repo_publish_manager.prep_publish ) publish_call_request.depends_on(sync_call_request) call_requests.append(publish_call_request) # this raises an exception that is handled by the middleware, # so no return is needed execution.execute_multiple(call_requests)
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 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) sync_call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, repo_sync_manager.prep_sync) 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.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, repo_publish_manager.prep_publish) publish_call_request.depends_on(sync_call_request.id, [dispatch_constants.CALL_FINISHED_STATE]) call_requests.append(publish_call_request) return call_requests
def bind_itinerary(consumer_id, repo_id, distributor_id, notify_agent, binding_config, agent_options): """ Get the bind itinerary: 1. Create the binding on the server. 2. Request that the consumer (agent) perform the bind. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param agent_options: Bind options passed to the agent handler. @type agent_options: dict @param notify_agent: indicates if the agent should be sent a message about the new binding @type notify_agent: bool @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 resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {distributor_id:dispatch_constants.RESOURCE_READ_OPERATION}, } 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('bind') ] args = [ consumer_id, repo_id, distributor_id, notify_agent, binding_config, ] bind_request = CallRequest( bind_manager.bind, args, resources=resources, weight=0, tags=tags) call_requests.append(bind_request) # notify agent if notify_agent: 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('agent_bind') ] args = [ consumer_id, repo_id, distributor_id, agent_options ] agent_request = CallRequest( agent_manager.bind, args, weight=0, asynchronous=True, archive=True, tags=tags) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, bind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, bind_failed) call_requests.append(agent_request) agent_request.depends_on(bind_request.id) return call_requests
def forced_unbind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the unbind itinerary. A forced unbind immediately deletes the binding instead of marking it deleted and going through that lifecycle. It is intended to be used to clean up orphaned bindings caused by failed/unconfirmed unbind actions on the consumer. The itinerary is: 1. Delete the binding on the server. 2. Request that the consumer (agent) perform the unbind. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @return: A list of call_requests @rtype list """ call_requests = [] bind_manager = managers.consumer_bind_manager() agent_manager = managers.consumer_agent_manager() # unbind resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, } 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('unbind') ] args = [ consumer_id, repo_id, distributor_id, True, ] delete_request = CallRequest( bind_manager.delete, args=args, resources=resources, tags=tags) call_requests.append(delete_request) # notify agent 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('agent_unbind') ] args = [ consumer_id, repo_id, distributor_id, options, ] agent_request = CallRequest( agent_manager.unbind, args, weight=0, asynchronous=True, archive=True, tags=tags) call_requests.append(agent_request) agent_request.depends_on(delete_request.id) return call_requests
def unbind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the unbind itinerary. The tasks in the itinerary are as follows: 1. Mark the binding as (deleted) on the server. 2. Request that the consumer (agent) perform the unbind. 3. Delete the binding on the server. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @return: A list of call_requests. @rtype list """ call_requests = [] bind_manager = managers.consumer_bind_manager() agent_manager = managers.consumer_agent_manager() # unbind resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, } 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('unbind') ] args = [ consumer_id, repo_id, distributor_id, ] unbind_request = CallRequest( bind_manager.unbind, args=args, resources=resources, tags=tags) call_requests.append(unbind_request) # notify agent 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('agent_unbind') ] args = [ consumer_id, repo_id, distributor_id, options, ] agent_request = CallRequest( agent_manager.unbind, args, weight=0, asynchronous=True, archive=True, tags=tags) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed) call_requests.append(agent_request) agent_request.depends_on(unbind_request.id) # delete the binding resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, } 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('delete_binding') ] args = [ consumer_id, repo_id, distributor_id ] delete_request = CallRequest( bind_manager.delete, args=args, resources=resources, tags=tags) call_requests.append(delete_request) delete_request.depends_on(agent_request.id) return call_requests
def bind_itinerary(consumer_id, repo_id, distributor_id, notify_agent, binding_config, agent_options): """ Get the bind itinerary: 1. Create the binding on the server. 2. Request that the consumer (agent) perform the bind. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param agent_options: Bind options passed to the agent handler. @type agent_options: dict @param notify_agent: indicates if the agent should be sent a message about the new binding @type notify_agent: bool @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) bind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) bind_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) bind_request.reads_resource( dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id) call_requests.append(bind_request) # notify agent if notify_agent: 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_AGENT_BIND) ] args = [consumer_id, repo_id, distributor_id, agent_options] agent_request = CallRequest(agent_manager.bind, args, weight=0, asynchronous=True, archive=True, tags=tags) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, bind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, bind_failed) call_requests.append(agent_request) agent_request.depends_on(bind_request.id) return call_requests
def forced_unbind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the unbind itinerary. A forced unbind immediately deletes the binding instead of marking it deleted and going through that lifecycle. It is intended to be used to clean up orphaned bindings caused by failed/unconfirmed unbind actions on the consumer. The itinerary is: 1. Delete the binding on the server. 2. Request that the consumer (agent) perform the unbind. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @return: A list of call_requests @rtype list """ call_requests = [] bind_manager = managers.consumer_bind_manager() agent_manager = managers.consumer_agent_manager() # unbind 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_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, True, ] delete_request = CallRequest(bind_manager.delete, args=args, tags=tags) delete_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_requests.append(delete_request) # notify agent 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_AGENT_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, options, ] agent_request = CallRequest(agent_manager.unbind, args, weight=0, asynchronous=True, archive=True, tags=tags) call_requests.append(agent_request) agent_request.depends_on(delete_request.id) return call_requests
def unbind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the unbind itinerary. The tasks in the itinerary are as follows: 1. Mark the binding as (deleted) on the server. 2. Request that the consumer (agent) perform the unbind. 3. Delete the binding on the server. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @return: A list of call_requests. @rtype list """ call_requests = [] bind_manager = managers.consumer_bind_manager() agent_manager = managers.consumer_agent_manager() # unbind 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_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, ] unbind_request = CallRequest(bind_manager.unbind, args=args, tags=tags) unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_requests.append(unbind_request) # notify agent 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_AGENT_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, options, ] agent_request = CallRequest(agent_manager.unbind, args, weight=0, asynchronous=True, archive=True, tags=tags) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed) call_requests.append(agent_request) agent_request.depends_on(unbind_request.id) # delete the binding 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_DELETE_BINDING) ] args = [consumer_id, repo_id, distributor_id] delete_request = CallRequest(bind_manager.delete, args=args, tags=tags) unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_requests.append(delete_request) delete_request.depends_on(agent_request.id) return call_requests
def unbind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the unbind itinerary. The tasks in the itinerary are as follows: 1. Mark the binding as (deleted) on the server. 2. Request that the consumer (agent) perform the unbind. 3. Delete the binding on the server. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @return: A list of call_requests. @rtype list """ call_requests = [] bind_manager = managers.consumer_bind_manager() binding = bind_manager.get_bind(consumer_id, repo_id, distributor_id) # agent not participating in the bind/unbind - always want a forced unbind. if not binding['notify_agent']: return forced_unbind_itinerary(consumer_id, repo_id, distributor_id, options) # unbind 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_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, ] unbind_request = CallRequest( bind_manager.unbind, args=args, tags=tags) unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_requests.append(unbind_request) # notify agent 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_AGENT_UNBIND) ] args = [ consumer_id, repo_id, distributor_id, options, ] agent_manager = managers.consumer_agent_manager() agent_request = CallRequest( agent_manager.unbind, args, weight=0, asynchronous=True, archive=True, tags=tags) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed) call_requests.append(agent_request) agent_request.depends_on(unbind_request.id) # delete the binding 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_DELETE_BINDING) ] args = [ consumer_id, repo_id, distributor_id ] delete_request = CallRequest(bind_manager.delete, args=args, tags=tags) unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_requests.append(delete_request) delete_request.depends_on(agent_request.id) return call_requests
def bind_itinerary(consumer_id, repo_id, distributor_id, options): """ Get the bind itinerary: 1. Create the binding on the server. 2. Request that the consumer (agent) perform the bind. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Bind options passed to the agent handler. @type options: dict @return: A list of call_requests known as an itinerary. @rtype list """ call_requests = [] # bind resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {distributor_id:dispatch_constants.RESOURCE_READ_OPERATION}, } args = [ consumer_id, repo_id, distributor_id, ] manager = managers.consumer_bind_manager() bind_request = CallRequest( manager.bind, args, resources=resources, weight=0) call_requests.append(bind_request) # notify agent args = [ consumer_id, repo_id, distributor_id, options ] manager = managers.consumer_agent_manager() agent_request = CallRequest( manager.bind, args, weight=0, asynchronous=True, archive=True) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, bind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, bind_failed) call_requests.append(agent_request) agent_request.depends_on(bind_request.id) return call_requests
def unbind_itinerary(consumer_id, repo_id, distributor_id, options, force=False): """ Get the unbind itinerary: 1. Mark the binding as (deleted) on the server. 2. Request that the consumer (agent) perform the unbind. 3. Delete the binding on the server. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repository ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @param options: Unbind options passed to the agent handler. @type options: dict @param force: Indicates a forced unbind. @type force: bool @return: A list of call_requests known as an itinerary. @rtype list """ call_requests = [] # unbind manager = managers.consumer_bind_manager() resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, } 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('unbind') ] args = [ consumer_id, repo_id, distributor_id, ] # A forced unbind immediately deletes the binding instead # of marking it deleted and going through that lifecycle. # It is intended to be used to clean up orphaned bindings # caused by failed/unconfirmed unbind actions on the consumer. if force: args.append(True) unbind_request = CallRequest( manager.delete, args=args, resources=resources, tags=tags) else: unbind_request = CallRequest( manager.unbind, args=args, resources=resources, tags=tags) call_requests.append(unbind_request) # notify agent args = [ consumer_id, repo_id, distributor_id, options, ] manager = managers.consumer_agent_manager() agent_request = CallRequest( manager.unbind, args, weight=0, asynchronous=True, archive=True) agent_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded) agent_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed) call_requests.append(agent_request) agent_request.depends_on(unbind_request.id) # delete the bind manager = managers.consumer_bind_manager() resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id:dispatch_constants.RESOURCE_READ_OPERATION}, } args = [ consumer_id, repo_id, distributor_id ] 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('delete') ] delete_request = CallRequest( manager.delete, args=args, resources=resources, tags=tags) call_requests.append(delete_request) delete_request.depends_on(agent_request.id) return call_requests