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')
95 security.declareProtected('View', 'getPingStatusNumber')
96 getPingStatusNumber = getPingStatus
97
98
99 security.declareProtected('View', 'getSnmpStatus')
113 getSnmpStatusNumber = getSnmpStatus
114 security.declareProtected('View', 'getSnmpStatusNumber')
115
116
117 security.declareProtected('View', 'isResultLockedFromUpdates')
119 """Return the locked from updates flag"""
120 d = self.device()
121 if d:
122 return d.isLockedFromUpdates()
123 return False
124
125 security.declareProtected('View', 'isResultLockedFromDeletion')
127 """Return the locked from deletion flag"""
128 d = self.device()
129 if d:
130 return d.isLockedFromDeletion()
131 return False
132
133 security.declareProtected('View', 'sendEventWhenResultBlocked')
140
141
142 security.declareProtected('View', 'getDeviceIp')
144 """Get the management ip (only) of a device"""
145 d = self.device()
146 if d:
147 return d.manageIp
148 return ""
149
150
151 security.declareProtected('View', 'getDeviceIpAddress')
153 """Get the management ip with netmask (1.1.1.1/24) of a device"""
154 d = self.device()
155 if d:
156 int = d.getManageInterface()
157 if int:
158 return int.getIpAddress()
159 return ""
160
161
162 security.declareProtected('View', 'getDeviceMacaddress')
171
172 security.declareProtected('View', 'getNonLoopbackIpAddresses')
174 """
175 List the IP addresses to which we can contact the service.
176 Discards the loopback (127.0.0.1) address.
177 By default do not show the netmasks.
178
179 @parameter showNetMask: return IP addresses with netmasks?
180 @type showNetMask: Boolean
181 @return: list of IP addresses
182 @rtype: array of strings
183 """
184 ip_list = []
185 dev = self.device()
186 if dev:
187 ip_list = ( obj.getIpAddress()
188 for obj in dev.os.interfaces.objectValuesAll() )
189 ip_list = [ ip for ip in ip_list if ip and \
190 not ip.startswith('127.0.0.1') and \
191 not ip.startswith('::1')]
192 else:
193 manage_ip = self.getDeviceIp()
194 if manage_ip:
195 ip_list = [ manage_ip ]
196
197 if not showNetMask:
198 ip_list = [ ip.split('/',1)[0] for ip in ip_list ]
199
200 return ip_list
201
202
203 InitializeClass(DeviceResultInt)
204