当前位置: 首页>>代码示例>>Python>>正文


Python ConsumerIdentity.getConsumerId方法代码示例

本文整理汇总了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
开发者ID:Syba54,项目名称:openshift-extras,代码行数:85,代码来源:reconcile_rhsm_config.py


注:本文中的subscription_manager.identity.ConsumerIdentity.getConsumerId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。