3 # lmc - lustre configurtion data manager
10 print """usage: lmc [--ost | --mtpt | --lov] cmd args
12 --ost "device" "host" [size]
13 Creates an OBD/OST/OSC configuration triplet for a new device.
14 When used on "host", the device will be initialized and the OST
15 will be enabled. On client nodes, the OSC will be avaiable.
17 --mtpt "mds" "ost/lov-name" /mnt/point
18 Creates a client mount point.
20 --lov "mds" "lov name < "all-ost.xml"
21 Produces a logical volum striped over the OSTs found in all-ost.xml.
22 (Not sure how all-ost.xml is created, exactly.)
25 --merge="xml file" Add the new objects to an existing file
26 --format Format the partitions if unformated
27 --reformat Reformat partitions (this should be an lconf arg,
29 (SCRIPT STILL UNDER DEVELOPMENT, MOST COMMANDS/OPTIONS UNIMPLEMENTED)
33 # manage names and uuids
34 # need to initialize this by walking tree to ensure
35 # no duplicate names or uuids are created.
36 # this are just place holders for now.
37 # consider changing this to be like OBD-dev-host
41 name = "%s_%d" % (base, name_ctr)
46 return "%s_UUID" % (name)
49 # Create a new empty lustre document
53 dom = xml.dom.minidom.parseString(str)
57 # Create a new object the "correct" way by using the DOM api.
59 def new_OBD(dom, name, fs, devname, format, dev_size=0, dev_file=""):
62 obd = dom.createElement("obd")
63 obd.setAttribute("name", name)
64 obd.setAttribute("uuid", uuid)
66 fstype = dom.createElement("fstype")
67 txt= dom.createTextNode(fs)
68 fstype.appendChild(txt)
69 obd.appendChild(fstype)
71 dev = dom.createElement("device")
73 dev.setAttribute("size", "%s" % (dev_size))
74 txt = dom.createTextNode(devname)
78 fmt = dom.createElement("autoformat")
79 txt = dom.createTextNode(format)
86 # Create new object the fast and easy way
87 # (note: dom is not needed for this way)
88 def new_OSC(dom, osc, obd):
89 osc_uuid = get_uuid(osc)
90 obd_uuid = get_uuid(obd)
93 <osc name="%s" uuid="%s">
94 <service_id num="1" name="%s" uuid="%s"/>
95 </osc> """ % (osc, osc_uuid, obd, obd_uuid)
96 osc = xml.dom.minidom.parseString(osc_str)
97 return osc.getElementsByTagName("osc")[0]
100 # Create new object the fast and easy way
102 def new_OST(dom, ost, host, port, obd):
103 ost_uuid = get_uuid(ost)
104 obd_uuid = get_uuid(obd)
107 <ost name="%s" uuid="%s">
112 <server_id num="1" name="%s" uuid="%s"/>
113 </ost> """ % (ost, ost_uuid, host, port, obd, obd_uuid)
114 node = xml.dom.minidom.parseString(str)
115 return node.getElementsByTagName("ost")[0]
118 # Create a new obd, osc, and ost. Add them to the DOM.
120 def add_OST(dom, options, args):
121 # XXX need some error checking
126 obdname = new_name("obd")
127 oscname = new_name("osc")
128 ostname = new_name("ost")
130 obd = new_OBD(dom, obdname, "extN", devname, "no", size)
131 osc = new_OSC(dom, oscname, obdname)
132 ost = new_OST(dom, ostname, host, 2020, obdname)
134 dom.getElementsByTagName("lustre")[0].appendChild(obd)
135 dom.getElementsByTagName("lustre")[0].appendChild(osc)
136 dom.getElementsByTagName("lustre")[0].appendChild(ost)
140 # Command line processing
145 long_opts = ["ost", "mtpt", "lov",
146 "merge=", "format", "reformat", "output=",
152 opts, args = getopt.getopt(argv, short_opts, long_opts)
153 except getopt.GetoptError:
159 if o in ("-h", "--help"):
162 if o in ("-o", "--output"):
163 options['output'] = a
169 options['format'] = 1
170 if o == "--reformat":
171 options['reformat'] = 1
176 options, args = cmdline(sys.argv[1:])
179 if options.has_key('merge'):
180 outFile = options['merge']
181 dom = xml.dom.minidom.parse(outFile)
185 if options.has_key('output'):
186 outFile = options['output']
188 if options.has_key('ost'):
189 add_OST(dom, options, args)
190 elif options.has_key('mtpt'):
191 print "--mtpt not implemented"
192 elif options.has_key('lov'):
193 print "--lov not implemented"
195 print "Missing command"
203 dom.writexml(open(outFile,"w"))
205 if __name__ == "__main__":