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

# Source Code for Module Products.ZenModel.IpServiceLoader

     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  __doc__ ='''IpServiceLoader
    12
    13  A script to load the IANA well known port numbers.
    14
    15  $Id: IpServiceLoader.py,v 1.5 2004/04/15 23:47:50 edahl Exp $'''
    16
    17  __version__ = "$Revision: 1.5 $"[11:-2]
    18
    19  import os
    20  import re
    21
    22  import Globals #initalize imports correctly magic!
    23
    24  from Products.ZenUtils.BasicLoader import BasicLoader
    25
    26  from Products.ZenModel.IpService import getIpServiceKey
    27  from Products.ZenModel.IpServiceClass import IpServiceClass
    28
    29 -class IpServiceLoader(BasicLoader):
    30
    31      lineparse = re.compile(r"^(\S+)\s+(\d+)/(\S+)(.*)")
    32
    33
    34 -    def __init__(self, noopts=0, app=None):
    35          self.filename = os.path.join(os.path.dirname(__file__),
    36                              "port-numbers.txt")
    37          BasicLoader.__init__(self, noopts, app, ignoreComments=False)
    38          services = self.dmd.getDmdRoot('Services')
    39          self.privserv = services.createOrganizer("/IpService/Privileged")
    40          self.regserv = services.createOrganizer("/IpService/Registered")
    41          self.lastservice = None
    42
    43
    44 -    def loaderBody(self, line):
    45          if line.startswith("#"): return
    46          m = self.lineparse.search(line)
    47          if not m: return
    48          keyword, port, proto, descr = m.groups()
    49          descr = descr.strip()
    50          port = int(port)
    51          svc = self.privserv.find(keyword)
    52          portkey = getIpServiceKey(proto, port)
    53          if not svc:
    54              serviceKeys = (keyword, portkey)
    55              svc = IpServiceClass(keyword, serviceKeys=serviceKeys,
    56                                 description=descr, port=port)
    57              if port < 1024:
    58                  self.privserv.serviceclasses._setObject(svc.id, svc)
    59              else:
    60                  self.regserv.serviceclasses._setObject(svc.id, svc)
    61              self.log.info("Added IpServiceClass %s" % keyword)
    62          else:
    63              svc.addServiceKey(portkey)
    64
    65
    66  if __name__ == "__main__":
    67      loader = IpServiceLoader()
    68      loader.loadDatabase()
    69      print "Database Load is finished!"
    70