summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorBrian Pellin <bpellin@mcs.anl.gov>2005-01-06 22:50:49 +0000
committerBrian Pellin <bpellin@mcs.anl.gov>2005-01-06 22:50:49 +0000
commit7cf265cc4ad8640d1afd37a63e46f3ac22805a07 (patch)
tree3b282206ffebdff894f37ff67303f89cf47de082 /src/sbin
parent754cd16e834da7e24f788f15f5ac875fab13c5c7 (diff)
downloadbcfg2-7cf265cc4ad8640d1afd37a63e46f3ac22805a07.tar.gz
bcfg2-7cf265cc4ad8640d1afd37a63e46f3ac22805a07.tar.bz2
bcfg2-7cf265cc4ad8640d1afd37a63e46f3ac22805a07.zip
Added support for the read config from file (-f) flag.
(Logical change 1.175) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@764 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rw-r--r--src/sbin/bcfg274
1 files changed, 43 insertions, 31 deletions
diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2
index 9264e91c4..bff86e62e 100644
--- a/src/sbin/bcfg2
+++ b/src/sbin/bcfg2
@@ -70,30 +70,41 @@ if __name__ == '__main__':
doptions = {'b':'bundle', 'f':'file', 'c':'cache', 'p':'profile', 'i':'image'}
setup = dgetopt(argv[1:], options, doptions)
- # connect to bcfg2d
- comm = comm_lib()
- h = comm.ClientInit("bcfg2")
-
- # get probes
- comm.SendMessage(h, "<get-probes/>")
- data = comm.RecvMessage(h)
- #if setup['verbose']: print data
- probes = XML(data)
- # execute probes
- cpd = Element("probe-data")
- [cpd.append(RunProbe(x)) for x in probes.findall(".//probe")]
+ comm = None
+ if setup['file']:
+ try:
+ configfile = open(setup['file'], 'r')
+ r = configfile.read()
+ configfile.close()
+ except IOError:
+ print "Failed to read cached config file: %s" % (setup['file'])
+ sysexit(1)
+ else:
+ # connect to bcfg2d
+ comm = comm_lib()
+ h = comm.ClientInit("bcfg2")
+
+ # get probes
+ comm.SendMessage(h, "<get-probes/>")
+ data = comm.RecvMessage(h)
+ #if setup['verbose']: print data
+ probes = XML(data)
+ # execute probes
+ cpd = Element("probe-data")
+ [cpd.append(RunProbe(x)) for x in probes.findall(".//probe")]
- # upload probe responses
- comm.SendMessage(h, tostring(cpd))
- r = comm.RecvMessage(h)
- msg = Element("get-config")
- if setup['profile']:
- msg.attrib['profile'] = setup['profile']
- if setup['image']:
- msg.attrib['image'] = setup['image']
- # get config
- comm.SendMessage(h, tostring(msg))
- r = comm.RecvMessage(h)
+ # upload probe responses
+ comm.SendMessage(h, tostring(cpd))
+ r = comm.RecvMessage(h)
+ msg = Element("get-config")
+ if setup['profile']:
+ msg.attrib['profile'] = setup['profile']
+ if setup['image']:
+ msg.attrib['image'] = setup['image']
+ # get config
+ comm.SendMessage(h, tostring(msg))
+ r = comm.RecvMessage(h)
+
if setup['cache']:
try:
open(setup['cache'], 'w').write(r)
@@ -141,12 +152,13 @@ if __name__ == '__main__':
else:
client.CondPrint("verbose", "All entries correct")
- # upload statistics
- m = Element("upload-statistics")
- stats = client.GenerateStats()
- m.append(stats)
+ if not setup['file']:
+ # upload statistics
+ m = Element("upload-statistics")
+ stats = client.GenerateStats()
+ m.append(stats)
- comm.SendMessage(h, tostring(m))
- r = comm.RecvMessage(h)
- # clean up
- comm.ClientClose(h)
+ comm.SendMessage(h, tostring(m))
+ r = comm.RecvMessage(h)
+ # clean up
+ comm.ClientClose(h)