mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #27768 from rallytime/cleanup_bootstrap
Clean up bootstrap function to be slightly cleaner
This commit is contained in:
commit
4ac5344c31
@ -295,8 +295,13 @@ def bootstrap(vm_, opts):
|
||||
Windows) to install Salt. It will make the decision on its own as to which
|
||||
deploy function to call.
|
||||
'''
|
||||
if salt.config.get_cloud_config_value('deploy', vm_, opts) is False \
|
||||
and not salt.config.get_cloud_config_value('inline_script', vm_, opts):
|
||||
deploy_config = salt.config.get_cloud_config_value(
|
||||
'deploy',
|
||||
vm_, opts, default=False)
|
||||
inline_script_config = salt.config.get_cloud_config_value(
|
||||
'inline_script',
|
||||
vm_, opts, default=None)
|
||||
if deploy_config is False and inline_script_config is None:
|
||||
return {
|
||||
'Error': {
|
||||
'No Deploy': '\'deploy\' is not enabled. Not deploying.'
|
||||
@ -313,9 +318,10 @@ def bootstrap(vm_, opts):
|
||||
)
|
||||
)
|
||||
has_ssh_agent = False
|
||||
if opts.get('ssh_agent', False) and 'SSH_AUTH_SOCK' in os.environ:
|
||||
if stat.S_ISSOCK(os.stat(os.environ['SSH_AUTH_SOCK']).st_mode):
|
||||
has_ssh_agent = True
|
||||
if (opts.get('ssh_agent', False) and
|
||||
'SSH_AUTH_SOCK' in os.environ and
|
||||
stat.S_ISSOCK(os.stat(os.environ['SSH_AUTH_SOCK']).st_mode)):
|
||||
has_ssh_agent = True
|
||||
|
||||
if (key_filename is None and
|
||||
salt.config.get_cloud_config_value(
|
||||
@ -342,10 +348,6 @@ def bootstrap(vm_, opts):
|
||||
vm_, opts, minion_conf
|
||||
)
|
||||
|
||||
inline_script_code = salt.config.get_cloud_config_value(
|
||||
'inline_script', vm_, opts, default=None
|
||||
)
|
||||
|
||||
ssh_username = salt.config.get_cloud_config_value(
|
||||
'ssh_username', vm_, opts, default='root'
|
||||
)
|
||||
@ -364,7 +366,7 @@ def bootstrap(vm_, opts):
|
||||
'salt_host': vm_.get('salt_host', vm_['ssh_host']),
|
||||
'username': ssh_username,
|
||||
'script': deploy_script_code,
|
||||
'inline_script': inline_script_code,
|
||||
'inline_script': inline_script_config,
|
||||
'name': vm_['name'],
|
||||
'has_ssh_agent': has_ssh_agent,
|
||||
'tmp_dir': salt.config.get_cloud_config_value(
|
||||
@ -480,27 +482,19 @@ def bootstrap(vm_, opts):
|
||||
transport=opts.get('transport', 'zeromq')
|
||||
)
|
||||
|
||||
deployed = False
|
||||
inline_script_deployed = False
|
||||
|
||||
if salt.config.get_cloud_config_value('inline_script', vm_, opts) \
|
||||
and salt.config.get_cloud_config_value('deploy', vm_, opts) is False:
|
||||
|
||||
if inline_script_code:
|
||||
inline_script_deployed = run_inline_script(**inline_script_kwargs)
|
||||
if inline_script_deployed is not False:
|
||||
log.info('Inline script(s) ha(s|ve) run on {0}'.format(vm_['name']))
|
||||
if inline_script_config and deploy_config is False:
|
||||
inline_script_deployed = run_inline_script(**inline_script_kwargs)
|
||||
if inline_script_deployed is not False:
|
||||
log.info('Inline script(s) ha(s|ve) run on {0}'.format(vm_['name']))
|
||||
ret['deployed'] = False
|
||||
return ret
|
||||
|
||||
else:
|
||||
|
||||
if win_installer:
|
||||
deployed = deploy_windows(**deploy_kwargs)
|
||||
else:
|
||||
deployed = deploy_script(**deploy_kwargs)
|
||||
|
||||
if inline_script_code:
|
||||
if inline_script_config:
|
||||
inline_script_deployed = run_inline_script(**inline_script_kwargs)
|
||||
if inline_script_deployed is not False:
|
||||
log.info('Inline script(s) ha(s|ve) run on {0}'.format(vm_['name']))
|
||||
@ -1184,7 +1178,6 @@ def deploy_script(host,
|
||||
|
||||
if wait_for_port(host=host, port=port, gateway=gateway):
|
||||
log.debug('SSH port {0} on {1} is available'.format(port, host))
|
||||
newtimeout = timeout - (time.mktime(time.localtime()) - starttime)
|
||||
if wait_for_passwd(host, port=port, username=username,
|
||||
password=password, key_filename=key_filename,
|
||||
ssh_timeout=ssh_timeout,
|
||||
@ -1197,7 +1190,6 @@ def deploy_script(host,
|
||||
host, port, username
|
||||
)
|
||||
)
|
||||
newtimeout = timeout - (time.mktime(time.localtime()) - starttime)
|
||||
ssh_kwargs = {
|
||||
'hostname': host,
|
||||
'port': port,
|
||||
@ -1224,7 +1216,7 @@ def deploy_script(host,
|
||||
tty, sudo, **ssh_kwargs)
|
||||
if ret:
|
||||
raise SaltCloudSystemExit(
|
||||
'Cant create temporary '
|
||||
'Can\'t create temporary '
|
||||
'directory in {0} !'.format(tmp_dir)
|
||||
)
|
||||
if sudo:
|
||||
|
Loading…
Reference in New Issue
Block a user