Clean up bootstrap function to be slightly cleaner

This commit is contained in:
rallytime 2015-10-07 01:12:30 -06:00
parent d3f2dfe835
commit 9df6e106c3

View File

@ -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,8 +318,9 @@ 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):
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
@ -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:
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: