本文整理汇总了Python中pulp.server.managers.factory.consumer_history_manager函数的典型用法代码示例。如果您正苦于以下问题:Python consumer_history_manager函数的具体用法?Python consumer_history_manager怎么用?Python consumer_history_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了consumer_history_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: 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')
示例4: register
def register(consumer_id,
display_name=None,
description=None,
notes=None,
capabilities=None,
rsa_pub=None):
"""
Registers a new Consumer
:param consumer_id: unique identifier for the consumer
:type consumer_id: str
:param rsa_pub: The consumer public key used for message authentication.
:type rsa_pub: str
:param display_name: user-friendly name for the consumer
:type display_name: str
:param description: user-friendly text describing the consumer
:type description: str
:param notes: key-value pairs to pragmatically tag the consumer
:type notes: dict
:param capabilities: operations supported on the consumer
:type capabilities: dict
:raises DuplicateResource: if there is already a consumer or a used with the requested ID
:raises InvalidValue: if any of the fields is unacceptable
:return: A tuple of: (consumer, certificate)
:rtype: tuple
"""
if not is_consumer_id_valid(consumer_id):
raise InvalidValue(['id'])
collection = Consumer.get_collection()
consumer = collection.find_one({'id': consumer_id})
if consumer is not None:
raise DuplicateResource(consumer_id)
if notes is not None and not isinstance(notes, dict):
raise InvalidValue(['notes'])
if capabilities is not None and not isinstance(capabilities, dict):
raise InvalidValue(['capabilities'])
# Use the ID for the display name if one was not specified
display_name = display_name or consumer_id
# Creation
consumer = Consumer(consumer_id, display_name, description, notes, capabilities, rsa_pub)
_id = collection.save(consumer, safe=True)
# Generate certificate
cert_gen_manager = factory.cert_generation_manager()
expiration_date = config.config.getint('security', 'consumer_cert_expiration')
key, certificate = cert_gen_manager.make_cert(consumer_id, expiration_date, uid=str(_id))
factory.consumer_history_manager().record_event(consumer_id, 'consumer_registered')
return consumer, Bundle.join(key, certificate)
示例5: unregister
def unregister(self, consumer_id):
"""
Unregisters given consumer.
@param consumer_id: identifies the consumer being unregistered
@type consumer_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(consumer_id)
# Remove associate bind
manager = factory.consumer_bind_manager()
manager.consumer_deleted(consumer_id)
# Remove associated profiles
manager = factory.consumer_profile_manager()
manager.consumer_deleted(consumer_id)
# Notify agent
agent_consumer = factory.consumer_agent_manager()
agent_consumer.unregistered(consumer_id)
# remove from consumer groups
group_manager = factory.consumer_group_manager()
group_manager.remove_consumer_from_groups(consumer_id)
# delete any scheduled unit installs
schedule_manager = factory.schedule_manager()
schedule_manager.delete_all_unit_install_schedules(consumer_id)
schedule_manager.delete_all_unit_update_schedules(consumer_id)
schedule_manager.delete_all_unit_uninstall_schedules(consumer_id)
# Database Updates
try:
Consumer.get_collection().remove({'id' : consumer_id}, safe=True)
except Exception:
_LOG.exception('Error updating database collection while removing '
'consumer [%s]' % consumer_id)
raise PulpExecutionException("database-error"), None, sys.exc_info()[2]
# remove the consumer from any groups it was a member of
group_manager = factory.consumer_group_manager()
group_manager.remove_consumer_from_groups(consumer_id)
factory.consumer_history_manager().record_event(consumer_id, 'consumer_unregistered')
示例6: register
def register(self, id, display_name=None, description=None, notes=None, capabilities=None):
"""
Registers a new Consumer
@param id: unique identifier for the consumer
@type id: str
@param display_name: user-friendly name for the consumer
@type display_name: str
@param description: user-friendly text describing the consumer
@type description: str
@param notes: key-value pairs to programmatically tag the consumer
@type notes: dict
@param capabilities: operations permitted on the consumer
@type capabilities: dict
@raises DuplicateResource: if there is already a consumer or a used with the requested ID
@raises InvalidValue: if any of the fields is unacceptable
"""
if not is_consumer_id_valid(id):
raise InvalidValue(['id'])
existing_consumer = Consumer.get_collection().find_one({'id' : id})
if existing_consumer is not None:
raise DuplicateResource(id)
if notes is not None and not isinstance(notes, dict):
raise InvalidValue(['notes'])
if capabilities is not None and not isinstance(capabilities, dict):
raise InvalidValue(['capabilities'])
# Use the ID for the display name if one was not specified
display_name = display_name or id
# Generate certificate
cert_gen_manager = factory.cert_generation_manager()
expiration_date = config.config.getint('security', 'consumer_cert_expiration')
key, crt = cert_gen_manager.make_cert(id, expiration_date)
# Creation
create_me = Consumer(id, display_name, description, notes, capabilities, certificate=crt.strip())
Consumer.get_collection().save(create_me, safe=True)
factory.consumer_history_manager().record_event(id, 'consumer_registered')
create_me.certificate = Bundle.join(key, crt)
return create_me
示例7: unregister
def unregister(consumer_id):
"""
Unregisters given consumer.
:param consumer_id: identifies the consumer being unregistered
:type consumer_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
"""
ConsumerManager.get_consumer(consumer_id)
# Remove associate bind
manager = factory.consumer_bind_manager()
manager.consumer_deleted(consumer_id)
# Remove associated profiles
manager = factory.consumer_profile_manager()
manager.consumer_deleted(consumer_id)
# Notify agent
agent_consumer = factory.consumer_agent_manager()
agent_consumer.unregister(consumer_id)
# remove from consumer groups
group_manager = factory.consumer_group_manager()
group_manager.remove_consumer_from_groups(consumer_id)
# delete any scheduled unit installs
schedule_manager = factory.consumer_schedule_manager()
for schedule in schedule_manager.get(consumer_id):
# using "delete" on utils skips validation that the consumer exists.
schedule_utils.delete(schedule.id)
# Database Updates
try:
Consumer.get_collection().remove({'id': consumer_id})
except Exception:
_logger.exception(
'Error updating database collection while removing consumer [%s]' % consumer_id)
raise PulpExecutionException("database-error"), None, sys.exc_info()[2]
# remove the consumer from any groups it was a member of
group_manager = factory.consumer_group_manager()
group_manager.remove_consumer_from_groups(consumer_id)
factory.consumer_history_manager().record_event(consumer_id, 'consumer_unregistered')
示例8: unbind
def unbind(self, consumer_id, repo_id, distributor_id):
"""
Unbind a consumer from 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
"""
collection = Bind.get_collection()
query = self.bind_id(consumer_id, repo_id, distributor_id)
query['deleted'] = False
bind = collection.find_one(query)
if bind is None:
# idempotent
return
self.mark_deleted(consumer_id, repo_id, distributor_id)
details = {
'repo_id':repo_id,
'distributor_id':distributor_id
}
manager = factory.consumer_history_manager()
manager.record_event(consumer_id, 'repo_unbound', details)
return bind
示例9: GET
def GET(self, id):
"""
@type id: str
@param id: consumer id
"""
valid_filters = ['event_type', 'limit', 'sort', 'start_date', 'end_date']
filters = self.filters(valid_filters)
event_type = filters.get('event_type', None)
limit = filters.get('limit', None)
sort = filters.get('sort', None)
start_date = filters.get('start_date', None)
end_date = filters.get('end_date', None)
if sort is None:
sort = 'descending'
else:
sort = sort[0]
if limit:
limit = int(limit[0])
if start_date:
start_date = start_date[0]
if end_date:
end_date = end_date[0]
if event_type:
event_type = event_type[0]
results = managers.consumer_history_manager().query(consumer_id=id, event_type=event_type, limit=limit,
sort=sort, start_date=start_date, end_date=end_date)
return self.ok(results)
示例10: 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.
"""
# ensure the consumer is valid
manager = factory.consumer_manager()
manager.get_consumer(consumer_id)
# ensure the repository & distributor are valid
manager = factory.repo_distributor_manager()
manager.get_distributor(repo_id, distributor_id)
# perform the bind
collection = Bind.get_collection()
try:
bind = Bind(consumer_id, repo_id, distributor_id)
collection.save(bind, safe=True)
except DuplicateKeyError:
self.__reset_bind(consumer_id, repo_id, distributor_id)
# fetch the inserted/updated bind
bind = self.get_bind(consumer_id, repo_id, distributor_id)
# update history
details = {'repo_id':repo_id, 'distributor_id':distributor_id}
manager = factory.consumer_history_manager()
manager.record_event(consumer_id, 'repo_bound', details)
return bind
示例11: unassociate
def unassociate(group_id, criteria):
"""
Unassociate a set of consumers, that match the passed in criteria, from a consumer group.
@param group_id: unique id of the group to unassociate consumers from
@type group_id: str
@param criteria: Criteria specifying the set of consumers to unassociate
@type criteria: L{pulp.server.db.model.criteria.Criteria}
"""
group_collection = validate_existing_consumer_group(group_id)
consumer_collection = Consumer.get_collection()
cursor = consumer_collection.query(criteria)
consumer_ids = [r['id'] for r in cursor]
if consumer_ids:
group_collection.update(
{'id': group_id},
{'$pullAll': {'consumer_ids': consumer_ids}})
details = {'group_id': group_id}
for consumer_id in consumer_ids:
manager_factory.consumer_history_manager().record_event(consumer_id,
'removed_from_group', details)
示例12: associate
def associate(group_id, criteria):
"""
Associate a set of consumers, that match the passed in criteria, to a consumer group.
@param group_id: unique id of the group to associate consumers to
@type group_id: str
@param criteria: Criteria instance representing the set of consumers to associate
@type criteria: L{pulp.server.db.model.criteria.Criteria}
"""
group_collection = validate_existing_consumer_group(group_id)
consumer_collection = Consumer.get_collection()
cursor = consumer_collection.query(criteria)
consumer_ids = [r['id'] for r in cursor]
if consumer_ids:
group_collection.update(
{'id': group_id},
{'$addToSet': {'consumer_ids': {'$each': consumer_ids}}})
details = {'group_id': group_id}
for consumer_id in consumer_ids:
manager_factory.consumer_history_manager().record_event(consumer_id,
'added_to_group', details)
示例13: bind
def bind(consumer_id, repo_id, distributor_id, notify_agent, binding_config):
"""
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.
:raise InvalidValid: when the repository or distributor id is invalid, or
if the notify_agent value is invalid
"""
# Validation
missing_values = BindManager._validate_consumer_repo(consumer_id, repo_id, distributor_id)
if missing_values:
if 'consumer_id' in missing_values:
# This is passed in via the URL so a 404 should be raised
raise MissingResource(consumer_id=missing_values['consumer_id'])
else:
# Everything else is a parameter so raise a 400
raise InvalidValue(missing_values.keys())
# ensure notify_agent is a boolean
if not isinstance(notify_agent, bool):
raise InvalidValue(['notify_agent'])
# perform the bind
collection = Bind.get_collection()
try:
bind = Bind(consumer_id, repo_id, distributor_id, notify_agent, binding_config)
collection.save(bind, safe=True)
except DuplicateKeyError:
BindManager._update_binding(consumer_id, repo_id, distributor_id, notify_agent,
binding_config)
BindManager._reset_bind(consumer_id, repo_id, distributor_id)
# fetch the inserted/updated bind
bind = BindManager.get_bind(consumer_id, repo_id, distributor_id)
# update history
details = {'repo_id': repo_id, 'distributor_id': distributor_id}
manager = factory.consumer_history_manager()
manager.record_event(consumer_id, 'repo_bound', details)
return bind
示例14: uninstall_content
def uninstall_content(consumer_id, units, options):
"""
Uninstall content units on a consumer.
:param consumer_id: The consumer ID.
:type consumer_id: str
:param units: A list of content units to be uninstalled.
:type units: list of:
{ type_id:<str>, type_id:<dict> }
:param options: Uninstall options; based on unit type.
:type options: dict
:return: A task ID that may be used to track the agent request.
:rtype: dict
"""
# track agent operations using a pseudo task
task_id = str(uuid4())
task_tags = [
tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer_id),
tags.action_tag(tags.ACTION_AGENT_UNIT_UNINSTALL)
]
task = TaskStatus(task_id, 'agent', tags=task_tags).save()
# agent request
manager = managers.consumer_manager()
consumer = manager.get_consumer(consumer_id)
conduit = ProfilerConduit()
collated = Units(units)
for typeid, units in collated.items():
pc = AgentManager._profiled_consumer(consumer_id)
profiler, cfg = AgentManager._profiler(typeid)
units = AgentManager._invoke_plugin(
profiler.uninstall_units,
pc,
units,
options,
cfg,
conduit)
collated[typeid] = units
units = collated.join()
context = Context(consumer, task_id=task_id, consumer_id=consumer_id)
agent = PulpAgent()
agent.content.uninstall(context, units, options)
history_manager = managers.consumer_history_manager()
history_manager.record_event(consumer_id, 'content_unit_uninstalled', {'units': units})
return task
示例15: get
def get(self, request, consumer_id):
"""
Retrieve histroy for the specified consumer
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param consumer_id: A consumer ID.
:type consumer_id: str
:return: Response representing the binding
:rtype: django.http.HttpResponse
"""
# Check that the consumer exists and raise a MissingResource exception, in case it doesn't.
factory.consumer_manager().get_consumer(consumer_id)
query_param = request.GET
filters = _ensure_input_encoding(query_param)
event_type = filters.get('event_type', None)
limit = filters.get('limit', None)
sort = filters.get('sort', 'descending')
start_date = filters.get('start_date', None)
end_date = filters.get('end_date', None)
if limit:
try:
limit = int(limit)
except ValueError:
raise InvalidValue('limit')
results = factory.consumer_history_manager().query(consumer_id=consumer_id,
event_type=event_type,
limit=limit,
sort=sort,
start_date=start_date,
end_date=end_date)
return generate_json_response_with_pulp_encoder(results)