本文整理汇总了Python中barman.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_config_from_dicts
def build_config_from_dicts(global_conf=None, main_conf=None,
test_conf=None,
config_name=None):
"""
Utility method, generate a barman.config.Config object
It has a minimal configuration and a single server called "main".
All options can be override using the optional arguments
:param dict[str,str|None]|None global_conf: using this dictionary
it is possible to override or add new values to the [barman] section
:param dict[str,str|None]|None main_conf: using this dictionary
it is possible to override/add new values to the [main] section
:return barman.config.Config: a barman configuration object
"""
# base barman section
base_barman = {
'barman_home': '/some/barman/home',
'barman_user': '{USER}',
'log_file': '%(barman_home)s/log/barman.log',
'archiver': True
}
# base main section
base_main = {
'description': '" Text with quotes "',
'ssh_command': 'ssh -c "arcfour" -p 22 [email protected]',
'conninfo': 'host=pg01.nowhere user=postgres port=5432'
}
# base test section
base_test = {
'description': '" Text with quotes "',
'ssh_command': 'ssh -c "arcfour" -p 22 [email protected]',
'conninfo': 'host=pg02.nowhere user=postgres port=5433'
}
# update map values of the two sections
if global_conf is not None:
base_barman.update(global_conf)
if main_conf is not None:
base_main.update(main_conf)
if test_conf is not None:
base_test.update(test_conf)
# writing the StringIO obj with the barman and main sections
config_file = StringIO()
config_file.write('\n[barman]\n')
for key in base_barman.keys():
config_file.write('%s = %s\n' % (key, base_barman[key]))
config_file.write('[main]\n')
for key in base_main.keys():
config_file.write('%s = %s\n' % (key, base_main[key]))
config_file.write('[test]\n')
for key in base_test.keys():
config_file.write('%s = %s\n' % (key, base_main[key]))
config_file.seek(0)
config = Config(config_file)
config.config_file = config_name or 'build_config_from_dicts'
return config
示例2: test_interpolation
def test_interpolation(self):
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
expected = dict(config=c)
expected.update(MINIMAL_CONFIG_MAIN)
assert main.__dict__ == expected
示例3: test_server_list
def test_server_list(self):
"""
Test parsing of a config file
"""
fp = StringIO(TEST_CONFIG.format(**os.environ))
c = Config(fp)
dbs = c.server_names()
assert set(dbs) == set(['main', 'web'])
示例4: test_interpolation
def test_interpolation(self):
self.maxDiff = None
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
expected = dict(config=c)
expected.update(MINIMAL_CONFIG_MAIN)
self.assertEqual(main.__dict__,expected)
示例5: test_interpolation
def test_interpolation(self):
self.maxDiff = None
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
self.assertEqual(main.__dict__,
dict(MINIMAL_CONFIG_MAIN.items() +
[('config',c)]))
示例6: test_quotes
def test_quotes(self):
"""
Test quotes management during configuration parsing
"""
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
assert main.description == ' Text with quotes '
assert main.ssh_command == 'ssh -c "arcfour" ' \
'-p 22 [email protected]'
示例7: test_interpolation
def test_interpolation(self):
"""
Basic interpolation test
"""
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
# create the expected dictionary
expected = build_config_dictionary({'config': main.config})
assert main.__dict__ == expected
示例8: test_config
def test_config(self):
fp = StringIO(TEST_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
expected = dict(config=c)
expected.update(TEST_CONFIG_MAIN)
assert main.__dict__ == expected
web = c.get_server('web')
expected = dict(config=c)
expected.update(TEST_CONFIG_WEB)
assert web.__dict__ == expected
示例9: test_config
def test_config(self):
"""
Test for a basic configuration object construction
"""
fp = StringIO(TEST_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
# create the expected dictionary
expected = build_config_dictionary({
'config': main.config,
'compression': 'gzip',
'last_backup_maximum_age': timedelta(1),
'last_backup_minimum_size': 1048576,
'last_wal_maximum_age': timedelta(hours=1),
'retention_policy': 'redundancy 3',
'reuse_backup': 'link',
'description': 'Main PostgreSQL Database',
'ssh_command': 'ssh -c arcfour -p 22 [email protected]',
'wal_retention_policy': 'base',
'custom_compression_filter': 'bzip2 -c -9',
'wals_directory': 'wals',
'custom_decompression_filter': 'bzip2 -c -d'
})
assert main.__dict__ == expected
web = c.get_server('web')
# create the expected dictionary
expected = build_config_dictionary({
'config': web.config,
'backup_directory': '/some/barman/home/web',
'basebackups_directory': '/some/barman/home/web/base',
'compression': None,
'conninfo': 'host=web01 user=postgres port=5432',
'description': 'Web applications database',
'incoming_wals_directory': '/some/barman/home/web/incoming',
'name': 'web',
'reuse_backup': None,
'retention_policy': 'redundancy 2',
'wals_directory': '/some/barman/home/web/wals',
'wal_retention_policy': 'base',
'last_backup_maximum_age': timedelta(1),
'last_backup_minimum_size': 1048576,
'last_wal_maximum_age': timedelta(hours=1),
'ssh_command': 'ssh -I ~/.ssh/web01_rsa -c arcfour '
'-p 22 [email protected]',
'streaming_conninfo': 'host=web01 user=postgres port=5432',
'streaming_wals_directory': '/some/barman/home/web/streaming',
'errors_directory': '/some/barman/home/web/errors',
})
assert web.__dict__ == expected
示例10: main
def main():
parser = argparse.ArgumentParser(description="Barman plugin for NRPE.")
parser.add_argument("-s", "--server", dest="server",
help="server to check")
parser.add_argument('-w', '--warning', type=int, dest="warning",
metavar="W", help="warning threshold.")
parser.add_argument('-c', '--critical', type=int, dest="critical",
metavar="C", help="critical threshold.")
parser.add_argument('-u' '--user', dest='user', metavar='U',
help="user needed to run this script. If the "
"current user is not this one, the script will try " +
"to rerun itself using sudo.")
subparsers = parser.add_subparsers()
for key, value in ACTIONS.items():
(action, help) = value
subparser = subparsers.add_parser(key, help=help)
subparser.set_defaults(action=action)
parser.error = unknown
args = parser.parse_args()
user = pwd.getpwuid(os.getuid())[0]
if args.user and user != args.user:
import subprocess
retval = subprocess.call(["/usr/bin/sudo", "-u", args.user] + sys.argv)
raise SystemExit(retval)
from barman.config import Config
from barman.server import Server
config = Config()
config.load_configuration_files_directory()
server = Server(config.get_server(args.server))
try:
args.action(server, args)
except KeyError:
unknown("The action %s does not exist." % args.action)
示例11: test_quotes
def test_quotes(self):
fp = StringIO(MINIMAL_CONFIG.format(**os.environ))
c = Config(fp)
main = c.get_server('main')
assert main.description == ' Text with quotes '
assert main.ssh_command == 'ssh -c "arcfour" -p 22 [email protected]'
示例12: test_server_list
def test_server_list(self):
fp = StringIO(TEST_CONFIG.format(**os.environ))
c = Config(fp)
dbs = c.server_names()
self.assertEqual(set(dbs), set(['main', 'web']))