本文整理汇总了Python中pulp.server.managers.factory.consumer_bind_manager函数的典型用法代码示例。如果您正苦于以下问题:Python consumer_bind_manager函数的具体用法?Python consumer_bind_manager怎么用?Python consumer_bind_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了consumer_bind_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bind
def bind(self, consumer_id, repo_id, distributor_id, options):
"""
Request the agent to perform the specified bind. This method will be called
after the server-side representation of the binding has been created.
:param consumer_id: The 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: The options are handler specific.
:type options: dict
"""
# agent request
consumer_manager = managers.consumer_manager()
binding_manager = managers.consumer_bind_manager()
consumer = consumer_manager.get_consumer(consumer_id)
binding = binding_manager.get_bind(consumer_id, repo_id, distributor_id)
agent_bindings = self.__bindings([binding])
agent = PulpAgent(consumer)
agent.consumer.bind(agent_bindings, options)
# request tracking
action_id = factory.context().call_request_id
consumer_manager = managers.consumer_bind_manager()
consumer_manager.action_pending(
consumer_id,
repo_id,
distributor_id,
Bind.Action.BIND,
action_id)
示例2: test_bind
def test_bind(self):
# Setup
self.populate()
# Test
options = {}
itinerary = bind_itinerary(
self.CONSUMER_ID,
self.REPO_ID,
self.DISTRIBUTOR_ID,
self.NOTIFY_AGENT,
self.BINDING_CONFIG,
options)
call_reports = self.coordinator.execute_multiple_calls(itinerary)
# Verify
self.assertEqual(len(call_reports), 2)
self.assertEqual(call_reports[0].call_request_tags, self.BIND_TAGS)
self.assertEqual(call_reports[1].call_request_tags, self.AGENT_BIND_TAGS)
for call in call_reports:
self.assertNotEqual(call.state, dispatch_constants.CALL_REJECTED_RESPONSE)
# run task #1 (actual bind)
self.run_next()
# verify bind created
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEquals(len(binds), 1)
bind = binds[0]
self.assertEqual(bind['consumer_id'], self.CONSUMER_ID)
self.assertEqual(bind['repo_id'], self.REPO_ID)
self.assertEqual(bind['distributor_id'], self.DISTRIBUTOR_ID)
self.assertEqual(bind['notify_agent'], self.NOTIFY_AGENT)
self.assertEqual(bind['binding_config'], self.BINDING_CONFIG)
# run task #2 (notify consumer)
self.run_next()
# verify pending consumer request (pending)
request_id = call_reports[1].call_request_id
bind = manager.get_bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
actions = bind['consumer_actions']
self.assertEqual(len(actions), 1)
self.assertEqual(actions[0]['id'], request_id)
self.assertEqual(actions[0]['action'], Bind.Action.BIND)
self.assertEqual(actions[0]['status'], Bind.Status.PENDING)
self.assertTrue(isinstance(actions[0]['timestamp'], float))
# verify agent notified
self.assertTrue(mock_agent.Consumer.bind.called)
# simulated asynchronous task result
report = DispatchReport()
self.coordinator.complete_call_success(request_id, report.dict())
# verify pending consumer request (confirmed)
manager = factory.consumer_bind_manager()
bind = manager.get_bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
self.assertEqual(len(bind['consumer_actions']), 0)
示例3: bind
def bind(consumer_id, repo_id, distributor_id, options):
"""
Request the agent to perform the specified bind. This method will be called
after the server-side representation of the binding has been created.
:param consumer_id: The 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: The options are handler specific.
:type options: dict
:return: The task created by the bind
:rtype: dict
"""
# track agent operations using a pseudo task
task_id = str(uuid4())
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)
]
task = TaskStatusManager.create_task_status(task_id, 'agent', tags=tags)
# agent request
consumer_manager = managers.consumer_manager()
binding_manager = managers.consumer_bind_manager()
consumer = consumer_manager.get_consumer(consumer_id)
binding = binding_manager.get_bind(consumer_id, repo_id, distributor_id)
agent_bindings = AgentManager._bindings([binding])
context = Context(
consumer,
task_id=task_id,
action='bind',
consumer_id=consumer_id,
repo_id=repo_id,
distributor_id=distributor_id)
agent = PulpAgent()
agent.consumer.bind(context, agent_bindings, options)
# bind action tracking
consumer_manager = managers.consumer_bind_manager()
consumer_manager.action_pending(
consumer_id,
repo_id,
distributor_id,
Bind.Action.BIND,
task_id)
return task
示例4: test_consumer_unregister_cleanup
def test_consumer_unregister_cleanup(self):
# Setup
self.test_bind()
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEquals(len(binds), 1)
# Test
manager = factory.consumer_manager()
manager.unregister(self.CONSUMER_ID)
# Verify
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEquals(len(binds), 0)
示例5: test_remove_distributor_cleanup
def test_remove_distributor_cleanup(self):
# Setup
self.test_bind()
manager = factory.consumer_bind_manager()
binds = manager.find_by_distributor(self.REPO_ID, self.DISTRIBUTOR_ID)
self.assertEquals(len(binds), 1)
# Test
manager = factory.repo_distributor_manager()
manager.remove_distributor(self.REPO_ID, self.DISTRIBUTOR_ID)
# Verify
manager = factory.consumer_bind_manager()
binds = manager.find_by_distributor(self.REPO_ID, self.DISTRIBUTOR_ID)
self.assertEquals(len(binds), 0)
示例6: test_remove_repo_cleanup
def test_remove_repo_cleanup(self):
# Setup
self.test_bind()
manager = factory.consumer_bind_manager()
binds = manager.find_by_repo(self.REPO_ID)
self.assertEquals(len(binds), 1)
# Test
manager = factory.repo_manager()
manager.delete_repo(self.REPO_ID)
# Verify
manager = factory.consumer_bind_manager()
binds = manager.find_by_repo(self.REPO_ID)
self.assertEquals(len(binds), 0)
示例7: test_consumer_unregister_cleanup
def test_consumer_unregister_cleanup(self, *unused):
self.populate()
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID, self.NOTIFY_AGENT, self.BINDING_CONFIG)
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEqual(len(binds), 1)
# Test
manager = factory.consumer_manager()
manager.unregister(self.CONSUMER_ID)
# Verify
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEqual(len(binds), 0)
示例8: test_unbind
def test_unbind(self, mock_repo_qs):
# Setup
self.populate()
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID, self.NOTIFY_AGENT, self.BINDING_CONFIG)
# Test
manager = factory.consumer_bind_manager()
manager.unbind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
# Verify
collection = Bind.get_collection()
bind_id = dict(consumer_id=self.CONSUMER_ID, repo_id=self.REPO_ID, distributor_id=self.DISTRIBUTOR_ID)
bind = collection.find_one(bind_id)
self.assertTrue(bind is not None)
self.assertTrue(bind["deleted"])
示例9: repo_delete_itinerary
def repo_delete_itinerary(repo_id):
"""
Get the itinerary for deleting a repository.
1. Delete the repository on the sever.
2. Unbind any bound consumers.
@param repo_id: A repository ID.
@type repo_id: str
@return: A list of call_requests known as an itinerary.
@rtype list
"""
call_requests = []
# delete repository
manager = managers.repo_manager()
resources = {dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_DELETE_OPERATION}}
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag("delete")]
delete_request = CallRequest(manager.delete_repo, [repo_id], resources=resources, tags=tags, archive=True)
call_requests.append(delete_request)
# append unbind itineraries foreach bound consumer
options = {}
manager = managers.consumer_bind_manager()
for bind in manager.find_by_repo(repo_id):
unbind_requests = unbind_itinerary(bind["consumer_id"], bind["repo_id"], bind["distributor_id"], options)
if unbind_requests:
unbind_requests[0].depends_on(delete_request.id)
call_requests.extend(unbind_requests)
return call_requests
示例10: expand_consumers
def expand_consumers(options, consumers):
"""
Expand a list of users based on flags specified in the
post body or query parameters. The _href is always added by the
serialization function used.
Supported options:
details - synonym for: (bindings=True,)
bindings - include bindings
@param options: The (expanding) options.
@type options: dict
@param consumers: A list of consumers
@type consumers: list
@return: A list of expanded consumers.
@rtype: list
"""
if options.get('details', False):
options['bindings'] = True
# add bindings
if options.get('bindings', False):
ids = [c['id'] for c in consumers]
manager = managers.consumer_bind_manager()
criteria = Criteria({'consumer_id': {'$in': ids}})
bindings = manager.find_by_criteria(criteria)
collated = {}
for b in bindings:
lst = collated.setdefault(b['consumer_id'], [])
lst.append(b)
for _consumer in consumers:
_consumer['bindings'] = \
[serialization.binding.serialize(b, False)
for b in collated.get(_consumer['id'], [])]
return consumers
示例11: GET
def GET(self, consumer_id, repo_id=None):
"""
Fetch all bind objects referencing the specified consumer_id. Optionally,
specify a repo_id to fetch all bind objects for the consumer_id to the repo_id
:param consumer_id: The specified consumer.
:type consumer_id: str
:param repo_id: The repository to retrieve bindings for (optional)
:type repo_id: str
:return: A list of dictionaries that represent pulp.server.db.model.consumer.Bind objects
:rtype: list
"""
# Check to make sure the resources exist
missing_resources = {}
if repo_id is not None:
repo = managers.repo_query_manager().find_by_id(repo_id)
if repo is None:
missing_resources['repo_id'] = repo_id
# If get_consumer raises MissingResource we might miss reporting a bad repo_id
try:
managers.consumer_manager().get_consumer(consumer_id)
except MissingResource:
missing_resources['consumer_id'] = consumer_id
if len(missing_resources) > 0:
raise MissingResource(**missing_resources)
manager = managers.consumer_bind_manager()
bindings = manager.find_by_consumer(consumer_id, repo_id)
bindings = [serialization.binding.serialize(b) for b in bindings]
return self.ok(bindings)
示例12: test_delete
def test_delete(self):
# Setup
self.populate()
manager = factory.consumer_bind_manager()
bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
# Test
manager.delete(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
示例13: test_consumer_unregister_cleanup
def test_consumer_unregister_cleanup(self):
# Setup
self.populate()
# Test
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEquals(len(binds), 1)
# Test
manager = factory.consumer_manager()
manager.unregister(self.CONSUMER_ID)
# Verify
manager = factory.consumer_bind_manager()
binds = manager.find_by_consumer(self.CONSUMER_ID)
self.assertEquals(len(binds), 0)
示例14: distributor_delete
def distributor_delete(repo_id, distributor_id):
"""
Get the itinerary for deleting a repository distributor.
1. Delete the distributor on the sever.
2. Unbind any bound consumers.
:param repo_id: A repository ID.
:type repo_id: str
:param distributor_id: A distributor id
:type distributor_id: str
:return: Any errors that may have occurred and the list of tasks spawned for each consumer
:rtype TaskResult
"""
# delete distributor
manager = managers.repo_distributor_manager()
manager.remove_distributor(repo_id, distributor_id)
# append unbind itineraries foreach bound consumer
unbind_errors = []
additional_tasks = []
options = {}
manager = managers.consumer_bind_manager()
for bind in manager.find_by_distributor(repo_id, distributor_id):
try:
report = consumer.unbind(bind["consumer_id"], bind["repo_id"], bind["distributor_id"], options)
if report:
additional_tasks.extend(report.spawned_tasks)
except Exception, e:
unbind_errors.append(e)
示例15: test_find_by_criteria
def test_find_by_criteria(self, mock_repo_qs):
self.populate()
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID,
self.NOTIFY_AGENT, self.BINDING_CONFIG)
# Test
criteria = Criteria({'consumer_id': self.CONSUMER_ID})
bindings = manager.find_by_criteria(criteria)
bind = bindings[0]
self.assertEqual(len(bindings), 1)
self.assertEqual(bind['consumer_id'], self.CONSUMER_ID)
self.assertEqual(bind['repo_id'], self.REPO_ID)
self.assertEqual(bind['distributor_id'], self.DISTRIBUTOR_ID)
self.assertEqual(bind['notify_agent'], self.NOTIFY_AGENT)
self.assertEqual(bind['binding_config'], self.BINDING_CONFIG)
# Test ($in)
criteria = Criteria({'consumer_id': {'$in': [self.CONSUMER_ID]}})
bindings = manager.find_by_criteria(criteria)
bind = bindings[0]
self.assertEqual(len(bindings), 1)
self.assertEqual(bind['consumer_id'], self.CONSUMER_ID)
self.assertEqual(bind['repo_id'], self.REPO_ID)
self.assertEqual(bind['distributor_id'], self.DISTRIBUTOR_ID)
self.assertEqual(bind['notify_agent'], self.NOTIFY_AGENT)
self.assertEqual(bind['binding_config'], self.BINDING_CONFIG)