Package ZenUtils :: Module LocationDump
[hide private]
[frames] | no frames]

Source Code for Module ZenUtils.LocationDump

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
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   
22 -class LocationDump(ZCmdBase):
23 """ 24 Dump location data 25 """ 26
27 - def dump(self):
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
48 - def buildOptions(self):
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