[ClusterLabs] Antw: [EXT] Re: Determine a resource's current host in the CIB
Digimer
lists at alteeve.ca
Tue Sep 29 11:33:18 EDT 2020
On 2020-09-29 9:15 a.m., Ulrich Windl wrote:
>>>> Christopher Lumens <clumens at redhat.com> schrieb am 24.09.2020 um 17:48 in
> Nachricht <801519843.20826233.1600962508662.JavaMail.zimbra at redhat.com>:
>> 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.
>
> Hi!
>
> A few years ago I wrote a (Perl) tool that parses and linearizes the XML CIB.
> For example using that tool to sort all resources by operation execution time,
> the command was:
>
> ./pmkrstat.pl --cib-object=status --query '*:exec-time' \
> --attribute id=1 --attribute operation=2 --attribute on_node=3 \
> --attribute rc-code=4 --attribute queue-time=5 --attribute exec-time=6 \
> --attribute last-run=7 \
> --show full_path=0 --show name=0 --show attr_name=0 --no-handle-values | \
> sed -e 's/(//' -e 's/)//' -e 's/"//g' -e 's/,/ /g' | grep "$1" | sort -k6n
> -k1
>
> So on output you have 7 fields: id, operation, on_node, rc-code, queue-time,
> exec-time, and last-run
>
> So an output line could be:
> prm_db_last_0 start node-13 0 0 31858 1592836459
>
> Ugly, isn't it?
>
> Regards,
> Ulrich
<Insert perl joke here>
<3 perl
Thanks for this, but I decided to use crm_mon's XML output to determine
running resource location and state (building on the CIB parser I
already had working). So I'm sorted now, but this would likely have been
helpful had I not already.
Cheers
--
Digimer
Papers and Projects: https://alteeve.com/w/
"I am, somehow, less interested in the weight and convolutions of
Einstein’s brain than in the near certainty that people of equal talent
have lived and died in cotton fields and sweatshops." - Stephen Jay Gould
More information about the Users
mailing list