Ejemplo n.º 1
0
    def parse(self, args):
        tg = super().parse(args)

        if tg.iface:
            if not wait_for_network_devices([tg.iface]):
                raise KickstartParseError(
                    lineno=self.lineno,
                    msg=
                    _("Network interface \"%(nic)s\" required by iSCSI \"%(iscsiTarget)s\" target is not up."
                      ) % {
                          "nic": tg.iface,
                          "iscsiTarget": tg.target
                      })

        mode = iscsi.mode
        if mode == "none":
            if tg.iface:
                network_proxy = NETWORK.get_proxy()
                activated_ifaces = network_proxy.GetActivatedInterfaces()
                iscsi.create_interfaces(activated_ifaces)
        elif ((mode == "bind" and not tg.iface)
              or (mode == "default" and tg.iface)):
            raise KickstartParseError(
                lineno=self.lineno,
                msg=
                _("iscsi --iface must be specified (binding used) either for all targets or for none"
                  ))

        try:
            if tg.target:
                log.info("adding iscsi target %s at %s:%d via %s", tg.target,
                         tg.ipaddr, tg.port, tg.iface)
            else:
                log.info("adding all iscsi targets discovered at %s:%d via %s",
                         tg.ipaddr, tg.port, tg.iface)
            iscsi.add_target(tg.ipaddr,
                             tg.port,
                             tg.user,
                             tg.password,
                             tg.user_in,
                             tg.password_in,
                             target=tg.target,
                             iface=tg.iface)
        except (IOError, ValueError) as e:
            raise KickstartParseError(lineno=self.lineno, msg=str(e))

        return tg
Ejemplo n.º 2
0
    def _update_interfaces(self, interfaces_mode):
        """Update the interfaces according to requested mode.

        :param interfaces_mode: required mode specified by IscsiInterfacesMode
        """
        if interfaces_mode == IscsiInterfacesMode.DEFAULT and iscsi.mode in (
                "default", "none"):
            if iscsi.ifaces:
                iscsi.delete_interfaces()
        elif interfaces_mode == IscsiInterfacesMode.IFACENAME and iscsi.mode in (
                "bind", "none"):
            network_proxy = NETWORK.get_proxy()
            activated = set(network_proxy.GetActivatedInterfaces())
            created = set(iscsi.ifaces.values())
            iscsi.create_interfaces(activated - created)
        else:
            raise StorageDiscoveryError(
                'Requiring "{}" mode while "{}" is already set.'.format(
                    interfaces_mode, iscsi.mode))