Package Products :: Package ZenModel :: Module MaintenanceWindowable |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.MaintenanceWindowable

     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 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  __doc__ = """MaintenanceWindowable
    14
    15  Management functions for devices and device classes on their
    16  maintenance windows.
    17
    18  """
    19
    20  import logging
    21  log = logging.getLogger("zen.MaintenanceWindowable")
    22
    23  from AccessControl import ClassSecurityInfo
    24  from Globals import InitializeClass
    25  from ZenossSecurity import *
    26  from MaintenanceWindow import MaintenanceWindow
    27  from Products.ZenUtils.Utils import prepId
    28  from Products.ZenWidgets import messaging
    29
    30 -class MaintenanceWindowable:
    31
    32      security = ClassSecurityInfo()
    33
    34      security.declareProtected(ZEN_MAINTENANCE_WINDOW_VIEW,
    35          'getMaintenanceWindows')
    36 -    def getMaintenanceWindows(self):
    37          "Get the Maintenance Windows on this device"
    38          return self.maintenanceWindows.objectValuesAll()
    39
    40      security.declareProtected(ZEN_MAINTENANCE_WINDOW_EDIT,
    41          'manage_addMaintenanceWindow')
    42 -    def manage_addMaintenanceWindow(self, newId=None, REQUEST=None):
    43          "Add a Maintenance Window to this device"
    44          mw = None
    45          if newId:
    46              preppedId = prepId(newId)
    47              mw = MaintenanceWindow(preppedId)
    48              mw.name = newId
    49              self.maintenanceWindows._setObject(preppedId, mw)
    50              if hasattr(self, 'setLastChange'):
    51                  # Only Device and DeviceClass have setLastChange for now.
    52                  self.setLastChange()
    53          if REQUEST:
    54              if mw:
    55                  messaging.IMessageSender(self).sendToBrowser(
    56                      'Window Added',
    57                      'Maintenance window "%s" has been created.' % mw.name
    58                  )
    59              return self.callZenScreen(REQUEST)
    60
    61
    62      security.declareProtected(ZEN_MAINTENANCE_WINDOW_EDIT,
    63          'manage_deleteMaintenanceWindow')
    64 -    def manage_deleteMaintenanceWindow(self, maintenanceIds=(), REQUEST=None):
    65          "Delete a Maintenance Window to this device"
    66          if isinstance(maintenanceIds, basestring):
    67              maintenanceIds = [maintenanceIds]
    68          for id in maintenanceIds:
    69              mw = getattr(self.maintenanceWindows, id)
    70              if mw.started:
    71                  if REQUEST:
    72                      msg = "Closing and removing maintenance window " \
    73                            "%s which affects %s" % (
    74                           mw.displayName(), self.id)
    75                      log.info(msg)
    76                      messaging.IMessageSender(self).sendToBrowser(
    77                          'Window Stopping',
    78                          msg,
    79                      )
    80                  mw.end()
    81
    82              self.maintenanceWindows._delObject(id)
    83          if hasattr(self, 'setLastChange'):
    84              # Only Device and DeviceClass have setLastChange for now.
    85              self.setLastChange()
    86          if REQUEST:
    87              messaging.IMessageSender(self).sendToBrowser(
    88                  'Windows Deleted',
    89                  'Maintenance windows deleted: %s' % ', '.join(maintenanceIds)
    90              )
    91              return self.callZenScreen(REQUEST)
    92
    93
    94  InitializeClass(MaintenanceWindowable)
    95