Package ZenModel :: Module OperatingSystem
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.OperatingSystem

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  import logging 
 15  log = logging.getLogger("zen.OS") 
 16   
 17  import types 
 18   
 19  from Software import Software 
 20   
 21  from AccessControl import ClassSecurityInfo 
 22  from Globals import InitializeClass 
 23  from Acquisition import aq_base 
 24  from DateTime import DateTime 
 25   
 26  from AccessControl import Permissions as permissions 
 27   
 28  from Products.ZenUtils.Utils import convToUnits 
 29  from Products.ZenRelations.RelSchema import * 
 30   
 31  from ZenStatus import ZenStatus 
 32  from ZenDate import ZenDate 
 33  from Exceptions import * 
 34   
 35  from IpInterface import manage_addIpInterface 
 36  from WinService import manage_addWinService 
 37  from IpService import manage_addIpService 
 38  from OSProcess import manage_addOSProcess 
 39  from IpRouteEntry import manage_addIpRouteEntry 
 40  from FileSystem import manage_addFileSystem 
 41   
 42  from Products.ZenUtils.Utils import prepId 
 43   
44 -class OperatingSystem(Software):
45 46 totalSwap = 0L 47 uname = "" 48 49 _properties = Software._properties + ( 50 {'id':'totalSwap', 'type':'long', 'mode':'w'}, 51 {'id':'uname', 'type':'string', 'mode':''}, 52 ) 53 54 _relations = Software._relations + ( 55 ("interfaces", ToManyCont(ToOne, "Products.ZenModel.IpInterface", "os")), 56 ("routes", ToManyCont(ToOne, "Products.ZenModel.IpRouteEntry", "os")), 57 ("ipservices", ToManyCont(ToOne, "Products.ZenModel.IpService", "os")), 58 ("winservices", ToManyCont(ToOne, "Products.ZenModel.WinService", "os")), 59 ("processes", ToManyCont(ToOne, "Products.ZenModel.OSProcess", "os")), 60 ("filesystems", ToManyCont(ToOne, "Products.ZenModel.FileSystem", "os")), 61 ("software", ToManyCont(ToOne, "Products.ZenModel.Software", "os")), 62 ) 63 64 security = ClassSecurityInfo() 65 66 routeTypeMap = ('other', 'invalid', 'direct', 'indirect') 67 routeProtoMap = ('other', 'local', 'netmgmt', 'icmp', 68 'egp', 'ggp', 'hello', 'rip', 'is-is', 'es-is', 69 'ciscoIgrp', 'bbnSpfIgrp', 'ospf', 'bgp') 70 71 factory_type_information = ( 72 { 73 'id' : 'Device', 74 'meta_type' : 'Device', 75 'description' : """Base class for all devices""", 76 'icon' : 'Device_icon.gif', 77 'product' : 'ZenModel', 78 'factory' : 'manage_addDevice', 79 'immediate_view' : 'deviceOsDetail', 80 'actions' : 81 ( 82 { 'id' : 'status' 83 , 'name' : 'Status' 84 , 'action' : '../deviceStatus' 85 , 'permissions' : (permissions.view, ) 86 }, 87 { 'id' : 'osdetail' 88 , 'name' : 'OS' 89 , 'action' : 'deviceOsDetail' 90 , 'permissions' : (permissions.view, ) 91 }, 92 { 'id' : 'hwdetail' 93 , 'name' : 'Hardware' 94 , 'action' : '../deviceHardwareDetail' 95 , 'permissions' : (permissions.view, ) 96 }, 97 { 'id' : 'swdetail' 98 , 'name' : 'Software' 99 , 'action' : '../deviceSoftwareDetail' 100 , 'permissions' : (permissions.view, ) 101 }, 102 { 'id' : 'events' 103 , 'name' : 'Events' 104 , 'action' : '../viewEvents' 105 , 'permissions' : (permissions.view, ) 106 }, 107 { 'id' : 'historyEvents' 108 , 'name' : 'History' 109 , 'action' : '../viewHistoryEvents' 110 , 'permissions' : (permissions.view, ) 111 }, 112 { 'id' : 'perfServer' 113 , 'name' : 'Perf' 114 , 'action' : '../viewDevicePerformance' 115 , 'permissions' : (permissions.view, ) 116 }, 117 { 'id' : 'edit' 118 , 'name' : 'Edit' 119 , 'action' : '../editDevice' 120 , 'permissions' : ("Change Device",) 121 }, 122 ) 123 }, 124 ) 125 126
127 - def __init__(self):
128 id = "os" 129 Software.__init__(self, id) 130 self._delObject("os") # OperatingSystem is a software
131 # but doens't have os relationship 132 133
134 - def totalSwapString(self):
135 return self.totalSwap and convToUnits(self.totalSwap) or 'unknown'
136
137 - def traceRoute(self, target, ippath):
138 """Trace the route to target using our routing table. 139 """ 140 log.debug("device %s target %s", self.getDeviceName(), target) 141 nextdev = None 142 for route in self.getRouteObjs(): 143 ip = route.getNextHopIp() 144 log.debug("target %s next hop %s", route.getTarget(), ip) 145 if ip == target.getManageIp(): 146 ippath.append(ip) 147 return ippath 148 if route.matchTarget(target.getManageIp()): 149 nextdev = route.getNextHopDevice() 150 break 151 else: 152 log.debug("device %s default route", self.getDeviceName()) 153 ip = "" 154 default = self.routes._getOb("0.0.0.0_0", None) 155 if default: 156 ip = default.getNextHopIp() 157 nextdev = default.getNextHopDevice() 158 if target == nextdev or ip=="0.0.0.0": 159 ippath.append(target.id) 160 return ippath 161 if nextdev: 162 ippath.append(ip) 163 return nextdev.traceRoute(target, ippath) 164 raise TraceRouteGap("unable to trace to %s, gap at %s" % (target.id, 165 self.getDeviceName()))
166 167
168 - def getRouteObjs(self):
169 """Return our real route objects. 170 """ 171 return filter(lambda r: r.target(), self.routes())
172 173
174 - def device(self):
175 """Return our Device object for DeviceResultInt. 176 """ 177 return self.getPrimaryParent()
178
179 - def deleteDeviceComponents(self, context, componentNames=[], REQUEST=None):
180 """Delete device components""" 181 if not componentNames: return self() 182 if type(componentNames) in types.StringTypes: componentNames = (componentNames,) 183 for componentName in componentNames: 184 dc = context._getOb(componentName) 185 dc.manage_deleteComponent() 186 if REQUEST: 187 return self.callZenScreen(REQUEST)
188
189 - def unlockDeviceComponents(self, context, componentNames=[], REQUEST=None):
190 """Unlock device components""" 191 if not componentNames: return self() 192 if type(componentNames) in types.StringTypes: componentNames = (componentNames,) 193 for componentName in componentNames: 194 dc = context._getOb(componentName) 195 dc.unlock() 196 if REQUEST: 197 return self.callZenScreen(REQUEST)
198
199 - def lockDeviceComponentsFromDeletion(self, context, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
200 """Lock device components from deletion""" 201 if not componentNames: return self() 202 if type(componentNames) in types.StringTypes: componentNames = (componentNames,) 203 for componentName in componentNames: 204 dc = context._getOb(componentName) 205 dc.lockFromDeletion(sendEventWhenBlocked) 206 if REQUEST: 207 return self.callZenScreen(REQUEST)
208
209 - def lockDeviceComponentsFromUpdates(self, context, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
210 """Lock device components from updates""" 211 if not componentNames: return self() 212 if type(componentNames) in types.StringTypes: componentNames = (componentNames,) 213 for componentName in componentNames: 214 dc = context._getOb(componentName) 215 dc.lockFromUpdates(sendEventWhenBlocked) 216 if REQUEST: 217 return self.callZenScreen(REQUEST)
218 219
220 - def addIpInterface(self, id, userCreated, REQUEST=None):
221 """Add IpInterfaces. 222 """ 223 manage_addIpInterface(self.interfaces, id, userCreated) 224 if REQUEST: 225 REQUEST['message'] = 'IpInterface created' 226 REQUEST['RESPONSE'].redirect(self.interfaces._getOb(id).absolute_url()) 227 return self.callZenScreen(REQUEST)
228
229 - def deleteIpInterfaces(self, componentNames=[], REQUEST=None):
230 """Delete IpInterfaces""" 231 self.deleteDeviceComponents(self.interfaces, componentNames, REQUEST) 232 if REQUEST: 233 REQUEST['message'] = 'IpInterfaces deleted' 234 return self.callZenScreen(REQUEST)
235
236 - def unlockIpInterfaces(self, componentNames=[], REQUEST=None):
237 """Unlock IpInterfaces""" 238 self.unlockDeviceComponents(self.interfaces, componentNames, REQUEST) 239 if REQUEST: 240 REQUEST['message'] = 'IpInterfaces unlocked' 241 return self.callZenScreen(REQUEST)
242
243 - def lockIpInterfacesFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
244 """Lock IpInterfaces from deletion""" 245 self.lockDeviceComponentsFromDeletion(self.interfaces, componentNames, sendEventWhenBlocked, REQUEST) 246 if REQUEST: 247 REQUEST['message'] = 'IpInterfaces locked from deletion' 248 return self.callZenScreen(REQUEST)
249
250 - def lockIpInterfacesFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
251 """Lock IpInterfaces from updates""" 252 self.lockDeviceComponentsFromUpdates(self.interfaces, componentNames, sendEventWhenBlocked, REQUEST) 253 if REQUEST: 254 REQUEST['message'] = 'IpInterfaces locked from updates and deletion' 255 return self.callZenScreen(REQUEST)
256
257 - def addWinService(self, 258 className, 259 userCreated, 260 REQUEST=None):
261 """Add an WinService. 262 """ 263 org = self.dmd.Services.WinService 264 wsc = org.find(org.parseServiceLiveSearchString(className)) 265 if wsc is not None: 266 ws = manage_addWinService(self.winservices, 267 wsc.id, 268 wsc.description, 269 userCreated=userCreated) 270 elif REQUEST: 271 REQUEST['message'] = \ 272 'Could not find a WinService named %s' % className 273 return self.callZenScreen(REQUEST) 274 275 if REQUEST: 276 REQUEST['message'] = 'WinService added' 277 REQUEST['RESPONSE'].redirect(ws.absolute_url()) 278 return self.callZenScreen(REQUEST)
279
280 - def deleteWinServices(self, componentNames=[], REQUEST=None):
281 """Delete WinServices""" 282 self.deleteDeviceComponents(self.winservices, componentNames, REQUEST) 283 if REQUEST: 284 REQUEST['message'] = 'WinServices deleted' 285 return self.callZenScreen(REQUEST)
286
287 - def unlockWinServices(self, componentNames=[], REQUEST=None):
288 """Unlock WinServices""" 289 self.unlockDeviceComponents(self.winservices, componentNames, REQUEST) 290 if REQUEST: 291 REQUEST['message'] = 'WinServices unlocked' 292 return self.callZenScreen(REQUEST)
293
294 - def lockWinServicesFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
295 """Lock WinServices from deletion""" 296 self.lockDeviceComponentsFromDeletion(self.winservices, componentNames, sendEventWhenBlocked, REQUEST) 297 if REQUEST: 298 REQUEST['message'] = 'WinServices locked from deletion' 299 return self.callZenScreen(REQUEST)
300
301 - def lockWinServicesFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
302 """Lock WinServices from updates""" 303 self.lockDeviceComponentsFromUpdates(self.winservices, componentNames, sendEventWhenBlocked, REQUEST) 304 if REQUEST: 305 REQUEST['message'] = 'WinServices locked from updates and deletion' 306 return self.callZenScreen(REQUEST)
307
308 - def addOSProcess(self, className, userCreated, REQUEST=None):
309 """Add an OSProcess. 310 """ 311 osp = manage_addOSProcess(self.processes, className, userCreated) 312 if REQUEST: 313 REQUEST['message'] = 'OSProcess created' 314 REQUEST['RESPONSE'].redirect(osp.absolute_url())
315
316 - def deleteOSProcesses(self, componentNames=[], REQUEST=None):
317 """Delete OSProcesses""" 318 self.deleteDeviceComponents(self.processes, componentNames, REQUEST) 319 if REQUEST: 320 REQUEST['message'] = 'OSProcesses deleted' 321 return self.callZenScreen(REQUEST)
322
323 - def unlockOSProcesses(self, componentNames=[], REQUEST=None):
324 """Unlock OSProcesses""" 325 self.unlockDeviceComponents(self.processes, componentNames, REQUEST) 326 if REQUEST: 327 REQUEST['message'] = 'OSProcesses unlocked' 328 return self.callZenScreen(REQUEST)
329
330 - def lockOSProcessesFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
331 """Lock OSProcesses from deletion""" 332 self.lockDeviceComponentsFromDeletion(self.processes, componentNames, sendEventWhenBlocked, REQUEST) 333 if REQUEST: 334 REQUEST['message'] = 'OSProcesses locked from deletion' 335 return self.callZenScreen(REQUEST)
336
337 - def lockOSProcessesFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
338 """Lock OSProcesses from updates""" 339 self.lockDeviceComponentsFromUpdates(self.processes, componentNames, sendEventWhenBlocked, REQUEST) 340 if REQUEST: 341 REQUEST['message'] = 'OSProcesses locked from updates and deletion' 342 return self.callZenScreen(REQUEST)
343
344 - def addIpService(self, className, protocol, userCreated, REQUEST=None):
345 """Add IpServices. 346 """ 347 org = self.dmd.Services.IpService 348 ipsc = org.find(org.parseServiceLiveSearchString(className)) 349 if ipsc is not None: 350 ips = manage_addIpService(self.ipservices, 351 ipsc.id, 352 protocol, 353 ipsc.port, 354 userCreated=userCreated) 355 elif REQUEST: 356 REQUEST['message'] = \ 357 'Could not find an IpService named %s' % className 358 return self.callZenScreen(REQUEST) 359 360 if REQUEST: 361 REQUEST['message'] = 'IpService added' 362 REQUEST['RESPONSE'].redirect(ips.absolute_url()) 363 return self.callZenScreen(REQUEST)
364
365 - def deleteIpServices(self, componentNames=[], REQUEST=None):
366 """Delete IpServices""" 367 self.deleteDeviceComponents(self.ipservices, componentNames, REQUEST) 368 if REQUEST: 369 REQUEST['message'] = 'IpServices deleted' 370 return self.callZenScreen(REQUEST)
371
372 - def unlockIpServices(self, componentNames=[], REQUEST=None):
373 """Unlock IpServices""" 374 self.unlockDeviceComponents(self.ipservices, componentNames, REQUEST) 375 if REQUEST: 376 REQUEST['message'] = 'IpServices unlocked' 377 return self.callZenScreen(REQUEST)
378
379 - def lockIpServicesFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
380 """Lock IpServices from deletion""" 381 self.lockDeviceComponentsFromDeletion(self.ipservices, componentNames, sendEventWhenBlocked, REQUEST) 382 if REQUEST: 383 REQUEST['message'] = 'IpServices locked from deletion' 384 return self.callZenScreen(REQUEST)
385
386 - def lockIpServicesFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
387 """Lock IpServices from updates""" 388 self.lockDeviceComponentsFromUpdates(self.ipservices, componentNames, sendEventWhenBlocked, REQUEST) 389 if REQUEST: 390 REQUEST['message'] = 'IpServices locked from updates and deletion' 391 return self.callZenScreen(REQUEST)
392
393 - def addFileSystem(self, id, userCreated, REQUEST=None):
394 """Add a FileSystem. 395 """ 396 fsid = prepId(id) 397 manage_addFileSystem(self.filesystems, id, userCreated) 398 if REQUEST: 399 REQUEST['message'] = 'FileSystem created' 400 REQUEST['RESPONSE'].redirect(self.filesystems._getOb(fsid).absolute_url()) 401 return self.callZenScreen(REQUEST)
402
403 - def deleteFileSystems(self, componentNames=[], REQUEST=None):
404 """Delete FileSystems""" 405 self.deleteDeviceComponents(self.filesystems, componentNames, REQUEST) 406 if REQUEST: 407 REQUEST['message'] = 'FileSystems deleted' 408 return self.callZenScreen(REQUEST)
409
410 - def unlockFileSystems(self, componentNames=[], REQUEST=None):
411 """Unlock FileSystems""" 412 self.unlockDeviceComponents(self.filesystems, componentNames, REQUEST) 413 if REQUEST: 414 REQUEST['message'] = 'FileSystems unlocked' 415 return self.callZenScreen(REQUEST)
416
417 - def lockFileSystemsFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
418 """Lock FileSystems from deletion""" 419 self.lockDeviceComponentsFromDeletion(self.filesystems, componentNames, sendEventWhenBlocked, REQUEST) 420 if REQUEST: 421 REQUEST['message'] = 'FileSystems locked from deletion' 422 return self.callZenScreen(REQUEST)
423
424 - def lockFileSystemsFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
425 """Lock FileSystems from updates""" 426 self.lockDeviceComponentsFromUpdates(self.filesystems, componentNames, sendEventWhenBlocked, REQUEST) 427 if REQUEST: 428 REQUEST['message'] = 'FileSystems locked from updates and deletion' 429 return self.callZenScreen(REQUEST)
430
431 - def addIpRouteEntry(self, 432 dest, 433 routemask, 434 nexthopid, 435 interface, 436 routeproto, 437 routetype, 438 userCreated, 439 REQUEST=None):
440 """Add an IpRouteEntry. 441 """ 442 manage_addIpRouteEntry(self.routes, 443 dest, 444 routemask, 445 nexthopid, 446 interface, 447 routeproto, 448 routetype, 449 userCreated=userCreated) 450 if REQUEST: 451 REQUEST['message'] = 'IpRouteEntry created' 452 REQUEST['RESPONSE'].redirect(self.absolute_url()) 453 return self.callZenScreen(REQUEST)
454
455 - def deleteIpRouteEntries(self, componentNames=[], REQUEST=None):
456 """Delete IpRouteEntries""" 457 self.deleteDeviceComponents(self.routes, componentNames, REQUEST) 458 if REQUEST: 459 REQUEST['message'] = 'IpRouteEntries deleted' 460 return self.callZenScreen(REQUEST)
461
462 - def unlockIpRouteEntries(self, componentNames=[], REQUEST=None):
463 """Unlock IpRouteEntries""" 464 self.unlockDeviceComponents(self.routes, componentNames, REQUEST) 465 if REQUEST: 466 REQUEST['message'] = 'IpRouteEntries unlocked' 467 return self.callZenScreen(REQUEST)
468
469 - def lockIpRouteEntriesFromDeletion(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
470 """Lock IpRouteEntries from deletion""" 471 self.lockDeviceComponentsFromDeletion(self.routes, componentNames, sendEventWhenBlocked, REQUEST) 472 if REQUEST: 473 REQUEST['message'] = 'IpRouteEntries locked from deletion' 474 return self.callZenScreen(REQUEST)
475
476 - def lockIpRouteEntriesFromUpdates(self, componentNames=[], sendEventWhenBlocked=None, REQUEST=None):
477 """Lock IpRouteEntries from updates""" 478 self.lockDeviceComponentsFromUpdates(self.routes, componentNames, sendEventWhenBlocked, REQUEST) 479 if REQUEST: 480 REQUEST['message'] = 'IpRouteEntries locked from updates and deletion' 481 return self.callZenScreen(REQUEST)
482 483 InitializeClass(OperatingSystem) 484