예제 #1
0
    def build_interface(self, interface_type, name):
        iobj = Interface(self.conn)
        iobj.type = interface_type
        iobj.name = name

        return iobj
예제 #2
0
    def validate_details_page(self):
        itype = self.get_config_interface_type()
        name = self.get_config_interface_name()
        start = self.get_config_interface_startmode()
        ifaces = self.get_config_selected_interfaces()

        if not name:
            return self.err.val_err(_("An interface name is required."))

        if (itype != Interface.INTERFACE_TYPE_BRIDGE and len(ifaces) == 0):
            return self.err.val_err(_("An interface must be selected"))

        try:
            iobj = Interface(self.conn.get_backend())
            iobj.type = itype
            iobj.name = name
            iobj.start_mode = start
            check_conflict = False

            # Pull info from selected interfaces
            if (itype == Interface.INTERFACE_TYPE_BRIDGE
                    or itype == Interface.INTERFACE_TYPE_BOND):
                for row in ifaces:
                    if row[INTERFACE_ROW_IS_DEFINED]:
                        vmmiface = self.conn.get_interface(
                            row[INTERFACE_ROW_NAME])

                        # Use the inactive XML, which drops a bunch
                        # elements that might cause netcf to choke on
                        # for a sub-interface
                        xml = vmmiface.get_xmlobj(
                            inactive=True).get_xml_config()
                    else:
                        xml = row[INTERFACE_ROW_KEY].get_xml_config()

                    child = Interface(self.conn.get_backend(), parsexml=xml)
                    iobj.add_interface(child)
                check_conflict = True

            elif itype == Interface.INTERFACE_TYPE_VLAN:
                iobj.parent_interface = ifaces[0][INTERFACE_ROW_NAME]

            elif itype == Interface.INTERFACE_TYPE_ETHERNET:
                iobj.macaddr = ifaces[0][INTERFACE_ROW_MAC]

            # Warn about defined interfaces
            defined_ifaces = ""
            if check_conflict:
                for row in ifaces:
                    if not row[INTERFACE_ROW_IS_DEFINED]:
                        continue

                    if defined_ifaces:
                        defined_ifaces += ", "
                    defined_ifaces += row[INTERFACE_ROW_NAME]

            if defined_ifaces:
                ret = self.err.yes_no(
                    _("The following interface(s) are already "
                      "configured:\n\n%s\n\nUsing these may overwrite "
                      "their existing configuration. Are you sure you "
                      "want to use the selected interface(s)?") %
                    defined_ifaces)
                if not ret:
                    return ret

            # Validate IP info (get_config validates for us)
            (is_manual, copy_name, ipv4, ipv6,
             proto_xml) = self.get_config_ip_info()
            ignore = copy_name

            if is_manual:
                if ipv4:
                    iobj.add_protocol(ipv4)
                if ipv6:
                    iobj.add_protocol(ipv6)
            else:
                for proto in proto_xml:
                    iobj.add_protocol(
                        InterfaceProtocol(self.conn.get_backend(),
                                          parsexml=proto.get_xml_config()))

            if itype == Interface.INTERFACE_TYPE_BRIDGE:
                ret = self.validate_bridge(iobj)
            elif itype == Interface.INTERFACE_TYPE_BOND:
                ret = self.validate_bond(iobj)
            elif itype == Interface.INTERFACE_TYPE_VLAN:
                ret = self.validate_vlan(iobj)
            elif itype == Interface.INTERFACE_TYPE_ETHERNET:
                ret = self.validate_ethernet(iobj)

            if not ret:
                return ret

            iobj.get_xml_config()
            iobj.validate()

            self.interface = iobj
        except Exception as e:
            return self.err.val_err(_("Error setting interface parameters."),
                                    e)

        return True
