From ca9b9ab6dd3cf4045b9cfecbf312559cfde8b461 Mon Sep 17 00:00:00 2001 From: rread Date: Tue, 2 Jul 2002 20:27:25 +0000 Subject: [PATCH] - initial version --- lustre/utils/lmc | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100755 lustre/utils/lmc diff --git a/lustre/utils/lmc b/lustre/utils/lmc new file mode 100755 index 0000000..c68652d --- /dev/null +++ b/lustre/utils/lmc @@ -0,0 +1,211 @@ +#!/usr/bin/env python + +import sys, getopt +import xml.dom.minidom + +# +# Example of walking the tree +# +def handleLustre(lustre): + handleHost(lustre.getElementsByTagName("node")) + +def handleHost(hosts): + for host in hosts: + name = host.getAttribute("name") + uuid = host.getAttribute("uuid") + +# +# manage names and uuids +# need to initialize this by walking tree to ensure +# no duplicate names or uuids are created. +# this are just place holders for now. +name_ctr = 1 +def new_name(base): + global name_ctr + name = "%s_%d" % (base, name_ctr) + name_ctr += 1 + return name + +def get_uuid(name): + return "%s_UUID" % (name) + +# +# Create a new empty lustre document +def new_Lustre(): + str = """ +""" + dom = xml.dom.minidom.parseString(str) + return dom + +# +# Create a new object the "correct" way by using the DOM api. +# +def new_OBD(dom, name, fs, devname, format, dev_size=0, dev_file=""): + uuid = get_uuid(name) + + obd = dom.createElement("obd") + obd.setAttribute("name", name) + obd.setAttribute("uuid", uuid) + + fstype = dom.createElement("fstype") + txt= dom.createTextNode(fs) + fstype.appendChild(txt) + obd.appendChild(fstype) + + dev = dom.createElement("device") + if (dev_size): + dev.setAttribute("size", "%s" % (dev_size)) + txt = dom.createTextNode(devname) + dev.appendChild(txt) + obd.appendChild(dev) + + fmt = dom.createElement("autoformat") + txt = dom.createTextNode(format) + fmt.appendChild(txt) + obd.appendChild(fmt) + + return obd + +# +# Create new object the fast and easy way +# (note: dom is not needed for this way) +def new_OSC(dom, osc, obd): + osc_uuid = get_uuid(osc) + obd_uuid = get_uuid(obd) + + osc_str =""" + + + """ % (osc, osc_uuid, obd, obd_uuid) + osc = xml.dom.minidom.parseString(osc_str) + return osc.getElementsByTagName("osc")[0] + +# +# Create new object the fast and easy way +# +def new_OST(dom, ost, host, port, obd): + ost_uuid = get_uuid(ost) + obd_uuid = get_uuid(obd) + + str =""" + + + %s + %d + + + """ % (ost, ost_uuid, host, port, obd, obd_uuid) + node = xml.dom.minidom.parseString(str) + return node.getElementsByTagName("ost")[0] + +# +# Create a new obd, osc, and ost. Add them to the DOM. +# +def add_OST(dom, options, args): + # XXX need some error checking + devname = args[0] + host = args[1] + + obdname = new_name("obd") + oscname = new_name("osc") + ostname = new_name("ost") + + obd = new_OBD(dom, obdname, "extN", devname, "no") + osc = new_OSC(dom, oscname, obdname) + ost = new_OST(dom, ostname, host, 2020, obdname) + + dom.getElementsByTagName("lustre")[0].appendChild(obd) + dom.getElementsByTagName("lustre")[0].appendChild(osc) + dom.getElementsByTagName("lustre")[0].appendChild(ost) + + +# +# Command line processing +# +def usage(): + print """usage: lmc [--ost | --mtpt | --lov] cmd args +Commands: +--ost "device" "host" + Creates an OBD/OST/OSC configuration triplet for a new device. + When used on "host", the device will be initialized and the OST + will be enabled. On client nodes, the OSC will be avaiable. + +--mtpt "mds" "ost/lov-name" /mnt/point + Creates a client mount point. + +--lov "mds" "lov name < "all-ost.xml" + Produces a logical volum striped over the OSTs found in all-ost.xml. + (Not sure how all-ost.xml is created, exactly.) + +Options: +--merge="xml file" Add the new objects to an existing file +--format Format the partitions if unformated +--reformat Reformat partitions (this should be an lconf arg, + I think) +(SCRIPT STILL UNDER DEVELOPMENT, MOST COMMANDS/OPTIONS UNIMPLEMENTED) +""" + +def cmdline(argv): + short_opts = "ho:" + long_opts = ["ost", "mtpt", "lov", + "merge=", "format", "reformat", "output=", + "help"] + opts = [] + args = [] + options = {} + try: + opts, args = getopt.getopt(argv, short_opts, long_opts) + except getopt.GetoptError: + print "invalid opt" + usage() + sys.exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + if o in ("-o", "--output"): + options['output'] = a + if o == "--ost": + options['ost'] = 1 + if o == "--merge": + options['merge'] = a + if o == "--format": + options['format'] = 1 + if o == "--reformat": + options['reformat'] = 1 + + return options, args + +def main(): + options, args = cmdline(sys.argv[1:]) + + if options.has_key('merge'): + outFile = options['merge'] + dom = xml.dom.minidom.parse(outFile) + else: + if options.has_key('output'): + outFile = options['output'] + else: + outFile = '-' + dom = new_Lustre() + + if options.has_key('ost'): + add_OST(dom, options, args) + elif options.has_key('mtpt'): + print "--mtpt not implemented" + elif options.has_key('lov'): + print "--mtpt not implemented" + else: + print "Missing command" + usage() + sys.exit(1) + + + if outFile == '-': + print dom.toxml() + else: + dom.writexml(open(outFile,"w")) + +if __name__ == "__main__": + main() -- 1.8.3.1