Ejemplo n.º 1
0
    def accepted(mrc=mrc):
        try:
            url, connect, autoconnect = dialog.result()

            if url == mrc.cfg.url and mrc.cfg.autoconnect == autoconnect:
                return

            device_configs = [d for d in mrc.cfg]

            for d in device_configs:
                mrc.cfg.remove_device(d)

            name = mrc.cfg.name
            registry.cfg.remove_mrc(mrc.cfg)

            new_mrc = cm.ConfigMrc(url)
            new_mrc.name = name
            new_mrc.autoconnect = autoconnect

            for d in device_configs:
                new_mrc.add_device(d)

            registry.cfg.add_mrc(new_mrc)

            if connect:
                mrc = registry.hw.get_mrc(url)
                if not mrc:
                    add_mrc_connection(registry.hw, url, connect)
                elif mrc.is_disconnected():
                    mrc.connect()

        except Exception as e:
            log.exception("run_edit_mrc_config")
Ejemplo n.º 2
0
    def _cfg_registry_set(self, app_registry, old_cfg_reg, new_cfg_reg):
        if old_cfg_reg is not None:
            old_cfg_reg.mrc_added.disconnect(self._cfg_mrc_added)
            old_cfg_reg.mrc_about_to_be_removed.disconnect(self._cfg_mrc_about_to_be_removed)

            for mrc in old_cfg_reg.mrcs:
                self._cfg_mrc_about_to_be_removed(mrc)

        if new_cfg_reg is not None:
            new_cfg_reg.mrc_added.connect(self._cfg_mrc_added)
            new_cfg_reg.mrc_about_to_be_removed.connect(self._cfg_mrc_about_to_be_removed)

            for mrc in new_cfg_reg.mrcs:
                self._cfg_mrc_added(mrc)

            gen = (mrc for mrc in new_cfg_reg.mrcs
                    if new_cfg_reg.autoconnect and mrc.autoconnect)

            for cfg_mrc in gen:
                self.log.info("auto connecting %s", cfg_mrc)
                hw_mrc = self.registry.hw.get_mrc(cfg_mrc.url)
                if not hw_mrc:
                    add_mrc_connection(self.registry.hw, cfg_mrc.url, True)
                elif hw_mrc.is_disconnected():
                    hw_mrc.connect()
Ejemplo n.º 3
0
    def accepted():
        url, connect, autoconnect = dialog.result()
        mrc = cm.ConfigMrc(url)
        mrc.autoconnect = autoconnect
        registry.cfg.add_mrc(mrc)

        if connect:
            mrc = registry.hw.get_mrc(url)
            if not mrc:
                add_mrc_connection(registry.hw, url, True)
            elif mrc.is_disconnected():
                mrc.connect()
Ejemplo n.º 4
0
def establish_connections(setup, hardware_registry):
    progress = ProgressUpdate(current=0, total=len(setup))

    for cfg_mrc in setup:
        progress.text = "Connecting to %s" % cfg_mrc.get_display_url()
        yield progress

        hw_mrc = hardware_registry.get_mrc(cfg_mrc.url)

        if hw_mrc is None:
            model_util.add_mrc_connection(hardware_registry=hardware_registry,
                                          url=cfg_mrc.url,
                                          do_connect=False)

            hw_mrc = hardware_registry.get_mrc(cfg_mrc.url)

        if hw_mrc.is_connecting():
            # Cancel active connection attempts as we need the Future returned
            # by connect().
            yield hw_mrc.disconnectMrc()

        if hw_mrc.is_disconnected():
            action = ACTION_RETRY

            while action == ACTION_RETRY:
                f = yield hw_mrc.connectMrc()

                try:
                    f.result()
                    break
                except hardware_controller.TimeoutError as e:
                    action = yield e

                    if action == ACTION_SKIP:
                        break

            if action == ACTION_SKIP:
                continue

        if hw_mrc.is_connected():
            progress.text = "Connected to %s" % cfg_mrc.get_display_url()
            yield progress
            yield hw_mrc.scanbus(0)
            yield hw_mrc.scanbus(1)

        progress.increment()
