7 # Example of walking the tree
9 def handleLustre(lustre):
10 handleHost(lustre.getElementsByTagName("node"))
12 def handleHost(hosts):
14 name = host.getAttribute("name")
15 uuid = host.getAttribute("uuid")
18 # manage names and uuids
19 # need to initialize this by walking tree to ensure
20 # no duplicate names or uuids are created.
21 # this are just place holders for now.
25 name = "%s_%d" % (base, name_ctr)
30 return "%s_UUID" % (name)
33 # Create a new empty lustre document
37 dom = xml.dom.minidom.parseString(str)
41 # Create a new object the "correct" way by using the DOM api.
43 def new_OBD(dom, name, fs, devname, format, dev_size=0, dev_file=""):
46 obd = dom.createElement("obd")
47 obd.setAttribute("name", name)
48 obd.setAttribute("uuid", uuid)
50 fstype = dom.createElement("fstype")
51 txt= dom.createTextNode(fs)
52 fstype.appendChild(txt)
53 obd.appendChild(fstype)
55 dev = dom.createElement("device")
57 dev.setAttribute("size", "%s" % (dev_size))
58 txt = dom.createTextNode(devname)
62 fmt = dom.createElement("autoformat")
63 txt = dom.createTextNode(format)
70 # Create new object the fast and easy way
71 # (note: dom is not needed for this way)
72 def new_OSC(dom, osc, obd):
73 osc_uuid = get_uuid(osc)
74 obd_uuid = get_uuid(obd)
77 <osc name="%s" uuid="%s">
78 <service_id num="1" name="%s" uuid="%s"/>
79 </osc> """ % (osc, osc_uuid, obd, obd_uuid)
80 osc = xml.dom.minidom.parseString(osc_str)
81 return osc.getElementsByTagName("osc")[0]
84 # Create new object the fast and easy way
86 def new_OST(dom, ost, host, port, obd):
87 ost_uuid = get_uuid(ost)
88 obd_uuid = get_uuid(obd)
91 <ost name="%s" uuid="%s">
96 <server_id num="1" name="%s" uuid="%s"/>
97 </ost> """ % (ost, ost_uuid, host, port, obd, obd_uuid)
98 node = xml.dom.minidom.parseString(str)
99 return node.getElementsByTagName("ost")[0]
102 # Create a new obd, osc, and ost. Add them to the DOM.
104 def add_OST(dom, options, args):
105 # XXX need some error checking
109 obdname = new_name("obd")
110 oscname = new_name("osc")
111 ostname = new_name("ost")
113 obd = new_OBD(dom, obdname, "extN", devname, "no")
114 osc = new_OSC(dom, oscname, obdname)
115 ost = new_OST(dom, ostname, host, 2020, obdname)
117 dom.getElementsByTagName("lustre")[0].appendChild(obd)
118 dom.getElementsByTagName("lustre")[0].appendChild(osc)
119 dom.getElementsByTagName("lustre")[0].appendChild(ost)
123 # Command line processing
126 print """usage: lmc [--ost | --mtpt | --lov] cmd args
128 --ost "device" "host"
129 Creates an OBD/OST/OSC configuration triplet for a new device.
130 When used on "host", the device will be initialized and the OST
131 will be enabled. On client nodes, the OSC will be avaiable.
133 --mtpt "mds" "ost/lov-name" /mnt/point
134 Creates a client mount point.
136 --lov "mds" "lov name < "all-ost.xml"
137 Produces a logical volum striped over the OSTs found in all-ost.xml.
138 (Not sure how all-ost.xml is created, exactly.)
141 --merge="xml file" Add the new objects to an existing file
142 --format Format the partitions if unformated
143 --reformat Reformat partitions (this should be an lconf arg,
145 (SCRIPT STILL UNDER DEVELOPMENT, MOST COMMANDS/OPTIONS UNIMPLEMENTED)
150 long_opts = ["ost", "mtpt", "lov",
151 "merge=", "format", "reformat", "output=",
157 opts, args = getopt.getopt(argv, short_opts, long_opts)
158 except getopt.GetoptError:
164 if o in ("-h", "--help"):
167 if o in ("-o", "--output"):
168 options['output'] = a
174 options['format'] = 1
175 if o == "--reformat":
176 options['reformat'] = 1
181 options, args = cmdline(sys.argv[1:])
183 if options.has_key('merge'):
184 outFile = options['merge']
185 dom = xml.dom.minidom.parse(outFile)
187 if options.has_key('output'):
188 outFile = options['output']
193 if options.has_key('ost'):
194 add_OST(dom, options, args)
195 elif options.has_key('mtpt'):
196 print "--mtpt not implemented"
197 elif options.has_key('lov'):
198 print "--mtpt not implemented"
200 print "Missing command"
208 dom.writexml(open(outFile,"w"))
210 if __name__ == "__main__":