[ClusterLabs] Determine a resource's current host in the CIB

Christopher Lumens clumens at redhat.com
Thu Sep 24 11:48:28 EDT 2020


This is the kind of stuff I've been working on a lot, so hopefully I've
added enough tools to make this easy to do.  If not, I guess I've got
more work to do.

What's your time frame, are you lucky enough to be able to use the latest
pacemaker releases, and are you going to use command line tools or the
library?

> > A quick look to the code shows that crm_resource - where we would
> > have --locate -does have the --xml-file as well. But that seems
> > not to do what I expected althoughI haven't looked into the details.
> 
> This is an interesting option... I can see that it shows me running
> resources only (not what resources are configured but off). It does show
> more directly "VM x is on node y";

Coming eventually, crm_resource will support --output-as=xml, which means
you'd potentially get the output of "crm_resource -W" in a structured
format you could easily parse.

You could also use crm_mon and xmllint to do this right now on the
command line.  First you could use crm_mon to dump a single resource as
XML:

$ crm_mon --include=none,resources --resource dummy --output-as xml
<pacemaker-result api-version="2.3" request="crm_mon --include=none,resources --resource dummy --output-as xml">
  <resources>
    <resource id="dummy" resource_agent="ocf::pacemaker:Dummy" role="Started" active="true" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="1">
      <node name="cluster02" id="2" cached="true"/>
    </resource>
  </resources>
  <status code="0" message="OK"/>
</pacemaker-result>

And then you construct an xpath query to get just the attribute you
want:

$ crm_mon --include=none,resources --resource dummy --output-as xml | xmllint --xpath '//resource/node/@name' -
name="cluster02"

You could do the same kinds of queries using libxml2 once you've parsed
stdout of crm_mon.  We've got examples scattered throughout the
pacemaker code, or I could probably try to remember how it's done.

- Chris



More information about the Users mailing list