本文整理汇总了Python中pulp.server.managers.factory.consumer_agent_manager函数的典型用法代码示例。如果您正苦于以下问题:Python consumer_agent_manager函数的具体用法?Python consumer_agent_manager怎么用?Python consumer_agent_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了consumer_agent_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_content_install
def test_content_install(self):
# Setup
self.populate()
# Test
units = [
{'type_id':'rpm',
'unit_key':{'name':'zsh', 'version':'1.0'}},
{'type_id':'rpm',
'unit_key':{'name':'bar', 'version':'1.0'}},
{'type_id':'rpm',
'unit_key':{'name':'abc', 'version':'1.0'}},
{'type_id':'mock-type',
'unit_key':{'name':'monster', 'version':'5.0'}},
{'type_id':'unsupported',
'unit_key':{'name':'xxx', 'version':'1.0'}},
]
options = dict(importkeys=True)
manager = factory.consumer_agent_manager()
manager.install_content(self.CONSUMER_ID, units, options)
# Verify
profiler = plugin_api.get_profiler_by_type('rpm')[0]
pargs = profiler.install_units.call_args[0]
self.assertEquals(pargs[0].id, self.CONSUMER_ID)
self.assertEquals(pargs[0].profiles, {})
self.assertEquals(pargs[1], units[:3])
self.assertEquals(pargs[2], options)
profiler = plugin_api.get_profiler_by_type('mock-type')[0]
pargs = profiler.install_units.call_args[0]
self.assertEquals(pargs[0].id, self.CONSUMER_ID)
self.assertEquals(pargs[0].profiles, {})
self.assertEquals(pargs[1], units[3:4])
self.assertEquals(pargs[2], options)
示例2: unregister
def unregister(self, id):
"""
Unregisters given consumer.
@param id: identifies the consumer being unregistered
@type id: str
@raises MissingResource: if the given consumer does not exist
@raises OperationFailed: if any part of the unregister process fails;
the exception will contain information on which sections failed
@raises PulpExecutionException: if error during updating database collection
"""
self.get_consumer(id)
# Remove associate bind
manager = factory.consumer_bind_manager()
manager.consumer_deleted(id)
# Remove associated profiles
manager = factory.consumer_profile_manager()
manager.consumer_deleted(id)
# Notify agent
agent_consumer = factory.consumer_agent_manager()
agent_consumer.unregistered(id)
# Database Updates
try:
Consumer.get_collection().remove({'id' : id}, safe=True)
except Exception:
_LOG.exception('Error updating database collection while removing consumer [%s]' % id)
raise PulpExecutionException("database-error"), None, sys.exc_info()[2]
factory.consumer_history_manager().record_event(id, 'consumer_unregistered')
示例3: 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
示例4: force_unbind
def force_unbind(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
:returns TaskResult containing the result of the unbind & any spawned tasks or a dictionary
of the unbind result if no tasks were spawned.
:rtype: TaskResult
"""
bind_manager = managers.consumer_bind_manager()
binding = bind_manager.get_bind(consumer_id, repo_id, distributor_id)
bind_manager.delete(consumer_id, repo_id, distributor_id, True)
response = None
if binding['notify_agent']:
agent_manager = managers.consumer_agent_manager()
task = agent_manager.unbind(consumer_id, repo_id, distributor_id, options)
response = TaskResult(spawned_tasks=[task])
return response
示例5: uninstall_content
def uninstall_content(self, consumer_group_id, units, options):
group_collection = validate_existing_consumer_group(consumer_group_id)
consumer_group = group_collection.find_one({'id': consumer_group_id})
agent_manager = manager_factory.consumer_agent_manager()
for consumer_id in consumer_group['consumer_ids']:
agent_manager.uninstall_content(consumer_id, units, options)
示例6: unbind
def unbind(self, consumer_id, repo_id, distributor_id):
"""
Unbind consumer to a specifiec distirbutor associated with
a repository. This call is idempotent.
@param consumer_id: uniquely identifies the consumer.
@type consumer_id: str
@param repo_id: uniquely identifies the repository.
@type repo_id: str
@param distributor_id: uniquely identifies a distributor.
@type distributor_id: str
@return: The Bind object
@rtype: SON
"""
query = dict(consumer_id=consumer_id, repo_id=repo_id, distributor_id=distributor_id)
collection = Bind.get_collection()
bind = collection.find_one(query)
if bind is None:
# idempotent
return
collection.remove(bind, safe=True)
manager = factory.consumer_agent_manager()
manager.unbind(consumer_id, repo_id)
consumer_event_details = {"repo_id": repo_id, "distributor_id": distributor_id}
factory.consumer_history_manager().record_event(consumer_id, "repo_unbound", consumer_event_details)
return bind
示例7: bind
def bind(self, consumer_id, repo_id, distributor_id):
"""
Bind consumer to a specific distributor associated with
a repository. This call is idempotent.
@param consumer_id: uniquely identifies the consumer.
@type consumer_id: str
@param repo_id: uniquely identifies the repository.
@type repo_id: str
@param distributor_id: uniquely identifies a distributor.
@type distributor_id: str
@return: The Bind object
@rtype: SON
@raise MissingResource: when given consumer does not exist.
"""
manager = factory.consumer_manager()
manager.get_consumer(consumer_id)
manager = factory.repo_distributor_manager()
distributor = manager.get_distributor(repo_id, distributor_id)
bind = Bind(consumer_id, repo_id, distributor_id)
collection = Bind.get_collection()
try:
collection.save(bind, safe=True)
bind = self.get_bind(consumer_id, repo_id, distributor_id)
except DuplicateKeyError:
# idempotent
pass
manager = factory.consumer_agent_manager()
manager.bind(consumer_id, repo_id)
consumer_event_details = {"repo_id": repo_id, "distributor_id": distributor_id}
factory.consumer_history_manager().record_event(consumer_id, "repo_bound", consumer_event_details)
return bind
示例8: uninstall
def uninstall(self, id):
"""
Uninstall content (units) on a consumer.
Expected body: {units:[], options:<dict>}
where unit is: {type_id:<str>, unit_key={}} and the
options is a dict of uninstall options.
@param id: A consumer ID.
@type id: str
@return: TBD
@rtype: dict
"""
body = self.params()
units = body.get('units')
options = body.get('options')
resources = {
dispatch_constants.RESOURCE_CONSUMER_TYPE:
{id:dispatch_constants.RESOURCE_READ_OPERATION},
}
args = [
id,
units,
options,
]
manager = managers.consumer_agent_manager()
call_request = CallRequest(
manager.uninstall_content,
args,
resources=resources,
weight=pulp_config.config.getint('tasks', 'consumer_content_weight'),
asynchronous=True,
archive=True,)
result = execution.execute_async(self, call_request)
return result
示例9: 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]
示例10: test_content_install
def test_content_install(self):
# Setup
self.populate()
# Test
units = [
{"type_id": "rpm", "unit_key": {"name": "zsh", "version": "1.0"}},
{"type_id": "rpm", "unit_key": {"name": "bar", "version": "1.0"}},
{"type_id": "rpm", "unit_key": {"name": "abc", "version": "1.0"}},
{"type_id": "mock-type", "unit_key": {"name": "monster", "version": "5.0"}},
{"type_id": "unsupported", "unit_key": {"name": "xxx", "version": "1.0"}},
]
options = dict(importkeys=True)
manager = factory.consumer_agent_manager()
manager.install_content(self.CONSUMER_ID, units, options)
# Verify
# agent call
params = mock_agent.Content.install.call_args[0]
self.assertEqual(sorted(params[0]), sorted(units))
self.assertEqual(params[1], options)
# profiler call
profiler = plugin_api.get_profiler_by_type("rpm")[0]
pargs = profiler.install_units.call_args[0]
self.assertEquals(pargs[0].id, self.CONSUMER_ID)
self.assertEquals(pargs[0].profiles, {})
self.assertEquals(pargs[1], units[:3])
self.assertEquals(pargs[2], options)
profiler = plugin_api.get_profiler_by_type("mock-type")[0]
pargs = profiler.install_units.call_args[0]
self.assertEquals(pargs[0].id, self.CONSUMER_ID)
self.assertEquals(pargs[0].profiles, {})
self.assertEquals(pargs[1], units[3:4])
self.assertEquals(pargs[2], options)
示例11: test_unregistered
def test_unregistered(self):
# Setup
self.populate()
# Test
manager = factory.consumer_agent_manager()
manager.unregistered(self.CONSUMER_ID)
# verify
mock_agent.Consumer.unregistered.assert_called_once_with()
示例12: test_unbind
def test_unbind(self):
# Setup
self.populate()
manager = factory.consumer_bind_manager()
bind = manager.bind(
self.CONSUMER_ID,
self.REPO_ID,
self.DISTRIBUTOR_ID)
# Test
manager = factory.consumer_agent_manager()
manager.unbind(self.CONSUMER_ID, self.REPO_ID)
示例13: create_unit_uninstall_schedule
def create_unit_uninstall_schedule(self, consumer_id, units, uninstall_options, schedule_data):
"""
Create a schedule for uninstalling content units on a consumer.
@param consumer_id: unique id for the consumer
@param units: list of unit type and unit key dicts
@param uninstall_options: options to pass to the uninstall manager
@param schedule_data: scheduling data
@return: schedule id
"""
manager = managers_factory.consumer_agent_manager()
return self._create_schedule(manager.uninstall_content, UNIT_UNINSTALL_ACTION, consumer_id, units, uninstall_options, schedule_data)
示例14: cancel_agent_request
def cancel_agent_request(call_request, call_report):
"""
Cancel the agent request associated with the task.
:param call_request: The call request that has been cancelled.
:type call_request: pulp.server.dispatch.call.CallRequest
:param call_report: The report associated with the call request to be cancelled.
:type call_report: pulp.server.dispatch.call.CallReport
"""
task_id = call_report.call_request_id
consumer_id = call_request.args[0]
agent_manager = managers_factory.consumer_agent_manager()
agent_manager.cancel_request(consumer_id, task_id)
示例15: consumer_deleted
def consumer_deleted(self, id):
"""
Notification that a consumer has been deleted.
Associated binds are removed.
@param id: A consumer ID.
@type id: str
"""
collection = Bind.get_collection()
agent_manager = factory.consumer_agent_manager()
for bind in self.find_by_consumer(id):
collection.remove(bind, safe=True)
repo_id = bind["repo_id"]
agent_manager.unbind(id, repo_id)