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

Source Code for Module Products.ZenModel.BasicDeviceLoader

  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 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  __doc__="""BasicDeviceLoader.py 
 15   
 16  BasicDeviceLoader.py populates the dmd with devices from a file.  The input file 
 17  only needs to have a list of machines.  It uses the Classifier system 
 18  to figure out where in the DeviceClass a new device should be created. 
 19  If no location is found it will use a specified default path or put 
 20  the device in the top level of the DevicesClass tree. 
 21  """ 
 22   
 23  from logging import info 
 24   
 25  from Products.ZenModel.Exceptions import * 
 26   
 27   
28 -class BasicDeviceLoader:
29 '''Load a machine''' 30
31 - def loadDevice(self, deviceName, devicePath="", systemPath="", 32 manufacturer="", model="", groupPath="", 33 locationPath="", rack="", 34 perfMonitorName="localhost", 35 snmpCommunity="", snmpPort=None, 36 loginName="", loginPassword=""):
37 """load a device into the database""" 38 info("adding device %s" % deviceName) 39 device = self.getDevice(deviceName, devicePath, snmpCommunity, snmpPort, 40 loginName, loginPassword) 41 42 if manufacturer and model: 43 info("setting manufacturer to %s model to %s" 44 % (manufacturer, model)) 45 device.setModel(manufacturer, model) 46 47 if not locationPath: locationPath = self.getLocationPath() 48 if locationPath: 49 if rack: 50 locationPath += "/%s" % rack 51 info("setting rack location to %s" % locationPath) 52 device.setRackLocation(locationPath) 53 else: 54 info("setting location to %s" % locationPath) 55 device.setLocation(locationPath) 56 57 if not groupPath: groupPath = self.getGroupPath() 58 if groupPath: 59 info("setting group %s" % groupPath) 60 device.setGroups(groupPath) 61 62 if not systemPath: systemPath = self.getSystemPath() 63 if systemPath: 64 info("setting system %s" % systemPath) 65 device.setSystems(systemPath) 66 67 if not perfMonitorName: 68 perfMonitorName = self.getPerformanceMonitorName() 69 info("setting performance monitor to %s" % perfMonitorName) 70 device.setPerformanceMonitor(perfMonitorName) 71 72 return device
73 74
75 - def getDevice(self, deviceName, devicePath, 76 snmpCommunity, snmpPort, loginName, loginPassword):
77 """get a device if devicePath is None try classifier""" 78 self.classificationEntry = None 79 dev = self.getDmdRoot("Devices").findDevice(deviceName) 80 if dev: 81 raise DeviceExistsError("Device %s already exists" % 82 deviceName, dev) 83 if not devicePath: 84 self.classificationEntry = \ 85 self.getDmdRoot("Devices").ZenClassifier.classifyDevice( 86 deviceName, 87 snmpCommunity, snmpPort, 88 loginName, loginPassword) 89 if not self.classificationEntry: 90 raise NotImplemented( 91 "Classifier failed to classify device %s" % deviceName) 92 devicePath = self.classificationEntry.getDeviceClassPath 93 94 deviceClass = self.getDmdRoot("Devices").getOrganizer(devicePath) 95 if not deviceClass: 96 raise PathNotFoundError( 97 "Path to device %s is not valid" % deviceName) 98 return deviceClass.createInstance(deviceName)
99 100
101 - def getLocationPath(self):
102 """get the location path for an object""" 103 pass
104 105
106 - def getGroupPath(self):
107 """override if you need to derive the group name from something else""" 108 pass
109 110
111 - def getSystemPath(self):
112 """override if you need to derive the system name from something else""" 113 pass
114 115
117 """return the performance monitor name, default is localhost""" 118 return "localhost"
119 120 121 if __name__ == "__main__": 122 loader = BasicDeviceLoader() 123 loader.loadDatabase() 124 print "Database Load is finished!" 125