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   
 14  __doc__="""ServiceClass 
 15   
 16  The service classification class.  default identifiers, screens, 
 17  and data collectors live here. 
 18   
 19  $Id: ServiceClass.py,v 1.9 2003/03/11 23:32:13 edahl Exp $""" 
 20   
 21  __version__ = "$Revision: 1.9 $"[11:-2] 
 22   
 23  from Globals import DTMLFile 
 24  from Globals import InitializeClass 
 25  from AccessControl import ClassSecurityInfo 
 26  from AccessControl import Permissions 
 27  from Acquisition import aq_base 
 28  from Commandable import Commandable 
 29  from ZenPackable import ZenPackable 
 30   
 31  from Products.ZenRelations.RelSchema import * 
 32   
 33  from ZenModelRM import ZenModelRM 
 34   
 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 ) 65 66 _relations = ZenPackable._relations + ( 67 ("instances", ToMany(ToOne, "Products.ZenModel.Service", "serviceclass")), 68 ("serviceorganizer", 69 ToOne(ToManyCont,"Products.ZenModel.ServiceOrganizer","serviceclasses")), 70 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 71 ) 72 73 74 factory_type_information = ( 75 { 76 'id' : 'ServiceClass', 77 'meta_type' : 'ServiceClass', 78 'icon' : 'ServiceClass.gif', 79 'product' : 'ZenModel', 80 'factory' : 'manage_addServiceClass', 81 'immediate_view' : 'serviceClassStatus', 82 'actions' : 83 ( 84 { 'id' : 'status' 85 , 'name' : 'Status' 86 , 'action' : 'serviceClassStatus' 87 , 'permissions' : ( 88 Permissions.view, ) 89 }, 90 { 'id' : 'edit' 91 , 'name' : 'Edit' 92 , 'action' : 'serviceClassEdit' 93 , 'permissions' : ("Manage DMD", ) 94 }, 95 { 'id' : 'manage' 96 , 'name' : 'Administration' 97 , 'action' : 'serviceClassManage' 98 , 'permissions' : ("Manage DMD",) 99 }, 100 { 'id' : 'zproperties' 101 , 'name' : 'zProperties' 102 , 'action' : 'zPropertyEdit' 103 , 'permissions' : ("Change Device",) 104 }, 105 { 'id' : 'viewHistory' 106 , 'name' : 'Modifications' 107 , 'action' : 'viewHistory' 108 , 'permissions' : ( 109 Permissions.view, ) 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 169 security.declareProtected('Manage DMD', 'manage_editServiceClass')
170 - def manage_editServiceClass(self, name="", monitor=False, serviceKeys="", 171 port=0, description="", REQUEST=None):
172 """ 173 Edit a ProductClass from a web page. 174 """ 175 self.name = name 176 id = self.prepId(name) 177 if self.zMonitor != monitor: 178 self.setZenProperty("zMonitor", monitor) 179 for inst in self.instances(): 180 inst = inst.primaryAq() 181 inst.index_object() 182 redirect = self.rename(id) 183 serviceKeys = [ l.strip() for l in serviceKeys.split('\n') ] 184 if serviceKeys != self.serviceKeys: 185 self.unindex_object() 186 self.serviceKeys = serviceKeys 187 self.index_object() 188 self.port = port 189 self.description = description 190 if REQUEST: 191 from Products.ZenUtils.Time import SaveMessage 192 REQUEST['message'] = SaveMessage() 193 return self.callZenScreen(REQUEST, redirect)
194 195
196 - def getUserCommandTargets(self):
197 ''' Called by Commandable.doCommand() to ascertain objects on which 198 a UserCommand should be executed. 199 ''' 200 return self.instances()
201 202
203 - def getUrlForUserCommands(self):
204 return self.getPrimaryUrlPath() + '/serviceClassManage'
205 206 207 InitializeClass(ServiceClass) 208