Execute a command on a random subset of the targeted systems The function signature is the same as :py:meth:`cmd` with the following exceptions. :param subset: The number of systems to execute on .. code-block:: python >>> import salt.client.s
(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type="glob",
ret="",
kwarg=None,
subset=3,
**kwargs,
)
| 225 | raise SaltClientError |
| 226 | |
| 227 | def cmd_subset( |
| 228 | self, |
| 229 | tgt, |
| 230 | fun, |
| 231 | arg=(), |
| 232 | timeout=None, |
| 233 | tgt_type="glob", |
| 234 | ret="", |
| 235 | kwarg=None, |
| 236 | subset=3, |
| 237 | **kwargs, |
| 238 | ): |
| 239 | """ |
| 240 | Execute a command on a random subset of the targeted systems |
| 241 | |
| 242 | The function signature is the same as :py:meth:`cmd` with the |
| 243 | following exceptions. |
| 244 | |
| 245 | :param subset: The number of systems to execute on |
| 246 | |
| 247 | .. code-block:: python |
| 248 | |
| 249 | >>> import salt.client.ssh.client |
| 250 | >>> sshclient= salt.client.ssh.client.SSHClient() |
| 251 | >>> sshclient.cmd_subset('*', 'test.ping', subset=1) |
| 252 | {'jerry': True} |
| 253 | |
| 254 | .. versionadded:: 2017.7.0 |
| 255 | """ |
| 256 | minion_ret = self.cmd(tgt, "sys.list_functions", tgt_type=tgt_type, **kwargs) |
| 257 | minions = list(minion_ret) |
| 258 | random.shuffle(minions) |
| 259 | f_tgt = [] |
| 260 | for minion in minions: |
| 261 | if fun in minion_ret[minion]["return"]: |
| 262 | f_tgt.append(minion) |
| 263 | if len(f_tgt) >= subset: |
| 264 | break |
| 265 | return self.cmd_iter( |
| 266 | f_tgt, fun, arg, timeout, tgt_type="list", ret=ret, kwarg=kwarg, **kwargs |
| 267 | ) |
| 268 | |
| 269 | def destroy(self): |
| 270 | """ |