1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""IpInterface
15
16 IpInterface is a collection of devices and subsystems that make
17 up a business function
18
19 $Id: IpInterface.py,v 1.59 2004/04/23 03:01:02 edahl Exp $"""
20
21 __version__ = "$Revision: 1.59 $"[11:-2]
22
23 import re
24 import copy
25 import logging
26 log = logging.getLogger("zen.IpInterface")
27
28 from Globals import Persistent
29 from Globals import DTMLFile
30 from Globals import InitializeClass
31 from Acquisition import aq_parent
32 from Acquisition import aq_base
33 from App.Dialogs import MessageDialog
34 from AccessControl import ClassSecurityInfo
35
36 from Products.ZenRelations.RelSchema import *
37
38 from IpAddress import IpAddress, findIpAddress
39 from Products.ZenUtils.Utils import localIpCheck, localInterfaceCheck
40 from Products.ZenUtils.IpUtil import *
41
42 from ConfmonPropManager import ConfmonPropManager
43 from OSComponent import OSComponent
44 from Products.ZenModel.Exceptions import *
45
56
57 addIpInterface = DTMLFile('dtml/addIpInterface',globals())
58
59
61 """IpInterface object"""
62
63 portal_type = meta_type = 'IpInterface'
64
65 manage_editIpInterfaceForm = DTMLFile('dtml/manageEditIpInterface',
66 globals())
67
68
69
70
71
72 ifindex = '0'
73 interfaceName = ''
74 macaddress = ""
75 type = ""
76 description = ""
77 mtu = 0
78 speed = 0
79 adminStatus = 0
80 operStatus = 0
81 _ipAddresses = []
82
83
84 _properties = OSComponent._properties + (
85 {'id':'ips', 'type':'lines', 'mode':'w', 'setter':'setIpAddresses'},
86 {'id':'interfaceName', 'type':'string', 'mode':'w'},
87 {'id':'ifindex', 'type':'string', 'mode':'w'},
88 {'id':'macaddress', 'type':'string', 'mode':'w'},
89 {'id':'type', 'type':'string', 'mode':'w'},
90 {'id':'description', 'type':'string', 'mode':'w'},
91 {'id':'mtu', 'type':'int', 'mode':'w'},
92 {'id':'speed', 'type':'long', 'mode':'w'},
93 {'id':'adminStatus', 'type':'int', 'mode':'w'},
94 {'id':'operStatus', 'type':'int', 'mode':'w'},
95 )
96
97 _relations = OSComponent._relations + (
98 ("os", ToOne(ToManyCont,"Products.ZenModel.OperatingSystem","interfaces")),
99 ("ipaddresses", ToMany(ToOne,"Products.ZenModel.IpAddress","interface")),
100 ("iproutes", ToMany(ToOne,"Products.ZenModel.IpRouteEntry","interface")),
101 )
102
103 zNoPropertiesCopy = ('ips','macaddress')
104
105 localipcheck = re.compile(r'^127.|^0.').search
106 localintcheck = re.compile(r'^lo0').search
107
108 defaultIgnoreTypes = ('Other', 'softwareLoopback', 'CATV MAC Layer')
109
110 factory_type_information = (
111 {
112 'id' : 'IpInterface',
113 'meta_type' : 'IpInterface',
114 'description' : """Arbitrary device grouping class""",
115 'icon' : 'IpInterface_icon.gif',
116 'product' : 'ZenModel',
117 'factory' : 'manage_addIpInterface',
118 'immediate_view' : 'viewIpInterface',
119 'actions' :
120 (
121 { 'id' : 'status'
122 , 'name' : 'Status'
123 , 'action' : 'viewIpInterface'
124 , 'permissions' : ('View',)
125 },
126 { 'id' : 'perfConf'
127 , 'name' : 'Template'
128 , 'action' : 'objTemplates'
129 , 'permissions' : ("Change Device", )
130 },
131 { 'id' : 'viewHistory'
132 , 'name' : 'Modifications'
133 , 'action' : 'viewHistory'
134 , 'permissions' : ('View',)
135 },
136 )
137 },
138 )
139
140 security = ClassSecurityInfo()
141
145
146
147 security.declareProtected('View', 'viewName')
149 """Use the unmagled interface name for display"""
150 return self.interfaceName.rstrip('\x00')
151 name = primarySortKey = viewName
152
153
161
162
163
173
174
180
181
182 - def _prepIp(self, ip, netmask=24):
183 """Split ips in the format 1.1.1.1/24 into ip and netmask.
184 Default netmask is 24.
185 """
186 iparray = ip.split("/")
187 if len(iparray) > 1:
188 ip = iparray[0]
189 checkip(ip)
190 netmask = maskToBits(iparray[1])
191 return ip, netmask
192
193
210
211
220
221
255
256
264
265
273
274
282
283
291
292
294 """Return the first real ipaddress object or None if none are found.
295 """
296 if len(self.ipaddresses()):
297 return self.ipaddresses()[0]
298
299
308
309
311 """Return list of ip addresses as strings in the form 1.1.1.1/24.
312 """
313 return map(str, self.getIpAddressObjs())
314
315
321
322
324 """Return the network name for the first ip on this interface.
325 """
326 net = self.getNetwork()
327 if net: return net.getNetworkName()
328 return ""
329
330
344
345
347 """Return a list of network links for each ip in this interface.
348 """
349 addrs = self.ipaddresses() + self._ipAddresses
350 if addrs:
351 links = []
352 for addr in addrs:
353 if hasattr(aq_base(addr), 'network'):
354 if self.checkRemotePerm('View', addr.network()):
355 links.append(addr.network.getPrimaryLink())
356 else:
357 links.append(addr.network.getRelatedId())
358 else:
359 links.append("")
360 return "<br/>".join(links)
361 else:
362 return ""
363
364
365 security.declareProtected('View', 'getInterfaceName')
372
373 security.declareProtected('View', 'getInterfaceMacaddress')
375 """Return the mac address of this interface.
376 """
377 return self.macaddress
378
379
381 """Return the interface type as the target type name.
382 """
383 return self.prepId(self.type or "Unknown")
384
385
391
392
394 """Ignore interface that are operationally down.
395 """
396 return self.operStatus > 1
397
398
400 if not self.speed:
401 return 'Unknown'
402 speed = self.speed
403 for unit in ('bps', 'Kbps', 'Mbps', 'Gbps'):
404 if speed < 1000: break
405 speed /= 1000
406 return "%.1f%s" % (speed, unit)
407
408
410 """Unindex this interface after it is deleted.
411 """
412 if (item == self or item == self.device()
413 or getattr(item, "_operation", -1) < 1):
414 OSComponent.manage_beforeDelete(self, item, container)
415
416
417
418 InitializeClass(IpInterface)
419