Package Products :: Package DataCollector :: Module CommandPluginUtils |
[hide private]
[frames] | no frames]

# Source Code for Module Products.DataCollector.CommandPluginUtils

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2009, 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 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13
    14  """
    15  Utility functions for command plugins.
    16  """
    17
    18
    19  from time import strftime
    20
    21  from Products.ZenUtils import Utils
    22
    23  from Products.DataCollector.plugins.DataMaps \
    24          import RelationshipMap, ObjectMap, MultiArgs
    25
    26
    27 -def formatDate(timeTuple):
    28      """
    29      Formats timeTuple to YYYY/MM/DD HH:MM:SS.
    30
    31      >>> formatDate((2008, 12, 16, 13, 56, 29, 1, 351, -1))
    32      '2008/12/16 13:56:29'
    33      """
    34      return strftime("%Y/%m/%d %H:%M:%S", timeTuple)
    35
    36
    37 -def createSoftwareDict(prodKey, vendor, description, installDate):
    38      """
    39      Create a software dictionary that can be passed as the data parameter when
    40      constructing an ObjectMap that represents a Software entity.
    41      """
    42      return {"id": Utils.prepId(prodKey),
    43              "setProductKey": MultiArgs(prodKey, Utils.prepId(vendor)),
    44              "setDescription": description,
    45              "setInstallDate": formatDate(installDate)}
    46
    47
    48 -def createSoftwareRelationshipMap(softwareDicts):
    49      """
    50      Takes a list of software dictionaries and returns a RelationshipMap that
    51      represents that software collection.
    52      """
    53      kwargs = dict(compname="os", modname="Products.ZenModel.Software")
    54      objmaps = []
    55
    56      for softwareDict in softwareDicts:
    57          objmaps.append(ObjectMap(softwareDict, **kwargs))
    58
    59      return RelationshipMap("software", objmaps=objmaps, **kwargs)
    60