From cf4b95f1b9e460a3905701feb1040b6c9038e141 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Tue, 7 Aug 2007 18:11:05 +0000 Subject: Make bcfg2-query usable as nodeattr for pdsh git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3610 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-query | 13 ++++++++-- tools/nodeattr.py | 73 ---------------------------------------------------- 2 files changed, 11 insertions(+), 75 deletions(-) delete mode 100644 tools/nodeattr.py diff --git a/src/sbin/bcfg2-query b/src/sbin/bcfg2-query index 9880035d5..3f0209192 100755 --- a/src/sbin/bcfg2-query +++ b/src/sbin/bcfg2-query @@ -13,6 +13,9 @@ if len(sys.argv) < 2: print "Usage bcfg2-query -d|u|p " print "\t -d\t\t shows the clients that are currently down" print "\t -u\t\t shows the clients that are currently up" + print "\t -c\t\t prints node names in a comma delimited list" + print "\t -s\t\t prints node names in a space delimited list" + print "\t -n\t\t prints node names in a newline delimited list (default)" print "\t -p \t shows all the clients of that profile" print "\t -a\t shows all clients" sys.exit(1) @@ -28,5 +31,11 @@ elif '-u' in sys.argv: elif '-a' in sys.argv: clients = xml.xpath(".//Client") -for client in clients: - print client.get('name') +cnames = [client.get('name') for client in clients] +if '-c' in sys.argv: + print ",".join(cnames) +elif '-s' in sys.argv: + print " ".join(cnames) +else: + print "\n".join(cnames) + diff --git a/tools/nodeattr.py b/tools/nodeattr.py deleted file mode 100644 index db769fdd8..000000000 --- a/tools/nodeattr.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python - -from elementtree.ElementTree import XML, tostring -from pdis.xpath import compile as xcompile -from sys import argv - -outputmode = argv[1] -attr = argv[2] - -#this will need to be extrapolated from the bcfg2.conf file -#but for testing it can stay as is - -xmlfile="testing.xml" -file=open(xmlfile, 'r').readlines() -myxmlfile="" -for line in file: - myxmlfile+=line -metadata=XML(myxmlfile) -nodelist=[] - -(level,searchterm)=attr.split("=") - -if level.lower() == 'image': - xexpression="/*/Client[@image='%s']"%searchterm - path = xcompile(xexpression) - nodelist += [ element.attrib['name'] for element in path.evaluate(metadata) ] -else: - profilelist=[] - if level.lower() == "profile": - profilelist.append(searchterm) - else: - classlist=[] - xexpression="/*/Profile" - path=xcompile(xexpression) - for profile in path.evaluate(metadata): - if level.lower() == 'class': - xexpression="/*/Class[@name='%s']"%searchterm - path=xcompile(xexpression) - if path.evaluate(profile) and profile.attrib['name'] not in profilelist: - profilelist.append(profile.attrib['name']) - else: - xexpression="/*/Class" - path=xcompile(xexpression) - for profclass in path.evaluate(profile): - xepression="/*/Class[@name='%s']"%profclass.attrib['name'] - path = xcompile(xexpression) - for myclass in path.evaluate(metadata): - xexpression="/*/Bundle[@name='%s']"%searchterm - path=xcompile(xexpression) - if path.evaluate(myclass) and myclass.attrib['name'] not in classlist: - classlist.append(myclass.attrib['name']) - xexpression="/*/Profile" - path=xcompile(xexpression) - for profile in path.evaluate(metadata): - for myclass in classlist: - xexpression="/*/Class[@name='%s']"%myclass - path=xcompile(xexpression) - if path.evaluate(profile) and profile.attrib['name'] not in profilelist: - profilelist.append(profile.attrib['name']) - - for profile in profilelist: - xexpression="/*/Client[@profile='%s']"%profile - path = xcompile(xexpression) - nodelist += [ element.attrib['name'] for element in path.evaluate(metadata) ] - -if outputmode == '-c': - print ",".join(nodelist) -if outputmode == '-n': - for node in nodelist: - print node -if outputmode == '-s': - print "not yet implemented" - -- cgit v1.2.3-1-g7c22