Ejemplo n.º 5
0
def read_config_parameters(devices):
    skipped_mrcs = set()
    mrcs_to_connect = set(d.mrc for d in devices
                          if (not d.mrc.has_hw or not d.mrc.hw.is_connected()))

    if not isinstance(devices, list):
        devices = list(devices)

    progress = ProgressUpdate(current=0,
                              total=len(mrcs_to_connect) + len(devices))
    progress.subprogress = ProgressUpdate(current=0, total=0)

    yield progress

    for device in devices:
        mrc = device.mrc

        if mrc.hw is None:
            model_util.add_mrc_connection(
                hardware_registry=mrc.mrc_registry.hw,
                url=mrc.url,
                do_connect=False)

        if mrc in skipped_mrcs:
            continue

        if mrc.hw.is_connecting():
            # Cancel active connection attempts as we need the Future returned
            # by connect().
            yield mrc.hw.disconnectMrc()

        if mrc.hw.is_disconnected():
            progress.text = "Connecting to %s" % mrc.get_display_url()
            yield progress

            action = ACTION_RETRY

            while action == ACTION_RETRY:
                f = yield mrc.hw.connectMrc()

                try:
                    f.result()
                    (yield mrc.hw.scanbus(0)).result()
                    (yield mrc.hw.scanbus(1)).result()
                    progress.text = "Connected to %s" % mrc.get_display_url()
                    break
                except hardware_controller.TimeoutError as e:
                    action = yield e

                    if action == ACTION_SKIP:
                        skipped_mrcs.add(mrc)
                        break

            if action == ACTION_SKIP:
                yield progress.increment()
                continue

        if device.hw is None:
            yield progress.increment()
            continue

        params = (yield device.get_config_parameters()).result()
        log.debug("read_config_parameters: params=%s",
                  [p.address for p in params])
        progress.subprogress.current = 0
        progress.subprogress.total = len(params)
        pt = "Reading from (%s, %d, %X" % (device.mrc.get_display_url(),
                                           device.bus, device.address)
        if device.get_device_name():
            pt += f", {device.get_device_name()})"
        else:
            pt += ")"
        progress.text = pt
        yield progress

        for param in params:
            log.debug("read_config_parameters: reading %d", param.address)
            yield device.hw.read_parameter(param.address)
            progress.subprogress.text = "Reading parameter %s (address=%d)" % (
                param.name, param.address)
            progress.subprogress.increment()
            yield progress

        device.update_config_applied()

        yield progress.increment()
Ejemplo n.º 6
0
def fill_device_configs(devices):
    """For each of the given devices read config parameters from the hardware
    and use them to fill the device config.
    Device extensions will also be copied from hardware to config.
    """
    skipped_mrcs = set()
    mrcs_to_connect = set(d.mrc for d in devices
                          if (not d.mrc.has_hw or not d.mrc.hw.is_connected()))

    progress = ProgressUpdate(current=0,
                              total=len(mrcs_to_connect) + len(devices))
    progress.subprogress = ProgressUpdate(current=0, total=0)

    for device in devices:
        mrc = device.mrc

        if mrc.hw is None:
            model_util.add_mrc_connection(
                hardware_registry=mrc.mrc_registry.hw,
                url=mrc.url,
                do_connect=False)

        if mrc in skipped_mrcs:
            continue

        if mrc.hw.is_connecting():
            # Cancel active connection attempts as we need the Future returned
            # by connect().
            yield mrc.hw.disconnectMrc()

        if mrc.hw.is_disconnected():
            progress.text = "Connecting to %s" % mrc.get_display_url()
            yield progress

            action = ACTION_RETRY

            while action == ACTION_RETRY:
                f = yield mrc.hw.connectMrc()

                try:
                    f.result()
                    yield progress.increment()
                    break
                except hardware_controller.TimeoutError as e:
                    action = yield e

                    if action == ACTION_SKIP:
                        skipped_mrcs.add(mrc)
                        break

            if action == ACTION_SKIP:
                continue

        (yield mrc.hw.scanbus(0)).result()
        (yield mrc.hw.scanbus(1)).result()

        if not device.has_cfg:
            device.create_config()

        progress.text = "Current device: (%s, %d, %d)" % (
            device.mrc.get_display_url(), device.bus, device.address)
        yield progress

        parameters = (yield device.get_config_parameters()).result()

        gen = apply_parameters(source=device.hw,
                               dest=device.cfg,
                               criticals=list(),
                               non_criticals=parameters)
        arg = None

        while True:
            try:
                obj = gen.send(arg)

                if isinstance(obj, SetParameterError):
                    obj.url = device.mrc.url
                    obj.device = device
                    arg = yield obj

                elif isinstance(obj, ProgressUpdate):
                    progress.subprogress = obj
                    yield progress
                    arg = None
                else:
                    arg = yield obj
            except StopIteration:
                break
            except GeneratorExit:
                gen.close()
                return

        # extensions
        for name, value in device.hw.get_extensions().items():
            device.cfg.set_extension(name, value)

        yield progress.increment()
