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

Source Code for Module Products.DataCollector.CommandPluginUtils

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