def get_device(cls, device_id):
        ds = Device.objects.get(id=device_id)

        with lock:
            if ds.id not in cls.devices:
                for module, pkg in plugins.devices():
                    if ds.module == module:
                        i = importlib.import_module(pkg)
                        break
                else:
                    msg = "Module %s for device %s not found." % (ds.module, ds.name)
                    raise DeviceModuleNotFound(msg)

                create_func = i.new_device_instance

                logger.debug("Creating new Device: %s(%s:%s)" % (ds.module, ds.host, ds.port))
                cls.devices[ds.id] = create_func(host=ds.host, port=ds.port, auth=UserAuth(ds.username, ds.password))
        return cls.devices[ds.id]
Esempio n. 2
0
    def get_device(cls, device_id):
        ds = Device.objects.get(id=device_id)

        with lock:
            if ds.id not in cls.devices:
                for module, pkg in plugins.devices():
                    if ds.module == module:
                        i = importlib.import_module(pkg)
                        break
                else:
                    msg = 'Module %s for device %s not found.' % (ds.module,
                                                                  ds.name)
                    raise DeviceModuleNotFound(msg)

                create_func = i.new_device_instance

                logger.debug("Creating new Device: %s(%s:%s)" %
                             (ds.module, ds.host, ds.port))
                cls.devices[ds.id] = create_func(host=ds.host,
                                                 port=ds.port,
                                                 auth=UserAuth(
                                                     ds.username, ds.password))
        return cls.devices[ds.id]
Esempio n. 3
0
 def get_modules(cls):
     """ Returns list of device modules. """
     return [module for module, pkg in plugins.devices()]
 def get_modules(cls):
     """ Returns list of device modules. """
     return [module for module, pkg in plugins.devices()]