1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""LocationDump
15
16 Dump location data from pre 0.11.7 database to text to be reloaded
17 in new location format
18 """
19
20 from ZCmdBase import ZCmdBase
21
23 """
24 Dump location data
25 """
26
28 """
29 Dump location data to the specified output file.
30 """
31 outfile = open(self.options.outfile, "w")
32 if not hasattr(self.dataroot, "getSubDevices"):
33 raise RuntimeError, "dataroot doesn't have getSubDevices"
34 devs = self.dataroot.getSubDevices()
35 for dev in devs:
36 dcname = dev.getDataCenterName()
37 rname = dev.getRackName()
38 if rname:
39 locpath = dcname.split("-")
40 locpath.append(rname)
41 else:
42 locpath = ("NoLocation",)
43 line = "%s|%s\n" % (dev.getId(), "/" + "/".join(locpath))
44 outfile.write(line)
45 outfile.close()
46
47
49 """
50 Command-line options for LocationDump
51 """
52 ZCmdBase.buildOptions(self)
53 self.parser.add_option('-o', '--outfile',
54 dest='outfile',
55 default="locdump.out",
56 help='output file')
57
58
59 if __name__ == "__main__":
60 ld = LocationDump()
61 ld.dump()
62