mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Cache the results for the jid using salt-ssh
This commit is contained in:
parent
1e1585c009
commit
ad16b5cce3
@ -29,6 +29,7 @@ import salt.state
|
||||
import salt.utils
|
||||
import salt.utils.args
|
||||
import salt.utils.event
|
||||
import salt.utils.atomicfile
|
||||
import salt.utils.thin
|
||||
import salt.utils.verify
|
||||
import salt.utils.event
|
||||
@ -193,12 +194,12 @@ class SSH(object):
|
||||
else:
|
||||
self.event = None
|
||||
self.opts = opts
|
||||
tgt_type = self.opts['selected_target_option'] \
|
||||
self.tgt_type = self.opts['selected_target_option'] \
|
||||
if self.opts['selected_target_option'] else 'glob'
|
||||
self.roster = salt.roster.Roster(opts)
|
||||
self.targets = self.roster.targets(
|
||||
self.opts['tgt'],
|
||||
tgt_type)
|
||||
self.tgt_type)
|
||||
priv = self.opts.get(
|
||||
'ssh_priv',
|
||||
os.path.join(
|
||||
@ -300,9 +301,9 @@ class SSH(object):
|
||||
**target)
|
||||
if salt.utils.which('ssh-copy-id'):
|
||||
# we have ssh-copy-id, use it!
|
||||
single.shell.copy_id()
|
||||
stdout, stderr, retcode = single.shell.copy_id()
|
||||
else:
|
||||
ret = single.run()
|
||||
stdout, stderr, retcode = single.run()
|
||||
if re_run:
|
||||
target.pop('passwd')
|
||||
single = Single(
|
||||
@ -318,7 +319,9 @@ class SSH(object):
|
||||
if stderr:
|
||||
return {host: stderr}
|
||||
return {host: 'Bad Return'}
|
||||
return ret
|
||||
if os.EX_OK != retcode:
|
||||
return {host: stderr}
|
||||
return {host: stdout}
|
||||
|
||||
def handle_routine(self, que, opts, host, target):
|
||||
'''
|
||||
@ -464,6 +467,39 @@ class SSH(object):
|
||||
self.opts['cachedir'],
|
||||
self.opts['hash_type'],
|
||||
self.opts['user'])
|
||||
|
||||
jid_dir = salt.utils.jid_dir(jid, self.opts['cachedir'], self.opts['hash_type'])
|
||||
# Save the invocation information
|
||||
arg_str = self.opts['arg_str']
|
||||
|
||||
if self.opts['raw_shell']:
|
||||
fun = 'ssh_raw_shell'
|
||||
args = [arg_str]
|
||||
else:
|
||||
cmd_args = arg_str.split(None, 1)
|
||||
fun = cmd_args[0]
|
||||
args = [cmd_args[1]]
|
||||
|
||||
job_load = {
|
||||
'jid': jid,
|
||||
'tgt_type': self.tgt_type,
|
||||
'tgt': self.opts['tgt'],
|
||||
'user': self.opts['user'],
|
||||
'fun': fun,
|
||||
'arg': args,
|
||||
}
|
||||
self.serial.dump(
|
||||
job_load,
|
||||
salt.utils.fopen(os.path.join(jid_dir, '.load.p'), 'w+b')
|
||||
)
|
||||
# save the targets to a cache so we can see them in the UI
|
||||
targets = self.targets.keys()
|
||||
targets.sort()
|
||||
self.serial.dump(
|
||||
targets,
|
||||
salt.utils.fopen(os.path.join(jid_dir, '.minions.p'), 'w+b')
|
||||
)
|
||||
|
||||
if self.opts.get('verbose'):
|
||||
msg = 'Executing job with jid {0}'.format(jid)
|
||||
print(msg)
|
||||
@ -471,7 +507,7 @@ class SSH(object):
|
||||
print('')
|
||||
for ret in self.handle_ssh():
|
||||
host = ret.keys()[0]
|
||||
#self.cache_job(jid, host, ret)
|
||||
self.cache_job(jid, host, ret)
|
||||
ret = self.key_deploy(host, ret)
|
||||
salt.output.display_output(
|
||||
ret,
|
||||
|
@ -165,9 +165,10 @@ class Shell(object):
|
||||
'''
|
||||
Execute ssh-copy-id to plant the id file on the target
|
||||
'''
|
||||
_, stderr, _ = self._run_cmd(self._copy_id_str_old())
|
||||
if stderr.startswith('Usage'):
|
||||
self._run_cmd(self._copy_id_str_new())
|
||||
stdout, stderr, retcode = self._run_cmd(self._copy_id_str_old())
|
||||
if os.EX_OK != retcode and stderr.startswith('Usage'):
|
||||
stdout, stderr, retcode = self._run_cmd(self._copy_id_str_new())
|
||||
return stdout, stderr, retcode
|
||||
|
||||
def _cmd_str(self, cmd, ssh='ssh'):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user