예제 #3
0
    def populate_interface_list(self, itype):
        iface_list = self.widget("interface-list")
        model = iface_list.get_model()
        model.clear()

        ifilter = [Interface.INTERFACE_TYPE_ETHERNET]
        msg = None
        if itype == Interface.INTERFACE_TYPE_BRIDGE:
            ifilter.append(Interface.INTERFACE_TYPE_VLAN)
            ifilter.append(Interface.INTERFACE_TYPE_BOND)
            msg = _("Choose interface(s) to bridge:")

        elif itype == Interface.INTERFACE_TYPE_VLAN:
            msg = _("Choose parent interface:")
        elif itype == Interface.INTERFACE_TYPE_BOND:
            msg = _("Choose interfaces to bond:")
        elif itype == Interface.INTERFACE_TYPE_ETHERNET:
            msg = _("Choose an unconfigured interface:")

        self.widget("interface-list-text").set_text(msg)

        nodedevs = {}
        for phys in self.conn.filter_nodedevs("net"):
            nodedevs[phys.xmlobj.interface] = [
                None, False, False, phys.xmlobj.interface, "ethernet", False,
                True, None, phys.xmlobj.address
            ]

        row_dict = {}
        for iface in self.conn.list_interfaces():
            name = iface.get_name()
            key = iface.get_xmlobj()
            iface_type = iface.get_type()
            active = iface.is_active()
            name = iface.get_name()

            if iface_type not in ifilter:
                continue

            if itype == Interface.INTERFACE_TYPE_ETHERNET:
                # When adding an ethernet definition, we only want
                # 'unconfigured' interfaces, so stuff in nodedevs that's
                # not in returned by the interface APIs
                if name in nodedevs:
                    del (nodedevs[name])

                # We only want 'unconfigured' interfaces here
                continue

            if name in nodedevs:
                # Interface was listed via nodedev APIs
                row = nodedevs.pop(name)
                row[INTERFACE_ROW_KEY] = key
                row[INTERFACE_ROW_IS_DEFINED] = True
                row[INTERFACE_ROW_IS_ACTIVE] = True

            else:
                # Brand new row
                row = [
                    key, False, False,
                    iface.get_name(),
                    iface.get_type(), True, active, None,
                    iface.get_mac()
                ]
            row_dict[name] = row

        for name, row in nodedevs.items():
            try:
                key = Interface(self.conn.get_backend())
                key.type = Interface.INTERFACE_TYPE_ETHERNET
                key.name = name
            except Exception as e:
                logging.debug("Error creating stub interface '%s': %s", name,
                              e)
                continue
            row[INTERFACE_ROW_KEY] = key
            row_dict[name] = row

        for row in list(row_dict.values()):
            name = row[INTERFACE_ROW_NAME]
            row[INTERFACE_ROW_IN_USE_BY] = self.iface_in_use_by(
                self.conn, name)

        for row in list(row_dict.values()):
            model.append(row)
예제 #4
0
    def validate_details_page(self):
        itype = self.get_config_interface_type()
        name = self.get_config_interface_name()
        start = self.get_config_interface_startmode()
        ifaces = self.get_config_selected_interfaces()

        if not name:
            return self.err.val_err(_("An interface name is required."))

        if (itype != Interface.INTERFACE_TYPE_BRIDGE and
            len(ifaces) == 0):
            return self.err.val_err(_("An interface must be selected"))

        try:
            iobj = Interface(self.conn.get_backend())
            iobj.type = itype
            iobj.name = name
            iobj.start_mode = start
            check_conflict = False

            # Pull info from selected interfaces
            if (itype == Interface.INTERFACE_TYPE_BRIDGE or
                itype == Interface.INTERFACE_TYPE_BOND):
                for row in ifaces:
                    child = Interface(self.conn.get_backend(),
                        parsexml=row[INTERFACE_ROW_KEY].get_xml_config())
                    iobj.add_interface(child)
                check_conflict = True

            elif itype == Interface.INTERFACE_TYPE_VLAN:
                iobj.parent_interface = ifaces[0][INTERFACE_ROW_NAME]

            elif itype == Interface.INTERFACE_TYPE_ETHERNET:
                iobj.macaddr = ifaces[0][INTERFACE_ROW_MAC]

            # Warn about defined interfaces
            defined_ifaces = ""
            if check_conflict:
                for row in ifaces:
                    if not row[INTERFACE_ROW_IS_DEFINED]:
                        continue

                    if defined_ifaces:
                        defined_ifaces += ", "
                    defined_ifaces += row[INTERFACE_ROW_NAME]

            if defined_ifaces:
                ret = self.err.yes_no(
                        _("The following interface(s) are already "
                          "configured:\n\n%s\n\nUsing these may overwrite "
                          "their existing configuration. Are you sure you "
                          "want to use the selected interface(s)?") %
                          defined_ifaces)
                if not ret:
                    return ret

            # Validate IP info (get_config validates for us)
            (is_manual, copy_name, ipv4,
             ipv6, proto_xml) = self.get_config_ip_info()

            if is_manual:
                if ipv4:
                    iobj.add_protocol(ipv4)
                if ipv6:
                    iobj.add_protocol(ipv6)
            else:
                for proto in proto_xml:
                    iobj.add_protocol(InterfaceProtocol(
                        self.conn.get_backend(),
                        parsexml=proto.get_xml_config()))

            if itype == Interface.INTERFACE_TYPE_BRIDGE:
                ret = self.validate_bridge(iobj, ifaces)
            elif itype == Interface.INTERFACE_TYPE_BOND:
                ret = self.validate_bond(iobj, ifaces)
            elif itype == Interface.INTERFACE_TYPE_VLAN:
                ret = self.validate_vlan(iobj, ifaces)
            elif itype == Interface.INTERFACE_TYPE_ETHERNET:
                ret = self.validate_ethernet(iobj, ifaces)

            if not ret:
                return ret

            iobj.get_xml_config()
            iobj.validate()

            self.interface = iobj
        except Exception, e:
            return self.err.val_err(
                            _("Error setting interface parameters."), e)
