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

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