Ejemplo n.º 1
0
def _get_software_instance(softwarert):
    impl = softwarert.get("implements")
    if not impl:
        raise ConfigError("No implementation defined for software.")
    FM = models.Function
    impl = FM.select(FM.implementation).where(FM.name == impl).scalar()
    obj = importlib.get_callable(impl)
    return obj(softwarert)
Ejemplo n.º 2
0
 def get_equipment(self, name, role="unspecified"):
     """Get any equipment runtime from the configuration by name."""
     try:
         eqrow = models.Equipment.select().where(
             models.Equipment.name.contains(name)).get()
     except models.DoesNotExist as err:
         raise ConfigError("Bad equipment name {!r}: {!s}".format(
             name, err))
     return EquipmentRuntime(eqrow, role, debug=self._debug)
Ejemplo n.º 3
0
def _get_controller(equipmentrt, rolename):
    FM = models.Function
    impl = FM.select(FM.implementation).where(FM.name == rolename).scalar()
    if impl is None:
        raise ConfigError(
            "No implementation for role {!r} found in Function list.".format(
                rolename))
    klass = importlib.get_callable(impl)
    return klass(equipmentrt)
Ejemplo n.º 4
0
def get_testbed(name, storageurl=None, debug=False):
    """Entry point for Testbed, container of the device tree.

    Returns:
        TestBedRuntime initialized from the testbed in the database.
    """
    models.connect(storageurl)
    try:
        testbed = models.TestBed.select().where(
            models.TestBed.name == name).get()
    except models.DoesNotExist as err:
        raise ConfigError("Bad TestBed name {!r}: {}".format(name,
                                                             err)) from None
    return TestBedRuntime(testbed, debug=debug)
Ejemplo n.º 5
0
 def initializer(self):
     """The initializing controller defined for this equipment.
     
     Usually a special controller to "bootstrap" a device so that the main
     controller can function.
     """
     if self._initializer is None:
         iobjname = self._attributes.get(
             "initializer", self.model._attributes.get("initializer"))
         if iobjname is None:
             msg = "'initializer' is not defined in properties."
             logging.error(msg)
             raise ConfigError(msg)
         try:
             self._initializer = _get_controller(self, iobjname)
         except:  # noqa
             ex, err, tb = sys.exc_info()
             msg = "Initializer {!r} could not be created".format(iobjname)
             logging.exception_error(msg, err)
             if self._debug:
                 debugger.post_mortem(tb)
             tb = None
             raise ConfigError(msg) from err
     return self._initializer
Ejemplo n.º 6
0
    def console(self):
        """Console access to device.

        Often a serial port or port concentrator.
        """
        try:
            return self.get_console()
        except:  # noqa
            ex, err, tb = sys.exc_info()
            msg = "Console could not be created for {!r}".format(
                self._attributes["hostname"])
            logging.exception_error(msg, err)
            if self._debug:
                debugger.post_mortem(tb)
            tb = None
            raise ConfigError(msg) from err
Ejemplo n.º 7
0
 def get_console(self):
     """Fetch any console controller.
     
     A console is another kind of controller that provides console access to
     a device, if it defines one. Usually a serial port.
     """
     if self._console is None:
         console_config = self._attributes.get("console")
         if console_config is None:
             raise ConfigError("Equipment has no console config.")
         signals.service_dontwant.send(self, service="seriallog")
         self._console = _get_console(
             console_config,
             login=self._attributes.get("login"),
             password=self._attributes.get("password"))
     return self._console
Ejemplo n.º 8
0
 def device(self):
     """The controller defined for this equipment."""
     self._initializer = None
     if self._device is None:
         try:
             role = self._attributes["role"]
             self._device = _get_controller(self, role)
         except:  # noqa
             ex, err, tb = sys.exc_info()
             logging.exception_error(
                 "Error in device controller construction", err)
             if self._debug:
                 debugger.post_mortem(tb)
             tb = None
             raise ConfigError(
                 "controller for {!r} could not be created.".format(
                     role)) from err
     return self._device