本文整理汇总了Python中trove.guestagent.common.configuration.ConfigurationManager类的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationManager类的具体用法?Python ConfigurationManager怎么用?Python ConfigurationManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigurationManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, state_change_wait_time=None):
"""
Sets default status and state_change_wait_time
"""
if state_change_wait_time:
self.state_change_wait_time = state_change_wait_time
else:
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(system.REDIS_CONFIG),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
config_value_mappings = {'yes': True, 'no': False, "''": None}
self._value_converter = StringConverter(config_value_mappings)
self.configuration_manager = ConfigurationManager(
system.REDIS_CONFIG,
system.REDIS_OWNER, system.REDIS_OWNER,
PropertiesCodec(
unpack_singletons=False,
string_mappings=config_value_mappings
), requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
self.admin = self._build_admin_client()
self.status = RedisAppStatus(self.admin)
开发者ID:bhaskarduvvuri,项目名称:trove,代码行数:25,代码来源:service.py
示例2: __init__
def __init__(self, state_change_wait_time=None):
"""
Sets default status and state_change_wait_time
"""
if state_change_wait_time:
self.state_change_wait_time = state_change_wait_time
else:
self.state_change_wait_time = CONF.state_change_wait_time
config_value_mappings = {'yes': True, 'no': False, "''": None}
self._value_converter = StringConverter(config_value_mappings)
self.configuration_manager = ConfigurationManager(
system.REDIS_CONFIG,
system.REDIS_OWNER, system.REDIS_OWNER,
PropertiesCodec(
unpack_singletons=False,
string_mappings=config_value_mappings
), requires_root=True)
import_dir = os.path.dirname(system.REDIS_CONFIG)
override_strategy = RollingOverrideStrategy(import_dir)
self.configuration_manager.set_override_strategy(override_strategy)
self.admin = self._build_admin_client()
self.status = RedisAppStatus(self.admin)
开发者ID:openstacking,项目名称:trove,代码行数:26,代码来源:service.py
示例3: __init__
def __init__(self):
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = self._init_overrides_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.status = MongoDBAppStatus()
开发者ID:tarunmohanty,项目名称:trove,代码行数:12,代码来源:service.py
示例4: __init__
def __init__(self):
self.state_change_wait_time = CONF.state_change_wait_time
self.status = CassandraAppStatus(self.get_current_superuser())
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(self.cassandra_conf),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
self.configuration_manager = ConfigurationManager(
self.cassandra_conf,
self.cassandra_owner, self.cassandra_owner,
SafeYamlCodec(default_flow_style=False), requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
开发者ID:gongwayne,项目名称:Openstack,代码行数:12,代码来源:service.py
示例5: __init__
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()
开发者ID:Hopebaytech,项目名称:trove,代码行数:15,代码来源:service.py
示例6: __init__
def __init__(self):
super(PgSqlApp, self).__init__()
self._current_admin_user = None
self.status = PgSqlAppStatus(self.pgsql_extra_bin_dir)
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(self.pgsql_config),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
self.configuration_manager = ConfigurationManager(
self.pgsql_config, self.pgsql_owner, self.pgsql_owner,
PropertiesCodec(
delimiter='=',
string_mappings={'on': True, 'off': False, "''": None}),
requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:16,代码来源:service.py
示例7: __init__
def __init__(self, status):
self.state_change_wait_time = CONF.state_change_wait_time
self.status = status
revision_dir = \
guestagent_utils.build_file_path(
os.path.join(MOUNT_POINT,
os.path.dirname(system.VERTICA_ADMIN)),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
if not operating_system.exists(FAKE_CFG):
operating_system.write_file(FAKE_CFG, '', as_root=True)
operating_system.chown(FAKE_CFG, system.VERTICA_ADMIN,
system.VERTICA_ADMIN_GRP, as_root=True)
operating_system.chmod(FAKE_CFG, FileMode.ADD_GRP_RX_OTH_RX(),
as_root=True)
self.configuration_manager = \
ConfigurationManager(FAKE_CFG, system.VERTICA_ADMIN,
system.VERTICA_ADMIN_GRP,
PropertiesCodec(delimiter='='),
requires_root=True,
override_strategy=ImportOverrideStrategy(
revision_dir, "cnf"))
开发者ID:melvinj1123,项目名称:trove,代码行数:22,代码来源:service.py
示例8: MongoDBApp
class MongoDBApp(object):
"""Prepares DBaaS on a Guest container."""
@classmethod
def _init_overrides_dir(cls):
"""Initialize a directory for configuration overrides.
"""
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(CONFIG_FILE), ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR
)
if not os.path.exists(revision_dir):
operating_system.create_directory(
revision_dir, user=system.MONGO_USER, group=system.MONGO_USER, force=True, as_root=True
)
return revision_dir
def __init__(self):
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = self._init_overrides_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(self):
if self.is_query_router:
return operating_system.service_discovery(system.MONGOS_SERVICE_CANDIDATES)
else:
return operating_system.service_discovery(system.MONGOD_SERVICE_CANDIDATES)
def _enable_db_on_boot(self):
LOG.info(_("Enabling MongoDB on boot."))
try:
mongo_service = self._get_service()
utils.execute_with_timeout(mongo_service["cmd_enable"], shell=True)
except KeyError:
raise RuntimeError(_("MongoDB service is not discovered."))
def _disable_db_on_boot(self):
LOG.info(_("Disabling MongoDB on boot."))
try:
mongo_service = self._get_service()
utils.execute_with_timeout(mongo_service["cmd_disable"], shell=True)
except KeyError:
raise RuntimeError("MongoDB service is not discovered.")
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
LOG.info(_("Stopping MongoDB."))
if do_not_start_on_reboot:
self._disable_db_on_boot()
try:
mongo_service = self._get_service()
# TODO(ramashri) see if hardcoded values can be removed
utils.execute_with_timeout(mongo_service["cmd_stop"], shell=True, timeout=100)
except KeyError:
raise RuntimeError(_("MongoDB service is not discovered."))
if not self.status.wait_for_real_status_to_change_to(
ds_instance.ServiceStatuses.SHUTDOWN, self.state_change_wait_time, update_db
):
LOG.error(_("Could not stop MongoDB."))
self.status.end_install_or_restart()
raise RuntimeError(_("Could not stop MongoDB"))
def restart(self):
LOG.info(_("Restarting MongoDB."))
try:
self.status.begin_restart()
self.stop_db()
self.start_db()
finally:
self.status.end_install_or_restart()
def start_db(self, update_db=False):
LOG.info(_("Starting MongoDB."))
self._enable_db_on_boot()
try:
mongo_service = self._get_service()
#.........这里部分代码省略.........
开发者ID:bbgw,项目名称:trove,代码行数:101,代码来源:service.py
示例9: MongoDBApp
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(
#.........这里部分代码省略.........
开发者ID:Hopebaytech,项目名称:trove,代码行数:101,代码来源:service.py
示例10: test_read_write_configuration
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)
])
开发者ID:HoratiusTang,项目名称:trove,代码行数:46,代码来源:test_configuration.py
示例11: _assert_get_value
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,代码行数:93,代码来源:test_configuration.py
示例12: RedisApp
class RedisApp(object):
"""
Handles installation and configuration of redis
on a trove instance.
"""
@classmethod
def _init_overrides_dir(cls):
"""Initialize a directory for configuration overrides.
"""
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(system.REDIS_CONFIG),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
if not os.path.exists(revision_dir):
operating_system.create_directory(
revision_dir,
user=system.REDIS_OWNER, group=system.REDIS_OWNER,
force=True, as_root=True)
return revision_dir
def __init__(self, state_change_wait_time=None):
"""
Sets default status and state_change_wait_time
"""
if state_change_wait_time:
self.state_change_wait_time = state_change_wait_time
else:
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = self._init_overrides_dir()
config_value_mappings = {'yes': True, 'no': False, "''": None}
self._value_converter = StringConverter(config_value_mappings)
self.configuration_manager = ConfigurationManager(
system.REDIS_CONFIG,
system.REDIS_OWNER, system.REDIS_OWNER,
PropertiesCodec(
unpack_singletons=False,
string_mappings=config_value_mappings
), requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
self.admin = self._build_admin_client()
self.status = RedisAppStatus(self.admin)
def _build_admin_client(self):
password = self.get_configuration_property('requirepass')
socket = self.get_configuration_property('unixsocket')
return RedisAdmin(password=password, unix_socket_path=socket)
def install_if_needed(self, packages):
"""
Install redis if needed do nothing if it is already installed.
"""
LOG.info(_('Preparing Guest as Redis Server.'))
if not packager.pkg_is_installed(packages):
LOG.info(_('Installing Redis.'))
self._install_redis(packages)
LOG.info(_('Redis installed completely.'))
def complete_install_or_restart(self):
"""
finalize status updates for install or restart.
"""
LOG.debug("Complete install or restart called.")
self.status.end_install_or_restart()
def _install_redis(self, packages):
"""
Install the redis server.
"""
LOG.debug('Installing redis server.')
msg = "Creating %s." % system.REDIS_CONF_DIR
LOG.debug(msg)
operating_system.create_directory(system.REDIS_CONF_DIR, as_root=True)
pkg_opts = {}
packager.pkg_install(packages, pkg_opts, TIME_OUT)
self.start_redis()
LOG.debug('Finished installing redis server.')
def _enable_redis_on_boot(self):
"""
Enables redis on boot.
"""
LOG.info(_('Enabling Redis on boot.'))
operating_system.enable_service_on_boot(system.SERVICE_CANDIDATES)
def _disable_redis_on_boot(self):
"""
Disables redis on boot.
"""
LOG.info(_("Disabling Redis on boot."))
operating_system.disable_service_on_boot(system.SERVICE_CANDIDATES)
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
"""
Stops the redis application on the trove instance.
"""
#.........这里部分代码省略.........
开发者ID:cp16net,项目名称:trove,代码行数:101,代码来源:service.py
示例13: RedisApp
class RedisApp(object):
"""
Handles installation and configuration of redis
on a trove instance.
"""
def __init__(self, state_change_wait_time=None):
"""
Sets default status and state_change_wait_time
"""
if state_change_wait_time:
self.state_change_wait_time = state_change_wait_time
else:
self.state_change_wait_time = CONF.state_change_wait_time
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(system.REDIS_CONFIG),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
config_value_mappings = {'yes': True, 'no': False, "''": None}
self._value_converter = StringConverter(config_value_mappings)
self.configuration_manager = ConfigurationManager(
system.REDIS_CONFIG,
system.REDIS_OWNER, system.REDIS_OWNER,
PropertiesCodec(
unpack_singletons=False,
string_mappings=config_value_mappings
), requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
self.admin = self._build_admin_client()
self.status = RedisAppStatus(self.admin)
def _build_admin_client(self):
password = self.get_configuration_property('requirepass')
socket = self.get_configuration_property('unixsocket')
return RedisAdmin(password=password, unix_socket_path=socket)
def install_if_needed(self, packages):
"""
Install redis if needed do nothing if it is already installed.
"""
LOG.info(_('Preparing Guest as Redis Server.'))
if not packager.pkg_is_installed(packages):
LOG.info(_('Installing Redis.'))
self._install_redis(packages)
LOG.info(_('Redis installed completely.'))
def _install_redis(self, packages):
"""
Install the redis server.
"""
LOG.debug('Installing redis server.')
msg = "Creating %s." % system.REDIS_CONF_DIR
LOG.debug(msg)
operating_system.create_directory(system.REDIS_CONF_DIR, as_root=True)
pkg_opts = {}
packager.pkg_install(packages, pkg_opts, TIME_OUT)
self.start_db()
LOG.debug('Finished installing redis server.')
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
self.status.stop_db_service(
system.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(
system.SERVICE_CANDIDATES, self.state_change_wait_time)
def update_overrides(self, context, overrides, remove=False):
if overrides:
self.configuration_manager.apply_user_override(overrides)
def apply_overrides(self, client, overrides):
"""Use the 'CONFIG SET' command to apply configuration at runtime.
Commands that appear multiple times have values separated by a
white space. For instance, the following two 'save' directives from the
configuration file...
save 900 1
save 300 10
... would be applied in a single command as:
CONFIG SET save "900 1 300 10"
Note that the 'CONFIG' command has been renamed to prevent
users from using it to bypass configuration groups.
"""
for prop_name, prop_args in overrides.items():
args_string = self._join_lists(
self._value_converter.to_strings(prop_args), ' ')
client.config_set(prop_name, args_string)
def _join_lists(self, items, sep):
"""Join list items (including items from sub-lists) into a string.
Non-list inputs are returned unchanged.
#.........这里部分代码省略.........
开发者ID:bhaskarduvvuri,项目名称:trove,代码行数:101,代码来源:service.py
示例14: PgSqlApp
class PgSqlApp(object):
OS = operating_system.get_os()
LISTEN_ADDRESSES = ['*'] # Listen on all available IP (v4/v6) interfaces.
ADMIN_USER = 'os_admin' # Trove's administrative user.
def __init__(self):
super(PgSqlApp, self).__init__()
self._current_admin_user = None
self.status = PgSqlAppStatus(self.pgsql_extra_bin_dir)
revision_dir = guestagent_utils.build_file_path(
os.path.dirname(self.pgsql_config),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
self.configuration_manager = ConfigurationManager(
self.pgsql_config, self.pgsql_owner, self.pgsql_owner,
PropertiesCodec(
delimiter='=',
string_mappings={'on': True, 'off': False, "''": None}),
requires_root=True,
override_strategy=OneFileOverrideStrategy(revision_dir))
@property
def service_candidates(self):
return ['postgresql']
@property
def pgsql_owner(self):
return 'postgres'
@property
def default_superuser_name(self):
return "postgres"
@property
def pgsql_base_data_dir(self):
return '/var/lib/postgresql/'
@property
def pgsql_pid_file(self):
return guestagent_utils.build_file_path(self.pgsql_run_dir,
'postgresql.pid')
@property
def pgsql_run_dir(self):
return '/var/run/postgresql/'
@property
def pgsql_extra_bin_dir(self):
"""Redhat and Ubuntu packages for PgSql do not place 'extra' important
binaries in /usr/bin, but rather in a directory like /usr/pgsql-9.4/bin
in the case of PostgreSQL 9.4 for RHEL/CentOS
"""
return {
operating_system.DEBIAN: '/usr/lib/postgresql/%s/bin/',
operating_system.REDHAT: '/usr/pgsql-%s/bin/',
operating_system.SUSE: '/usr/bin/'
}[self.OS] % self.pg_version[1]
@property
def pgsql_config(self):
return self._find_config_file('postgresql.conf')
@property
def pgsql_hba_config(self):
return self._find_config_file('pg_hba.conf')
@property
def pgsql_ident_config(self):
return self._find_config_file('pg_ident.conf')
def _find_config_file(self, name_pattern):
version_base = guestagent_utils.build_file_path(self.pgsql_config_dir,
self.pg_version[1])
return sorted(operating_system.list_files_in_directory(
version_base, recursive=True, pattern=name_pattern,
as_root=True), key=len)[0]
@property
def pgsql_config_dir(self):
return {
operating_system.DEBIAN: '/etc/postgresql/',
operating_system.REDHAT: '/var/lib/postgresql/',
operating_system.SUSE: '/var/lib/pgsql/'
}[self.OS]
@property
def pgsql_log_dir(self):
return "/var/log/postgresql/"
def build_admin(self):
return PgSqlAdmin(self.get_current_admin_user())
def update_overrides(self, context, overrides, remove=False):
if remove:
self.configuration_manager.remove_user_override()
elif overrides:
self.configuration_manager.apply_user_override(overrides)
#.........这里部分代码省略.........
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:101,代码来源:service.py
示例15: _assert_get_value
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,代码行数:85,代码来源:test_configuration.py
示例16: VerticaApp
class VerticaApp(object):
"""Prepares DBaaS on a Guest container."""
def __init__(self, status):
self.state_change_wait_time = CONF.state_change_wait_time
self.status = status
revision_dir = \
guestagent_utils.build_file_path(
os.path.join(MOUNT_POINT,
os.path.dirname(system.VERTICA_ADMIN)),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
if not operating_system.exists(FAKE_CFG):
operating_system.write_file(FAKE_CFG, '', as_root=True)
operating_system.chown(FAKE_CFG, system.VERTICA_ADMIN,
system.VERTICA_ADMIN_GRP, as_root=True)
operating_system.chmod(FAKE_CFG, FileMode.ADD_GRP_RX_OTH_RX(),
as_root=True)
self.configuration_manager = \
ConfigurationManager(FAKE_CFG, system.VERTICA_ADMIN,
system.VERTICA_ADMIN_GRP,
PropertiesCodec(delimiter='='),
requires_root=True,
override_strategy=ImportOverrideStrategy(
revision_dir, "cnf"))
def update_overrides(self, context, overrides, remove=False):
if overrides:
self.apply_overrides(overrides)
def remove_overrides(self):
config = self.configuration_manager.get_user_override()
self._reset_config(config)
self.configuration_manager.remove_user_override()
def apply_overrides(self, overrides):
self.configuration_manager.apply_user_override(overrides)
self._apply_config(overrides)
def _reset_config(self, config):
try:
db_password = self._get_database_password()
for k, v in config.iteritems():
alter_db_cmd = system.ALTER_DB_RESET_CFG % (DB_NAME, str(k))
out, err = system.exec_vsql_command(db_password, alter_db_cmd)
if err:
if err.is_warning():
LOG.warning(err)
else:
LOG.error(err)
raise RuntimeError(_("Failed to remove config %s") % k)
except Exception:
LOG.exception(_("Vertica configuration remove failed."))
raise RuntimeError(_("Vertica configuration remove failed."))
LOG.info(_("Vertica configuration reset completed."))
def _apply_config(self, config):
try:
db_password = self._get_database_password()
for k, v in config.iteritems():
alter_db_cmd = system.ALTER_DB_CFG % (DB_NAME, str(k), str(v))
out, err = system.exec_vsql_command(db_password, alter_db_cmd)
if err:
if err.is_warning():
LOG.warning(err)
else:
LOG.error(err)
raise RuntimeError(_("Failed to apply config %s") % k)
except Exception:
LOG.exception(_("Vertica configuration apply failed"))
raise RuntimeError(_("Vertica configuration apply failed"))
LOG.info(_("Vertica config apply completed."))
def _enable_db_on_boot(self):
try:
command = ["sudo", "su", "-", system.VERTICA_ADMIN, "-c",
(system.SET_RESTART_POLICY % (DB_NAME, "always"))]
subprocess.Popen(command)
command = ["sudo", "su", "-", "root", "-c",
(system.VERTICA_AGENT_SERVICE_COMMAND % "enable")]
subprocess.Popen(command)
except Exception:
LOG.exception(_("Failed to enable db on boot."))
raise RuntimeError("Could not enable db on boot.")
def _disable_db_on_boot(self):
try:
command = (system.SET_RESTART_POLICY % (DB_NAME, "never"))
system.shell_execute(command, system.VERTICA_ADMIN)
command = (system.VERTICA_AGENT_SERVICE_COMMAND % "disable")
system.shell_execute(command)
except exceptio
|
请发表评论