AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 602527
Accepted
Merlijn Sebrechts
Merlijn Sebrechts
Asked: 2015-03-29 12:02:59 +0800 CST2015-03-29 12:02:59 +0800 CST 2015-03-29 12:02:59 +0800 CST

provide_data 在 required_keys 不满足时不发送数据(使用服务框架的 juju 魅力)

  • 772

我不确定我是否以正确的方式使用它。我有一个类为相同的关系定义required_keys和provide_data。以下代码provide_data在关系加入/更改时执行,但不执行关系集namenode_sshkey。如果我删除该required_keys行,代码突然工作(但我不能使用此类来指定关系所需的数据)。

[...]
    {
        'service': 'namenode',
        'ports': [9000, 50070],  # ports to open after start
        'provided_data': [
            NamenodeRelation()
        ],
        'required_data': [
            NamenodeRelation(),
            {'role' : 'namenode', 'command' : 'hadoop-daemon.sh'}
        ],
        'data_ready': [
            configure_namenode,
            helpers.render_template(
                 source='upstart.conf',
                 target='/etc/init/namenode.conf')
        ],
    },
[...]


class NamenodeRelation(RelationContext):
    name = 'namenode'
    interface = 'dfs'

    def __init__(self, *args, **kwargs):
        self.required_keys = ['slave_IP', 'private-address']
        RelationContext.__init__(self,name=self.name, *args, **kwargs)

    def provide_data(self):
        return {'namenode_sshkey' : get_ssh_key() }

这种行为是故意的还是错误?

juju
  • 1 1 个回答
  • 72 Views

1 个回答

  • Voted
  1. Best Answer
    Adam Israel
    2015-03-29T18:47:55+08:002015-03-29T18:47:55+08:00

    这确实是一个错误。这周我在使用服务框架重写 charm 时遇到了这个问题。我正在努力修复它,但与此同时,我确实有一个解决方法。

    在 ServiceManager 设置中,传递要通过关系线发送的 key=value,不要传递 required_data 关系的任何内容。

    def manage():
        manager = ServiceManager([
            {
                'service': 'example',
                'ports': [80],  # ports to after start
                'provided_data': [
                    RabbitMQRelation(username='example', vhost='/')
                ],
                'required_data': [
                   RabbitMQRelation(),
                ],
                'data_ready': [
                    configure_rabbitmq,
                ],
                'data_lost': [
                ],
            },
        ])
        manager.manage()
    

    Relation 类基本上通过仅在没有提供的数据要处理时设置它来短路 required_keys。

    class RabbitMQRelation(helpers.RelationContext):
        name = 'amqp'
        interface = 'rabbitmq'
    
        vhost = None
        username = None
        required_keys = []
    
        def __init__(self, username=None, vhost=None):
            """
            This works around a bug with the RelationContext class that expects
            the required keys to be set before it will call provide_data.
            """
            if username and vhost:
                self.username = username
                self.vhost = vhost
            else:
                self.required_keys = ['private-address', 'hostname', 'password']
    
            super(RabbitMQRelation, self).__init__(self.name)
    
    • 3

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve