1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""DeviceResult
15
16 A mixin for objects that get listed like devices
17 The primary object must implement device.
18
19 """
20
21
22 from AccessControl import ClassSecurityInfo
23 from Globals import InitializeClass
24
25
27
28 security = ClassSecurityInfo()
29
30 security.declareProtected('View', 'getDeviceName')
32 '''Get the id of this device or associated device'''
33 d = self.device()
34 if d:
35 return d.getId()
36 return "No Device"
37
38
39 security.declareProtected('View', 'getDeviceUrl')
41 '''Get the primary url path of the device in which this
42 interface is located'''
43 d = self.device()
44 if d:
45 return d.getPrimaryUrlPath()
46 return ""
47
48
49 security.declareProtected('View', 'getDeviceLink')
60
61
62 security.declareProtected('View', 'getDeviceClassPath')
64 '''Get the device class for this device'''
65 d = self.device()
66 if d:
67 return d.deviceClass().getOrganizerName()
68 return "No Device"
69 security.declareProtected('View', 'getDeviceClassName')
70 getDeviceClassName = getDeviceClassPath
71
72
73 security.declareProtected('View', 'getProdState')
81
82
83 security.declareProtected('View', 'getPingStatus')
97 security.declareProtected('View', 'getPingStatusNumber')
98 getPingStatusNumber = getPingStatus
99
100
101 security.declareProtected('View', 'getSnmpStatus')
115 getSnmpStatusNumber = getSnmpStatus
116 security.declareProtected('View', 'getSnmpStatusNumber')
117
118
119 security.declareProtected('View', 'isResultLockedFromUpdates')
121 """Return the locked from updates flag"""
122 d = self.device()
123 if d:
124 return d.isLockedFromUpdates()
125 return False
126
127 security.declareProtected('View', 'isResultLockedFromDeletion')
129 """Return the locked from deletion flag"""
130 d = self.device()
131 if d:
132 return d.isLockedFromDeletion()
133 return False
134
135 security.declareProtected('View', 'sendEventWhenResultBlocked')
142
143
144 security.declareProtected('View', 'getDeviceIp')
146 """Get the management ip (only) of a device"""
147 d = self.device()
148 if d:
149 return d.manageIp
150 return ""
151
152
153 security.declareProtected('View', 'getDeviceIpAddress')
155 """Get the management ip with netmask (1.1.1.1/24) of a device"""
156 d = self.device()
157 if d:
158 int = d.getManageInterface()
159 if int:
160 return int.getIpAddress()
161 return ""
162
163
164 security.declareProtected('View', 'getDeviceMacaddress')
173
174 security.declareProtected('View', 'getNonLoopbackIpAddresses')
176 """
177 List the IP addresses to which we can contact the service.
178 Discards the loopback (127.0.0.1) address.
179 By default do not show the netmasks.
180
181 @parameter showNetMask: return IP addresses with netmasks?
182 @type showNetMask: Boolean
183 @return: list of IP addresses
184 @rtype: array of strings
185 """
186 ip_list = []
187 dev = self.device()
188 if dev:
189 ip_list = ( obj.getIpAddress()
190 for obj in dev.os.interfaces.objectValuesAll() )
191 ip_list = [ ip for ip in ip_list if ip and \
192 not ip.startswith('127.0.0.1')]
193 else:
194 manage_ip = self.getDeviceIp()
195 if manage_ip:
196 ip_list = [ manage_ip ]
197
198 if not showNetMask:
199 ip_list = [ ip.split('/',1)[0] for ip in ip_list ]
200
201 return ip_list
202
203
204 InitializeClass(DeviceResultInt)
205