當前位置: 首頁>>代碼示例>>Python>>正文


Python hookenv.relation_set方法代碼示例

本文整理匯總了Python中charmhelpers.core.hookenv.relation_set方法的典型用法代碼示例。如果您正苦於以下問題:Python hookenv.relation_set方法的具體用法?Python hookenv.relation_set怎麽用?Python hookenv.relation_set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在charmhelpers.core.hookenv的用法示例。


在下文中一共展示了hookenv.relation_set方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_relation_clear

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_set [as 別名]
def test_relation_clear(self, local_unit,
                            relation_get,
                            relation_set):
        local_unit.return_value = 'local-unit'
        relation_get.return_value = {
            'private-address': '10.5.0.1',
            'foo': 'bar',
            'public-address': '146.192.45.6'
        }
        hookenv.relation_clear('relation:1')
        relation_get.assert_called_with(rid='relation:1',
                                        unit='local-unit')
        relation_set.assert_called_with(
            relation_id='relation:1',
            **{'private-address': '10.5.0.1',
               'foo': None,
               'public-address': '146.192.45.6'}) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:19,代碼來源:test_hookenv.py

示例2: test_relation_set_file

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_set [as 別名]
def test_relation_set_file(self, check_call, check_output, remove):
        """If relation-set accepts a --file parameter, it's used.

        Juju 1.23.2 introduced a --file parameter, which means you can
        pass the data through a file. Not using --file would make
        relation_set break if the relation data is too big.
        """
        # check_output(["relation-set", "--help"]) is used to determine
        # whether we can pass --file to it.
        check_output.return_value = "--file"
        hookenv.relation_set(foo="bar")
        check_output.assert_called_with(
            ["relation-set", "--help"], universal_newlines=True)
        # relation-set is called with relation-set --file <temp_file>
        # with data as YAML and the temp_file is then removed.
        self.assertEqual(1, len(check_call.call_args[0]))
        command = check_call.call_args[0][0]
        self.assertEqual(3, len(command))
        self.assertEqual("relation-set", command[0])
        self.assertEqual("--file", command[1])
        temp_file = command[2]
        with open(temp_file, "r") as f:
            self.assertEqual("{foo: bar}", f.read().strip())
        remove.assert_called_with(temp_file) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:26,代碼來源:test_hookenv.py

示例3: test_relation_set_file_non_str

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_set [as 別名]
def test_relation_set_file_non_str(self, check_call, check_output, remove):
        """If relation-set accepts a --file parameter, it's used.

        Any value that is not a string is converted to a string before encoding
        the settings to YAML.
        """
        # check_output(["relation-set", "--help"]) is used to determine
        # whether we can pass --file to it.
        check_output.return_value = "--file"
        hookenv.relation_set(foo={"bar": 1})
        check_output.assert_called_with(
            ["relation-set", "--help"], universal_newlines=True)
        # relation-set is called with relation-set --file <temp_file>
        # with data as YAML and the temp_file is then removed.
        self.assertEqual(1, len(check_call.call_args[0]))
        command = check_call.call_args[0][0]
        self.assertEqual(3, len(command))
        self.assertEqual("relation-set", command[0])
        self.assertEqual("--file", command[1])
        temp_file = command[2]
        with open(temp_file, "r") as f:
            self.assertEqual("{foo: '{''bar'': 1}'}", f.read().strip())
        remove.assert_called_with(temp_file) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:25,代碼來源:test_hookenv.py

示例4: _save_state

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_set [as 別名]
def _save_state(self):
        self.msg('Publishing state'.format(self._name()))
        if hookenv.is_leader():
            # sort_keys to ensure stability.
            raw = json.dumps(self.grants, sort_keys=True)
            hookenv.leader_set({self.key: raw})

        local_unit = hookenv.local_unit()

        if self.relid is None:
            # No peers relation yet. Fallback to local state.
            self.msg('No peer relation. Saving local state')
            self._save_local_state(self.requests[local_unit])
        else:
            # sort_keys to ensure stability.
            raw = json.dumps(self.requests[local_unit], sort_keys=True)
            hookenv.relation_set(self.relid, relation_settings={self.key: raw}) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:19,代碼來源:coordinator.py

示例5: provide_data

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_set [as 別名]
def provide_data(self):
        """
        Set the relation data for each provider in the ``provided_data`` list.

        A provider must have a `name` attribute, which indicates which relation
        to set data on, and a `provide_data()` method, which returns a dict of
        data to set.

        The `provide_data()` method can optionally accept two parameters:

          * ``remote_service`` The name of the remote service that the data will
            be provided to.  The `provide_data()` method will be called once
            for each connected service (not unit).  This allows the method to
            tailor its data to the given service.
          * ``service_ready`` Whether or not the service definition had all of
            its requirements met, and thus the ``data_ready`` callbacks run.

        Note that the ``provided_data`` methods are now called **after** the
        ``data_ready`` callbacks are run.  This gives the ``data_ready`` callbacks
        a chance to generate any data necessary for the providing to the remote
        services.
        """
        for service_name, service in self.services.items():
            service_ready = self.is_ready(service_name)
            for provider in service.get('provided_data', []):
                for relid in hookenv.relation_ids(provider.name):
                    units = hookenv.related_units(relid)
                    if not units:
                        continue
                    remote_service = units[0].split('/')[0]
                    argspec = getargspec(provider.provide_data)
                    if len(argspec.args) > 1:
                        data = provider.provide_data(remote_service, service_ready)
                    else:
                        data = provider.provide_data()
                    if data:
                        hookenv.relation_set(relid, data) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:39,代碼來源:base.py


注:本文中的charmhelpers.core.hookenv.relation_set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。