本文整理汇总了Python中scalarizr.libs.metaconf.Configuration类的典型用法代码示例。如果您正苦于以下问题:Python Configuration类的具体用法?Python Configuration怎么用?Python Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_path_option
def _test_path_option(self, option):
self.assertRaises(ValueError, setattr, self.cnf, option, '/not/exists')
setattr(self.cnf, option, '/tmp')
c = Configuration('mongodb')
c.read(self.cnf_path)
self.assertEqual('/tmp', c.get(option))
self.assertEqual('/tmp', getattr(self.cnf, option))
示例2: Cassandra
class Cassandra(object):
def __init__(self):
self._logger = logging.getLogger(__name__)
self._initd = initdv2.lookup(SERVICE_NAME)
bus.on(reload=self.on_reload)
self.on_reload()
def on_reload(self):
self.queryenv = bus.queryenv_service
self.platform = bus.platform
self.private_ip = self.platform.get_private_ip()
self.zone = self.platform.get_avail_zone()
cnf = bus.cnf
self.ini = cnf.rawini
self.role_name = self.ini.get(config.SECT_GENERAL, config.OPT_ROLE_NAME)
self.storage_path = self.ini.get(CNF_SECTION, OPT_STORAGE_PATH)
self.storage_conf_path = self.ini.get(CNF_SECTION, OPT_STORAGE_CNF_PATH)
self.data_file_directory = self.storage_path + "/datafile"
self.commit_log_directory = self.storage_path + "/commitlog"
self.cassandra_conf = Configuration('xml')
try:
self.cassandra_conf.read(self.storage_conf_path)
except (OSError, MetaconfError, ParseError), e:
self._logger.error('Cassandra storage-conf.xml is broken. %s' % e)
示例3: get_system_variables
def get_system_variables(self):
#TESTING REQUIRED!
conf = Configuration(self._config_format)
conf.read(self._config_path)
vars = {}
for section in conf.sections('./'):
vars[section] = conf.get(section)
return vars
示例4: __init__
def __init__(self, body):
config = Configuration("apache")
try:
config.reads(str(body))
except ParseError, e:
LOG.error("MetaConf failed to parse Apache VirtualHost body: \n%s" % body)
e._err = body + "\n" + e._err
raise
示例5: _update_main_config
def _update_main_config(self, remove_server_section=True, reload_service=True):
config_dir = os.path.dirname(self.api.app_inc_path)
nginx_conf_path = os.path.join(config_dir, 'nginx.conf')
config = None
try:
config = Configuration('nginx')
config.read(nginx_conf_path)
except (Exception, BaseException), e:
raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
示例6: _https_config_exists
def _https_config_exists(self):
config_dir = os.path.dirname(self.api.app_inc_path)
conf_path = os.path.join(config_dir, 'https.include')
config = None
try:
config = Configuration('nginx')
config.read(conf_path)
except (Exception, BaseException), e:
raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
示例7: _main_config_contains_server
def _main_config_contains_server(self):
config_dir = os.path.dirname(self.api.app_inc_path)
nginx_conf_path = os.path.join(config_dir, 'nginx.conf')
config = None
result = False
try:
config = Configuration('nginx')
config.read(nginx_conf_path)
except (Exception, BaseException), e:
raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
示例8: load
def load(self, preset_type):
'''
@rtype: Preset
@raise OSError: When cannot read preset file
@raise MetaconfError: When experience problems with preset file parsing
'''
self._logger.debug('Loading %s %s preset' % (preset_type, self.service_name))
ini = Configuration('ini')
ini.read(self._filename(preset_type))
return CnfPreset(ini.get('general/name'), dict(ini.items('settings/')))
示例9: __init__
def __init__(self, manifest_path):
self._options = []
ini = Configuration('ini')
ini.read(manifest_path)
try:
self._defaults = dict(ini.items('__defaults__'))
except NoPathError:
self._defaults = dict()
for name in ini.sections("./"):
if name == '__defaults__':
continue
self._options.append(_OptionSpec.from_ini(ini, name, self._defaults))
示例10: ApacheConfigManager
class ApacheConfigManager(object):
_cnf = None
path = None
def __init__(self, path):
self._cnf = Configuration("apache")
self.path = path
def __enter__(self):
self._cnf.read(self.path)
return self._cnf
def __exit__(self, type, value, traceback):
self._cnf.write(self.path)
示例11: download_and_restore
def download_and_restore(self, volume, snapshot, tranzit_path):
# Load manifest
clear_queue(self._writer_queue)
clear_queue(self._download_queue)
self._download_finished.clear()
transfer = self._transfer_cls()
mnf_path = transfer.download(snapshot.path, tranzit_path)
mnf = Configuration('ini')
mnf.read(mnf_path)
volume.fs_created = False
volume.mkfs(snapshot.fstype)
remote_path = os.path.dirname(snapshot.path)
# Get links with md5 sums
links = [(os.path.join(remote_path, chunk[0]), chunk[1]) for chunk in mnf.items('chunks')]
links.sort()
# Download 2 first chunks
for link in links[:2]:
transfer.download(link[0], tranzit_path)
chunk_path = os.path.join(tranzit_path, os.path.basename(link[0]))
if self._md5sum(chunk_path) != link[1]:
raise Exception("md5sum of chunk %s is not correct." % chunk_path)
self._writer_queue.put(chunk_path)
if hasattr(snapshot, 'snap_strategy') and snapshot.snap_strategy == 'data':
restore_strategy = DataRestoreStrategy(self._logger)
else:
restore_strategy = DeviceRestoreStrategy(self._logger)
writer = threading.Thread(target=restore_strategy.restore, name='writer',
args=(self._writer_queue, volume, self._download_finished))
writer.start()
# Add remaining files to download queue
for link in links[2:]:
self._download_queue.put(link)
downloader = threading.Thread(name="Downloader", target=self._downloader,
args=(tranzit_path,))
downloader.start()
downloader.join()
writer.join()
示例12: _manifest
def _manifest(self):
f_manifest = CnfController._manifest
base_manifest = f_manifest.fget(self)
path = self._manifest_path
s = {}
out = None
if not self._merged_manifest:
cmd = '%s --no-defaults --verbose SU_EXEC' % mysql_svc.MYSQLD_PATH
out = system2('%s - mysql -s %s -c "%s"' % (SU_EXEC, BASH, cmd),
shell=True, raise_exc=False, silent=True)[0]
if out:
raw = out.split(49*'-'+' '+24*'-')
if raw:
a = raw[-1].split('\n')
if len(a) > 5:
b = a[1:-5]
for item in b:
c = item.split()
if len(c) > 1:
key = c[0]
val = ' '.join(c[1:])
s[key.strip()] = val.strip()
if s:
m_config = Configuration('ini')
if os.path.exists(path):
m_config.read(path)
for variable in base_manifest:
name = variable.name
dv_path = './%s/default-value' % name
try:
old_value = m_config.get(dv_path)
if name in s:
new_value = s[name]
else:
name = name.replace('_','-')
if name in s:
new_value = self.definitions[s[name]] if s[name] in self.definitions else s[name]
if old_value != new_value and new_value != '(No default value)':
LOG.debug('Replacing %s default value %s with precompiled value %s',
name, old_value, new_value)
m_config.set(path=dv_path, value=new_value, force=True)
except NoPathError:
pass
m_config.write(path)
self._merged_manifest = _CnfManifest(path)
return self._merged_manifest
示例13: _test_option
def _test_option(self, option):
setattr(self.cnf, option, 'value')
c = Configuration('mongodb')
c.read(self.cnf_path)
self.assertEqual('value', c.get(option))
setattr(self.cnf, option, None)
c = Configuration('mongodb')
c.read(self.cnf_path)
self.assertRaises(NoPathError, c.get, option)
示例14: set
def set(self, option, value):
if not self.data:
self.data = Configuration(self.config_type)
if os.path.exists(self.path):
self.data.read(self.path)
if value:
self.data.set(option, value, force=True)
else:
self.data.remove(option)
if self.autosave:
self.save_data()
self.data = None
示例15: set
def set(self, option, value):
if not self.data:
self.data = Configuration(self.config_type)
if os.path.exists(self.path):
self.data.read(self.path)
if value:
self.data.set(option,str(value), force=True)
elif self.comment_empty:
self.data.comment(option)
if self.autosave:
self.save_data()
self.data = None