[Pacemaker] how to determin crm version / features from within a RA
Dejan Muhamedagic
dejanmm at fastmail.fm
Mon Jun 15 07:17:29 UTC 2009
On Thu, Jun 11, 2009 at 03:16:28PM +0200, Lars Ellenberg wrote:
> On Thu, Jun 11, 2009 at 01:59:56PM +0200, Dejan Muhamedagic wrote:
> > > so, to summarize, I hacked up a compare_version.
> > > and I think I even avoided bashisms! that is once in a life time :)
> >
> > Exemplary ;-)
>
> It may depend on some GNU stuff in sed and sort, though.
>
> > > comments?
> > > overkill?
> > > useful?
> >
> > Yes. Unfortunately, the thing got quite complicated. Some
> > comments:
> >
> > sort_keys=$(seq $l | sed -e 's/.*/ -k&,&/;2~2 s/$/n/')
> >
> > Won't even try to unravel this magic.
>
> l was set to the number or version parts (non-numeric, numeric).
> so I get $l "columns", need that many sort keys.
> and they need to do "ascii" and "numeric" sort.
>
> seq 3
> 1
> 2
> 3
> seq 3 | sed -e 's/.*/ -k&,&/'
> -k1,1
> -k2,2
> -k3,3
> ... | -e '2~2 s/$/n/'
> "every second of two lines, append an n" (for numeric sort).
> -k1,1
> -k2,2n
> -k3,3
OK. Never saw the ~ thing before. It is amazing the
things one can do with sed.
> > eval $(cibadmin -Ql |
> > sed -n -e '1 s/^<cib validate-with=\("[^"]*"\).*$/_CIB_VALIDATE_WITH=\1/p' \
> >
> > Beware: Attributes may come in any order. AFAIK, no guarantee at
> > all about it.
> >
> > -e 's/^[[:space:]]*<nvpair id="cib.bootstrap.options.dc.version".*
> >
> > Also, the id may be just about anything, can't rely on that,
> > better use the name attribute.
>
> is it, really arbitrary for the cib bootstrap things?
Yes. In most cases it'd be as you see, but in general the users
can do (almost) whatever they like to the IDs.
> > value="\([0-9.:]*\).*$/_DC_VERSION=\1/p')
> >
> > Hmm, don't really like eval here. If you really can't do without
> > it, at least protect the value with quotes. The same above with
> > _CIB_VALIDATE_WITH.
>
> of course I can do without it.
> I want to avoid to have to do it in two passes.
> but no need. the _DC_VERSION value only contains [0-9.:],
> which does not need to be quoted.
> for the _CIB_VALIDATE_WITH, the \("[^"]*"\) intentionally
> captures the enclosing quotes. ok, it could theoretically
> at one point in the future contain a backslash.
> but would
> <cib validate-with="something\" ...> be valid xml?
Not an expert on XML, but it could as well be.
> and yes, it could in theory contain "`rm -rf /`" ;)
>
> Ok. I'll add some comments,
> and rewrite that part to
> sed -ne '/^<cib/ { s/^.*\bvalidate-with="\([^"]*\)".*$/\1/;s/[^-%+.\/0-9:=@A-Z_a-z]/\\&/g;s/^/_CIB_VALIDATE_WITH=/;p;}'
> -e '1,/<cluster_property_set\b/d;/<\/cluster_property_set>/q;'
> -e '/^[[:space:]]*<nvpair .*\bname="dc-version"/ s/^.*\bvalue="\([0-9.:]*\).*$/_DC_VERSION=\1/p'
>
> hey, you asked for it
OK ;-)
> ;)
>
>
> --
> : Lars Ellenberg
> : LINBIT | Your Way to High Availability
> : DRBD/HA support and consulting http://www.linbit.com
>
> DRBD? and LINBIT? are registered trademarks of LINBIT, Austria.
>
> _______________________________________________
> Pacemaker mailing list
> Pacemaker at oss.clusterlabs.org
> http://oss.clusterlabs.org/mailman/listinfo/pacemaker
More information about the Pacemaker
mailing list