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

Source Code for Module Products.ZenModel.ServiceClass

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