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


Python consumer_utils.load_consumer_id函数代码示例

本文整理汇总了Python中pulp.client.consumer_utils.load_consumer_id函数的典型用法代码示例。如果您正苦于以下问题:Python load_consumer_id函数的具体用法?Python load_consumer_id怎么用?Python load_consumer_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_consumer_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bind

    def bind(self, **kwargs):
        consumer_id = load_consumer_id(self.context)

        if not consumer_id:
            m = _('This consumer is not registered to the Pulp server')
            self.prompt.render_failure_message(m)
            return

        repo_id = kwargs['repo-id']

        try:
            response = self.context.server.bind.bind(consumer_id, repo_id, YUM_DISTRIBUTOR_TYPE_ID)
            msg = _('Bind tasks successfully created:')
            self.context.prompt.render_success_message(msg)
            tasks = [dict(task_id=str(t.task_id)) for t in response.response_body.spawned_tasks]
            self.context.prompt.render_document_list(tasks)
        except NotFoundException, e:
            resources = e.extra_data['resources']
            if 'consumer' in resources:
                r_type = _('Consumer')
                r_id = consumer_id
            else:
                r_type = _('Repository')
                r_id = repo_id
            msg = _('%(t)s [%(id)s] does not exist on the server')
            self.context.prompt.write(msg % {'t': r_type, 'id': r_id}, tag='not-found')
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:26,代码来源:pulp_cli.py

示例2: run

    def run(self, **kwargs):

        repo_id = kwargs[OPTION_REPO_ID.keyword]
        node_id = load_consumer_id(self.context)
        dist_id = constants.HTTP_DISTRIBUTOR
        strategy = kwargs[STRATEGY_OPTION.keyword]
        binding_config = {constants.STRATEGY_KEYWORD: strategy}

        if not node_activated(self.context, node_id):
            msg = NOT_ACTIVATED_ERROR
            self.context.prompt.render_failure_message(msg)
            return os.EX_USAGE

        if strategy not in constants.STRATEGIES:
            msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES)
            self.context.prompt.render_failure_message(msg)
            return os.EX_DATAERR

        try:
            self.context.server.bind.bind(node_id, repo_id, dist_id, notify_agent=False, binding_config=binding_config)
            self.context.prompt.render_success_message(BIND_SUCCEEDED)
            warning = BIND_WARNING % dict(r=repo_id)
            self.context.prompt.render_warning_message(warning)
        except NotFoundException, e:
            unhandled = self.missing_resources(self.context.prompt, e)
            for _id, _type in unhandled:
                if _type == "distributor":
                    msg = BIND_FAILED_NOT_ENABLED
                    self.context.prompt.render_failure_message(msg)
                else:
                    raise
            return os.EX_DATAERR
开发者ID:kbotc,项目名称:pulp,代码行数:32,代码来源:commands.py

示例3: unregister

    def unregister(self, **kwargs):

        force = kwargs['force']

        # Check write permissions to cert directory
        id_cert_dir = self.context.config['filesystem']['id_cert_dir']
        if not os.access(id_cert_dir, os.W_OK):
            msg = _("Write permission is required for %(d)s to perform this operation.")
            self.prompt.render_failure_message(msg % {'d': id_cert_dir})
            return exceptions.CODE_PERMISSIONS_EXCEPTION

        # Get the consumer ID
        try:
            consumer_id = load_consumer_id(self.context)
            if not consumer_id:
                msg = _('This consumer is not registered to the Pulp server.')
                self.context.prompt.render_failure_message(msg)
                return exceptions.CODE_NOT_FOUND
        except X509Error:
            self.context.logger.exception('Consumer certificate not valid.')
            if force:
                self._delete_cert()
                msg = _('Consumer certificate deleted.')
                self.context.prompt.render_success_message(msg)
                self._forced_warning()
                return os.EX_OK
            else:
                msg = _('Consumer certificate not valid. Please retry using the --force option.')
                self.context.prompt.render_failure_message(msg)
                return os.EX_DATAERR

        # Unregister on the server
        forced = True
        try:
            self.context.server.consumer.unregister(consumer_id)
            forced = False
        except NotFoundException:
            if not force:
                msg = _('This consumer does not exist on the server. Please retry using the --force option.')
                self.prompt.render_failure_message(msg)
                return exceptions.CODE_NOT_FOUND
        except X509Error:
            self.context.logger.exception('SSL connection failed.')
            if not force:
                msg = _('SSL connection failed. This error may be ignored by using the --force option.')
                self.prompt.render_failure_message(msg)
                return os.EX_OSERR
        except Exception:
            self.context.logger.exception('Unregistration failed')
            if not force:
                msg = _('Unregistration failed on the server. This error may be ignored by using the --force option.')
                self.prompt.render_failure_message(msg)
                return exceptions.CODE_UNEXPECTED

        # Unregister locally
        self._delete_cert()
        msg = 'Consumer [%(c)s] successfully unregistered' % dict(c=consumer_id)
        self.context.prompt.render_success_message(msg)
        if forced:
            self._forced_warning()
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:60,代码来源:cli.py

