Trees | Indices | Help |
|
---|
|
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 import types 15 import logging 16 log = logging.getLogger("zen.ServiceOrganizer") 17 18 from Globals import DTMLFile 19 from Globals import InitializeClass 20 from AccessControl import ClassSecurityInfo 21 from AccessControl import Permissions 22 from Products.ZenModel.ZenossSecurity import * 23 from Acquisition import aq_base 24 from Commandable import Commandable 25 from ZenPackable import ZenPackable 26 27 from Products.ZenRelations.RelSchema import * 28 from Products.ZenRelations.ZenPropertyManager import iszprop 29 30 31 from Organizer import Organizer 32 from ServiceClass import ServiceClass 33 from IpServiceClass import IpServiceClass 3436 """make a device class""" 37 sc = ServiceOrganizer(id) 38 context._setObject(id, sc) 39 sc = context._getOb(id) 40 if REQUEST is not None: 41 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')42 43 addServiceOrganizer = DTMLFile('dtml/addServiceOrganizer',globals()) 4446 meta_type = "ServiceOrganizer" 47 dmdRootName = "Services" 48 default_catalog = "serviceSearch" 49 50 description = "" 51 52 _properties = ( 53 {'id':'description', 'type':'text', 'mode':'w'}, 54 ) 55 56 _relations = Organizer._relations + ZenPackable._relations + ( 57 ("serviceclasses", ToManyCont(ToOne,"Products.ZenModel.ServiceClass","serviceorganizer")), 58 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 59 ) 60 61 factory_type_information = ( 62 { 63 'id' : 'ServiceOrganizer', 64 'meta_type' : 'ServiceOrganizer', 65 'icon' : 'ServiceOrganizer.gif', 66 'product' : 'ZenModel', 67 'factory' : 'manage_addServiceOrganizer', 68 'immediate_view' : 'serviceOrganizerOverview', 69 'actions' : 70 ( 71 { 'id' : 'classes' 72 , 'name' : 'Classes' 73 , 'action' : 'serviceOrganizerOverview' 74 , 'permissions' : ( 75 Permissions.view, ) 76 }, 77 { 'id' : 'manage' 78 , 'name' : 'Administration' 79 , 'action' : 'serviceOrganizerManage' 80 , 'permissions' : ("Manage DMD",) 81 }, 82 { 'id' : 'zproperties' 83 , 'name' : 'zProperties' 84 , 'action' : 'zPropertyEdit' 85 , 'permissions' : ("Change Device",) 86 }, 87 { 'id' : 'viewHistory' 88 , 'name' : 'Modifications' 89 , 'action' : 'viewHistory' 90 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97304 305 306 InitializeClass(ServiceOrganizer) 30799 if not id: id = self.dmdRootName 100 super(ServiceOrganizer, self).__init__(id) 101 if self.id == self.dmdRootName: 102 self.createCatalog() 103 self.buildZProperties()104 105107 """Find a service class by is serviceKey. 108 """ 109 cat = getattr(self, self.default_catalog, None) 110 if not cat: return 111 brains = cat({'serviceKeys': query}) 112 if not brains: return None 113 for brain in brains: 114 if brain.getPrimaryId.startswith(self.getPrimaryId()): 115 try: 116 return self.getObjByPath(brain.getPrimaryId) 117 except KeyError: 118 log.warn("bad path '%s' for index '%s'", 119 brain.getPrimaryId, self.default_catalog)120 121123 """Count all serviceclasses with in a ServiceOrganizer. 124 """ 125 count = self.serviceclasses.countObjects() 126 for group in self.children(): 127 count += group.countClasses() 128 return count129 130131 - def createServiceClass(self, name="", description="", 132 path="", factory=ServiceClass, **kwargs):133 """Create a service class (or retrun existing) based on keywords. 134 """ 135 svcs = self.getDmdRoot(self.dmdRootName) 136 svcorg = svcs.createOrganizer(path) 137 svccl = svcorg.find(name) 138 if not svccl: 139 svccl = factory(name, (name,),description=description, **kwargs) 140 svcorg.serviceclasses._setObject(svccl.id, svccl) 141 svccl = svcorg.serviceclasses._getOb(svccl.id) 142 return svccl143145 """ 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(ServiceOrganizer, self).saveZenProperties( pfilt, REQUEST) 152 153 if monitor != self.zMonitor : 154 #indexes need to be updated so that the updated config will be sent 155 #can be slow if done at /Services would be nice to run asynch 156 self._indexServiceClassInstances() 157 return result158160 """ 161 Delete device tree properties from the this DeviceClass object. 162 Overridden to intercept zMonitor changes 163 """ 164 monitor = self.zMonitor 165 result = super(ServiceOrganizer, self).deleteZenProperty( propname, REQUEST) 166 if monitor != self.zMonitor : 167 #indexes need to be updated so that the updated config will be sent 168 #can be slow if done at /Services would be nice to run asynch 169 self._indexServiceClassInstances() 170 171 return result172174 """ 175 indexes any service class instances in the hierarchy 176 """ 177 organizers = [self] 178 while organizers: 179 for org in organizers: 180 for sc in org.serviceclasses(): 181 sc._indexInstances() 182 183 oldOrgs = organizers 184 organizers = [] 185 for org in oldOrgs: 186 organizers.extend(org.children())187 188 189 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addServiceClass')191 """Create a new service class in this Organizer. 192 """ 193 if id: 194 sc = ServiceClass(id) 195 self.serviceclasses._setObject(id, sc) 196 if REQUEST or not id: 197 return self.callZenScreen(REQUEST) 198 else: 199 return self.serviceclasses._getOb(id)200 201 202 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')204 """Create a new service class in this Organizer. 205 """ 206 if id: 207 sc = IpServiceClass(id) 208 self.serviceclasses._setObject(id, sc) 209 if REQUEST or not id: 210 return self.callZenScreen(REQUEST) 211 else: 212 return self.serviceclasses._getOb(id)213 214 217 218220 """Remove ServiceClasses from an EventClass. 221 """ 222 if not ids: return self() 223 if type(ids) == types.StringType: ids = (ids,) 224 for id in ids: 225 svc = self.serviceclasses._getOb(id) 226 svc.setZenProperty("zMonitor", monitor) 227 if REQUEST: return self()228 229231 """Remove ServiceClasses from an EventClass. 232 """ 233 if not ids: return self() 234 if type(ids) == types.StringType: ids = (ids,) 235 for id in ids: 236 self.serviceclasses._delObject(id) 237 if REQUEST: return self()238 239241 """Move ServiceClasses from this EventClass to moveTarget. 242 """ 243 if not moveTarget or not ids: return self() 244 if type(ids) == types.StringType: ids = (ids,) 245 target = self.getChildMoveTarget(moveTarget) 246 for id in ids: 247 rec = self.serviceclasses._getOb(id) 248 rec._operation = 1 # moving object state 249 self.serviceclasses._delObject(id) 250 target.serviceclasses._setObject(id, rec) 251 if REQUEST: 252 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())253 254256 if hasattr(aq_base(self), "zMonitor"): return 257 self._setProperty("zMonitor", False, type="boolean") 258 self._setProperty("zFailSeverity", 5, type="int") 259 self._setProperty("zHideFieldsFromList", [], type="lines")260 261263 """Go through all devices in this tree and reindex them.""" 264 zcat = self._getOb(self.default_catalog) 265 zcat.manage_catalogClear() 266 for srv in self.getSubOrganizers(): 267 for inst in srv.serviceclasses(): 268 inst.index_object()269 270272 """Create a catalog for ServiceClass searching""" 273 from Products.ZCatalog.ZCatalog import manage_addZCatalog 274 manage_addZCatalog(self, self.default_catalog, 275 self.default_catalog) 276 zcat = self._getOb(self.default_catalog) 277 zcat.addIndex('serviceKeys', 'KeywordIndex') 278 zcat.addColumn('getPrimaryId')279 280282 ''' Called by Commandable.doCommand() to ascertain objects on which 283 a UserCommand should be executed. 284 ''' 285 targets = [] 286 for sc in self.serviceclasses(): 287 targets += sc.getUserCommandTargets() 288 for so in self.children(): 289 targets += so.getUserCommandTargets() 290 return targets291 292294 return self.getPrimaryUrlPath() + '/serviceOrganizerManage'295 296
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Mon Oct 19 14:44:17 2009 | http://epydoc.sourceforge.net |