Execute a function from low data Low data includes: required: - fun: the name of the function to run optional: - arg: a list of args to pass to fun - kwarg: kwargs for fun - __user__: user who is
(self, fun, low, print_event=True, full_return=False)
| 279 | return True |
| 280 | |
| 281 | def low(self, fun, low, print_event=True, full_return=False): |
| 282 | """ |
| 283 | Execute a function from low data |
| 284 | Low data includes: |
| 285 | required: |
| 286 | - fun: the name of the function to run |
| 287 | optional: |
| 288 | - arg: a list of args to pass to fun |
| 289 | - kwarg: kwargs for fun |
| 290 | - __user__: user who is running the command |
| 291 | - __jid__: jid to run under |
| 292 | - __tag__: tag to run under |
| 293 | """ |
| 294 | # fire the mminion loading (if not already done) here |
| 295 | # this is not to clutter the output with the module loading |
| 296 | # if we have a high debug level. |
| 297 | self.mminion # pylint: disable=W0104 |
| 298 | jid = low.get("__jid__", salt.utils.jid.gen_jid(self.opts)) |
| 299 | tag = low.get("__tag__", salt.utils.event.tagify(jid, prefix=self.tag_prefix)) |
| 300 | |
| 301 | data = { |
| 302 | "fun": f"{self.client}.{fun}", |
| 303 | "jid": jid, |
| 304 | "user": low.get("__user__", "UNKNOWN"), |
| 305 | } |
| 306 | |
| 307 | if print_event: |
| 308 | print_func = ( |
| 309 | self.print_async_event if hasattr(self, "print_async_event") else None |
| 310 | ) |
| 311 | else: |
| 312 | # Suppress printing of return event (this keeps us from printing |
| 313 | # runner/wheel output during orchestration). |
| 314 | print_func = None |
| 315 | |
| 316 | with salt.utils.event.NamespacedEvent( |
| 317 | salt.utils.event.get_event( |
| 318 | "master", |
| 319 | self.opts["sock_dir"], |
| 320 | opts=self.opts, |
| 321 | listen=False, |
| 322 | ), |
| 323 | tag, |
| 324 | print_func=print_func, |
| 325 | ) as namespaced_event: |
| 326 | |
| 327 | # TODO: test that they exist |
| 328 | # TODO: Other things to inject?? |
| 329 | func_globals = { |
| 330 | "__jid__": jid, |
| 331 | "__user__": data["user"], |
| 332 | "__tag__": tag, |
| 333 | # weak ref to avoid the Exception in interpreter |
| 334 | # teardown of event |
| 335 | "__jid_event__": weakref.proxy(namespaced_event), |
| 336 | } |
| 337 | |
| 338 | try: |