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

Source Code for Module ZenUtils.FixIps

 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  from Products.ZenUtils.Utils import getSubObjects 
14   
15  from Products.ZenUtils.ZCmdBase import ZCmdBase 
16  from transaction import get_transaction 
17   
18 -class FixIps(ZCmdBase):
19
20 - def fixips(self):
21 ips = getSubObjects(self.dmd, self.filter, self.decend) 22 self.ccount = 0 23 for ip in ips: 24 self.log.debug("fixing ip %s" % ip.id) 25 int = ip.interface() 26 if int: 27 ip.removeRelation("interface") 28 ip.addRelation("interface", int) 29 self.ccount += 1 30 if (self.ccount >= self.options.commitCount 31 and not self.options.noCommit): 32 self.mycommit(ip) 33 if self.options.noCommit: 34 self.log.info("not commiting any changes") 35 else: 36 self.mycommit()
37 38
39 - def filter(self, obj):
40 return obj.meta_type == "IpAddress"
41 42
43 - def decend(self, obj):
44 return (obj.meta_type == "IpNetwork" or 45 (obj.meta_type == "To Many Relationship" and 46 (obj.id == "subnetworks" or obj.id == "ipaddresses")))
47 48
49 - def mycommit(self, ip=None):
50 if not ip: 51 ipname = "all" 52 else: 53 ipname = ip.id 54 self.log.info('commiting group of ips ending with %s' % ipname) 55 trans = get_transaction() 56 trans.note('FixIps reconnect ips') 57 trans.commit() 58 self.ccount = 0
59 60
61 - def buildOptions(self):
62 ZCmdBase.buildOptions(self) 63 self.parser.add_option('-x', '--commitCount', 64 dest='commitCount', 65 default=20, 66 type="int", 67 help='how many lines should be loaded before commit') 68 69 self.parser.add_option('-n', '--noCommit', 70 dest='noCommit', 71 action="store_true", 72 default=0, 73 help='Do not store changes to the Dmd (for debugging)')
74 75 76 if __name__ == "__main__": 77 fips = FixIps() 78 fips.fixips() 79