本文整理汇总了Python中trove.guestagent.common.configuration.ConfigurationManager.apply_system_override方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationManager.apply_system_override方法的具体用法?Python ConfigurationManager.apply_system_override怎么用?Python ConfigurationManager.apply_system_override使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trove.guestagent.common.configuration.ConfigurationManager
的用法示例。
在下文中一共展示了ConfigurationManager.apply_system_override方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_write_configuration
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [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')
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)
])
示例2: MongoDBApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [as 别名]
class MongoDBApp(object):
"""Prepares DBaaS on a Guest container."""
def __init__(self):
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(CONFIG_FILE),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
self.configuration_manager = ConfigurationManager(
CONFIG_FILE, system.MONGO_USER, system.MONGO_USER,
SafeYamlCodec(default_flow_style=False),
requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
self.is_query_router = False
self.is_cluster_member = False
self.status = MongoDBAppStatus()
def install_if_needed(self, packages):
"""Prepare the guest machine with a MongoDB installation."""
LOG.info(_("Preparing Guest as MongoDB."))
if not system.PACKAGER.pkg_is_installed(packages):
LOG.debug("Installing packages: %s." % str(packages))
system.PACKAGER.pkg_install(packages, {}, system.TIME_OUT)
LOG.info(_("Finished installing MongoDB server."))
def _get_service_candidates(self):
if self.is_query_router:
return system.MONGOS_SERVICE_CANDIDATES
return system.MONGOD_SERVICE_CANDIDATES
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
self.status.stop_db_service(
self._get_service_candidates(), self.state_change_wait_time,
disable_on_boot=do_not_start_on_reboot, update_db=update_db)
def restart(self):
self.status.restart_db_service(
self._get_service_candidates(), self.state_change_wait_time)
def start_db(self, update_db=False):
self.status.start_db_service(
self._get_service_candidates(), self.state_change_wait_time,
enable_on_boot=True, update_db=update_db)
def update_overrides(self, context, overrides, remove=False):
if overrides:
self.configuration_manager.apply_user_override(overrides)
def remove_overrides(self):
self.configuration_manager.remove_user_override()
def start_db_with_conf_changes(self, config_contents):
LOG.info(_('Starting MongoDB with configuration 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(
None, mount_point=system.MONGODB_MOUNT_POINT)
self.start_db(True)
def apply_initial_guestagent_configuration(
self, cluster_config, mount_point=None):
LOG.debug("Applying initial configuration.")
# Mongodb init scripts assume the PID-file path is writable by the
# database service.
# See: https://jira.mongodb.org/browse/SERVER-20075
self._initialize_writable_run_dir()
self.configuration_manager.apply_system_override(
{'processManagement.fork': False,
'processManagement.pidFilePath': system.MONGO_PID_FILE,
'systemLog.destination': 'file',
'systemLog.path': system.MONGO_LOG_FILE,
'systemLog.logAppend': True
})
if mount_point:
self.configuration_manager.apply_system_override(
{'storage.dbPath': mount_point})
if cluster_config is not None:
self._configure_as_cluster_instance(cluster_config)
else:
self._configure_network(MONGODB_PORT)
def _initialize_writable_run_dir(self):
"""Create a writable directory for Mongodb's runtime data
(e.g. PID-file).
"""
mongodb_run_dir = os.path.dirname(system.MONGO_PID_FILE)
LOG.debug("Initializing a runtime directory: %s" % mongodb_run_dir)
operating_system.create_directory(
#.........这里部分代码省略.........
示例3: RedisApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [as 别名]
#.........这里部分代码省略.........
def remove_overrides(self):
self.configuration_manager.remove_user_override()
def make_read_only(self, read_only):
# Redis has no mechanism to make an instance read-only at present
pass
def start_db_with_conf_changes(self, config_contents):
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):
示例4: _assert_get_value
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [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'))
示例5: PgSqlApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [as 别名]
#.........这里部分代码省略.........
"""
self.build_admin().psql(
"SELECT pg_reload_conf()")
def reset_configuration(self, context, configuration):
"""Reset the PgSql configuration to the one given.
"""
config_contents = configuration['config_contents']
self.configuration_manager.save_configuration(config_contents)
def start_db_with_conf_changes(self, context, config_contents):
"""Starts the PgSql instance with a new configuration."""
if self.status.is_running:
raise RuntimeError(_("The service is still running."))
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()
def apply_initial_guestagent_configuration(self):
"""Update guestagent-controlled configuration properties.
"""
LOG.debug("Applying initial guestagent configuration.")
file_locations = {
'data_directory': self._quote(self.pgsql_data_dir),
'hba_file': self._quote(self.pgsql_hba_config),
'ident_file': self._quote(self.pgsql_ident_config),
'external_pid_file': self._quote(self.pgsql_pid_file),
'unix_socket_directories': self._quote(self.pgsql_run_dir),
'listen_addresses': self._quote(','.join(self.LISTEN_ADDRESSES)),
'port': cfg.get_configuration_property('postgresql_port')}
self.configuration_manager.apply_system_override(file_locations)
self._apply_access_rules()
@staticmethod
def _quote(value):
return "'%s'" % value
def _apply_access_rules(self):
LOG.debug("Applying database access rules.")
# Connections to all resources are granted.
#
# Local access from administrative users is implicitly trusted.
#
# Remote access from the Trove's account is always rejected as
# it is not needed and could be used by malicious users to hijack the
# instance.
#
# Connections from other accounts always require a double-MD5-hashed
# password.
#
# Make the rules readable only by the Postgres service.
#
# NOTE: The order of entries is important.
# The first failure to authenticate stops the lookup.
# That is why the 'local' connections validate first.
# The OrderedDict is necessary to guarantee the iteration order.
local_admins = ','.join([self.default_superuser_name, self.ADMIN_USER])
remote_admins = self.ADMIN_USER
access_rules = OrderedDict(
[('local', [['all', local_admins, None, 'trust'],
['replication', local_admins, None, 'trust'],
['all', 'all', None, 'md5']]),
示例6: _assert_get_value
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [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"))
示例7: MongoDBApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [as 别名]
#.........这里部分代码省略.........
self.configuration_manager.apply_user_override(overrides)
def remove_overrides(self):
self.configuration_manager.remove_user_override()
def start_db_with_conf_changes(self, config_contents):
LOG.info(_("Starting MongoDB with configuration 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(None, mount_point=system.MONGODB_MOUNT_POINT)
self.start_db(True)
def reset_configuration(self, configuration):
LOG.info(_("Resetting configuration."))
config_contents = configuration["config_contents"]
self.configuration_manager.save_configuration(config_contents)
def apply_initial_guestagent_configuration(self, cluster_config, mount_point=None):
LOG.debug("Applying initial configuration.")
# Mongodb init scripts assume the PID-file path is writable by the
# database service.
# See: https://jira.mongodb.org/browse/SERVER-20075
self._initialize_writable_run_dir()
# todo mvandijk: enable authorization.
# 'security.authorization': True
self.configuration_manager.apply_system_override(
{
"processManagement.fork": False,
"processManagement.pidFilePath": system.MONGO_PID_FILE,
"systemLog.destination": "file",
"systemLog.path": system.MONGO_LOG_FILE,
"systemLog.logAppend": True,
}
)
if mount_point:
self.configuration_manager.apply_system_override({"storage.dbPath": mount_point})
if cluster_config is not None:
self._configure_as_cluster_instance(cluster_config)
else:
self._configure_network(MONGODB_PORT)
def _initialize_writable_run_dir(self):
"""Create a writable directory for Mongodb's runtime data
(e.g. PID-file).
"""
mongodb_run_dir = os.path.dirname(system.MONGO_PID_FILE)
LOG.debug("Initializing a runtime directory: %s" % mongodb_run_dir)
operating_system.create_directory(
mongodb_run_dir, user=system.MONGO_USER, group=system.MONGO_USER, force=True, as_root=True
)
def _configure_as_cluster_instance(self, cluster_config):
"""Configure this guest as a cluster instance and return its
new status.
"""
if cluster_config["instance_type"] == "query_router":
示例8: CassandraApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [as 别名]
#.........这里部分代码省略.........
if self.has_user_config():
return self._load_current_superuser()
LOG.warn(_("Trove administrative user has not been configured yet. "
"Using the built-in default: %s")
% self.default_superuser_name)
return models.CassandraUser(self.default_superuser_name,
self.default_superuser_password)
def has_user_config(self):
"""
Return TRUE if there is a client configuration file available
on the guest.
"""
return os.path.exists(self._get_cqlsh_conf_path())
def _load_current_superuser(self):
config = operating_system.read_file(self._get_cqlsh_conf_path(),
codec=IniCodec())
return models.CassandraUser(
config[self._CONF_AUTH_SEC][self._CONF_USR_KEY],
config[self._CONF_AUTH_SEC][self._CONF_PWD_KEY]
)
def apply_initial_guestagent_configuration(self, cluster_name=None):
"""Update guestagent-controlled configuration properties.
These changes to the default template are necessary in order to make
the database service bootable and accessible in the guestagent context.
:param cluster_name: The 'cluster_name' configuration property.
Use the unique guest id by default.
:type cluster_name: string
"""
self.configuration_manager.apply_system_override(
{'data_file_directories': [self.cassandra_data_dir]})
self._make_host_reachable()
self._update_cluster_name_property(cluster_name or CONF.guest_id)
# A single-node instance may use the SimpleSnitch
# (keyspaces use SimpleStrategy).
# A network-aware snitch has to be used otherwise.
if cluster_name is None:
updates = {'endpoint_snitch': 'SimpleSnitch'}
else:
updates = {'endpoint_snitch': 'GossipingPropertyFileSnitch'}
self.configuration_manager.apply_system_override(updates)
def _make_host_reachable(self):
"""
Some of these settings may be overriden by user defined
configuration groups.
authenticator and authorizer
- Necessary to enable users and permissions.
rpc_address - Enable remote connections on all interfaces.
broadcast_rpc_address - RPC address to broadcast to drivers and
other clients. Must be set if
rpc_address = 0.0.0.0 and can never be
0.0.0.0 itself.
listen_address - The address on which the node communicates with
other nodes. Can never be 0.0.0.0.
seed_provider - A list of discovery contact points.
"""
self.__enable_authentication()
self.__enable_remote_access()
def __enable_remote_access(self):
示例9: RedisApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import apply_system_override [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.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):