Add the CLI client and pub_data as class attributes

This is necessary to filter up the jid to salt.scripts in order to
provide the JID in the SystemExit triggered by the handler added in
6569267.
This commit is contained in:
Erik Johnson 2016-10-03 18:15:43 -05:00
parent 93f1daa4ce
commit 9c9f1f620b
2 changed files with 22 additions and 18 deletions

View file

@ -44,7 +44,7 @@ class SaltCMD(parsers.SaltCMDOptionParser):
# process is run with the -a flag
skip_perm_errors = self.options.eauth != ''
local = salt.client.get_local_client(
self.local_client = salt.client.get_local_client(
self.get_config_file_path(),
skip_perm_errors=skip_perm_errors)
except SaltClientError as exc:
@ -55,7 +55,7 @@ class SaltCMD(parsers.SaltCMDOptionParser):
self._run_batch()
else:
if self.options.timeout <= 0:
self.options.timeout = local.opts['timeout']
self.options.timeout = self.local_client.opts['timeout']
kwargs = {
'tgt': self.config['tgt'],
@ -115,20 +115,20 @@ class SaltCMD(parsers.SaltCMDOptionParser):
kwargs['eauth'] = self.options.eauth
if self.config['async']:
jid = local.cmd_async(**kwargs)
jid = self.local_client.cmd_async(**kwargs)
print_cli('Executed command with job ID: {0}'.format(jid))
return
retcodes = []
try:
# local will be None when there was an error
errors = []
if local:
if self.local_client:
if self.options.subset:
cmd_func = local.cmd_subset
cmd_func = self.local_client.cmd_subset
kwargs['sub'] = self.options.subset
kwargs['cli'] = True
else:
cmd_func = local.cmd_cli
cmd_func = self.local_client.cmd_cli
if self.options.progress:
kwargs['progress'] = True
@ -147,7 +147,7 @@ class SaltCMD(parsers.SaltCMDOptionParser):
elif self.config['fun'] == 'sys.doc':
ret = {}
out = ''
for full_ret in local.cmd_cli(**kwargs):
for full_ret in self.local_client.cmd_cli(**kwargs):
ret_, out, retcode = self._format_ret(full_ret)
ret.update(ret_)
self._output_ret(ret, out)

View file

@ -602,7 +602,7 @@ class LocalClient(object):
:returns: A generator
'''
arg = salt.utils.args.condition_input(arg, kwarg)
pub_data = self.run_job(
self.pub_data = self.run_job(
tgt,
fun,
arg,
@ -611,13 +611,13 @@ class LocalClient(object):
timeout,
**kwargs)
if not pub_data:
yield pub_data
if not self.pub_data:
yield self.pub_data
else:
try:
for fn_ret in self.get_cli_event_returns(
pub_data['jid'],
pub_data['minions'],
self.pub_data['jid'],
self.pub_data['minions'],
self._get_timeout(timeout),
tgt,
expr_form,
@ -630,12 +630,16 @@ class LocalClient(object):
yield fn_ret
except KeyboardInterrupt:
msg = ('Exiting on Ctrl-C\nThis job\'s jid is:\n{0}\n'
'The minions may not have all finished running and any '
'remaining minions will return upon completion. To '
'look up the return data for this job later run:\n'
'salt-run jobs.lookup_jid {0}').format(pub_data['jid'])
raise SystemExit(msg)
raise SystemExit(
'\n'
'This job\'s jid is: {0}\n'
'Exiting gracefully on Ctrl-c\n'
'The minions may not have all finished running and any '
'remaining minions will return upon completion. To look '
'up the return data for this job later, run the following '
'command:\n\n'
'salt-run jobs.lookup_jid {0}'.format(self.pub_data['jid'])
)
def cmd_iter(
self,