3 # Copyright (C) 2002 Cluster File Systems, Inc.
4 # Author: Robert Read <rread@clusterfs.com>
6 # This file is part of Lustre, http://www.lustre.org.
8 # Lustre is free software; you can redistribute it and/or
9 # modify it under the terms of version 2 of the GNU General Public
10 # License as published by the Free Software Foundation.
12 # Lustre is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Lustre; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 # lmc - lustre configurtion data manager
25 import xml.dom.minidom
29 print """usage: lmc [--ost | --mtpt | --lov] cmd args
31 --ost "device" "host" [size]
32 Creates an OBD/OST/OSC configuration triplet for a new device.
33 When used on "host", the device will be initialized and the OST
34 will be enabled. On client nodes, the OSC will be avaiable.
36 --mtpt "mds" "ost/lov-name" /mnt/point
37 Creates a client mount point.
39 --lov "mds" "lov name" < "all-ost.xml"
40 Produces a logical volum striped over the OSTs found in all-ost.xml.
41 (Not sure how all-ost.xml is created, exactly.)
44 --merge="xml file" Add the new objects to an existing file
45 --format Format the partitions if unformated
46 --reformat Reformat partitions (this should be an lconf arg,
48 (SCRIPT STILL UNDER DEVELOPMENT, MOST COMMANDS/OPTIONS UNIMPLEMENTED)
52 # manage names and uuids
53 # need to initialize this by walking tree to ensure
54 # no duplicate names or uuids are created.
55 # this are just place holders for now.
56 # consider changing this to be like OBD-dev-host
60 name = "%s_%d" % (base, name_ctr)
65 return "%s_UUID" % (name)
68 # Create a new empty lustre document
72 dom = xml.dom.minidom.parseString(str)
76 # Create a new object the "correct" way by using the DOM api.
78 def new_OBD(dom, name, fs, devname, format, dev_size=0, dev_file=""):
81 obd = dom.createElement("obd")
82 obd.setAttribute("name", name)
83 obd.setAttribute("uuid", uuid)
85 fstype = dom.createElement("fstype")
86 txt= dom.createTextNode(fs)
87 fstype.appendChild(txt)
88 obd.appendChild(fstype)
90 dev = dom.createElement("device")
92 dev.setAttribute("size", "%s" % (dev_size))
93 txt = dom.createTextNode(devname)
97 fmt = dom.createElement("autoformat")
98 txt = dom.createTextNode(format)
105 # Create new object the fast and easy way
106 # (note: dom is not needed for this way)
107 def new_OSC(dom, osc, obd):
108 osc_uuid = get_uuid(osc)
109 obd_uuid = get_uuid(obd)
112 <osc name="%s" uuid="%s">
113 <service_id num="1" name="%s" uuid="%s"/>
114 </osc> """ % (osc, osc_uuid, obd, obd_uuid)
115 osc = xml.dom.minidom.parseString(osc_str)
116 return osc.getElementsByTagName("osc")[0]
119 # Create new object the fast and easy way
121 def new_OST(dom, ost, host, port, obd):
122 ost_uuid = get_uuid(ost)
123 obd_uuid = get_uuid(obd)
126 <ost name="%s" uuid="%s">
131 <server_id num="1" name="%s" uuid="%s"/>
132 </ost> """ % (ost, ost_uuid, host, port, obd, obd_uuid)
133 node = xml.dom.minidom.parseString(str)
134 return node.getElementsByTagName("ost")[0]
137 # Create a new obd, osc, and ost. Add them to the DOM.
139 def add_OST(dom, options, args):
140 # XXX need some error checking
145 obdname = new_name("obd")
146 oscname = new_name("osc")
147 ostname = new_name("ost")
149 obd = new_OBD(dom, obdname, "extN", devname, "no", size)
150 osc = new_OSC(dom, oscname, obdname)
151 ost = new_OST(dom, ostname, host, 2020, obdname)
153 dom.getElementsByTagName("lustre")[0].appendChild(obd)
154 dom.getElementsByTagName("lustre")[0].appendChild(osc)
155 dom.getElementsByTagName("lustre")[0].appendChild(ost)
159 # Command line processing
162 def parse_cmdline(argv):
164 long_opts = ["ost", "mtpt", "lov",
165 "merge=", "format", "reformat", "output=",
171 opts, args = getopt.getopt(argv, short_opts, long_opts)
172 except getopt.GetoptError:
178 if o in ("-h", "--help"):
181 if o in ("-o", "--output"):
182 options['output'] = a
188 options['format'] = 1
189 if o == "--reformat":
190 options['reformat'] = 1
195 options, args = parse_cmdline(sys.argv[1:])
198 if options.has_key('merge'):
199 outFile = options['merge']
200 dom = xml.dom.minidom.parse(outFile)
204 if options.has_key('output'):
205 outFile = options['output']
207 if options.has_key('ost'):
208 add_OST(dom, options, args)
209 elif options.has_key('mtpt'):
210 print "--mtpt not implemented"
211 elif options.has_key('lov'):
212 print "--lov not implemented"
214 print "Missing command"
222 dom.writexml(open(outFile,"w"))
224 if __name__ == "__main__":