Trees | Indices | Help |
|
---|
|
1 ############################################################################## 2 # 3 # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 4 # 5 # This content is made available according to terms specified in 6 # License.zenoss under the directory where your Zenoss product is installed. 7 # 8 ############################################################################## 9 10 11 import logging 12 log = logging.getLogger("zen.OS") 13 14 from Software import Software 15 16 from AccessControl import ClassSecurityInfo 17 from Globals import InitializeClass 18 19 from Products.ZenUtils.Utils import convToUnits 20 from Products.ZenRelations.RelSchema import * 21 22 from Products.ZenModel.Exceptions import * 23 from Products.ZenModel.Service import Service 24 25 from IpInterface import manage_addIpInterface 26 from WinService import manage_addWinService 27 from IpService import manage_addIpService 28 from OSProcess import manage_addOSProcess, OSProcess 29 from IpRouteEntry import manage_addIpRouteEntry 30 from FileSystem import manage_addFileSystem 31 32 from Products.ZenWidgets import messaging 33 from Products.ZenUtils.Utils import prepId 3436 37 totalSwap = 0L 38 uname = "" 39 40 _properties = Software._properties + ( 41 {'id':'totalSwap', 'type':'long', 'mode':'w'}, 42 {'id':'uname', 'type':'string', 'mode':''}, 43 ) 44 45 _relations = Software._relations + ( 46 ("interfaces", ToManyCont(ToOne, 47 "Products.ZenModel.IpInterface", "os")), 48 ("routes", ToManyCont(ToOne, "Products.ZenModel.IpRouteEntry", "os")), 49 ("ipservices", ToManyCont(ToOne, "Products.ZenModel.IpService", "os")), 50 ("winservices", ToManyCont(ToOne, 51 "Products.ZenModel.WinService", "os")), 52 ("processes", ToManyCont(ToOne, "Products.ZenModel.OSProcess", "os")), 53 ("filesystems", ToManyCont(ToOne, 54 "Products.ZenModel.FileSystem", "os")), 55 ("software", ToManyCont(ToOne, "Products.ZenModel.Software", "os")), 56 ) 57 58 security = ClassSecurityInfo() 59 60 routeTypeMap = ('other', 'invalid', 'direct', 'indirect') 61 routeProtoMap = ('other', 'local', 'netmgmt', 'icmp', 62 'egp', 'ggp', 'hello', 'rip', 'is-is', 'es-is', 63 'ciscoIgrp', 'bbnSpfIgrp', 'ospf', 'bgp') 64 65 factory_type_information = ( 66 { 67 'id' : 'Device', 68 'meta_type' : 'Device', 69 'description' : """Base class for all devices""", 70 'icon' : 'Device_icon.gif', 71 'product' : 'ZenModel', 72 'factory' : 'manage_addDevice', 73 'immediate_view' : '../deviceOsDetail', 74 'actions' : () 75 }, 76 ) 77 78656 657 InitializeClass(OperatingSystem) 65880 id = "os" 81 Software.__init__(self, id) 82 self._delObject("os") # OperatingSystem is a software83 # but doens't have os relationship 84 85 8890 """ 91 Trace the route to the target from this device using our routing 92 table and return an array of IP address strings showing the route. 93 94 If the route is not traversable (ie a gap in the routing table), 95 then return the incomplete path with a final value of None. 96 97 @parameter target: destination IP to find 98 @type target: DMD device object 99 @parameter ippath: used to store intermediate results in calls. Call with [] 100 @type ippath: array-like object used for 101 @return: IP addresses to target device 102 @rtype: array of strings 103 """ 104 log.debug("traceRoute from device %s to target %s", 105 self.getDeviceName(), target) 106 # Try to find a specific route to the target device 107 nextdev = None 108 for route in sorted(self.getRouteObjs(),key=lambda route:route.routemask,reverse=True): 109 ip = route.getNextHopIp() 110 log.debug("Route %s next hop %s", route.getTarget(), ip) 111 # Have a host-route 112 if ip == target.getManageIp(): 113 ippath.append(ip) 114 return ippath 115 116 # Have a net-route 117 if route.matchTarget(target.getManageIp()): 118 if route.routetype == 'direct': 119 nextdev = target 120 break 121 nextdev = route.getNextHopDevice() 122 break 123 else: 124 # No routes matched -- try the default route (if any) 125 log.debug("Device %s default route", self.getDeviceName()) 126 ip = "" 127 default = self.routes._getOb("0.0.0.0_0", None) 128 if default: 129 ip = default.getNextHopIp() 130 nextdev = default.getNextHopDevice() 131 132 if target == nextdev or ip == "0.0.0.0": 133 ippath.append(target.id) 134 return ippath 135 136 if nextdev: 137 # Look for a bizarre case where we find a loop 138 if nextdev.manageIp not in ippath: 139 ippath.append(ip) 140 return nextdev.traceRoute(target, ippath) 141 142 # Oops! No route! 143 log.debug("Unable to trace to %s, gap at %s", target.id, 144 self.getDeviceName()) 145 ippath.append(None) 146 return ippath147 148150 """Return our real route objects. 151 """ 152 return filter(lambda r: r.target(), self.routes())153 154 159161 """Delete device components""" 162 if not componentNames: return self() 163 if isinstance(componentNames, basestring): 164 componentNames = (componentNames,) 165 for componentName in componentNames: 166 dc = context._getOb(componentName, False) 167 if dc: dc.manage_deleteComponent() 168 if REQUEST: 169 return self.callZenScreen(REQUEST)170172 """Unlock device components""" 173 if not componentNames: return self() 174 if isinstance(componentNames, basestring): 175 componentNames = (componentNames,) 176 for componentName in componentNames: 177 dc = context._getOb(componentName) 178 dc.unlock() 179 if REQUEST: 180 return self.callZenScreen(REQUEST)181182 - def lockDeviceComponentsFromDeletion(self, context, componentNames=[], 183 sendEventWhenBlocked=None, REQUEST=None):184 """Lock device components from deletion""" 185 if not componentNames: return self() 186 if isinstance(componentNames, basestring): 187 componentNames = (componentNames,) 188 for componentName in componentNames: 189 dc = context._getOb(componentName) 190 dc.lockFromDeletion(sendEventWhenBlocked) 191 if REQUEST: 192 return self.callZenScreen(REQUEST)193194 - def lockDeviceComponentsFromUpdates(self, context, componentNames=[], 195 sendEventWhenBlocked=None, REQUEST=None):196 """Lock device components from updates""" 197 if not componentNames: return self() 198 if isinstance(componentNames, basestring): 199 componentNames = (componentNames,) 200 for componentName in componentNames: 201 dc = context._getOb(componentName, False) 202 if dc: dc.lockFromUpdates(sendEventWhenBlocked) 203 if REQUEST: 204 return self.callZenScreen(REQUEST)205 206208 """Add IpInterfaces. 209 """ 210 manage_addIpInterface(self.interfaces, newId, userCreated) 211 if REQUEST: 212 messaging.IMessageSender(self).sendToBrowser( 213 'Interface Created', 214 'IP Interface %s was created.' % newId 215 ) 216 REQUEST['RESPONSE'].redirect( 217 self.interfaces._getOb(newId).absolute_url()) 218 self._p_changed = True 219 return self.callZenScreen(REQUEST)220222 """Delete IpInterfaces""" 223 self.deleteDeviceComponents(self.interfaces, componentNames, REQUEST) 224 if REQUEST: 225 messaging.IMessageSender(self).sendToBrowser( 226 'Interfaces Deleted', 227 'IP Interfaces %s was created.' % (', '.join(componentNames)) 228 ) 229 REQUEST['RESPONSE'].redirect(self.absolute_url()) 230 return self.callZenScreen(REQUEST)231232 - def setComponentMonitored(self, context, componentNames=[], 233 monitored=True, REQUEST=None):234 """ 235 Set monitored status for selected components. 236 """ 237 if isinstance(context, basestring): 238 context = getattr(self, context) 239 if not componentNames: return self() 240 if isinstance(componentNames, basestring): 241 componentNames = (componentNames,) 242 monitored = bool(monitored) 243 for componentName in componentNames: 244 comp = context._getOb(componentName, False) 245 if comp and comp.monitored() != monitored: 246 comp.monitor = monitored 247 if isinstance(comp, (Service, OSProcess)): 248 comp.setAqProperty('zMonitor', monitored, 'boolean') 249 comp.index_object() 250 if REQUEST: 251 verb = monitored and "Enabled" or "Disabled" 252 messaging.IMessageSender(self).sendToBrowser( 253 'Monitoring %s' % verb, 254 'Monitoring was %s on %s.' % (verb.lower(), 255 ', '.join(componentNames)) 256 ) 257 return self.callZenScreen(REQUEST)258260 """Unlock IpInterfaces""" 261 self.unlockDeviceComponents(self.interfaces, componentNames, REQUEST) 262 if REQUEST: 263 messaging.IMessageSender(self).sendToBrowser( 264 'Interfaces Unlocked', 265 'Interfaces %s were unlocked.' % (', '.join(componentNames)) 266 ) 267 REQUEST['RESPONSE'].redirect(self.absolute_url()) 268 return self.callZenScreen(REQUEST)269270 - def lockIpInterfacesFromDeletion(self, componentNames=[], 271 sendEventWhenBlocked=None, REQUEST=None):272 """Lock IpInterfaces from deletion""" 273 self.lockDeviceComponentsFromDeletion(self.interfaces, componentNames, 274 sendEventWhenBlocked, REQUEST) 275 if REQUEST: 276 messaging.IMessageSender(self).sendToBrowser( 277 'Interfaces Locked', 278 'Interfaces %s were locked from deletion.' % ( 279 ', '.join(componentNames)) 280 ) 281 REQUEST['RESPONSE'].redirect(self.absolute_url()) 282 return self.callZenScreen(REQUEST)283284 - def lockIpInterfacesFromUpdates(self, componentNames=[], 285 sendEventWhenBlocked=None, REQUEST=None):286 """Lock IpInterfaces from updates""" 287 self.lockDeviceComponentsFromUpdates(self.interfaces, componentNames, 288 sendEventWhenBlocked, REQUEST) 289 if REQUEST: 290 messaging.IMessageSender(self).sendToBrowser( 291 'Interfaces Locked', 292 'Interfaces %s were locked from updates and deletion.' % ( 293 ', '.join(componentNames)) 294 ) 295 REQUEST['RESPONSE'].redirect(self.absolute_url()) 296 return self.callZenScreen(REQUEST)297299 """Add an WinService. 300 """ 301 org = self.dmd.Services 302 wsc = org.unrestrictedTraverse(newClassName) 303 if wsc is not None: 304 ws = manage_addWinService(self.winservices, 305 wsc.id, 306 wsc.description, 307 userCreated=userCreated) 308 self._p_changed = True 309 elif REQUEST: 310 messaging.IMessageSender(self).sendToBrowser( 311 'No Such WinService', 312 'Could not find a WinService named %s.' % (newClassName), 313 priority=messaging.WARNING 314 ) 315 return self.callZenScreen(REQUEST) 316 317 if REQUEST: 318 messaging.IMessageSender(self).sendToBrowser( 319 'WinService Added', 320 'WinService %s was added.' % (newClassName) 321 ) 322 REQUEST['RESPONSE'].redirect(ws.absolute_url()) 323 return self.callZenScreen(REQUEST)324326 """Delete WinServices""" 327 self.deleteDeviceComponents(self.winservices, componentNames, REQUEST) 328 if REQUEST: 329 messaging.IMessageSender(self).sendToBrowser( 330 'WinServices Deleted', 331 'WinServices %s were deleted.' % (', '.join(componentNames)) 332 ) 333 REQUEST['RESPONSE'].redirect(self.absolute_url()) 334 return self.callZenScreen(REQUEST)335337 """Unlock WinServices""" 338 self.unlockDeviceComponents(self.winservices, componentNames, REQUEST) 339 if REQUEST: 340 messaging.IMessageSender(self).sendToBrowser( 341 'WinServices Unlocked', 342 'WinServices %s were unlocked.' % (', '.join(componentNames)) 343 ) 344 REQUEST['RESPONSE'].redirect(self.absolute_url()) 345 return self.callZenScreen(REQUEST)346347 - def lockWinServicesFromDeletion(self, componentNames=[], 348 sendEventWhenBlocked=None, REQUEST=None):349 """Lock WinServices from deletion""" 350 self.lockDeviceComponentsFromDeletion(self.winservices, componentNames, 351 sendEventWhenBlocked, REQUEST) 352 if REQUEST: 353 messaging.IMessageSender(self).sendToBrowser( 354 'WinServices Locked', 355 'WinServices %s were locked from deletion.' % ( 356 ', '.join(componentNames)) 357 ) 358 REQUEST['RESPONSE'].redirect(self.absolute_url()) 359 return self.callZenScreen(REQUEST)360361 - def lockWinServicesFromUpdates(self, componentNames=[], 362 sendEventWhenBlocked=None, REQUEST=None):363 """Lock WinServices from updates""" 364 self.lockDeviceComponentsFromUpdates(self.winservices, componentNames, 365 sendEventWhenBlocked, REQUEST) 366 if REQUEST: 367 messaging.IMessageSender(self).sendToBrowser( 368 'WinServices Locked', 369 'WinServices %s were locked from updates and deletion.' % ( 370 ', '.join(componentNames)) 371 ) 372 REQUEST['RESPONSE'].redirect(self.absolute_url()) 373 return self.callZenScreen(REQUEST)374 379381 """Add an OSProcess. 382 """ 383 osp = manage_addOSProcess(self.processes, newClassName, userCreated) 384 self._p_changed = True 385 if REQUEST: 386 messaging.IMessageSender(self).sendToBrowser( 387 'Process Created', 388 'OS process %s was created.' % newClassName 389 ) 390 REQUEST['RESPONSE'].redirect(osp.absolute_url())391393 """Delete OSProcesses""" 394 self.deleteDeviceComponents(self.processes, componentNames, REQUEST) 395 if REQUEST: 396 messaging.IMessageSender(self).sendToBrowser( 397 'Processes Deleted', 398 'OS processes %s were deleted.' % (', '.join(componentNames)) 399 ) 400 REQUEST['RESPONSE'].redirect(self.absolute_url()) 401 return self.callZenScreen(REQUEST)402404 """Unlock OSProcesses""" 405 self.unlockDeviceComponents(self.processes, componentNames, REQUEST) 406 if REQUEST: 407 messaging.IMessageSender(self).sendToBrowser( 408 'Processes Unlocked', 409 'OS Processes %s were unlocked.' % (', '.join(componentNames)) 410 ) 411 REQUEST['RESPONSE'].redirect(self.absolute_url()) 412 return self.callZenScreen(REQUEST)413414 - def lockOSProcessesFromDeletion(self, componentNames=[], 415 sendEventWhenBlocked=None, REQUEST=None):416 """Lock OSProcesses from deletion""" 417 self.lockDeviceComponentsFromDeletion(self.processes, componentNames, 418 sendEventWhenBlocked, REQUEST) 419 if REQUEST: 420 messaging.IMessageSender(self).sendToBrowser( 421 'Processes Locked', 422 'OS processes %s were locked from deletion.' % ( 423 ', '.join(componentNames)) 424 ) 425 REQUEST['RESPONSE'].redirect(self.absolute_url()) 426 return self.callZenScreen(REQUEST)427428 - def lockOSProcessesFromUpdates(self, componentNames=[], 429 sendEventWhenBlocked=None, REQUEST=None):430 """Lock OSProcesses from updates""" 431 self.lockDeviceComponentsFromUpdates(self.processes, componentNames, 432 sendEventWhenBlocked, REQUEST) 433 if REQUEST: 434 messaging.IMessageSender(self).sendToBrowser( 435 'Processes Locked', 436 'OS processes %s were locked from updates and deletion.' % ( 437 ', '.join(componentNames)) 438 ) 439 REQUEST['RESPONSE'].redirect(self.absolute_url()) 440 return self.callZenScreen(REQUEST)441443 """Add IpServices. 444 """ 445 org = self.dmd.Services 446 ipsc = org.unrestrictedTraverse(newClassName) 447 if ipsc is not None: 448 ips = manage_addIpService(self.ipservices, 449 ipsc.id, 450 protocol, 451 ipsc.port, 452 userCreated=userCreated) 453 self._p_changed = True 454 elif REQUEST: 455 messaging.IMessageSender(self).sendToBrowser( 456 'No Such WinService', 457 'Could not find an IP Service named %s.' % (newClassName), 458 priority=messaging.WARNING 459 ) 460 return self.callZenScreen(REQUEST) 461 462 if REQUEST: 463 messaging.IMessageSender(self).sendToBrowser( 464 'IP Service Added', 465 'IP Service %s was added.' % (newClassName) 466 ) 467 REQUEST['RESPONSE'].redirect(ips.absolute_url()) 468 return self.callZenScreen(REQUEST)469471 """Delete IpServices""" 472 self.deleteDeviceComponents(self.ipservices, componentNames, REQUEST) 473 if REQUEST: 474 messaging.IMessageSender(self).sendToBrowser( 475 'IP Services Deleted', 476 'IP Services %s were deleted.' % (', '.join(componentNames)) 477 ) 478 REQUEST['RESPONSE'].redirect(self.absolute_url()) 479 return self.callZenScreen(REQUEST)480482 """Unlock IpServices""" 483 self.unlockDeviceComponents(self.ipservices, componentNames, REQUEST) 484 if REQUEST: 485 messaging.IMessageSender(self).sendToBrowser( 486 'IpServices Unlocked', 487 'IP Services %s were unlocked.' % (', '.join(componentNames)) 488 ) 489 REQUEST['RESPONSE'].redirect(self.absolute_url()) 490 return self.callZenScreen(REQUEST)491492 - def lockIpServicesFromDeletion(self, componentNames=[], 493 sendEventWhenBlocked=None, REQUEST=None):494 """Lock IpServices from deletion""" 495 self.lockDeviceComponentsFromDeletion(self.ipservices, componentNames, 496 sendEventWhenBlocked, REQUEST) 497 if REQUEST: 498 messaging.IMessageSender(self).sendToBrowser( 499 'Services Locked', 500 'IP services %s were locked from deletion.' % ( 501 ', '.join(componentNames)) 502 ) 503 REQUEST['RESPONSE'].redirect(self.absolute_url()) 504 return self.callZenScreen(REQUEST)505506 - def lockIpServicesFromUpdates(self, componentNames=[], 507 sendEventWhenBlocked=None, REQUEST=None):508 """Lock IpServices from updates""" 509 self.lockDeviceComponentsFromUpdates(self.ipservices, componentNames, 510 sendEventWhenBlocked, REQUEST) 511 if REQUEST: 512 messaging.IMessageSender(self).sendToBrowser( 513 'Services Locked', 514 'IP services %s were locked from updates and deletion.' % ( 515 ', '.join(componentNames)) 516 ) 517 REQUEST['RESPONSE'].redirect(self.absolute_url()) 518 return self.callZenScreen(REQUEST)519521 """Add a FileSystem. 522 """ 523 fsid = prepId(newId) 524 manage_addFileSystem(self.filesystems, newId, userCreated) 525 self._p_changed = True 526 if REQUEST: 527 messaging.IMessageSender(self).sendToBrowser( 528 'Filesystem Added', 529 'Filesystem %s was added.' % newId 530 ) 531 REQUEST['RESPONSE'].redirect( 532 self.filesystems._getOb(fsid).absolute_url()) 533 return self.callZenScreen(REQUEST)534536 """Delete FileSystems""" 537 self.deleteDeviceComponents(self.filesystems, componentNames, REQUEST) 538 if REQUEST: 539 messaging.IMessageSender(self).sendToBrowser( 540 'Filesystems Deleted', 541 'Filesystems %s were deleted.' % (', '.join(componentNames)) 542 ) 543 REQUEST['RESPONSE'].redirect(self.absolute_url()) 544 return self.callZenScreen(REQUEST)545547 """Unlock FileSystems""" 548 self.unlockDeviceComponents(self.filesystems, componentNames, REQUEST) 549 if REQUEST: 550 messaging.IMessageSender(self).sendToBrowser( 551 'Filesystems Unlocked', 552 'Filesystems %s were unlocked.' % (', '.join(componentNames)) 553 ) 554 REQUEST['RESPONSE'].redirect(self.absolute_url()) 555 return self.callZenScreen(REQUEST)556557 - def lockFileSystemsFromDeletion(self, componentNames=[], 558 sendEventWhenBlocked=None, REQUEST=None):559 """Lock FileSystems from deletion""" 560 self.lockDeviceComponentsFromDeletion(self.filesystems, componentNames, 561 sendEventWhenBlocked, REQUEST) 562 if REQUEST: 563 messaging.IMessageSender(self).sendToBrowser( 564 'Filesystems Locked', 565 'Filesystems %s were locked from deletion.' % ( 566 ', '.join(componentNames)) 567 ) 568 REQUEST['RESPONSE'].redirect(self.absolute_url()) 569 return self.callZenScreen(REQUEST)570571 - def lockFileSystemsFromUpdates(self, componentNames=[], 572 sendEventWhenBlocked=None, REQUEST=None):573 """Lock FileSystems from updates""" 574 self.lockDeviceComponentsFromUpdates(self.filesystems, componentNames, 575 sendEventWhenBlocked, REQUEST) 576 if REQUEST: 577 messaging.IMessageSender(self).sendToBrowser( 578 'Filesystems Locked', 579 'Filesystems %s were locked from updates and deletion.' % ( 580 ', '.join(componentNames)) 581 ) 582 REQUEST['RESPONSE'].redirect(self.absolute_url()) 583 return self.callZenScreen(REQUEST)584585 - def addIpRouteEntry(self, dest, routemask, nexthopid, interface, 586 routeproto, routetype, userCreated, REQUEST=None):587 """Add an IpRouteEntry. 588 """ 589 manage_addIpRouteEntry(self.routes, 590 dest, 591 routemask, 592 nexthopid, 593 interface, 594 routeproto, 595 routetype, 596 userCreated=userCreated) 597 self._p_changed = True 598 if REQUEST: 599 messaging.IMessageSender(self).sendToBrowser( 600 'Route Created', 601 'IP route entry was created.' 602 ) 603 REQUEST['RESPONSE'].redirect(self.absolute_url()) 604 return self.callZenScreen(REQUEST)605607 """Delete IpRouteEntries""" 608 self.deleteDeviceComponents(self.routes, componentNames, REQUEST) 609 if REQUEST: 610 messaging.IMessageSender(self).sendToBrowser( 611 'Routes Deleted', 612 'IP route entries %s were deleted.' % (', '.join(componentNames)) 613 ) 614 REQUEST['RESPONSE'].redirect(self.absolute_url()) 615 return self.callZenScreen(REQUEST)616618 """Unlock IpRouteEntries""" 619 self.unlockDeviceComponents(self.routes, componentNames, REQUEST) 620 if REQUEST: 621 messaging.IMessageSender(self).sendToBrowser( 622 'Routes Unlocked', 623 'IP route entries %s were unlocked.' % ( 624 ', '.join(componentNames)) 625 ) 626 REQUEST['RESPONSE'].redirect(self.absolute_url()) 627 return self.callZenScreen(REQUEST)628629 - def lockIpRouteEntriesFromDeletion(self, componentNames=[], 630 sendEventWhenBlocked=None, REQUEST=None):631 """Lock IpRouteEntries from deletion""" 632 self.lockDeviceComponentsFromDeletion(self.routes, componentNames, 633 sendEventWhenBlocked, REQUEST) 634 if REQUEST: 635 messaging.IMessageSender(self).sendToBrowser( 636 'Routes Locked', 637 'IP route entries %s were locked from deletion.' % ( 638 ', '.join(componentNames)) 639 ) 640 REQUEST['RESPONSE'].redirect(self.absolute_url()) 641 return self.callZenScreen(REQUEST)642643 - def lockIpRouteEntriesFromUpdates(self, componentNames=[], 644 sendEventWhenBlocked=None, REQUEST=None):645 """Lock IpRouteEntries from updates""" 646 self.lockDeviceComponentsFromUpdates(self.routes, componentNames, 647 sendEventWhenBlocked, REQUEST) 648 if REQUEST: 649 messaging.IMessageSender(self).sendToBrowser( 650 'Routes Locked', 651 'IP route entries %s were locked from updates and deletion.' % ( 652 ', '.join(componentNames)) 653 ) 654 REQUEST['RESPONSE'].redirect(self.absolute_url()) 655 return self.callZenScreen(REQUEST)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Mon Jul 30 17:11:34 2012 | http://epydoc.sourceforge.net |