1
2
3
4
5
6
7
8
9
10
11 __doc__="""DeviceResult
12
13 A mixin for objects that get listed like devices
14 The primary object must implement device.
15
16 """
17
18
19 from AccessControl import ClassSecurityInfo
20 from Globals import InitializeClass
21
22
24
25 security = ClassSecurityInfo()
26
27 security.declareProtected('View', 'getDeviceName')
29 '''Get the id of this device or associated device'''
30 d = self.device()
31 if d:
32 return d.getId()
33 return "No Device"
34
35
36 security.declareProtected('View', 'getDeviceUrl')
38 '''Get the primary url path of the device in which this
39 interface is located'''
40 d = self.device()
41 if d:
42 return d.getPrimaryUrlPath()
43 return ""
44
45
46 security.declareProtected('View', 'getDeviceLink')
57
58
59 security.declareProtected('View', 'getDeviceClassPath')
61 '''Get the device class name for this device'''
62 d = self.device()
63 if d:
64 return d.deviceClass().getOrganizerName()
65 return "No Device"
66 security.declareProtected('View', 'getDeviceClassName')
67 getDeviceClassName = getDeviceClassPath
68
69
70 security.declareProtected('View', 'getProdState')
78
79
80 security.declareProtected('View', 'getPingStatus')
92 security.declareProtected('View', 'getPingStatusNumber')
93 getPingStatusNumber = getPingStatus
94
95
96 security.declareProtected('View', 'getSnmpStatus')
110 getSnmpStatusNumber = getSnmpStatus
111 security.declareProtected('View', 'getSnmpStatusNumber')
112
113
114 security.declareProtected('View', 'isResultLockedFromUpdates')
116 """Return the locked from updates flag"""
117 d = self.device()
118 if d:
119 return d.isLockedFromUpdates()
120 return False
121
122 security.declareProtected('View', 'isResultLockedFromDeletion')
124 """Return the locked from deletion flag"""
125 d = self.device()
126 if d:
127 return d.isLockedFromDeletion()
128 return False
129
130 security.declareProtected('View', 'sendEventWhenResultBlocked')
137
138
139 security.declareProtected('View', 'getDeviceIp')
141 """Get the management ip (only) of a device"""
142 d = self.device()
143 if d:
144 return d.manageIp
145 return ""
146
147
148 security.declareProtected('View', 'getDeviceIpAddress')
150 """Get the management ip with netmask (1.1.1.1/24) of a device"""
151 d = self.device()
152 if d:
153 int = d.getManageInterface()
154 if int:
155 return int.getIpAddress()
156 return ""
157
158
159 security.declareProtected('View', 'getDeviceMacaddress')
168
169 security.declareProtected('View', 'getNonLoopbackIpAddresses')
171 """
172 List the IP addresses to which we can contact the service.
173 Discards the loopback (127.0.0.1) address.
174 By default do not show the netmasks.
175
176 @parameter showNetMask: return IP addresses with netmasks?
177 @type showNetMask: Boolean
178 @return: list of IP addresses
179 @rtype: array of strings
180 """
181 ip_list = []
182 dev = self.device()
183 if dev:
184 ip_list = ( obj.getIpAddress()
185 for obj in dev.os.interfaces.objectValuesAll() )
186 ip_list = [ ip for ip in ip_list if ip and \
187 not ip.startswith('127.0.0.1') and \
188 not ip.startswith('::1')]
189 else:
190 manage_ip = self.getDeviceIp()
191 if manage_ip:
192 ip_list = [ manage_ip ]
193
194 if not showNetMask:
195 ip_list = [ ip.split('/',1)[0] for ip in ip_list ]
196
197 return ip_list
198
199
200 InitializeClass(DeviceResultInt)
201