示例4: bind

    def bind(self, **kwargs):
        consumer_id = load_consumer_id(self.context)

        if not consumer_id:
            m = _("This consumer is not registered to the Pulp server")
            self.prompt.render_failure_message(m)
            return

        repo_id = kwargs["repo-id"]

        try:
            response = self.context.server.bind.bind(consumer_id, repo_id, YUM_DISTRIBUTOR_TYPE_ID)
            msg = _("Bind tasks successfully created:")
            self.context.prompt.render_success_message(msg)
            tasks = [dict(task_id=str(t.task_id)) for t in response.response_body]
            self.context.prompt.render_document_list(tasks)
        except NotFoundException, e:
            resources = e.extra_data["resources"]
            if "consumer" in resources:
                r_type = _("Consumer")
                r_id = consumer_id
            else:
                r_type = _("Repository")
                r_id = repo_id
            msg = _("%(t)s [%(id)s] does not exist on the server")
            self.context.prompt.write(msg % {"t": r_type, "id": r_id}, tag="not-found")
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:26,代码来源:pulp_cli.py

示例5: run

    def run(self, **kwargs):

        consumer_id = load_consumer_id(self.context)
        strategy = kwargs[STRATEGY_OPTION.keyword]
        delta = {'notes': {constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy}}

        if node_activated(self.context, consumer_id):
            self.context.prompt.render_success_message(ALREADY_ACTIVATED_NOTHING_DONE)
            return

        if strategy not in constants.STRATEGIES:
            msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES)
            self.context.prompt.render_failure_message(msg)
            return os.EX_DATAERR

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.context.prompt.render_success_message(NODE_ACTIVATED)
        except NotFoundException, e:
            for _id, _type in missing_resources(e):
                if _type == 'consumer':
                    self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE)
                else:
                    raise
            return os.EX_DATAERR
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:25,代码来源:commands.py

示例6: run

    def run(self, **kwargs):

        repo_id = kwargs[OPTION_REPO_ID.keyword]
        node_id = load_consumer_id(self.context)
        dist_id = constants.HTTP_DISTRIBUTOR
        strategy = kwargs[STRATEGY_OPTION.keyword]
        binding_config = {constants.STRATEGY_KEYWORD: strategy}

        if not node_activated(self.context, node_id):
            msg = NOT_ACTIVATED_ERROR
            self.context.prompt.render_failure_message(msg)
            return os.EX_USAGE

        if not repository_enabled(self.context, repo_id):
            msg = BIND_FAILED_NOT_ENABLED
            self.context.prompt.render_failure_message(msg)
            return os.EX_USAGE

        if strategy not in constants.STRATEGIES:
            msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES)
            self.context.prompt.render_failure_message(msg)
            return os.EX_DATAERR

        self.context.server.bind.bind(
            node_id,
            repo_id,
            dist_id,
            notify_agent=False,
            binding_config=binding_config)
        self.context.prompt.render_success_message(BIND_SUCCEEDED)
        warning = BIND_WARNING % dict(r=repo_id)
        self.context.prompt.render_warning_message(warning)
开发者ID:alanoe,项目名称:pulp,代码行数:32,代码来源:commands.py

示例7: unbind

    def unbind(self, **kwargs):
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            m = _('This consumer is not registered to the Pulp server')
            self.prompt.render_failure_message(m)
            return

        repo_id = kwargs['repo-id']
        force = kwargs['force']

        try:
            response = self.context.server.bind.unbind(consumer_id, repo_id,
                                                       YUM_DISTRIBUTOR_TYPE_ID, force)
            msg = _('Unbind tasks successfully created:')
            self.context.prompt.render_success_message(msg)
            tasks = [dict(task_id=str(t.task_id)) for t in response.response_body.spawned_tasks]
            self.context.prompt.render_document_list(tasks)
        except NotFoundException, e:
            bind_id = e.extra_data['resources']['bind_id']
            m = _('Binding [consumer: %(c)s, repository: %(r)s] does not exist on the server')
            d = {
                'c': bind_id['consumer_id'],
                'r': bind_id['repo_id'],
            }
            self.context.prompt.write(m % d, tag='not-found')
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:25,代码来源:pulp_cli.py

示例8: status

    def status(self):
        consumer_id = load_consumer_id(self.context)

        if consumer_id:
            m = 'This consumer is registered with the ID [%(i)s].'
            self.prompt.render_success_message(_(m) % {'i' : consumer_id})
        else:
            m = 'This consumer is not currently registered.'
            self.prompt.render_paragraph(_(m))
