本文整理汇总了Python中salt.utils.verify.verify_files函数的典型用法代码示例。如果您正苦于以下问题:Python verify_files函数的具体用法?Python verify_files怎么用?Python verify_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了verify_files函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: prepare
def prepare(self):
'''
Run the preparation sequence required to start a salt-api daemon.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).prepare()
'''
super(SaltAPI, self).prepare()
try:
if self.config['verify_env']:
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
current_umask = os.umask(0o027)
verify_files([logfile], self.config['user'])
os.umask(current_umask)
except OSError as err:
log.exception('Failed to prepare salt environment')
self.shutdown(err.errno)
self.setup_logfile_logger()
verify_log(self.config)
log.info('Setting up the Salt API')
self.api = salt.client.netapi.NetapiClient(self.config)
self.daemonize_if_required()
self.set_pidfile()
开发者ID:HowardMei,项目名称:saltstack,代码行数:30,代码来源:api.py
示例2: run
def run(self):
'''
Execute salt-key
'''
self.parse_args()
if self.config['verify_env']:
verify_env_dirs = []
if not self.config['gen_keys']:
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
os.path.join(self.config['pki_dir'], 'minions_pre'),
os.path.join(self.config['pki_dir'], 'minions_rejected'),
])
verify_env(
verify_env_dirs,
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if (not self.config['key_logfile'].startswith('tcp://') or
not self.config['key_logfile'].startswith('udp://') or
not self.config['key_logfile'].startswith('file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['key_logfile']],
self.config['user']
)
self.setup_logfile_logger()
key = salt.key.KeyCLI(self.config)
key.run()
开发者ID:sitepoint,项目名称:salt,代码行数:35,代码来源:__init__.py
示例3: run
def run(self):
"""
Execute salt-run
"""
self.parse_args()
if self.config["verify_env"]:
verify_env(
[self.config["pki_dir"], self.config["cachedir"]],
self.config["user"],
permissive=self.config["permissive_pki_access"],
pki_dir=self.config["pki_dir"],
)
if not self.config["log_file"].startswith(("tcp://", "udp://", "file://")):
# Logfile is not using Syslog, verify
verify_files([self.config["log_file"]], self.config["user"])
# Setup file logging!
self.setup_logfile_logger()
runner = salt.runner.Runner(self.config)
if self.options.doc:
runner._print_docs()
self.exit(salt.exitcodes.EX_OK)
# Run this here so SystemExit isn't raised anywhere else when
# someone tries to use the runners via the python API
try:
if check_user(self.config["user"]):
runner.run()
except SaltClientError as exc:
raise SystemExit(str(exc))
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:32,代码来源:__init__.py
示例4: prepare
def prepare(self):
'''
Run the preparation sequence required to start a salt master server.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).prepare()
'''
self.parse_args()
try:
if self.config['verify_env']:
verify_env(
[
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
os.path.join(self.config['pki_dir'], 'minions_pre'),
os.path.join(self.config['pki_dir'],
'minions_rejected'),
self.config['cachedir'],
os.path.join(self.config['cachedir'], 'jobs'),
os.path.join(self.config['cachedir'], 'proc'),
self.config['sock_dir'],
self.config['token_dir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files([logfile], self.config['user'])
except OSError as err:
sys.exit(err.errno)
self.setup_logfile_logger()
logger.info('Setting up the Salt Master')
if not verify_socket(self.config['interface'],
self.config['publish_port'],
self.config['ret_port']):
self.exit(4, 'The ports are not available to bind\n')
self.config['interface'] = ip_bracket(self.config['interface'])
migrations.migrate_paths(self.config)
# Late import so logging works correctly
import salt.master
self.master = salt.master.Master(self.config)
self.daemonize_if_required()
self.set_pidfile()
开发者ID:1mentat,项目名称:salt,代码行数:53,代码来源:__init__.py
示例5: run
def run(self):
'''
Execute the salt call!
'''
self.parse_args()
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
self.config['cachedir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
if self.options.file_root:
# check if the argument is pointing to a file on disk
file_root = os.path.abspath(self.options.file_root)
self.config['file_roots'] = {'base': [file_root]}
if self.options.pillar_root:
# check if the argument is pointing to a file on disk
pillar_root = os.path.abspath(self.options.pillar_root)
self.config['pillar_roots'] = {'base': [pillar_root]}
if self.options.local:
self.config['file_client'] = 'local'
if self.options.master:
self.config['master'] = self.options.master
# Setup file logging!
self.setup_logfile_logger()
caller = salt.cli.caller.Caller(self.config)
if self.options.doc:
caller.print_docs()
self.exit(0)
if self.options.grains_run:
caller.print_grains()
self.exit(0)
caller.run()
开发者ID:1mentat,项目名称:salt,代码行数:53,代码来源:__init__.py
示例6: prepare
def prepare(self):
'''
Run the preparation sequence required to start a salt syndic minion.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).prepare()
'''
super(Syndic, self).prepare()
try:
if self.config['verify_env']:
verify_env(
[
self.config['pki_dir'],
self.config['cachedir'],
self.config['sock_dir'],
self.config['extension_modules'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
current_umask = os.umask(0o027)
verify_files([logfile], self.config['user'])
os.umask(current_umask)
except OSError as err:
log.exception('Failed to prepare salt environment')
self.shutdown(err.errno)
self.setup_logfile_logger()
verify_log(self.config)
log.info(
'Setting up the Salt Syndic Minion "{0}"'.format(
self.config['id']
)
)
# Late import so logging works correctly
import salt.minion
self.daemonize_if_required()
# if its a multisyndic, do so
if isinstance(self.config.get('master'), list):
self.syndic = salt.minion.MultiSyndic(self.config)
else:
self.syndic = salt.minion.Syndic(self.config)
self.set_pidfile()
开发者ID:HowardMei,项目名称:saltstack,代码行数:51,代码来源:daemons.py
示例7: run
def run(self):
'''
Execute salt-key
'''
import salt.key
self.parse_args()
if self.config['verify_env']:
verify_env_dirs = []
if not self.config['gen_keys']:
if self.config['transport'] == 'raet':
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'accepted'),
os.path.join(self.config['pki_dir'], 'pending'),
os.path.join(self.config['pki_dir'], 'rejected'),
])
elif self.config['transport'] == 'zeromq':
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
os.path.join(self.config['pki_dir'], 'minions_pre'),
os.path.join(self.config['pki_dir'], 'minions_rejected'),
])
verify_env(
verify_env_dirs,
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['key_logfile']],
self.config['user']
)
self.setup_logfile_logger()
key = salt.key.KeyCLI(self.config)
if check_user(self.config['user']):
key.run()
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:46,代码来源:key.py
示例8: prepare
def prepare(self):
'''
Run the preparation sequence required to start a salt syndic minion.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).prepare()
'''
self.parse_args()
try:
if self.config['verify_env']:
verify_env(
[
self.config['pki_dir'],
self.config['cachedir'],
self.config['sock_dir'],
self.config['extension_modules'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files([logfile], self.config['user'])
except OSError as err:
logger.exception('Failed to prepare salt environment')
sys.exit(err.errno)
self.setup_logfile_logger()
logger.info(
'Setting up the Salt Syndic Minion "{0}"'.format(
self.config['id']
)
)
# Late import so logging works correctly
import salt.minion
self.daemonize_if_required()
self.syndic = salt.minion.Syndic(self.config)
self.set_pidfile()
开发者ID:bemehow,项目名称:salt,代码行数:44,代码来源:__init__.py
示例9: run
def run(self):
'''
Execute the salt call!
'''
self.parse_args()
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
self.config['cachedir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if (not self.config['log_file'].startswith('tcp://') or
not self.config['log_file'].startswith('udp://') or
not self.config['log_file'].startswith('file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
if self.options.local:
self.config['file_client'] = 'local'
if self.options.master:
self.config['master'] = self.options.master
# Setup file logging!
self.setup_logfile_logger()
caller = salt.cli.caller.Caller(self.config)
if self.options.doc:
caller.print_docs()
self.exit(0)
if self.options.grains_run:
caller.print_grains()
self.exit(0)
caller.run()
开发者ID:micahhausler,项目名称:salt,代码行数:43,代码来源:__init__.py
示例10: run
def run(self):
self.parse_args()
if self.config['verify_env']:
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
# Setup file logging!
self.setup_logfile_logger()
driver = FUSE(
SaltFuseDriver(self.config, self.remote_path, self.minion_id),
self.mount_path,
foreground=True
)
开发者ID:s0undt3ch,项目名称:salt-fuse,代码行数:21,代码来源:cli.py
示例11: run
def run(self):
'''
Execute salt-run
'''
import salt.runner
self.parse_args()
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
self.config['cachedir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
# Setup file logging!
self.setup_logfile_logger()
runner = salt.runner.Runner(self.config)
if self.options.doc:
runner.print_docs()
self.exit(os.EX_OK)
# Run this here so SystemExit isn't raised anywhere else when
# someone tries to use the runners via the python API
try:
if check_user(self.config['user']):
runner.run()
except SaltClientError as exc:
raise SystemExit(str(exc))
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:40,代码来源:run.py
示例12: run
def run(self):
'''
Execute the salt-cloud command line
'''
libcloud_version()
# Parse shell arguments
self.parse_args()
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
getpass.getuser()
)
logfile = self.config['log_file']
if logfile is not None and (
not logfile.startswith('tcp://') or
not logfile.startswith('udp://') or
not logfile.startswith('file://')):
# Logfile is not using Syslog, verify
verify_files([logfile], getpass.getuser())
except OSError as err:
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
# Late imports so logging works as expected
log.info('salt-cloud starting')
import saltcloud.cloud
mapper = saltcloud.cloud.Map(self.config)
if self.options.update_bootstrap:
import urllib
url = 'http://bootstrap.saltstack.org'
req = urllib.urlopen(url)
deploy_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'saltcloud', 'deploy', 'bootstrap-salt.sh'
)
print('Updating bootstrap-salt.sh.'
'\n\tSource: {0}'
'\n\tDestination: {1}'.format(url, deploy_path))
with salt.utils.fopen(deploy_path, 'w') as fp_:
fp_.write(req.read())
ret = {}
if self.selected_query_option is not None:
if self.config.get('map', None):
log.info('Applying map from {0!r}.'.format(self.config['map']))
try:
ret = mapper.interpolated_map(
query=self.selected_query_option
)
except Exception as exc:
log.debug(
'There was an error with a custom map.', exc_info=True
)
self.error(
'There was an error with a custom map: {0}'.format(
exc
)
)
self.exit(1)
else:
try:
ret = mapper.map_providers(
query=self.selected_query_option
)
except Exception as exc:
log.debug('There was an error with a map.', exc_info=True)
self.error(
'There was an error with a map: {0}'.format(exc)
)
self.exit(1)
elif self.options.list_locations is not None:
try:
saltcloud.output.double_layer(
mapper.location_list(self.options.list_locations)
)
except Exception as exc:
log.debug(
'There was an error listing locations.', exc_info=True
)
self.error(
'There was an error listing locations: {0}'.format(exc)
)
self.exit(1)
elif self.options.list_images is not None:
try:
saltcloud.output.double_layer(
mapper.image_list(self.options.list_images)
)
except Exception as exc:
log.debug('There was an error listing images.', exc_info=True)
self.error(
#.........这里部分代码省略.........
开发者ID:whodatninja,项目名称:salt-cloud,代码行数:101,代码来源:cli.py
示例13: run
def run(self):
'''
Execute the salt command line
'''
import salt.auth
import salt.client
self.parse_args()
if self.config['verify_env']:
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
# Setup file logging!
self.setup_logfile_logger()
try:
# We don't need to bail on config file permission errors
# if the CLI
# process is run with the -a flag
skip_perm_errors = self.options.eauth != ''
local = salt.client.get_local_client(
self.get_config_file_path(),
skip_perm_errors=skip_perm_errors)
except SaltClientError as exc:
self.exit(2, '{0}\n'.format(exc))
return
if self.options.batch or self.options.static:
import salt.cli.batch
eauth = {}
if 'token' in self.config:
eauth['token'] = self.config['token']
# If using eauth and a token hasn't already been loaded into
# kwargs, prompt the user to enter auth credentials
if 'token' not in eauth and self.options.eauth:
resolver = salt.auth.Resolver(self.config)
res = resolver.cli(self.options.eauth)
if self.options.mktoken and res:
tok = resolver.token_cli(
self.options.eauth,
res
)
if tok:
eauth['token'] = tok.get('token', '')
if not res:
sys.exit(2)
eauth.update(res)
eauth['eauth'] = self.options.eauth
if self.options.static:
if not self.options.batch:
self.config['batch'] = '100%'
batch = salt.cli.batch.Batch(self.config, eauth=eauth, quiet=True)
ret = {}
for res in batch.run():
ret.update(res)
self._output_ret(ret, '')
else:
batch = salt.cli.batch.Batch(self.config, eauth=eauth)
# Printing the output is already taken care of in run() itself
for res in batch.run():
if self.options.failhard:
for ret in res.itervalues():
retcode = salt.utils.job.get_retcode(ret)
if retcode != 0:
sys.exit(retcode)
else:
if self.options.timeout <= 0:
self.options.timeout = local.opts['timeout']
kwargs = {
'tgt': self.config['tgt'],
'fun': self.config['fun'],
'arg': self.config['arg'],
'timeout': self.options.timeout,
'show_timeout': self.options.show_timeout,
'show_jid': self.options.show_jid}
if 'token' in self.config:
try:
with salt.utils.fopen(os.path.join(self.config['cachedir'], '.root_key'), 'r') as fp_:
kwargs['key'] = fp_.readline()
except IOError:
kwargs['token'] = self.config['token']
#.........这里部分代码省略.........
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:101,代码来源:salt.py
示例14: run
def run(self):
'''
Execute the salt-cloud command line
'''
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user')
if salt_master_user is None:
salt_master_user = salt.utils.get_user()
if not check_user(salt_master_user):
self.error(
'If salt-cloud is running on a master machine, salt-cloud '
'needs to run as the same user as the salt-master, \'{0}\'. '
'If salt-cloud is not running on a salt-master, the '
'appropriate write permissions must be granted to \'{1}\'. '
'Please run salt-cloud as root, \'{0}\', or change '
'permissions for \'{1}\'.'.format(
salt_master_user,
syspaths.CONFIG_DIR
)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
verify_log(self.config)
if self.options.update_bootstrap:
ret = salt.utils.cloud.update_bootstrap(self.config)
salt.output.display_output(ret,
self.options.output,
opts=self.config)
self.exit(salt.defaults.exitcodes.EX_OK)
log.info('salt-cloud starting')
try:
mapper = salt.cloud.Map(self.config)
except SaltCloudSystemExit as exc:
self.handle_exception(exc.args, exc)
except SaltCloudException as exc:
msg = 'There was an error generating the mapper.'
self.handle_exception(msg, exc)
names = self.config.get('names', None)
if names is not None:
filtered_rendered_map = {}
for map_profile in mapper.rendered_map:
filtered_map_profile = {}
for name in mapper.rendered_map[map_profile]:
if name in names:
filtered_map_profile[name] = mapper.rendered_map[map_profile][name]
if filtered_map_profile:
filtered_rendered_map[map_profile] = filtered_map_profile
mapper.rendered_map = filtered_rendered_map
ret = {}
if self.selected_query_option is not None:
if self.selected_query_option == 'list_providers':
try:
ret = mapper.provider_list()
except (SaltCloudException, Exception) as exc:
msg = 'There was an error listing providers: {0}'
self.handle_exception(msg, exc)
elif self.selected_query_option == 'list_profiles':
provider = self.options.list_profiles
try:
ret = mapper.profile_list(provider)
except(SaltCloudException, Exception) as exc:
msg = 'There was an error listing profiles: {0}'
self.handle_exception(msg, exc)
elif self.config.get('map', None):
log.info(
'Applying map from \'{0}\'.'.format(self.config['map'])
)
try:
ret = mapper.interpolated_map(
query=self.selected_query_option
)
except (SaltCloudException, Exception) as exc:
msg = 'There was an error with a custom map: {0}'
#.........这里部分代码省略.........
开发者ID:HowardMei,项目名称:saltstack,代码行数:101,代码来源:cli.py
示例15: run
def run(self):
'''
Execute the salt-cloud command line
'''
if HAS_LIBCLOUD is False:
self.error('salt-cloud requires >= libcloud 0.11.4')
libcloud_version()
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user', salt.utils.get_user())
if salt_master_user is not None and not check_user(salt_master_user):
self.error(
'salt-cloud needs to run as the same user as salt-master, '
'{0!r}, but was unable to switch credentials. Please run '
'salt-cloud as root or as {0!r}'.format(salt_master_user)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
if self.options.update_bootstrap:
log.debug('Updating the bootstrap-salt.sh script to latest stable')
import urllib2
url = 'http://bootstrap.saltstack.org'
req = urllib2.urlopen(url)
if req.getcode() != 200:
self.error(
'Failed to download the latest stable version of the '
'bootstrap-salt.sh script from {0}. HTTP error: '
'{1}'.format(
url, req.getcode()
)
)
# Get the path to the built-in deploy scripts directory
builtin_deploy_dir = os.path.join(
os.path.dirname(__file__),
'deploy'
)
# Compute the search path from the current loaded opts conf_file
# value
deploy_d_from_conf_file = os.path.join(
os.path.dirname(self.config['conf_file']),
'cloud.deploy.d'
)
# Compute the search path using the install time defined
# syspaths.CONF_DIR
deploy_d_from_syspaths = os.path.join(
syspaths.CONFIG_DIR,
'cloud.deploy.d'
)
# Get a copy of any defined search paths, flagging them not to
# create parent
deploy_scripts_search_paths = []
for entry in self.config.get('deploy_scripts_search_path', []):
if entry.startswith(builtin_deploy_dir):
# We won't write the updated script to the built-in deploy
# directory
continue
if entry in (deploy_d_from_conf_file, deploy_d_from_syspaths):
# Allow parent directories to be made
deploy_scripts_search_paths.append((entry, True))
else:
deploy_scripts_search_paths.append((entry, False))
# In case the user is not using defaults and the computed
# 'cloud.deploy.d' from conf_file and syspaths is not included, add
# them
if deploy_d_from_conf_file not in deploy_scripts_search_paths:
deploy_scripts_search_paths.append(
(deploy_d_from_conf_file, True)
)
if deploy_d_from_syspaths not in deploy_scripts_search_paths:
deploy_scripts_search_paths.append(
(deploy_d_from_syspaths, True)
)
#.........这里部分代码省略.........
开发者ID:Anbcorp,项目名称:salt,代码行数:101,代码来源:cli.py
示例16: run
def run(self):
'''
Execute the salt-cloud command line
'''
if HAS_LIBCLOUD is False:
self.error('salt-cloud requires >= libcloud 0.11.4')
libcloud_version()
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user', getpass.getuser())
if salt_master_user is not None and not check_user(salt_master_user):
self.error(
'salt-cloud needs to run as the same user as salt-master, '
'{0!r}, but was unable to switch credentials. Please run '
'salt-cloud as root or as {0!r}'.format(salt_master_user)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
if self.options.update_bootstrap:
import urllib2
url = 'http://bootstrap.saltstack.org'
req = urllib2.urlopen(url)
if req.getcode() != 200:
self.error(
'Failed to download the latest stable version of the '
'bootstrap-salt.sh script from {0}. HTTP error: '
'{1}'.format(
url, req.getcode()
)
)
for entry in self.config.get('deploy_scripts_search_path'):
deploy_path = os.path.join(entry, 'bootstrap-salt.sh')
try:
print(
'Updating bootstrap-salt.sh.'
'\n\tSource: {0}'
'\n\tDestination: {1}'.format(
url,
deploy_path
)
)
with salt.utils.fopen(deploy_path, 'w') as fp_:
fp_.write(req.read())
# We were able to update, no need to continue trying to
# write up the search path
self.exit(0)
except (OSError, IOError), err:
log.debug(
'Failed to write the updated script: {0}'.format(err)
)
continue
self.error('Failed to update the bootstrap script')
开发者ID:1mentat,项目名称:salt,代码行数:74,代码来源:cli.py
示例17: run
def run(self):
'''
Execute the salt-cloud command line
'''
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user', salt.utils.get_user())
if salt_master_user is not None and not check_user(salt_master_user):
self.error(
'If salt-cloud is running on a master machine, salt-cloud '
'needs to run as the same user as the salt-master, {0!r}. If '
'salt-cloud is not running on a salt-master, the appropriate '
'write permissions must be granted to /etc/salt/. Please run '
'salt-cloud as root, {0!r}, or change permissions for '
'/etc/salt/.'.format(salt_master_user)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
if self.options.update_bootstrap:
ret = salt.utils.cloud.update_bootstrap(self.config)
display_output = salt.output.get_printout(
self.options.output, self.config
)
print(display_output(ret))
self.exit(salt.defaults.exitcodes.EX_OK)
log.info('salt-cloud starting')
mapper = salt.cloud.Map(self.config)
names = self.config.get('names', None)
if names is not None:
filtered_rendered_map = {}
for map_profile in mapper.rendered_map:
filtered_map_profile = {}
for name in mapper.rendered_map[map_profile]:
if name in names:
filtered_map_profile[name] = mapper.rendered_map[map_profile][name]
if filtered_map_profile:
filtered_rendered_map[map_profile] = filtered_map_profile
mapper.rendered_map = filtered_rendered_map
ret = {}
if self.selected_query_option is not None:
if self.selected_query_option == 'list_providers':
try:
ret = mapper.provider_list()
except (SaltCloudException, Exception) as exc:
msg = 'There was an error listing providers: {0}'
self.handle_exception(msg, exc)
elif self.selected_query_option == 'list_profiles':
provider = self.options.list_profiles
try:
ret = mapper.profile_list(provider)
except(SaltCloudException, Exception) as exc:
msg = 'There was an error listing profiles: {0}'
self.handle_exception(msg, exc)
elif self.config.get('map', None):
log.info('Applying map from {0!r}.'.format(self.config['map']))
try:
ret = mapper.interpolated_map(
query=self.selected_query_option
)
except (SaltCloudException, Exception) as exc:
msg = 'There was an error with a custom map: {0}'
self.handle_exception(msg, exc)
else:
try:
ret = mapper.map_providers_parallel(
query=self.selected_query_option
)
except (SaltCloudException, Exception) as exc:
msg = 'There was an error with a map: {0}'
self.handle_exception(msg, exc)
elif self.options.list_locations is not None:
try:
ret = mapper.location_list(
self.options.list_locations
#.........这里部分代码省略.........
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:101,代码来源:cli.py
|
请发表评论