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


Python ConfigurationManager.get_value方法代码示例

本文整理汇总了Python中trove.guestagent.common.configuration.ConfigurationManager.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationManager.get_value方法的具体用法?Python ConfigurationManager.get_value怎么用?Python ConfigurationManager.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trove.guestagent.common.configuration.ConfigurationManager的用法示例。


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

示例1: test_read_write_configuration

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def test_read_write_configuration(self, read_file, write_file,
                                      chown, chmod):
        sample_path = Mock()
        sample_owner = Mock()
        sample_group = Mock()
        sample_codec = MagicMock()
        sample_requires_root = Mock()
        sample_strategy = MagicMock()
        sample_strategy.configure = Mock()
        sample_strategy.parse_updates = Mock(return_value={})

        manager = ConfigurationManager(
            sample_path, sample_owner, sample_group, sample_codec,
            requires_root=sample_requires_root,
            override_strategy=sample_strategy)

        manager.parse_configuration()
        read_file.assert_called_with(sample_path, codec=sample_codec,
                                     as_root=sample_requires_root)

        with patch.object(manager, 'parse_configuration',
                          return_value={'key1': 'v1', 'key2': 'v2'}):
            self.assertEqual('v1', manager.get_value('key1'))
            self.assertIsNone(manager.get_value('key3'))

        sample_contents = Mock()
        manager.save_configuration(sample_contents)
        write_file.assert_called_with(
            sample_path, sample_contents, as_root=sample_requires_root)

        chown.assert_called_with(sample_path, sample_owner, sample_group,
                                 as_root=sample_requires_root)
        chmod.assert_called_with(
            sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)

        sample_data = {}
        manager.apply_system_override(sample_data)
        manager.apply_user_override(sample_data)
        manager.apply_system_override(sample_data, change_id='sys1')
        manager.apply_user_override(sample_data, change_id='usr1')
        manager.apply_system_override(sample_data, change_id='sys2',
                                      pre_user=True)
        sample_strategy.apply.has_calls([
            call(manager.SYSTEM_POST_USER_GROUP,
                 manager.DEFAULT_CHANGE_ID, sample_data),
            call(manager.USER_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
            call(manager.SYSTEM_POST_USER_GROUP,
                 'sys1', sample_data),
            call(manager.USER_GROUP, 'usr1', sample_data),
            call(manager.SYSTEM_PRE_USER_GROUP,
                 'sys2', sample_data),
        ])
开发者ID:Tesora,项目名称:tesora-trove,代码行数:54,代码来源:test_configuration.py

示例2: test_read_write_configuration

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def test_read_write_configuration(self, read_file, write_file, chown, chmod):
        sample_path = Mock()
        sample_owner = Mock()
        sample_group = Mock()
        sample_codec = MagicMock()
        sample_requires_root = Mock()
        sample_strategy = MagicMock()
        sample_strategy.configure = Mock()
        sample_strategy.parse_updates = Mock(return_value={})

        manager = ConfigurationManager(
            sample_path,
            sample_owner,
            sample_group,
            sample_codec,
            requires_root=sample_requires_root,
            override_strategy=sample_strategy,
        )

        manager.parse_configuration()
        read_file.assert_called_with(sample_path, codec=sample_codec)

        with patch.object(manager, "parse_configuration", return_value={"key1": "v1", "key2": "v2"}):
            self.assertEqual("v1", manager.get_value("key1"))
            self.assertIsNone(manager.get_value("key3"))

        sample_contents = Mock()
        manager.save_configuration(sample_contents)
        write_file.assert_called_with(sample_path, sample_contents, as_root=sample_requires_root)

        chown.assert_called_with(sample_path, sample_owner, sample_group, as_root=sample_requires_root)
        chmod.assert_called_with(sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)

        sample_data = {}
        manager.apply_system_override(sample_data)
        manager.apply_user_override(sample_data)
        manager.apply_system_override(sample_data, change_id="sys1")
        manager.apply_user_override(sample_data, change_id="usr1")
        sample_strategy.apply.has_calls(
            [
                call(manager.SYSTEM_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
                call(manager.USER_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
                call(manager.SYSTEM_GROUP, "sys1", sample_data),
                call(manager.USER_GROUP, "usr1", sample_data),
            ]
        )
开发者ID:jjmob,项目名称:trove,代码行数:48,代码来源:test_configuration.py

示例3: test_read_write_configuration

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def test_read_write_configuration(self, read_file, write_file,
                                      chown, chmod):
        sample_path = Mock()
        sample_owner = Mock()
        sample_group = Mock()
        sample_codec = MagicMock()
        sample_requires_root = Mock()

        manager = ConfigurationManager(
            sample_path, sample_owner, sample_group, sample_codec,
            requires_root=sample_requires_root)

        manager.parse_configuration()
        read_file.assert_called_with(sample_path, codec=sample_codec)

        with patch.object(manager, 'parse_configuration',
                          return_value={'key1': 'v1', 'key2': 'v2'}):
            self.assertEqual('v1', manager.get_value('key1'))
            self.assertEqual(None, manager.get_value('key3'))

        sample_contents = Mock()
        manager.save_configuration(sample_contents)
        write_file.assert_called_with(
            sample_path, sample_contents, as_root=sample_requires_root)

        chown.assert_called_with(sample_path, sample_owner, sample_group,
                                 as_root=sample_requires_root)
        chmod.assert_called_with(
            sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)

        sample_options = Mock()
        with patch.object(manager, 'save_configuration') as save_config:
            manager.render_configuration(sample_options)
            save_config.assert_called_once_with(
                sample_codec.serialize.return_value)
            sample_codec.serialize.assert_called_once_with(sample_options)

        with patch('trove.guestagent.common.configuration.'
                   'ConfigurationOverrideStrategy') as mock_strategy:
            manager.set_override_strategy(mock_strategy)
            manager._current_revision = 3
            manager.save_configuration(sample_contents)
            mock_strategy.remove_last.assert_called_once_with(
                manager._current_revision + 1)
            write_file.assert_called_with(
                sample_path, sample_contents, as_root=sample_requires_root)
开发者ID:cretta,项目名称:trove,代码行数:48,代码来源:test_configuration.py

示例4: MongoDBApp

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]

#.........这里部分代码省略.........
    def _configure_cluster_security(self, key_value):
        """Force cluster key-file-based authentication.

        This will enabled RBAC.
        """
        # Store the cluster member authentication key.
        self.store_key(key_value)

        self.configuration_manager.apply_system_override(
            {'security.clusterAuthMode': 'keyFile',
             'security.keyFile': self.get_key_file()}, CNF_CLUSTER)

    def _configure_network(self, port=None):
        """Make the service accessible at a given (or default if not) port.
        """
        instance_ip = netutils.get_my_ipv4()
        bind_interfaces_string = ','.join([instance_ip, '127.0.0.1'])
        options = {'net.bindIp': bind_interfaces_string}
        if port is not None:
            guestagent_utils.update_dict({'net.port': port}, options)

        self.configuration_manager.apply_system_override(options)
        self.status.set_host(instance_ip, port=port)

    def clear_storage(self):
        mount_point = "/var/lib/mongodb/*"
        LOG.debug("Clearing storage at %s." % mount_point)
        try:
            operating_system.remove(mount_point, force=True, as_root=True)
        except exception.ProcessExecutionError:
            LOG.exception(_("Error clearing storage."))

    def _has_config_db(self):
        value_string = self.configuration_manager.get_value(
            'sharding', {}).get('configDB')

        return value_string is not None

    # FIXME(pmalik): This method should really be called 'set_config_servers'.
    # The current name suggests it adds more config servers, but it
    # rather replaces the existing ones.
    def add_config_servers(self, config_server_hosts):
        """Set config servers on a query router (mongos) instance.
        """
        config_servers_string = ','.join(['%s:%s' % (host, CONFIGSVR_PORT)
                                          for host in config_server_hosts])
        LOG.info(_("Setting config servers: %s") % config_servers_string)
        self.configuration_manager.apply_system_override(
            {'sharding.configDB': config_servers_string}, CNF_CLUSTER)
        self.start_db(True)

    def add_shard(self, replica_set_name, replica_set_member):
        """
        This method is used by query router (mongos) instances.
        """
        url = "%(rs)s/%(host)s:%(port)s"\
              % {'rs': replica_set_name,
                 'host': replica_set_member,
                 'port': MONGODB_PORT}
        MongoDBAdmin().add_shard(url)

    def add_members(self, members):
        """
        This method is used by a replica-set member instance.
        """
        def check_initiate_status():
开发者ID:Hopebaytech,项目名称:trove,代码行数:70,代码来源:service.py

示例5: _assert_get_value

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def _assert_get_value(self, override_strategy):
        base_config_contents = {'Section_1': {'name': 'pi',
                                              'is_number': 'True',
                                              'value': '3.1415'}
                                }

        config_overrides_v1a = {'Section_1': {'name': 'sqrt(2)',
                                              'value': '1.4142'}
                                }

        config_overrides_v2 = {'Section_1': {'name': 'e',
                                             'value': '2.7183'},
                               'Section_2': {'foo': 'bar'}
                               }

        config_overrides_v1b = {'Section_1': {'name': 'sqrt(4)',
                                              'value': '2.0'}
                                }

        codec = IniCodec()
        current_user = getpass.getuser()

        with tempfile.NamedTemporaryFile() as base_config:

            # Write initial config contents.
            operating_system.write_file(
                base_config.name, base_config_contents, codec)

            manager = ConfigurationManager(
                base_config.name, current_user, current_user, codec,
                requires_root=False, override_strategy=override_strategy)

            # Test default value.
            self.assertIsNone(manager.get_value('Section_2'))
            self.assertEqual('foo', manager.get_value('Section_2', 'foo'))

            # Test value before applying overrides.
            self.assertEqual('pi', manager.get_value('Section_1')['name'])
            self.assertEqual('3.1415', manager.get_value('Section_1')['value'])

            # Test value after applying overrides.
            manager.apply_user_override(config_overrides_v1a, change_id='id1')
            self.assertEqual('sqrt(2)', manager.get_value('Section_1')['name'])
            self.assertEqual('1.4142', manager.get_value('Section_1')['value'])
            manager.apply_user_override(config_overrides_v2, change_id='id2')
            self.assertEqual('e', manager.get_value('Section_1')['name'])
            self.assertEqual('2.7183', manager.get_value('Section_1')['value'])
            self.assertEqual('bar', manager.get_value('Section_2')['foo'])

            # Editing change 'id1' become visible only after removing
            # change 'id2', which overrides 'id1'.
            manager.apply_user_override(config_overrides_v1b, change_id='id1')
            self.assertEqual('e', manager.get_value('Section_1')['name'])
            self.assertEqual('2.7183', manager.get_value('Section_1')['value'])

            # Test value after removing overrides.

            # The edited values from change 'id1' should be visible after
            # removing 'id2'.
            manager.remove_user_override(change_id='id2')
            self.assertEqual('sqrt(4)', manager.get_value('Section_1')['name'])
            self.assertEqual('2.0', manager.get_value('Section_1')['value'])

            # Back to the base.
            manager.remove_user_override(change_id='id1')
            self.assertEqual('pi', manager.get_value('Section_1')['name'])
            self.assertEqual('3.1415', manager.get_value('Section_1')['value'])
            self.assertIsNone(manager.get_value('Section_2'))

            # Test system overrides.
            manager.apply_system_override(
                config_overrides_v1b, change_id='id1')
            self.assertEqual('sqrt(4)', manager.get_value('Section_1')['name'])
            self.assertEqual('2.0', manager.get_value('Section_1')['value'])

            # The system values should take precedence over the user
            # override.
            manager.apply_user_override(
                config_overrides_v1a, change_id='id1')
            self.assertEqual('sqrt(4)', manager.get_value('Section_1')['name'])
            self.assertEqual('2.0', manager.get_value('Section_1')['value'])

            # The user values should become visible only after removing the
            # system change.
            manager.remove_system_override(change_id='id1')
            self.assertEqual('sqrt(2)', manager.get_value('Section_1')['name'])
            self.assertEqual('1.4142', manager.get_value('Section_1')['value'])

            # Back to the base.
            manager.remove_user_override(change_id='id1')
            self.assertEqual('pi', manager.get_value('Section_1')['name'])
            self.assertEqual('3.1415', manager.get_value('Section_1')['value'])
            self.assertIsNone(manager.get_value('Section_2'))
开发者ID:HoratiusTang,项目名称:trove,代码行数:95,代码来源:test_configuration.py

示例6: RedisApp

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]

#.........这里部分代码省略.........
        LOG.info(_('Starting redis with conf changes.'))
        if self.status.is_running:
            format = 'Cannot start_db_with_conf_changes because status is %s.'
            LOG.debug(format, self.status)
            raise RuntimeError(format % self.status)
        LOG.info(_("Initiating config."))
        self.configuration_manager.save_configuration(config_contents)
        # The configuration template has to be updated with
        # guestagent-controlled settings.
        self.apply_initial_guestagent_configuration()
        self.start_db(True)

    def start_db(self, update_db=False):
        self.status.start_db_service(
            system.SERVICE_CANDIDATES, self.state_change_wait_time,
            enable_on_boot=True, update_db=update_db)

    def apply_initial_guestagent_configuration(self):
        """Update guestagent-controlled configuration properties.
        """

        # Hide the 'CONFIG' command from end users by mangling its name.
        self.admin.set_config_command_name(self._mangle_config_command_name())

        self.configuration_manager.apply_system_override(
            {'daemonize': 'yes',
             'pidfile': system.REDIS_PID_FILE,
             'logfile': system.REDIS_LOG_FILE,
             'dir': system.REDIS_DATA_DIR})

    def get_config_command_name(self):
        """Get current name of the 'CONFIG' command.
        """
        renamed_cmds = self.configuration_manager.get_value('rename-command')
        for name_pair in renamed_cmds:
            if name_pair[0] == 'CONFIG':
                return name_pair[1]

        return None

    def _mangle_config_command_name(self):
        """Hide the 'CONFIG' command from the clients by renaming it to a
        random string known only to the guestagent.
        Return the mangled name.
        """
        mangled = utils.generate_random_password()
        self._rename_command('CONFIG', mangled)
        return mangled

    def _rename_command(self, old_name, new_name):
        """It is possible to completely disable a command by renaming it
        to an empty string.
        """
        self.configuration_manager.apply_system_override(
            {'rename-command': [old_name, new_name]})

    def get_logfile(self):
        """Specify the log file name. Also the empty string can be used to
        force Redis to log on the standard output.
        Note that if you use standard output for logging but daemonize,
        logs will be sent to /dev/null
        """
        return self.get_configuration_property('logfile')

    def get_db_filename(self):
        """The filename where to dump the DB.
开发者ID:bhaskarduvvuri,项目名称:trove,代码行数:70,代码来源:service.py

示例7: _assert_get_value

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def _assert_get_value(self, override_strategy):
        base_config_contents = {"Section_1": {"name": "pi", "is_number": "True", "value": "3.1415"}}

        config_overrides_v1a = {"Section_1": {"name": "sqrt(2)", "value": "1.4142"}}

        config_overrides_v2 = {"Section_1": {"name": "e", "value": "2.7183"}, "Section_2": {"foo": "bar"}}

        config_overrides_v1b = {"Section_1": {"name": "sqrt(4)", "value": "2.0"}}

        codec = IniCodec()
        current_user = getpass.getuser()

        with tempfile.NamedTemporaryFile() as base_config:

            # Write initial config contents.
            operating_system.write_file(base_config.name, base_config_contents, codec)

            manager = ConfigurationManager(
                base_config.name,
                current_user,
                current_user,
                codec,
                requires_root=False,
                override_strategy=override_strategy,
            )

            # Test default value.
            self.assertIsNone(manager.get_value("Section_2"))
            self.assertEqual("foo", manager.get_value("Section_2", "foo"))

            # Test value before applying overrides.
            self.assertEqual("pi", manager.get_value("Section_1")["name"])
            self.assertEqual("3.1415", manager.get_value("Section_1")["value"])

            # Test value after applying overrides.
            manager.apply_user_override(config_overrides_v1a, change_id="id1")
            self.assertEqual("sqrt(2)", manager.get_value("Section_1")["name"])
            self.assertEqual("1.4142", manager.get_value("Section_1")["value"])
            manager.apply_user_override(config_overrides_v2, change_id="id2")
            self.assertEqual("e", manager.get_value("Section_1")["name"])
            self.assertEqual("2.7183", manager.get_value("Section_1")["value"])
            self.assertEqual("bar", manager.get_value("Section_2")["foo"])

            # Editing change 'id1' become visible only after removing
            # change 'id2', which overrides 'id1'.
            manager.apply_user_override(config_overrides_v1b, change_id="id1")
            self.assertEqual("e", manager.get_value("Section_1")["name"])
            self.assertEqual("2.7183", manager.get_value("Section_1")["value"])

            # Test value after removing overrides.

            # The edited values from change 'id1' should be visible after
            # removing 'id2'.
            manager.remove_user_override(change_id="id2")
            self.assertEqual("sqrt(4)", manager.get_value("Section_1")["name"])
            self.assertEqual("2.0", manager.get_value("Section_1")["value"])

            # Back to the base.
            manager.remove_user_override(change_id="id1")
            self.assertEqual("pi", manager.get_value("Section_1")["name"])
            self.assertEqual("3.1415", manager.get_value("Section_1")["value"])
            self.assertIsNone(manager.get_value("Section_2"))

            # Test system overrides.
            manager.apply_system_override(config_overrides_v1b, change_id="id1")
            self.assertEqual("sqrt(4)", manager.get_value("Section_1")["name"])
            self.assertEqual("2.0", manager.get_value("Section_1")["value"])

            # The system values should take precedence over the user
            # override.
            manager.apply_user_override(config_overrides_v1a, change_id="id1")
            self.assertEqual("sqrt(4)", manager.get_value("Section_1")["name"])
            self.assertEqual("2.0", manager.get_value("Section_1")["value"])

            # The user values should become visible only after removing the
            # system change.
            manager.remove_system_override(change_id="id1")
            self.assertEqual("sqrt(2)", manager.get_value("Section_1")["name"])
            self.assertEqual("1.4142", manager.get_value("Section_1")["value"])

            # Back to the base.
            manager.remove_user_override(change_id="id1")
            self.assertEqual("pi", manager.get_value("Section_1")["name"])
            self.assertEqual("3.1415", manager.get_value("Section_1")["value"])
            self.assertIsNone(manager.get_value("Section_2"))
开发者ID:jjmob,项目名称:trove,代码行数:87,代码来源:test_configuration.py

示例8: MongoDBApp

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]

#.........这里部分代码省略.........

    def _configure_cluster_security(self, key_value):
        """Force cluster key-file-based authentication.
        """
        # Store the cluster member authentication key.
        self.store_key(key_value)

        # TODO(mvandijk): enable cluster security once Trove features are in
        # self.configuration_manager.apply_system_override(
        #     {'security.clusterAuthMode': 'keyFile',
        #      'security.keyFile': self.get_key_file()}, CNF_CLUSTER)

    def _configure_network(self, port=None):
        """Make the service accessible at a given (or default if not) port.
        """
        instance_ip = netutils.get_my_ipv4()
        bind_interfaces_string = ",".join([instance_ip, "127.0.0.1"])
        options = {"net.bindIp": bind_interfaces_string}
        if port is not None:
            guestagent_utils.update_dict({"net.port": port}, options)

        self.configuration_manager.apply_system_override(options)
        self.status.set_host(instance_ip, port=port)

    def clear_storage(self):
        mount_point = "/var/lib/mongodb/*"
        LOG.debug("Clearing storage at %s." % mount_point)
        try:
            operating_system.remove(mount_point, force=True, as_root=True)
        except exception.ProcessExecutionError:
            LOG.exception(_("Error clearing storage."))

    def _has_config_db(self):
        value_string = self.configuration_manager.get_value("sharding", {}).get("configDB")

        return value_string is not None

    # FIXME(pmalik): This method should really be called 'set_config_servers'.
    # The current name suggests it adds more config servers, but it
    # rather replaces the existing ones.
    def add_config_servers(self, config_server_hosts):
        """Set config servers on a query router (mongos) instance.
        """
        config_servers_string = ",".join(["%s:27019" % host for host in config_server_hosts])
        LOG.info(_("Setting config servers: %s") % config_servers_string)
        self.configuration_manager.apply_system_override({"sharding.configDB": config_servers_string}, CNF_CLUSTER)
        self.start_db(True)

    def add_shard(self, replica_set_name, replica_set_member):
        """
        This method is used by query router (mongos) instances.
        """
        url = "%(rs)s/%(host)s:%(port)s" % {"rs": replica_set_name, "host": replica_set_member, "port": MONGODB_PORT}
        MongoDBAdmin().add_shard(url)

    def add_members(self, members):
        """
        This method is used by a replica-set member instance.
        """

        def check_initiate_status():
            """
            This method is used to verify replica-set status.
            """
            status = MongoDBAdmin().get_repl_status()
开发者ID:bbgw,项目名称:trove,代码行数:69,代码来源:service.py

示例9: _assert_update_configuration

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]
    def _assert_update_configuration(self, override_strategy):
        base_config_contents = {'Section_1': {'name': 'pi',
                                              'is_number': 'True',
                                              'value': '3.1415'}
                                }

        config_overrides_v1 = {'Section_1': {'name': 'sqrt(2)',
                                             'value': '1.4142'}
                               }

        config_overrides_v2 = {'Section_1': {'name': 'e',
                                             'value': '2.7183'},
                               'Section_2': {'foo': 'bar'}
                               }

        codec = IniCodec()
        current_user = getpass.getuser()

        with tempfile.NamedTemporaryFile() as base_config:

            # Write initial config contents.
            operating_system.write_file(
                base_config.name, base_config_contents, codec)

            manager = ConfigurationManager(
                base_config.name, current_user, current_user, codec,
                requires_root=False)

            manager.update_configuration({'System': {'name': 'c',
                                                     'is_number': 'True',
                                                     'value': 'N/A'}})

            manager.set_override_strategy(override_strategy, 2)

            # Test value before applying overrides.
            self.assertEqual('pi', manager.get_value('Section_1')['name'])
            self.assertEqual('3.1415', manager.get_value('Section_1')['value'])
            self.assertEqual('N/A', manager.get_value('System')['value'])
            self.assertEqual(0, manager.current_revision)

            manager.update_configuration({'System': {'value': '300000000'}})
            self.assertEqual('300000000', manager.get_value('System')['value'])
            self.assertEqual(0, manager.current_revision)

            # Test value after applying overrides.
            manager.apply_override(config_overrides_v1)
            self.assertEqual('sqrt(2)', manager.get_value('Section_1')['name'])
            self.assertEqual('1.4142', manager.get_value('Section_1')['value'])
            self.assertEqual('300000000', manager.get_value('System')['value'])
            self.assertEqual(1, manager.current_revision)

            manager.update_configuration({'System': {'value': '299792458'}})

            manager.apply_override(config_overrides_v2)
            self.assertEqual('e', manager.get_value('Section_1')['name'])
            self.assertEqual('2.7183', manager.get_value('Section_1')['value'])
            self.assertEqual('bar', manager.get_value('Section_2')['foo'])
            self.assertEqual('299792458', manager.get_value('System')['value'])
            self.assertEqual(2, manager.current_revision)

            # Test value after removing overrides.
            manager.remove_override()
            self.assertEqual('sqrt(2)', manager.get_value('Section_1')['name'])
            self.assertEqual('1.4142', manager.get_value('Section_1')['value'])
            self.assertEqual(1, manager.current_revision)

            manager.update_configuration({'System': {'value': '299792458'}})

            manager.remove_override()
            self.assertEqual('pi', manager.get_value('Section_1')['name'])
            self.assertEqual('3.1415', manager.get_value('Section_1')['value'])
            self.assertEqual(None, manager.get_value('Section_2'))
            self.assertEqual(0, manager.current_revision)

            manager.update_configuration({'System': {'value': 'N/A'}})
            self.assertEqual('N/A', manager.get_value('System')['value'])
            self.assertEqual(0, manager.current_revision)
开发者ID:cretta,项目名称:trove,代码行数:79,代码来源:test_configuration.py

示例10: CassandraApp

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]

#.........这里部分代码省略.........
        config = operating_system.read_file(self.cassandra_topology,
                                            codec=self._TOPOLOGY_CODEC)
        return config['dc']

    def get_rack(self):
        config = operating_system.read_file(self.cassandra_topology,
                                            codec=self._TOPOLOGY_CODEC)
        return config['rack']

    def set_seeds(self, seeds):
        LOG.debug("Setting seed nodes: %s" % seeds)
        updates = {
            'seed_provider': {'parameters':
                              [{'seeds': ','.join(seeds)}]
                              }
        }

        self.configuration_manager.apply_system_override(updates)

    def get_seeds(self):
        """Return a list of seed node IPs if any.

        The seed IPs are stored as a comma-separated string in the
        seed-provider parameters:
        [{'class_name': '<name>', 'parameters': [{'seeds': '<ip>,<ip>'}, ...]}]
        """

        def find_first(key, dict_list):
            for item in dict_list:
                if key in item:
                    return item[key]
            return []

        sp_property = self.configuration_manager.get_value('seed_provider', [])
        seeds_str = find_first('seeds', find_first('parameters', sp_property))
        return seeds_str.split(',') if seeds_str else []

    def set_auto_bootstrap(self, enabled):
        """Auto-bootstrap makes new (non-seed) nodes automatically migrate the
        right data to themselves.
        The feature has to be turned OFF when initializing a fresh cluster
        without data.
        It must be turned back ON once the cluster is initialized.
        """
        LOG.debug("Setting auto-bootstrapping: %s" % enabled)
        updates = {'auto_bootstrap': enabled}
        self.configuration_manager.apply_system_override(updates)

    def node_cleanup_begin(self):
        """Suspend periodic status updates and mark the instance busy
        throughout the operation.
        """
        self.status.begin_restart()
        self.status.set_status(rd_instance.ServiceStatuses.BLOCKED)

    def node_cleanup(self):
        """Cassandra does not automatically remove data from nodes that
        lose part of their partition range to a newly added node.
        Cleans up keyspaces and partition keys no longer belonging to the node.

        Do not treat cleanup failures as fatal. Resume the heartbeat after
        finishing and let it signal the true state of the instance to the
        caller.
        """
        LOG.debug("Running node cleanup.")
        # nodetool -h <HOST> -p <PORT> -u <USER> -pw <PASSWORD> cleanup
开发者ID:gongwayne,项目名称:Openstack,代码行数:70,代码来源:service.py

示例11: RedisApp

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import get_value [as 别名]

#.........这里部分代码省略.........
        """
        LOG.info(_("Starting redis."))
        self._enable_redis_on_boot()
        operating_system.start_service(system.SERVICE_CANDIDATES)
        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of redis failed."))
            try:
                utils.execute_with_timeout('pkill', '-9',
                                           'redis-server',
                                           run_as_root=True,
                                           root_helper='sudo')
            except exception.ProcessExecutionError:
                LOG.exception(_('Error killing stalled redis start command.'))
            self.status.end_install_or_restart()

    def apply_initial_guestagent_configuration(self):
        """Update guestagent-controlled configuration properties.
        """

        # Hide the 'CONFIG' command from end users by mangling its name.
        self.admin.set_config_command_name(self._mangle_config_command_name())

        self.configuration_manager.apply_system_override(
            {'daemonize': 'yes',
             'pidfile': system.REDIS_PID_FILE,
             'logfile': system.REDIS_LOG_FILE,
             'dir': system.REDIS_DATA_DIR})

    def get_config_command_name(self):
        """Get current name of the 'CONFIG' command.
        """
        renamed_cmds = self.configuration_manager.get_value('rename-command')
        for name_pair in renamed_cmds:
            if name_pair[0] == 'CONFIG':
                return name_pair[1]

        return None

    def _mangle_config_command_name(self):
        """Hide the 'CONFIG' command from the clients by renaming it to a
        random string known only to the guestagent.
        Return the mangled name.
        """
        mangled = utils.generate_random_password()
        self._rename_command('CONFIG', mangled)
        return mangled

    def _rename_command(self, old_name, new_name):
        """It is possible to completely disable a command by renaming it
        to an empty string.
        """
        self.configuration_manager.apply_system_override(
            {'rename-command': [old_name, new_name]})

    def get_logfile(self):
        """Specify the log file name. Also the empty string can be used to
        force Redis to log on the standard output.
        Note that if you use standard output for logging but daemonize,
        logs will be sent to /dev/null
        """
        return self.get_configuration_property('logfile')

    def get_db_filename(self):
        """The filename where to dump the DB.
开发者ID:cp16net,项目名称:trove,代码行数:70,代码来源:service.py


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