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 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  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                  { 'id'            : 'viewHistory'
    110                  , 'name'          : 'Modifications'
    111                  , 'action'        : 'viewHistory'
    112                  , 'permissions'   : (ZEN_VIEW_MODIFICATIONS,)
    113                  },
    114              )
    115           },
    116          )
    117
    118      security = ClassSecurityInfo()
    119
    120
    121 -    def __init__(self, id, serviceKeys=(), description=""):
    122          self.name = id
    123          id = self.prepId(id)
    124          super(ServiceClass, self).__init__(id)
    125          self.serviceKeys = serviceKeys
    126          self.description = description
    127
    128
    129 -    def addServiceKey(self, key):
    130          """Add a key to the service keys.
    131          """
    132          if key not in self.serviceKeys:
    133              self.serviceKeys = self.serviceKeys + (key,)
    134              self.index_object()
    135
    136
    137 -    def count(self):
    138          """Return count of instances in this class.
    139          """
    140          return self.instances.countObjects()
    141
    142
    143 -    def getServiceClassName(self):
    144          """Return the full name of this service class.
    145          """
    146          return self.getPrimaryDmdId("Services", "serviceclasses")
    147
    148
    149 -    def saveZenProperties(self, pfilt=iszprop, REQUEST=None):
    150          """
    151          Save all ZenProperties found in the REQUEST.form object.
    152          Overridden so that service instances can be re-indexed if needed
    153          """
    154          #get value to see if it changes
    155          monitor = self.zMonitor
    156          result = super(ServiceClass, self).saveZenProperties( pfilt, REQUEST)
    157          if monitor != self.zMonitor :
    158              #indexes need to be updated so that the updated config will be sent
    159              self._indexInstances()
    160
    161          return result
    162
    163 -    def deleteZenProperty(self, propname=None, REQUEST=None):
    164          """
    165          Delete device tree properties from the this DeviceClass object.
    166          Overridden to intercept zMonitor changes
    167          """
    168          monitor = self.zMonitor
    169          result = super(ServiceClass, self).deleteZenProperty( propname, REQUEST)
    170          if monitor != self.zMonitor :
    171              #indexes need to be updated so that the updated config will be sent
    172              self._indexInstances()
    173
    174          return result
    175
    176 -    def _indexInstances(self):
    177          """
    178          index instances of this service class to ensure changes made on the
    179          Service Class are reflected in the instances indexes
    180          """
    181          for inst in self.instances():
    182                  inst = inst.primaryAq()
    183                  inst.index_object()
    184
    185      security.declareProtected('Manage DMD', 'manage_editServiceClass')
    186 -    def manage_editServiceClass(self, name="", monitor=False, serviceKeys="",
    187                                 port=0, description="", REQUEST=None):
    188          """
    189          Edit a ProductClass from a web page.
    190          """
    191          self.name = name
    192          id = self.prepId(name)
    193          if self.zMonitor != monitor:
    194              self.setZenProperty("zMonitor", monitor)
    195              for inst in self.instances():
    196                  inst = inst.primaryAq()
    197                  inst.index_object()
    198          redirect = self.rename(id)
    199          serviceKeys = [ l.strip() for l in serviceKeys.split('\n') ]
    200          if serviceKeys != self.serviceKeys:
    201              self.unindex_object()
    202              self.serviceKeys = serviceKeys
    203              self.index_object()
    204          self.port = port
    205          self.description = description
    206          if REQUEST:
    207              from Products.ZenUtils.Time import SaveMessage
    208              messaging.IMessageSender(self).sendToBrowser(
    209                  'Service Class Saved',
    210                  SaveMessage()
    211              )
    212              return self.callZenScreen(REQUEST, redirect)
    213
    214
    215 -    def getUserCommandTargets(self):
    216          ''' Called by Commandable.doCommand() to ascertain objects on which
    217          a UserCommand should be executed.
    218          '''
    219          return self.instances()
    220
    221
    222 -    def getUrlForUserCommands(self):
    223          return self.getPrimaryUrlPath() + '/serviceClassManage'
    224
    225
    226  InitializeClass(ServiceClass)
    227