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