FAQ
Hi,
I'm trying to get access to the information in the job cache from python
but ran into a problem early on:

import salt.runner
import salt.config

opts = salt.config.master_config('/etc/salt/master')
runner = salt.runner.RunnerClient(opts)
runner.cmd('jobs.list_jobs', [])

This code works but the result is printed to stdout and not returned which
is odd behavior. How can I get the printed result into a python variable?

Regards,
   Dennis

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Seth House at Feb 14, 2015 at 6:38 pm
    Calling that function should both return a value as well as print to
    stdout. Try assigning the result to a variable:
    ret = runner.cmd('jobs.list_jobs', [])
    print ret.keys()
    The reason for this is historical. Runners were one of the earliest
    module types and could use a bit of an update. This is issue #9444.
    You can track progress there; a workaround is also in a comment on
    that issue.

    https://github.com/saltstack/salt/issues/9444

    In the next feature release of Salt that function also gained an
    ``outputter`` argument which can be set to ``quiet``:

    http://docs.saltstack.com/en/latest/ref/runners/all/salt.runners.jobs.html#salt.runners.jobs.lookup_jid

    The good news is work on modernizing runners has already begun. Keep
    on eye on that issue to watch the progress.

    On Thu, Feb 12, 2015 at 5:47 PM, Dennis Jacobfeuerborn
    wrote:
    Hi,
    I'm trying to get access to the information in the job cache from python but
    ran into a problem early on:

    import salt.runner
    import salt.config

    opts = salt.config.master_config('/etc/salt/master')
    runner = salt.runner.RunnerClient(opts)
    runner.cmd('jobs.list_jobs', [])

    This code works but the result is printed to stdout and not returned which
    is odd behavior. How can I get the printed result into a python variable?

    Regards,
    Dennis

    --
    You received this message because you are subscribed to the Google Groups
    "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dennis Jacobfeuerborn at Feb 14, 2015 at 8:05 pm
    Thanks for the pointers. That gives me an idea on how to get this working.
    However:

    1. "outputters" seems to be broken. I reported this a few days ago:
    https://github.com/saltstack/salt/issues/20634

    2. The jobs.print_job function does seem to be broken as well in
    2015.2.0rc1:

    A state.highstate call does a lot of work and finishes with this:

    Summary
    -------------
    Succeeded: 51
    Failed: 0
    -------------
    Total states run: 51

    Howver when I do a jobs.print_job for that job I get this:

    20150214205831478470:
         ----------
         Arguments:
             - 20150214205826284393
         Function:
             saltutil.find_job
         Minions:
             - ldap2-auth1.service.test
         Result:
             ----------
             ldap2-auth1.service.test:
                 ----------
                 return:
                     ----------
         StartTime:
             2015, Feb 14 20:58:31.478470
         Target:
             ldap2-auth1.service.test
         Target-type:
             glob
         User:
             root

    Notice the missing return data.

    Regards,
       Dennis
    On Saturday, February 14, 2015 at 7:38:41 PM UTC+1, Seth House wrote:

    Calling that function should both return a value as well as print to
    stdout. Try assigning the result to a variable:
    ret = runner.cmd('jobs.list_jobs', [])
    print ret.keys()
    The reason for this is historical. Runners were one of the earliest
    module types and could use a bit of an update. This is issue #9444.
    You can track progress there; a workaround is also in a comment on
    that issue.

    https://github.com/saltstack/salt/issues/9444

    In the next feature release of Salt that function also gained an
    ``outputter`` argument which can be set to ``quiet``:


    http://docs.saltstack.com/en/latest/ref/runners/all/salt.runners.jobs.html#salt.runners.jobs.lookup_jid

    The good news is work on modernizing runners has already begun. Keep
    on eye on that issue to watch the progress.

    On Thu, Feb 12, 2015 at 5:47 PM, Dennis Jacobfeuerborn
    <djacobf...@gmail.com <javascript:>> wrote:
    Hi,
    I'm trying to get access to the information in the job cache from python but
    ran into a problem early on:

    import salt.runner
    import salt.config

    opts = salt.config.master_config('/etc/salt/master')
    runner = salt.runner.RunnerClient(opts)
    runner.cmd('jobs.list_jobs', [])

    This code works but the result is printed to stdout and not returned which
    is odd behavior. How can I get the printed result into a python variable?
    Regards,
    Dennis

    --
    You received this message because you are subscribed to the Google Groups
    "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to salt-users+...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedFeb 13, '15 at 12:47a
activeFeb 14, '15 at 8:05p
posts3
users2

People

Translate

site design / logo © 2022 Grokbase