开发者ID:ehelms,项目名称:pulp,代码行数:9,代码来源:pulp_cli.py

示例9: status

    def status(self):
        consumer_id = load_consumer_id(self.context)

        if consumer_id:
            server = self.context.config["server"]["host"]
            m = "This consumer is registered to the server [%(s)s] with the ID [%(i)s]."
            self.prompt.render_success_message(_(m) % {"s": server, "i": consumer_id})
        else:
            m = "This consumer is not currently registered."
            self.prompt.render_paragraph(_(m))
开发者ID:pieska,项目名称:pulp,代码行数:10,代码来源:pulp_cli.py

示例10: status

    def status(self):
        consumer_id = load_consumer_id(self.context)

        if consumer_id:
            server = self.context.config['server']['host']
            m = 'This consumer is registered to the server [%(s)s] with the ID [%(i)s].'
            self.prompt.render_success_message(_(m) % {'s': server, 'i' : consumer_id})
        else:
            m = 'This consumer is not currently registered.'
            self.prompt.render_paragraph(_(m))
开发者ID:juwu,项目名称:pulp,代码行数:10,代码来源:pulp_cli.py

示例11: unbind

 def unbind(self, **kwargs):
     consumer_id = load_consumer_id(self.context)
     if not consumer_id:
         self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
         return
     repo_id = kwargs['repo-id']
     distributor_id = kwargs['distributor-id']
     try:
         self.context.server.bind.unbind(consumer_id, repo_id, distributor_id)
         self.prompt.render_success_message('Consumer [%s] successfully unbound from repository distributor [%s : %s]' % (consumer_id, repo_id, distributor_id))
     except NotFoundException:
         self.prompt.write('Consumer [%s] does not exist on the server' % consumer_id, tag='not-found')
开发者ID:ehelms,项目名称:pulp,代码行数:12,代码来源:pulp_cli.py

示例12: history

    def history(self, **kwargs):
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
            return
        self.prompt.render_title(_('Consumer History [%(i)s]') % {'i' : consumer_id})

        history_list = self.context.server.consumer_history.history(consumer_id, kwargs['event-type'], kwargs['limit'], kwargs['sort'],
                                                            kwargs['start-date'], kwargs['end-date']).response_body
        filters = ['consumer_id', 'type', 'details', 'originator', 'timestamp']
        order = filters
        for history in history_list:
            self.prompt.render_document(history, filters=filters, order=order)
开发者ID:juwu,项目名称:pulp,代码行数:13,代码来源:pulp_cli.py

示例13: history

    def history(self, **kwargs):
        consumer_id = load_consumer_id(self.context)
        if not consumer_id:
            self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
            return
        self.prompt.render_title(_("Consumer History [%(i)s]") % {"i": consumer_id})

        history_list = self.context.server.consumer_history.history(
            consumer_id, kwargs["event-type"], kwargs["limit"], kwargs["sort"], kwargs["start-date"], kwargs["end-date"]
        ).response_body
        filters = ["consumer_id", "type", "details", "originator", "timestamp"]
        order = filters
        for history in history_list:
            self.prompt.render_document(history, filters=filters, order=order)
开发者ID:pieska,项目名称:pulp,代码行数:14,代码来源:pulp_cli.py

示例14: run

    def run(self, **kwargs):

        consumer_id = load_consumer_id(self.context)
        delta = {'notes': ACTIVATED_NOTE}

        try:
            self.context.server.consumer.update(consumer_id, delta)
            self.context.prompt.render_success_message(NODE_ACTIVATED)
        except NotFoundException, e:
            for _id, _type in missing_resources(e):
                if _type == 'consumer':
                    self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE)
                else:
                    raise
            return os.EX_DATAERR
开发者ID:juwu,项目名称:pulp,代码行数:15,代码来源:commands.py

示例15: bind

 def bind(self, **kwargs):
     consumer_id = load_consumer_id(self.context)
     if not consumer_id:
         self.prompt.render_failure_message("This consumer is not registered to the Pulp server.")
         return
     repo_id = kwargs["repo-id"]
     distributor_id = kwargs["distributor-id"]
     try:
         self.context.server.bind.bind(consumer_id, repo_id, distributor_id)
         self.prompt.render_success_message(
             "Consumer [%s] successfully bound to repository distributor [%s : %s]"
             % (consumer_id, repo_id, distributor_id)
         )
     except NotFoundException:
         self.prompt.write("Consumer [%s] does not exist on the server" % consumer_id, tag="not-found")
开发者ID:pieska,项目名称:pulp,代码行数:15,代码来源:pulp_cli.py


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