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
Example #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:
                    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)