1
2
3
4
5
6
7
8
9
10
11
12
13 from Products.ZenUtils.Utils import getSubObjects
14
15 from Products.ZenUtils.ZCmdBase import ZCmdBase
16 from transaction import get_transaction
17
19
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
41
42
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
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
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