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__="""CmdBase 
15   
16  Dump location data from pre 0.11.7 database to text to be reloaded 
17  in new location format 
18   
19  $Id: LocationDump.py,v 1.4 2003/11/21 21:18:11 edahl Exp $""" 
20   
21  __version__ = "$Revision: 1.4 $"[11:-2] 
22   
23   
24  from ZCmdBase import ZCmdBase 
25   
26 -class LocationDump(ZCmdBase):
27
28 - def dump(self):
29 outfile = open(self.options.outfile, "w") 30 if not hasattr(self.dataroot, "getSubDevices"): 31 raise "DataRootError", "dataroot doesn't have getSubDevices" 32 devs = self.dataroot.getSubDevices() 33 for dev in devs: 34 dcname = dev.getDataCenterName() 35 rname = dev.getRackName() 36 if rname: 37 locpath = dcname.split("-") 38 locpath.append(rname) 39 else: 40 locpath = ("NoLocation",) 41 line = "%s|%s\n" % (dev.getId(), "/" + "/".join(locpath)) 42 outfile.write(line) 43 outfile.close()
44 45
46 - def buildOptions(self):
47 ZCmdBase.buildOptions(self) 48 self.parser.add_option('-o', '--outfile', 49 dest='outfile', 50 default="locdump.out", 51 help='output file')
52 53 54 if __name__ == "__main__": 55 ld = LocationDump() 56 ld.dump() 57