本文整理汇总了Python中salt.config.master_config函数的典型用法代码示例。如果您正苦于以下问题:Python master_config函数的具体用法?Python master_config怎么用?Python master_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了master_config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_load_master_config_from_environ_var
def test_load_master_config_from_environ_var(self):
original_environ = os.environ.copy()
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
try:
env_root_dir = os.path.join(tempdir, "foo", "env")
os.makedirs(env_root_dir)
env_fpath = os.path.join(env_root_dir, "config-env")
salt.utils.fopen(env_fpath, "w").write("root_dir: {0}\n" "log_file: {1}\n".format(env_root_dir, env_fpath))
os.environ["SALT_MASTER_CONFIG"] = env_fpath
# Should load from env variable, not the default configuration file.
config = sconfig.master_config("/etc/salt/master")
self.assertEqual(config["log_file"], env_fpath)
os.environ.clear()
os.environ.update(original_environ)
root_dir = os.path.join(tempdir, "foo", "bar")
os.makedirs(root_dir)
fpath = os.path.join(root_dir, "config")
salt.utils.fopen(fpath, "w").write("root_dir: {0}\n" "log_file: {1}\n".format(root_dir, fpath))
# Let's set the environment variable, yet, since the configuration
# file path is not the default one, ie, the user has passed an
# alternative configuration file form the CLI parser, the
# environment variable will be ignored.
os.environ["SALT_MASTER_CONFIG"] = env_fpath
config = sconfig.master_config(fpath)
self.assertEqual(config["log_file"], fpath)
os.environ.clear()
os.environ.update(original_environ)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:joehealy,项目名称:pkg-salt,代码行数:35,代码来源:config_test.py
示例2: setup_config
def setup_config(self):
opts = config.master_config(self.get_config_file_path('master'))
user = opts.get('user', 'root')
opts['_minion_conf_file'] = opts['conf_file']
opts.update(config.minion_config(self.get_config_file_path('minion')))
# Over ride the user from the master config file
opts['user'] = user
if 'syndic_master' not in opts:
self.error(
"The syndic_master needs to be configured in the salt master "
"config, EXITING!"
)
from salt import utils
# Some of the opts need to be changed to match the needed opts
# in the minion class.
opts['master'] = opts['syndic_master']
opts['master_ip'] = utils.dns_check(opts['master'])
opts['master_uri'] = 'tcp://{0}:{1}'.format(
opts['master_ip'], str(opts['master_port'])
)
opts['_master_conf_file'] = opts['conf_file']
opts.pop('conf_file')
return opts
开发者ID:11craft,项目名称:salt,代码行数:26,代码来源:parsers.py
示例3: test_issue_6714_parsing_errors_logged
def test_issue_6714_parsing_errors_logged(self):
try:
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
test_config = os.path.join(tempdir, 'config')
# Let's populate a master configuration file with some basic
# settings
salt.utils.fopen(test_config, 'w').write(
'root_dir: {0}\n'
'log_file: {0}/foo.log\n'.format(tempdir) +
'\n\n\n'
'blah:false\n'
)
with TestsLoggingHandler() as handler:
# Let's load the configuration
config = sconfig.master_config(test_config)
for message in handler.messages:
if message.startswith('ERROR:Error parsing configuration'):
break
else:
raise AssertionError(
'No parsing error message was logged'
)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:AccelerationNet,项目名称:salt,代码行数:27,代码来源:config_test.py
示例4: test_master_confd_inclusion
def test_master_confd_inclusion(self):
try:
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
master_config = os.path.join(tempdir, 'master')
master_confd = os.path.join(tempdir, 'master.d')
os.makedirs(master_confd)
# Let's populate a master configuration file with some basic
# settings
salt.utils.fopen(master_config, 'w').write(
'blah: false\n'
'root_dir: {0}\n'
'log_file: {1}\n'.format(tempdir, master_config)
)
# Now, let's populate an extra configuration file under master.d
# Notice that above we've set blah as False and bellow as True.
# Since the master.d files are loaded after the main configuration
# file so overrides can happen, the final value of blah should be
# True.
extra_config = os.path.join(master_confd, 'extra.conf')
salt.utils.fopen(extra_config, 'w').write(
'blah: true\n'
)
# Let's load the configuration
config = sconfig.master_config(master_config)
self.assertEqual(config['log_file'], master_config)
# As proven by the assertion below, blah is True
self.assertTrue(config['blah'])
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:AccelerationNet,项目名称:salt,代码行数:34,代码来源:config_test.py
示例5: __init__
def __init__(self,main_config):
self.opts=master_config(main_config)
self.wheel=Wheel(self.opts)
self.client=LocalClient()
self.connected_minions_list=self.wheel.call_func('minions.connected')
self.key_dict=self.wheel.call_func('key.list_all')
self.total=len(self.key_dict['minions'])+len(self.key_dict['minions_pre'])+len(self.key_dict['minions_denied'])+len(self.key_dict['minions_rejected'])
开发者ID:Coffe2Cat,项目名称:OpsSystem,代码行数:7,代码来源:utils.py
示例6: _master_opts
def _master_opts(cfg='master'):
cfg = os.environ.get(
'SALT_MASTER_CONFIG',
__opts__.get('conf_file',
os.path.join(salt.syspaths.CONFIG_DIR, cfg)))
opts = config.master_config(cfg)
return opts
开发者ID:AccelerationNet,项目名称:salt,代码行数:7,代码来源:lxc.py
示例7: _get_local_grains
def _get_local_grains():
"""
Return the salt grains for this host that we are running
on. If we support SELinux in the future this may need
to be moved into a cthulhu RPC as the apache worker may
not have the right capabilities to query all the grains.
"""
# Stash grains as an attribute of this function
if not hasattr(_get_local_grains, 'grains'):
# >> work around salt issue #11402
import __main__ as main
main.__file__ = 'workaround'
# <<
# Use salt to get an interesting subset of the salt grains (getting
# everything is a bit slow)
grains = {}
c = master_config(config.get('cthulhu', 'salt_config_path'))
l = _create_loader(c, 'grains', 'grain')
funcs = l.gen_functions()
for key in [k for k in funcs.keys() if k.startswith('core.')]:
ret = funcs[key]()
if isinstance(ret, dict):
grains.update(ret)
_get_local_grains.grains = grains
else:
grains = _get_local_grains.grains
return grains
开发者ID:abonas,项目名称:calamari,代码行数:30,代码来源:v1.py
示例8: setup_config
def setup_config(self):
keys_config = config.master_config(self.get_config_file_path('master'))
if self.options.gen_keys:
# Since we're generating the keys, some defaults can be assumed
# or tweaked
keys_config['key_logfile'] = os.devnull
keys_config['pki_dir'] = self.options.gen_keys_dir
return keys_config
开发者ID:tristanhands,项目名称:salt,代码行数:9,代码来源:parsers.py
示例9: _master_opts
def _master_opts(cfg='master'):
if 'conf_file' in __opts__:
default_dir = os.path.dirname(__opts__['conf_file'])
else:
default_dir = __opts__['config_dir'],
cfg = os.environ.get(
'SALT_MASTER_CONFIG', os.path.join(default_dir, cfg))
opts = config.master_config(cfg)
return opts
开发者ID:bryson,项目名称:salt,代码行数:9,代码来源:lxc.py
示例10: test_load_client_config_from_environ_var
def test_load_client_config_from_environ_var(self):
original_environ = os.environ.copy()
try:
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
env_root_dir = os.path.join(tempdir, 'foo', 'env')
os.makedirs(env_root_dir)
# Let's populate a master configuration file which should not get
# picked up since the client configuration tries to load the master
# configuration settings using the provided client configuration
# file
master_config = os.path.join(env_root_dir, 'master')
with salt.utils.fopen(master_config, 'w') as fp_:
fp_.write(
'blah: true\n'
'root_dir: {0}\n'
'log_file: {1}\n'.format(env_root_dir, master_config)
)
os.environ['SALT_MASTER_CONFIG'] = master_config
# Now the client configuration file
env_fpath = os.path.join(env_root_dir, 'config-env')
with salt.utils.fopen(env_fpath, 'w') as fp_:
fp_.write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(env_root_dir, env_fpath)
)
os.environ['SALT_CLIENT_CONFIG'] = env_fpath
# Should load from env variable, not the default configuration file
config = sconfig.client_config(os.path.expanduser('~/.salt'))
self.assertEqual(config['log_file'], env_fpath)
self.assertTrue('blah' not in config)
os.environ.clear()
os.environ.update(original_environ)
root_dir = os.path.join(tempdir, 'foo', 'bar')
os.makedirs(root_dir)
fpath = os.path.join(root_dir, 'config')
with salt.utils.fopen(fpath, 'w') as fp_:
fp_.write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(root_dir, fpath)
)
# Let's set the environment variable, yet, since the configuration
# file path is not the default one, i.e., the user has passed an
# alternative configuration file form the CLI parser, the
# environment variable will be ignored.
os.environ['SALT_MASTER_CONFIG'] = env_fpath
config = sconfig.master_config(fpath)
self.assertEqual(config['log_file'], fpath)
os.environ.clear()
os.environ.update(original_environ)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:bryson,项目名称:salt,代码行数:57,代码来源:config_test.py
示例11: test_load_master_config_from_environ_var
def test_load_master_config_from_environ_var(self):
original_environ = os.environ.copy()
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
try:
env_root_dir = os.path.join(tempdir, 'foo', 'env')
os.makedirs(env_root_dir)
env_fpath = os.path.join(env_root_dir, 'config-env')
with salt.utils.fopen(env_fpath, 'w') as fp_:
fp_.write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(env_root_dir, env_fpath)
)
os.environ['SALT_MASTER_CONFIG'] = env_fpath
# Should load from env variable, not the default configuration file.
config = sconfig.master_config('/etc/salt/master')
self.assertEqual(config['log_file'], env_fpath)
os.environ.clear()
os.environ.update(original_environ)
root_dir = os.path.join(tempdir, 'foo', 'bar')
os.makedirs(root_dir)
fpath = os.path.join(root_dir, 'config')
with salt.utils.fopen(fpath, 'w') as fp_:
fp_.write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(root_dir, fpath)
)
# Let's set the environment variable, yet, since the configuration
# file path is not the default one, i.e., the user has passed an
# alternative configuration file form the CLI parser, the
# environment variable will be ignored.
os.environ['SALT_MASTER_CONFIG'] = env_fpath
config = sconfig.master_config(fpath)
self.assertEqual(config['log_file'], fpath)
os.environ.clear()
os.environ.update(original_environ)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:bryson,项目名称:salt,代码行数:43,代码来源:config_test.py
示例12: test_proper_path_joining
def test_proper_path_joining(self):
fpath = tempfile.mktemp()
open(fpath, 'w').write(
"root_dir: /\n"
"key_logfile: key\n"
)
config = sconfig.master_config(fpath)
# os.path.join behaviour
self.assertEqual(config['key_logfile'], os.path.join('/', 'key'))
# os.sep.join behaviour
self.assertNotEqual(config['key_logfile'], '//key')
开发者ID:conceptho,项目名称:salt,代码行数:11,代码来源:config_test.py
示例13: enable
def enable(container):
with open('/tmpwat', 'w') as what:
print('what', file=what)
config = sac.cloud_config('/etc/salt/cloud')
master = sac.master_config('/etc/salt/master')
api_key = config['providers']['my-nova']['nova']['api_key']
ident = config['providers']['my-nova']['nova']['identity_url']
tenant = config['providers']['my-nova']['nova']['tenant']
user = config['providers']['my-nova']['nova']['user']
region = config['providers']['my-nova']['nova']['compute_region']
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
payload={
"auth": {
"RAX-KSKEY:apiKeyCredentials": {
"username": user,
"apiKey": api_key
}
}
}
identity = requests.post(os.path.join(ident, 'tokens'), data=json.dumps(payload), headers=headers).json().get('access', {})
headers['X-Auth-Token'] = identity['token']['id']
catalog = identity['serviceCatalog']
endpoint = _get_endpoint('object-store', region, catalog)
cdnendpoint = _get_endpoint('rax:object-cdn', region, catalog)
containers = requests.get(endpoint, headers=headers).json()
cont = None
for c in containers:
if c['name'] == container:
cont = c
log.debug('Container: \n{0}'.format(pprint.pformat(cont)))
log.debug('Container: \n{0}'.format(pprint.pformat(headers)))
log.debug('Container: \n{0}'.format(pprint.pformat(endpoint)))
break
if cont is None:
log.debug("Container doesn't exist: {0}".format(container))
return False
headers['X-Ttl'] = 900
headers['X-Cdn-Enabled'] = 'True'
ret = requests.put('{0}/{1}'.format(cdnendpoint, container), headers=headers)
if ret.status_code == 201:
return True
elif ret.status_code == 202:
log.debug('Container already enabled: {0}'.format(container))
return None
else:
log.debug('Failed to enable container: {0}'.format(container))
return False
开发者ID:gtmanfred,项目名称:servermill,代码行数:54,代码来源:cloudfiles.py
示例14: test_common_prefix_stripping
def test_common_prefix_stripping(self):
tempdir = tempfile.mkdtemp()
root_dir = os.path.join(tempdir, 'foo', 'bar')
os.makedirs(root_dir)
fpath = os.path.join(root_dir, 'config')
salt.utils.fopen(fpath, 'w').write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(root_dir, fpath)
)
config = sconfig.master_config(fpath)
self.assertEqual(config['log_file'], fpath)
shutil.rmtree(tempdir)
开发者ID:gspradeep,项目名称:salt,代码行数:12,代码来源:config_test.py
示例15: test_proper_path_joining
def test_proper_path_joining(self):
fpath = tempfile.mktemp()
try:
salt.utils.fopen(fpath, "w").write("root_dir: /\n" "key_logfile: key\n")
config = sconfig.master_config(fpath)
# os.path.join behaviour
self.assertEqual(config["key_logfile"], os.path.join("/", "key"))
# os.sep.join behaviour
self.assertNotEqual(config["key_logfile"], "//key")
finally:
if os.path.isfile(fpath):
os.unlink(fpath)
开发者ID:joehealy,项目名称:pkg-salt,代码行数:12,代码来源:config_test.py
示例16: test_common_prefix_stripping
def test_common_prefix_stripping(self):
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
try:
root_dir = os.path.join(tempdir, "foo", "bar")
os.makedirs(root_dir)
fpath = os.path.join(root_dir, "config")
salt.utils.fopen(fpath, "w").write("root_dir: {0}\n" "log_file: {1}\n".format(root_dir, fpath))
config = sconfig.master_config(fpath)
self.assertEqual(config["log_file"], fpath)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:joehealy,项目名称:pkg-salt,代码行数:12,代码来源:config_test.py
示例17: test_sha256_is_default_for_master
def test_sha256_is_default_for_master(self):
fpath = tempfile.mktemp()
try:
salt.utils.fopen(fpath, 'w').write(
"root_dir: /\n"
"key_logfile: key\n"
)
config = sconfig.master_config(fpath)
self.assertEqual(config['hash_type'], 'sha256')
finally:
if os.path.isfile(fpath):
os.unlink(fpath)
开发者ID:bryson,项目名称:salt,代码行数:12,代码来源:config_test.py
示例18: test_proper_path_joining
def test_proper_path_joining(self):
fpath = tempfile.mktemp()
try:
with salt.utils.fopen(fpath, 'w') as fp_:
fp_.write(
'root_dir: /\n'
'key_logfile: key\n'
)
config = sconfig.master_config(fpath)
# os.path.join behavior
self.assertEqual(config['key_logfile'], os.path.join('/', 'key'))
# os.sep.join behavior
self.assertNotEqual(config['key_logfile'], '//key')
finally:
if os.path.isfile(fpath):
os.unlink(fpath)
开发者ID:bryson,项目名称:salt,代码行数:16,代码来源:config_test.py
示例19: test_common_prefix_stripping
def test_common_prefix_stripping(self):
tempdir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
try:
root_dir = os.path.join(tempdir, 'foo', 'bar')
os.makedirs(root_dir)
fpath = os.path.join(root_dir, 'config')
with salt.utils.fopen(fpath, 'w') as fp_:
fp_.write(
'root_dir: {0}\n'
'log_file: {1}\n'.format(root_dir, fpath)
)
config = sconfig.master_config(fpath)
self.assertEqual(config['log_file'], fpath)
finally:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
开发者ID:bryson,项目名称:salt,代码行数:16,代码来源:config_test.py
示例20: delete
def delete():
config = sac.cloud_config('/etc/salt/cloud')
master = sac.master_config('/etc/salt/master')
api_key = config['providers']['my-nova']['nova']['api_key']
ident = config['providers']['my-nova']['nova']['identity_url']
tenant = config['providers']['my-nova']['nova']['tenant']
user = config['providers']['my-nova']['nova']['user']
region = config['providers']['my-nova']['nova']['compute_region']
loadbalancer = master['loadbalancer']['name']
port = master['loadbalancer']['port']
lbendpoint = 'https://{0}.loadbalancers.api.rackspacecloud.com/v1.0/{1}'.format(region, tenant)
headers = {
'Content-Type': 'application/json'
}
payload={
"auth": {
"RAX-KSKEY:apiKeyCredentials": {
"username": user,
"apiKey": api_key
}
}
}
ret = requests.post(os.path.join(ident, 'tokens'), data=json.dumps(payload), headers=headers).json()
headers['X-Auth-Token'] = ret['access']['token']['id']
loadbalancers = requests.get('{0}/loadbalancers'.format(lbendpoint), headers=headers).json().get('loadBalancers', {})
lb = None
for l in loadbalancers:
if l['name'] == loadbalancer:
lb = l
if lb is None:
log.debug("Loadbalancer doesn't exist: {0}".format(loadbalancer))
return False
if _wait_for_loadbalancer(lb['id'], lbendpoint, headers):
ret = requests.delete('{0}/loadbalancers/{1}'.format(lbendpoint, lb['id']), headers=headers)
else:
log.debug("Loadbalancer stuck not in Active: {0}".format(loadbalancer))
return False
if ret.status_code == 202:
return True
else:
return False
开发者ID:gtmanfred,项目名称:servermill,代码行数:45,代码来源:loadbalancer.py
注:本文中的salt.config.master_config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论