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


Python ConfigurationManager.update_configuration方法代码示例

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


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

示例1: _assert_update_configuration

# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import update_configuration [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

示例2: RedisApp

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

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

    def reset_configuration(self, configuration):
        LOG.info(_("Resetting configuration."))
        config_contents = configuration['config_contents']
        self.configuration_manager.save_configuration(config_contents)

    def start_redis(self, update_db=False):
        """
        Start the redis daemon.
        """
        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.update_configuration(
            {'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.update_configuration(
            {'rename-command': [old_name, new_name]})

    def get_logfile(self):
开发者ID:openstacking,项目名称:trove,代码行数:70,代码来源:service.py


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