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

Source Code for Module Products.ZenModel.MaintenanceWindowable

 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  __doc__ = """MaintenanceWindowable 
12   
13  Management functions for devices and device classes on their 
14  maintenance windows. 
15   
16  """ 
17   
18  import logging 
19  log = logging.getLogger("zen.MaintenanceWindowable") 
20   
21  from AccessControl import ClassSecurityInfo 
22  from Globals import InitializeClass 
23  from ZenossSecurity import * 
24  from MaintenanceWindow import MaintenanceWindow 
25  from Products.ZenUtils.Utils import prepId 
26  from Products.ZenWidgets import messaging 
27  from Products.ZenMessaging.audit import audit 
28   
29 -class MaintenanceWindowable:
30 31 security = ClassSecurityInfo() 32 33 security.declareProtected(ZEN_MAINTENANCE_WINDOW_VIEW, 34 'getMaintenanceWindows')
35 - def getMaintenanceWindows(self):
36 "Get the Maintenance Windows on this device" 37 return self.maintenanceWindows.objectValuesAll()
38 39 security.declareProtected(ZEN_MAINTENANCE_WINDOW_EDIT, 40 'manage_addMaintenanceWindow')
41 - def manage_addMaintenanceWindow(self, newId=None, REQUEST=None):
42 "Add a Maintenance Window to this device" 43 mw = None 44 if newId: 45 preppedId = prepId(newId) 46 mw = MaintenanceWindow(preppedId) 47 mw.name = newId 48 self.maintenanceWindows._setObject(preppedId, mw) 49 if hasattr(self, 'setLastChange'): 50 # Only Device and DeviceClass have setLastChange for now. 51 self.setLastChange() 52 if REQUEST: 53 if mw: 54 messaging.IMessageSender(self).sendToBrowser( 55 'Window Added', 56 'Maintenance window "%s" has been created.' % mw.name 57 ) 58 audit('UI.MaintenanceWindow.Add', mw) 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 if REQUEST: 83 audit('UI.MaintenanceWindow.Delete', mw) 84 self.maintenanceWindows._delObject(id) 85 if hasattr(self, 'setLastChange'): 86 # Only Device and DeviceClass have setLastChange for now. 87 self.setLastChange() 88 if REQUEST: 89 messaging.IMessageSender(self).sendToBrowser( 90 'Windows Deleted', 91 'Maintenance windows deleted: %s' % ', '.join(maintenanceIds) 92 ) 93 return self.callZenScreen(REQUEST)
94 95 96 InitializeClass(MaintenanceWindowable) 97