本文整理汇总了Python中subscription_manager.identity.ConsumerIdentity.getConsumerId方法的典型用法代码示例。如果您正苦于以下问题:Python ConsumerIdentity.getConsumerId方法的具体用法?Python ConsumerIdentity.getConsumerId怎么用?Python ConsumerIdentity.getConsumerId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscription_manager.identity.ConsumerIdentity
的用法示例。
在下文中一共展示了ConsumerIdentity.getConsumerId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReconciliationEngine
# 需要导入模块: from subscription_manager.identity import ConsumerIdentity [as 别名]
# 或者: from subscription_manager.identity.ConsumerIdentity import getConsumerId [as 别名]
class ReconciliationEngine(object):
def __init__(self, oscs, rdb, logger, opts):
self.oscs = oscs
self.rdb = rdb
self.logger = logger
self.opts = opts
self.rhsmconfig = rhsm.config.initConfig()
try:
self.consumer_key = _read(ConsumerIdentity.keypath())
self.consumer_cert = _read(ConsumerIdentity.certpath())
except IOError as ioerr:
if 2 == ioerr.errno:
raise SubscriptionManagerNotRegisteredError()
self.consumer_identity = ConsumerIdentity(self.consumer_key, self.consumer_cert)
self.consumer_uuid = self.consumer_identity.getConsumerId()
self.cp_provider = inj.require(inj.CP_PROVIDER)
self.cp = self.cp_provider.get_consumer_auth_cp()
# self.ATTR_DEFAULTS = dict([(attr, RepoConf.optionobj(attr).default) for attr in IMPORTANT_ATTRS])
self._set_attr_defaults()
self.problem = False
def _set_attr_defaults(self):
self.ATTR_DEFAULTS = dict()
for attr in IMPORTANT_ATTRS:
try:
self.ATTR_DEFAULTS[attr] = RepoConf.optionobj(attr).default
except KeyError:
IMPORTANT_ATTRS.remove(attr)
def get_overrides_and_repos(self):
overrides = self.cp.getContentOverrides(self.consumer_uuid)
override_repos = list(set([ovrd['contentLabel'] for ovrd in overrides]))
ovrdict = defaultdict(lambda: defaultdict(lambda: None))
for ovrd in overrides:
ovrdict[ovrd['contentLabel']][ovrd['name']] = ovrd['value']
return ovrdict, override_repos
def set_override(self, repo, attr):
if not self.problem:
self.logger.error(SET_OVERRIDE_MSG)
if self.opts.fix:
self.logger.error(SET_OVERRIDE_FIX_MSG)
else:
self.logger.error(SET_OVERRIDE_REPORT_MSG)
self.problem = True
value = repo.getAttribute(attr)
option = RepoConf.optionobj(attr)
if self.opts.fix:
if isinstance(option, config.ListOption):
v_str = ' '.join(value)
else:
v_str = option.tostring(value)
if self.current_repoid != repo.id:
self.current_repoid = repo.id
self.logger.error("Updating repository %s" % repo.id)
self.logger.error(" %s: %s" % (attr, v_str))
self.oscs.set_save_repo_attr(repo.id, attr, value)
else:
self.logger.error(
"# %s" %
self.oscs.get_update_override_cmd(
repo, attr, repo.getAttribute(attr), for_output=True))
def fix_overrides_for_repo(self, repoid, overrides):
self.current_repoid=""
try:
repo = self.oscs.repo_for_repoid(repoid)
except KeyError:
if self.opts.fix:
self.logger.warning('Cannot modify content overrides for '
'non-existent repo %s' % repoid)
return # don't operate on nonexistant repos
for attr in IMPORTANT_ATTRS:
if repo.getAttribute(attr) != self.ATTR_DEFAULTS[attr]:
if not overrides[repoid] or not overrides[repoid][attr]:
self.set_override(repo, attr)
def reconcile_overrides(self):
(overrides, override_repos) = self.get_overrides_and_repos()
rhsm_repoids = self.rdb.find_repoids(subscription = 'rhsm')
for repoid in rhsm_repoids:
self.fix_overrides_for_repo(repoid, overrides)
return self.problem