本文整理汇总了Python中pulp.server.managers.factory.consumer_manager函数的典型用法代码示例。如果您正苦于以下问题:Python consumer_manager函数的具体用法?Python consumer_manager怎么用?Python consumer_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了consumer_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request, consumer_id):
"""
List schedules <action>.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param consumer_id: The consumer ID.
:type consumer_id: str
:raises MissingResource: if consumer does not exist
:return: Response containing consumer's schedules <action>
:rtype: django.http.HttpResponse
"""
try:
factory.consumer_manager().get_consumer(consumer_id)
except MissingResource:
raise MissingResource(consumer_id=consumer_id)
schedules = self.manager.get(consumer_id, self.ACTION)
schedule_objs = []
for schedule in schedules:
obj = scheduled_unit_management_obj(schedule.for_display())
add_link_schedule(obj, self.ACTION, consumer_id)
schedule_objs.append(obj)
return generate_json_response_with_pulp_encoder(schedule_objs)
示例2: 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)
示例3: _validate_consumer_repo
def _validate_consumer_repo(consumer_id, repo_id, distributor_id):
"""
Validate that the given consumer, repository, and distributor are present.
Rather than raising an exception, this method returns a dictionary of missing
values and allows the caller to decide what exception to raise.
:param consumer_id: The consumer id to validate
:type consumer_id: str
:param repo_id: The repository id to validate
:type repo_id: str
:param distributor_id: The distributor_id to validate
:type distributor_id: str
:return: A dictionary containing the missing values, or an empty dict if everything is valid
:rtype: dict
"""
missing_values = {}
try:
factory.consumer_manager().get_consumer(consumer_id)
except MissingResource:
missing_values['consumer_id'] = consumer_id
try:
model.Repository.objects.get_repo_or_missing_resource(repo_id)
except MissingResource:
missing_values['repo_id'] = repo_id
try:
factory.repo_distributor_manager().get_distributor(repo_id, distributor_id)
except MissingResource:
missing_values['distributor_id'] = distributor_id
return missing_values
示例4: POST
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)
示例5: 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
示例6: populate
def populate(self, strategy=constants.DEFAULT_STRATEGY, ssl=False):
PluginTestBase.populate(self)
# register child
manager = managers.consumer_manager()
manager.register(self.PULP_ID, notes={constants.STRATEGY_NOTE_KEY: strategy})
manager = managers.repo_importer_manager()
# add importer
importer_conf = {
constants.MANIFEST_URL_KEYWORD: 'http://redhat.com',
constants.STRATEGY_KEYWORD: constants.DEFAULT_STRATEGY,
constants.PROTOCOL_KEYWORD: 'file',
}
manager.set_importer(self.REPO_ID, constants.HTTP_IMPORTER, importer_conf)
# add distributors
if ssl:
dist_conf = self.dist_conf_with_ssl()
else:
dist_conf = self.dist_conf()
manager = managers.repo_distributor_manager()
manager.add_distributor(
self.REPO_ID,
constants.HTTP_DISTRIBUTOR,
dist_conf,
False,
constants.HTTP_DISTRIBUTOR)
manager.add_distributor(self.REPO_ID, FAKE_DISTRIBUTOR, {}, False, FAKE_DISTRIBUTOR)
# bind
conf = {constants.STRATEGY_KEYWORD: strategy}
manager = managers.consumer_bind_manager()
manager.bind(self.PULP_ID, self.REPO_ID, constants.HTTP_DISTRIBUTOR, False, conf)
示例7: test_syntactic_sugar_methods
def test_syntactic_sugar_methods(self):
"""
Tests the syntactic sugar methods for retrieving specific managers.
"""
# Setup
factory.initialize()
# Test
self.assertTrue(isinstance(factory.authentication_manager(), AuthenticationManager))
self.assertTrue(isinstance(factory.cert_generation_manager(), CertGenerationManager))
self.assertTrue(isinstance(factory.certificate_manager(), CertificateManager))
self.assertTrue(isinstance(factory.password_manager(), PasswordManager))
self.assertTrue(isinstance(factory.permission_manager(), PermissionManager))
self.assertTrue(isinstance(factory.permission_query_manager(), PermissionQueryManager))
self.assertTrue(isinstance(factory.role_manager(), RoleManager))
self.assertTrue(isinstance(factory.role_query_manager(), RoleQueryManager))
self.assertTrue(isinstance(factory.user_manager(), UserManager))
self.assertTrue(isinstance(factory.user_query_manager(), UserQueryManager))
self.assertTrue(isinstance(factory.repo_manager(), RepoManager))
self.assertTrue(isinstance(factory.repo_unit_association_manager(),
RepoUnitAssociationManager))
self.assertTrue(isinstance(factory.repo_publish_manager(), RepoPublishManager))
self.assertTrue(isinstance(factory.repo_query_manager(), RepoQueryManager))
self.assertTrue(isinstance(factory.repo_sync_manager(), RepoSyncManager))
self.assertTrue(isinstance(factory.content_manager(), ContentManager))
self.assertTrue(isinstance(factory.content_query_manager(), ContentQueryManager))
self.assertTrue(isinstance(factory.content_upload_manager(), ContentUploadManager))
self.assertTrue(isinstance(factory.consumer_manager(), ConsumerManager))
self.assertTrue(isinstance(factory.topic_publish_manager(), TopicPublishManager))
示例8: populate
def populate(self):
config = {"key1": "value1", "key2": None}
manager = factory.repo_distributor_manager()
manager.add_distributor(self.REPO_ID, "mock-distributor", config, True, distributor_id=self.DISTRIBUTOR_ID)
manager = factory.consumer_manager()
for consumer_id in self.ALL_CONSUMERS:
manager.register(consumer_id)
示例9: 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)
示例10: test_get_with_bindings
def test_get_with_bindings(self):
"""
Test consumer with bindings.
"""
# Setup
manager = factory.repo_manager()
repo = manager.create_repo(self.REPO_ID)
manager = factory.repo_distributor_manager()
manager.add_distributor(self.REPO_ID, self.DISTRIBUTOR_TYPE_ID, {}, True, distributor_id=self.DISTRIBUTOR_ID)
manager = factory.consumer_manager()
manager.register(self.CONSUMER_ID)
manager = factory.consumer_bind_manager()
bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
# Test
params = {"bindings": True}
path = "/v2/consumers/%s/" % self.CONSUMER_ID
status, body = self.get(path, params=params)
# Verify
self.assertEqual(200, status)
self.assertEqual(self.CONSUMER_ID, body["id"])
self.assertTrue("_href" in body)
self.assertTrue(body["_href"].endswith(path))
self.assertTrue("bindings" in body)
bindings = body["bindings"]
self.assertEquals(len(bindings), 1)
self.assertEquals(bindings[0], self.REPO_ID)
示例11: PUT
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)
示例12: populate
def populate(self):
consumer_manager = factory.consumer_manager()
consumer_manager.register(self.CONSUMER_ID1)
consumer_manager.register(self.CONSUMER_ID2)
consumer_group_manager = factory.consumer_group_manager()
consumer_group_manager.create_consumer_group(group_id=self.GROUP_ID,
consumer_ids = [self.CONSUMER_ID1, self.CONSUMER_ID2])
示例13: populate
def populate(self, ssl=False):
PluginTestBase.populate(self)
# register downstream
manager = managers.consumer_manager()
manager.register(self.PULP_ID)
manager = managers.repo_importer_manager()
# add importer
cfg = dict(manifest_url='http://apple.com', protocol='file')
manager.set_importer(self.REPO_ID, CITRUS_IMPORTER, cfg)
# add distributor
if ssl:
dist_conf = self.dist_conf_with_ssl()
else:
dist_conf = self.dist_conf()
manager = managers.repo_distributor_manager()
manager.add_distributor(
self.REPO_ID,
CITRUS_DISTRUBUTOR,
dist_conf,
False,
CITRUS_DISTRUBUTOR)
# bind
manager = managers.consumer_bind_manager()
manager.bind(self.PULP_ID, self.REPO_ID, CITRUS_DISTRUBUTOR)
示例14: update
def update(self, consumer_id, content_type, profile):
"""
Update a unit profile.
Created if not already exists.
@param consumer_id: uniquely identifies the consumer.
@type consumer_id: str
@param content_type: The profile (content) type ID.
@type content_type: str
@param profile: The unit profile
@type profile: object
"""
try:
profiler, config = plugin_api.get_profiler_by_type(content_type)
except plugin_exceptions.PluginNotFound:
# Not all profile types have a type specific profiler, so let's use the baseclass
# Profiler
profiler, config = (Profiler(), {})
consumer = factory.consumer_manager().get_consumer(consumer_id)
# Allow the profiler a chance to update the profile before we save it
profile = profiler.update_profile(consumer, content_type, profile, config)
try:
p = self.get_profile(consumer_id, content_type)
p['profile'] = profile
# We store the profile's hash anytime the profile gets altered
p['profile_hash'] = UnitProfile.calculate_hash(profile)
except MissingResource:
p = UnitProfile(consumer_id, content_type, profile)
collection = UnitProfile.get_collection()
collection.save(p, safe=True)
return p
示例15: POST
def POST(self):
body = self.params()
consumer_id = body.get('id')
display_name = body.get('display_name')
description = body.get('description')
notes = body.get('notes')
rsa_pub = body.get('rsa_pub')
manager = managers.consumer_manager()
created, certificate = manager.register(
consumer_id,
display_name=display_name,
description=description,
notes=notes,
rsa_pub=rsa_pub)
link = serialization.link.child_link_obj(consumer_id)
created.update({'_href': link})
document = {
'consumer': created,
'certificate': certificate
}
return self.created(link['_href'], document)