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