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

# Source Code for Module Products.ZenModel.OSProcessOrganizer

      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.OSProcessOrganizer")
     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 Products.ZenRelations.RelSchema import *
     26  from ZenPackable import ZenPackable
     27
     28  from Organizer import Organizer
     29  from OSProcessClass import OSProcessClass
     30
     31 -def manage_addOSProcessOrganizer(context, id, REQUEST = None):
     32      """make a device class"""
     33      sc = OSProcessOrganizer(id)
     34      context._setObject(id, sc)
     35      sc = context._getOb(id)
     36      if REQUEST is not None:
     37          REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
     38
     39  addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
     40
     41 -class OSProcessOrganizer(Organizer, Commandable, ZenPackable):
     42      meta_type = "OSProcessOrganizer"
     43      dmdRootName = "Processes"
     44      #default_catalog = "osprocessSearch"
     45
     46      description = ""
     47
     48      _properties = (
     49          {'id':'description', 'type':'text', 'mode':'w'},
     50          )
     51
     52      _relations = Organizer._relations + ZenPackable._relations + (
     53          ("osProcessClasses", ToManyCont(
     54              ToOne,"Products.ZenModel.OSProcessClass","osProcessOrganizer")),
     55          ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
     56          )
     57
     58      factory_type_information = (
     59          {
     60              'immediate_view' : 'osProcessOrganizerOverview',
     61              'actions'        :
     62              (
     63                  { 'id'            : 'classes'
     64                  , 'name'          : 'Classes'
     65                  , 'action'        : 'osProcessOrganizerOverview'
     66                  , 'permissions'   : (
     67                    Permissions.view, )
     68                  },
     69                  { 'id'            : 'resequence'
     70                  , 'name'          : 'Sequence'
     71                  , 'action'        : 'osProcessResequence'
     72                  , 'permissions'   : (
     73                    Permissions.view, )
     74                  },
     75                  { 'id'            : 'manage'
     76                  , 'name'          : 'Administration'
     77                  , 'action'        : 'osProcessOrganizerManage'
     78                  , 'permissions'   : ("Manage DMD",)
     79                  },
     80                  { 'id'            : 'zproperties'
     81                  , 'name'          : 'zProperties'
     82                  , 'action'        : 'zPropertyEdit'
     83                  , 'permissions'   : ("Change Device",)
     84                  },
     85                  { 'id'            : 'viewHistory'
     86                  , 'name'          : 'Modifications'
     87                  , 'action'        : 'viewHistory'
     88                  , 'permissions'   : (ZEN_VIEW_MODIFICATIONS,)
     89                  },
     90              )
     91           },
     92          )
     93
     94      security = ClassSecurityInfo()
     95
     96 -    def __init__(self, id=None):
     97          if not id: id = self.dmdRootName
     98          super(OSProcessOrganizer, self).__init__(id)
     99          if self.id == self.dmdRootName:
    100              self.buildZProperties()
    101
    102
    103 -    def zentinelTabs(self, templateName):
    104          """Return a list of hashs that define the screen tabs for this object.
    105          [{'name':'Name','action':'template','selected':False},...]
    106          """
    107          tabs = Organizer.zentinelTabs(self, templateName)
    108          if self.getPrimaryId() != '/zport/dmd/Processes':
    109              tabs = [t for t in tabs if t['id'] != 'resequence']
    110          return tabs
    111
    112
    113 -    def getSubOSProcessClassesGen(self):
    114          """Return generator that goes through all process classes.
    115          """
    116          for proc in self.osProcessClasses.objectValuesGen():
    117              yield proc
    118          for subgroup in self.children():
    119              for proc in subgroup.getSubOSProcessClassesGen():
    120                  yield proc
    121
    122
    123 -    def getSubOSProcessClassesSorted(self):
    124          '''Return list of the process classes sorted by sequence.
    125          '''
    126          def cmpProc(a, b):
    127              return cmp(a.sequence, b.sequence)
    128          procs = list(self.getSubOSProcessClassesGen())
    129          procs.sort(cmpProc)
    130          for i, p in enumerate(procs):
    131              p.sequence = i
    132          return procs
    133
    134
    135 -    def countClasses(self):
    136          """Count all osprocessclasses with in a ServiceOrganizer.
    137          """
    138          count = self.osProcessClasses.countObjects()
    139          for group in self.children():
    140              count += group.countClasses()
    141          return count
    142
    143
    144      security.declareProtected(ZEN_ADD, 'manage_addOSProcessClass')
    145 -    def manage_addOSProcessClass(self, id=None, REQUEST=None):
    146          """Create a new service class in this Organizer.
    147          """
    148          if id:
    149              sc = OSProcessClass(id)
    150              sc.sequence = len(self.osProcessClasses())
    151              self.osProcessClasses._setObject(id, sc)
    152          if REQUEST:
    153              return self.callZenScreen(REQUEST)
    154          else:
    155              return self.osProcessClasses._getOb(id)
    156
    157
    158 -    def manage_resequenceProcesses(self, seqmap=(), origseq=(), REQUEST=None):
    159          "resequence the OsProcesses"
    160          from Products.ZenUtils.Utils import resequence
    161          return resequence(self, self.getSubOSProcessClassesGen(),
    162                              seqmap, origseq, REQUEST)
    163
    164 -    def unmonitorOSProcessClasses(self, ids=None, REQUEST=None):
    165          return self.monitorOSProcessClasses(ids, False, REQUEST)
    166
    167
    168 -    def monitorOSProcessClasses(self, ids=None, monitor=True, REQUEST=None):
    169          """Remove OSProcessClasses from an EventClass.
    170          """
    171          if not ids: return self()
    172          if type(ids) == types.StringType: ids = (ids,)
    173          for id in ids:
    174              svc = self.osProcessClasses._getOb(id)
    175              svc.setZenProperty("zMonitor", monitor)
    176          if REQUEST: return self()
    177
    178
    179 -    def removeOSProcessClasses(self, ids=None, REQUEST=None):
    180          """Remove OSProcessClasses from an EventClass.
    181          """
    182          if not ids: return self()
    183          if type(ids) == types.StringType: ids = (ids,)
    184          for id in ids:
    185              # delete related os process instances
    186              klass = self.osProcessClasses._getOb(id)
    187              for p in klass.instances():
    188                  p.device().os.processes._delObject(p.id)
    189              self.osProcessClasses._delObject(id)
    190          self.manage_resequenceProcesses()
    191          if REQUEST: return self()
    192
    193
    194 -    def moveOSProcessClasses(self, moveTarget, ids=None, REQUEST=None):
    195          """Move OSProcessClasses from this EventClass to moveTarget.
    196          """
    197          if not moveTarget or not ids: return self()
    198          if type(ids) == types.StringType: ids = (ids,)
    199          target = self.getChildMoveTarget(moveTarget)
    200          for id in ids:
    201              rec = self.osProcessClasses._getOb(id)
    202              rec._operation = 1 # moving object state
    203              self.osProcessClasses._delObject(id)
    204              target.osProcessClasses._setObject(id, rec)
    205          if REQUEST:
    206              REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
    207
    208
    209 -    def buildZProperties(self):
    210          if hasattr(aq_base(self), "zCountProcs"): return
    211          self._setProperty("zCountProcs", False, type="boolean")
    212          self._setProperty("zAlertOnRestart", False, type="boolean")
    213          self._setProperty("zMonitor", True, type="boolean")
    214          self._setProperty("zFailSeverity", 4, type="int")
    215
    216
    217 -    def getUserCommandTargets(self):
    218          ''' Called by Commandable.doCommand() to ascertain objects on which
    219          a UserCommand should be executed.
    220          '''
    221          targets = []
    222          for osc in self.osProcessClasses():
    223              targets += osc.getUserCommandTargets()
    224          for org in self.children():
    225              targets += org.getUserCommandTargets()
    226          return targets
    227
    228
    229 -    def getUrlForUserCommands(self):
    230          return self.getPrimaryUrlPath() + '/osProcessOrganizerManage'
    231
    232
    233  InitializeClass(OSProcessOrganizer)
    234