Getting hostname information from the beaker command line

We use Beaker to allocate and loan computer hardware. If you want to talk to it via the comand line, you can use the bkr executable. Some of the information comes back as json, but beaker tends to speak xml. To look up a host name from a job, you need to be able to parse the xml. To do that, I used the xq execuable from the python yq package. Yes, x and y.

I installed yq via pip. That puts both the xq and yq executablees into ~/.local/bin.

If i know the job ID, I can parse it using the following syntax.

bkr job-results 'J:5078388' | xq -r  ".job | .recipeSet | .recipe| .task | .[] | .roles | .role | .system | .\"@value\""

UPDATE: So here is a useful script that makes use of bkr, jq, and xq to list the hostnames of the hosts I currently have on loan from beaker.

for job in $( bkr job-list -o $USER  --unfinished | jq -r '.[]' ) ; do bkr job-results $job | xq -r  ".job | .recipeSet | .recipe| .task | .[] | .roles | .role | .system | .\"@value\"" ; done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.