Ejemplo n.º 7
0
def apply_device_configs(devices):
    """Applies config values to the hardware for each of the given devices.
    Required MRC connections are established.
    """
    skipped_mrcs = set()
    mrcs_to_connect = set(d.mrc for d in devices
                          if (not d.mrc.has_hw or not d.mrc.hw.is_connected()))

    progress = ProgressUpdate(current=0,
                              total=len(mrcs_to_connect) + len(devices))
    progress.subprogress = ProgressUpdate(current=0, total=0)
    auto_enable_rc = False
    do_not_enable_rc = False

    yield progress

    for device in devices:
        mrc = device.mrc

        if mrc.hw is None:
            model_util.add_mrc_connection(
                hardware_registry=mrc.mrc_registry.hw,
                url=mrc.url,
                do_connect=False)

        if mrc in skipped_mrcs:
            continue

        if mrc.hw.is_connecting():
            # Cancel active connection attempts as we need the Future returned
            # by connect().
            yield mrc.hw.disconnectMrc()

        if mrc.hw.is_disconnected():
            progress.text = "Connecting to %s" % mrc.get_display_url()
            yield progress

            action = ACTION_RETRY

            while action == ACTION_RETRY:
                f = yield mrc.hw.connectMrc()

                try:
                    f.result()
                    (yield mrc.hw.scanbus(0)).result()
                    (yield mrc.hw.scanbus(1)).result()
                    progress.text = "Connected to %s" % mrc.get_display_url()
                    break
                except hardware_controller.TimeoutError as e:
                    action = yield e

                    if action == ACTION_SKIP:
                        skipped_mrcs.add(mrc)
                        break

            if action == ACTION_SKIP:
                yield progress.increment()
                continue

        # ===== Missing devices =====
        action = ACTION_RETRY

        while device.hw is None and action == ACTION_RETRY:
            action = yield MissingDestinationDevice(url=device.mrc.url,
                                                    bus=device.bus,
                                                    dev=device.address)

            if action == ACTION_SKIP:
                break

        if action == ACTION_SKIP:
            yield progress.increment()
            continue

        # ===== IDC conflict =====
        action = ACTION_RETRY

        while device.idc_conflict and action == ACTION_RETRY:
            action = yield IDCConflict(
                "%s, %d, %d)" %
                (device.mrc.get_display_url(), device.bus, device.address))

            if action == ACTION_SKIP:
                break

        if action == ACTION_SKIP:
            yield progress.increment()
            continue

        progress.text = "Current device: (%s, %d, %d)" % (
            device.mrc.get_display_url(), device.bus, device.address)
        yield progress

        # ===== RC =====
        if (device.hw and not device.idc_conflict and not device.hw.rc
                and not do_not_enable_rc):

            if auto_enable_rc:
                (yield device.hw.set_rc(True)).result()
            else:
                action = yield RcOff(device=device)

                if action in (ACTION_YES, ACTION_YES_TO_ALL):
                    (yield device.hw.set_rc(True)).result()

                    if action == ACTION_YES_TO_ALL:
                        auto_enable_rc = True
                elif action == ACTION_NO_TO_ALL:
                    do_not_enable_rc = True

        gen = apply_device_config(device)
        arg = None

        while True:
            try:
                obj = gen.send(arg)

                if isinstance(obj, ProgressUpdate):
                    progress.subprogress = obj
                    yield progress
                    arg = None
                else:
                    arg = yield obj

            except StopIteration:
                break
            except GeneratorExit:
                gen.close()
                return

        yield progress.increment()
Ejemplo n.º 8
0
 def accepted():
     try:
         url, doConnect, autoconnect = dialog.result()
         add_mrc_connection(registry.hw, url, doConnect)
     except Exception as e:
         log.exception("run_add_mrc_connection_dialog")