def run_job(
#关键函数
self,
tgt,
fun,
arg=(),
expr_form='glob',
ret='',
timeout=None,
jid='',
kwarg=None,
**kwargs):
'''
Asynchronously send a command to connected minions
#异步执行
Prep the job directory and publish a command to any targeted minions.
#准备job字典,并推送命令给minions
:return: A dictionary of (validated) ``pub_data`` or an empty
#返回一个pub_data,或者返回一个空字典 pub_data包含job ID 和minions和客户端主机名
dictionary on failure. The ``pub_data`` contains the job ID and a
list of all minions that are expected to return data.
.. code-block:: python
>>> local.run_job('*', 'test.sleep', [300])
{'jid': '20131219215650131543', 'minions': ['jerry']}
'''
arg = salt.utils.args.condition_input(arg, kwarg)
#这里应该是整理参数吧。这个函数的说明是“Return a single arg structure for the publisher to safely use”
try:
pub_data = self.pub(
tgt,
fun,
arg,
expr_form,
ret,
jid=jid,
timeout=self._get_timeout(timeout),
**kwargs)
#这个pub也是关键函数
except SaltClientError:
# Re-raise error with specific message
raise SaltClientError(
'The salt master could not be contacted. Is master running?'
)
except Exception as general_exception:
# Convert to generic client error and pass along mesasge
raise SaltClientError(general_exception)
return self._check_pub_data(pub_data)
#返回check_pub_data。实际上是返回job id和minions的主机名
#关键函数
self,
tgt,
fun,
arg=(),
expr_form='glob',
ret='',
timeout=None,
jid='',
kwarg=None,
**kwargs):
'''
Asynchronously send a command to connected minions
#异步执行
Prep the job directory and publish a command to any targeted minions.
#准备job字典,并推送命令给minions
:return: A dictionary of (validated) ``pub_data`` or an empty
#返回一个pub_data,或者返回一个空字典 pub_data包含job ID 和minions和客户端主机名
dictionary on failure. The ``pub_data`` contains the job ID and a
list of all minions that are expected to return data.
.. code-block:: python
>>> local.run_job('*', 'test.sleep', [300])
{'jid': '20131219215650131543', 'minions': ['jerry']}
'''
arg = salt.utils.args.condition_input(arg, kwarg)
#这里应该是整理参数吧。这个函数的说明是“Return a single arg structure for the publisher to safely use”
try:
pub_data = self.pub(
tgt,
fun,
arg,
expr_form,
ret,
jid=jid,
timeout=self._get_timeout(timeout),
**kwargs)
#这个pub也是关键函数
except SaltClientError:
# Re-raise error with specific message
raise SaltClientError(
'The salt master could not be contacted. Is master running?'
)
except Exception as general_exception:
# Convert to generic client error and pass along mesasge
raise SaltClientError(general_exception)
return self._check_pub_data(pub_data)
#返回check_pub_data。实际上是返回job id和minions的主机名