学习salt的源码2-run_job

本博客介绍了一个关键函数 `drun_job` 的使用,该函数用于异步发送命令到连接的 minions。它包括参数如目标 minions、命令、表达形式等,返回 pub_data 字典或空字典,用于跟踪 job ID 和 minions 的响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的主机名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值