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

Source Code for Module ZenModel.ServiceClass

  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__="""ServiceClass 
 14   
 15  The service classification class.  default identifiers, screens, 
 16  and data collectors live here. 
 17   
 18  $Id: ServiceClass.py,v 1.9 2003/03/11 23:32:13 edahl Exp $""" 
 19   
 20  __version__ = "$Revision: 1.9 $"[11:-2] 
 21   
 22  from Globals import DTMLFile 
 23  from Globals import InitializeClass 
 24  from AccessControl import ClassSecurityInfo 
 25  from AccessControl import Permissions 
 26  from Products.ZenModel.ZenossSecurity import * 
 27  from Commandable import Commandable 
 28  from ZenPackable import ZenPackable 
 29   
 30  from Products.ZenRelations.RelSchema import * 
 31  from Products.ZenRelations.ZenPropertyManager import iszprop 
 32  from Products.ZenWidgets import messaging 
 33   
 34  from ZenModelRM import ZenModelRM 
 35   
36 -def manage_addServiceClass(context, id=None, REQUEST = None):
37 """make a device class""" 38 if id: 39 sc = ServiceClass(id) 40 context._setObject(id, sc) 41 sc = context._getOb(id) 42 sc.createCatalog() 43 sc.buildZProperties() 44 45 if REQUEST is not None: 46 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
47 48 addServiceClass = DTMLFile('dtml/addServiceClass',globals()) 49
50 -class ServiceClass(ZenModelRM, Commandable, ZenPackable):
51 meta_type = "ServiceClass" 52 dmdRootName = "Services" 53 default_catalog = "serviceSearch" 54 55 name = "" 56 serviceKeys = () 57 description = "" 58 port = 0 #FIXME prevent failures when ServiceClass is added manually 59 60 _properties = ( 61 {'id':'name', 'type':'string', 'mode':'w'}, 62 {'id':'serviceKeys', 'type':'lines', 'mode':'w'}, 63 {'id':'description', 'type':'text', 'mode':'w'}, 64 {'id':'port', 'type':'int', 'mode':'w'}, 65 ) 66 67 _relations = ZenPackable._relations + ( 68 ("instances", ToMany(ToOne, "Products.ZenModel.Service", "serviceclass")), 69 ("serviceorganizer", 70 ToOne(ToManyCont,"Products.ZenModel.ServiceOrganizer","serviceclasses")), 71 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 72 ) 73 74 75 factory_type_information = ( 76 { 77 'id' : 'ServiceClass', 78 'meta_type' : 'ServiceClass', 79 'icon' : 'ServiceClass.gif', 80 'product' : 'ZenModel', 81 'factory' : 'manage_addServiceClass', 82 'immediate_view' : 'serviceClassStatus', 83 'actions' : 84 ( 85 { 'id' : 'status' 86 , 'name' : 'Status' 87 , 'action' : 'serviceClassStatus' 88 , 'permissions' : ( 89 Permissions.view, ) 90 }, 91 { 'id' : 'edit' 92 , 'name' : 'Edit' 93 , 'action' : 'serviceClassEdit' 94 , 'permissions' : ("Manage DMD", ) 95 }, 96 { 'id' : 'manage' 97 , 'name' : 'Administration' 98 , 'action' : 'serviceClassManage' 99 , 'permissions' : ("Manage DMD",) 100 }, 101 { 'id' : 'zproperties' 102 , 'name' : 'zProperties' 103 , 'action' : 'zPropertyEdit' 104 , 'permissions' : ("Change Device",) 105 }, 106 { 'id' : 'viewHistory' 107 , 'name' : 'Modifications' 108 , 'action' : 'viewHistory' 109 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 110 }, 111 ) 112 }, 113 ) 114 115 security = ClassSecurityInfo() 116 117
118 - def __init__(self, id, serviceKeys=(), description=""):
119 self.name = id 120 id = self.prepId(id) 121 super(ServiceClass, self).__init__(id) 122 self.serviceKeys = serviceKeys 123 self.description = description
124 125
126 - def addServiceKey(self, key):
127 """Add a key to the service keys. 128 """ 129 if key not in self.serviceKeys: 130 self.serviceKeys = self.serviceKeys + (key,) 131 self.index_object()
132 133
134 - def count(self):
135 """Return count of instances in this class. 136 """ 137 return self.instances.countObjects()
138 139
140 - def getServiceClassName(self):
141 """Return the full name of this service class. 142 """ 143 return self.getPrimaryDmdId("Services", "serviceclasses")
144 145
146 - def manage_afterAdd(self, item, container):
147 """ 148 Device only propagates afterAdd if it is the added object. 149 """ 150 super(ServiceClass,self).manage_afterAdd(item, container) 151 self.index_object()
152 153
154 - def manage_afterClone(self, item):
155 """Not really sure when this is called.""" 156 super(ServiceClass,self).manage_afterClone(item) 157 self.index_object()
158 159
160 - def manage_beforeDelete(self, item, container):
161 """ 162 Device only propagates beforeDelete if we are being deleted or copied. 163 Moving and renaming don't propagate. 164 """ 165 super(ServiceClass,self).manage_beforeDelete(item, container) 166 self.unindex_object()
167
168 - def saveZenProperties(self, pfilt=iszprop, REQUEST=None):
169 """ 170 Save all ZenProperties found in the REQUEST.form object. 171 Overridden so that service instances can be re-indexed if needed 172 """ 173 #get value to see if it changes 174 monitor = self.zMonitor 175 result = super(ServiceClass, self).saveZenProperties( pfilt, REQUEST) 176 if monitor != self.zMonitor : 177 #indexes need to be updated so that the updated config will be sent 178 self._indexInstances() 179 180 return result
181
182 - def deleteZenProperty(self, propname=None, REQUEST=None):
183 """ 184 Delete device tree properties from the this DeviceClass object. 185 Overridden to intercept zMonitor changes 186 """ 187 monitor = self.zMonitor 188 result = super(ServiceClass, self).deleteZenProperty( propname, REQUEST) 189 if monitor != self.zMonitor : 190 #indexes need to be updated so that the updated config will be sent 191 self._indexInstances() 192 193 return result
194
195 - def _indexInstances(self):
196 """ 197 index instances of this service class to ensure changes made on the 198 Service Class are reflected in the instances indexes 199 """ 200 for inst in self.instances(): 201 inst = inst.primaryAq() 202 inst.index_object()
203 204 security.declareProtected('Manage DMD', 'manage_editServiceClass')
205 - def manage_editServiceClass(self, name="", monitor=False, serviceKeys="", 206 port=0, description="", REQUEST=None):
207 """ 208 Edit a ProductClass from a web page. 209 """ 210 self.name = name 211 id = self.prepId(name) 212 if self.zMonitor != monitor: 213 self.setZenProperty("zMonitor", monitor) 214 for inst in self.instances(): 215 inst = inst.primaryAq() 216 inst.index_object() 217 redirect = self.rename(id) 218 serviceKeys = [ l.strip() for l in serviceKeys.split('\n') ] 219 if serviceKeys != self.serviceKeys: 220 self.unindex_object() 221 self.serviceKeys = serviceKeys 222 self.index_object() 223 self._updateProperty('port', port) 224 self.description = description 225 if REQUEST: 226 from Products.ZenUtils.Time import SaveMessage 227 messaging.IMessageSender(self).sendToBrowser( 228 'Service Class Saved', 229 SaveMessage() 230 ) 231 return self.callZenScreen(REQUEST, redirect)
232 233
234 - def getUserCommandTargets(self):
235 ''' Called by Commandable.doCommand() to ascertain objects on which 236 a UserCommand should be executed. 237 ''' 238 return self.instances()
239 240
241 - def getUrlForUserCommands(self):
242 return self.getPrimaryUrlPath() + '/serviceClassManage'
243 244 245 InitializeClass(ServiceClass) 246