Package Products :: Package Zuul :: Package routers :: Module devicedumpload
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.devicedumpload

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2013, 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  """DeviceDumpLoadRouter 
12   
13  Import and export device definitions using the same process 
14  provided by zenbatchload and zenbatchdump. 
15  """ 
16   
17  import logging 
18  log = logging.getLogger('zen.devicedumpload.router') 
19   
20  from Products import Zuul 
21  from Products.ZenUtils.Ext import DirectResponse, DirectRouter 
22   
23   
24 -class DeviceDumpLoadRouter(DirectRouter):
25 """ 26 Provide a file interface that device configuration can be compared 27 against and then imported into Zenoss. For large groups of devices, 28 doing each device separately consumes too much resources. 29 """ 30
31 - def _getFacade(self):
32 return Zuul.getFacade('devicedumpload', self.context)
33
34 - def exportDevices(self, deviceClass='/', options={}):
35 """ 36 Create zenbatchload format file starting from the device class. 37 """ 38 facade = self._getFacade() 39 data, dumpedCount = facade.exportDevices(deviceClass=deviceClass, 40 options=options) 41 return DirectResponse.succeed(data=data, deviceCount=dumpedCount)
42
43 - def importDevices(self, data, options={}):
44 """ 45 Create zenbatchload format file starting from the device class. 46 """ 47 facade = self._getFacade() 48 try: 49 stats = facade.importDevices(data=data, options=options) 50 except Exception: 51 log.exception("Unable to import devices: %s", data) 52 msg = "Failed -- see $ZENHOME/logs/event.log for details." 53 return DirectResponse.fail(msg=msg) 54 return DirectResponse.succeed(data=data, stats=stats)
55
56 - def listDevices(self, deviceClass='/'):
57 """ 58 List of all devices based at the device class 59 """ 60 facade = self._getFacade() 61 data = facade.listDevices(deviceClass) 62 count = len(data) 63 return DirectResponse.succeed(data=data, count=count, 64 success=True)
65