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

Source Code for Module 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 as published by 
 8  # 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 import types 67 if type(maintenanceIds) in types.StringTypes: 68 maintenanceIds = [maintenanceIds] 69 for id in maintenanceIds: 70 mw = getattr(self.maintenanceWindows, id) 71 if mw.started: 72 if REQUEST: 73 msg = "Closing and removing maintenance window " \ 74 "%s which affects %s" % ( 75 mw.displayName(), self.id) 76 log.info(msg) 77 messaging.IMessageSender(self).sendToBrowser( 78 'Window Stopping', 79 msg, 80 ) 81 mw.end() 82 83 self.maintenanceWindows._delObject(id) 84 if hasattr(self, 'setLastChange'): 85 # Only Device and DeviceClass have setLastChange for now. 86 self.setLastChange() 87 if REQUEST: 88 messaging.IMessageSender(self).sendToBrowser( 89 'Windows Deleted', 90 'Maintenance windows deleted: %s' % ', '.join(maintenanceIds) 91 ) 92 return self.callZenScreen(REQUEST)
93 94 95 InitializeClass(MaintenanceWindowable) 96