1
2
3
4
5
6
7
8
9
10
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
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
102 """get the location path for an object"""
103 pass
104
105
107 """override if you need to derive the group name from something else"""
108 pass
109
110
112 """override if you need to derive the system name from something else"""
113 pass
114
115
119
120
121 if __name__ == "__main__":
122 loader = BasicDeviceLoader()
123 loader.loadDatabase()
124 print "Database Load is finished!"
125