예제 #5
0
    def populate_interface_list(self, itype):
        iface_list = self.widget("interface-list")
        model = iface_list.get_model()
        model.clear()

        ifilter = [Interface.INTERFACE_TYPE_ETHERNET]
        msg = None
        if itype == Interface.INTERFACE_TYPE_BRIDGE:
            ifilter.append(Interface.INTERFACE_TYPE_VLAN)
            ifilter.append(Interface.INTERFACE_TYPE_BOND)
            msg = _("Choose interface(s) to bridge:")

        elif itype == Interface.INTERFACE_TYPE_VLAN:
            msg = _("Choose parent interface:")
        elif itype == Interface.INTERFACE_TYPE_BOND:
            msg = _("Choose interfaces to bond:")
        elif itype == Interface.INTERFACE_TYPE_ETHERNET:
            msg = _("Choose an unconfigured interface:")

        self.widget("interface-list-text").set_text(msg)

        nodedevs = {}
        for phys in self.conn.get_nodedevs("net"):
            nodedevs[phys.interface] = [None,
                                        False, False, phys.interface,
                                        "ethernet", False, True, None,
                                        phys.address]

        row_dict = {}
        for name in self.conn.list_interface_names():
            iface = self.conn.get_interface(name)
            key = iface.get_xmlobj()
            iface_type = iface.get_type()
            active = iface.is_active()
            name = iface.get_name()

            if iface_type not in ifilter:
                continue

            if itype == Interface.INTERFACE_TYPE_ETHERNET:
                # When adding an ethernet definition, we only want
                # 'unconfigured' interfaces, so stuff in nodedevs that's
                # not in returned by the interface APIs
                if name in nodedevs:
                    del(nodedevs[name])

                # We only want 'unconfigured' interfaces here
                continue

            if name in nodedevs:
                # Interface was listed via nodedev APIs
                row = nodedevs.pop(name)
                row[INTERFACE_ROW_KEY] = key
                row[INTERFACE_ROW_IS_DEFINED] = True
                row[INTERFACE_ROW_IS_ACTIVE] = True

            else:
                # Brand new row
                row = [key, False, False,
                       iface.get_name(), iface.get_type(), True,
                       active, None, iface.get_mac()]
            row_dict[name] = row

        for name, row in nodedevs.items():
            try:
                key = Interface(self.conn.get_backend())
                key.type = Interface.INTERFACE_TYPE_ETHERNET
                key.name = name
            except Exception, e:
                logging.debug("Error creating stub interface '%s': %s",
                    name, e)
                continue
            row[INTERFACE_ROW_KEY] = key
            row_dict[name] = row
예제 #6
0
    def build_interface(self, interface_type, name):
        iobj = Interface(self.conn)
        iobj.type = interface_type
        iobj.name = name

        return iobj