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

# Source Code for Module Products.ZenModel.OSProcessOrganizer

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