def set_general_params(self, iface_obj): iface_obj.mtu = 1501 iface_obj.macaddr = "AA:AA:AA:AA:AA:AA" iface_obj.start_mode = Interface.INTERFACE_START_MODE_ONBOOT proto = InterfaceProtocol(self.conn) proto.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4 iface_obj.add_protocol(proto)
def testEthernetProtocolInterface(self): filename = "ethernet-copy-proto" obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET, "test-%s" % filename) protoxml = (" <protocol family='ipv6'>\n" " <dhcp/>\n" " </protocol>\n") proto = InterfaceProtocol(self.conn, parsexml=protoxml) obj.add_protocol(proto) self.define_xml(obj)
def testBridgeInterfaceIP(self): filename = "bridge-ip" obj = self.build_interface(Interface.INTERFACE_TYPE_BRIDGE, "test-%s" % filename) self.add_child_interfaces(obj) # IPv4 proto iface_proto1 = InterfaceProtocol(self.conn) iface_proto1.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4 iface_proto1.add_ip("129.63.1.2") iface_proto1.add_ip("255.255.255.0") iface_proto1.gateway = "1.2.3.4" iface_proto1.dhcp = True iface_proto1.dhcp_peerdns = True # IPv6 proto iface_proto2 = InterfaceProtocol(self.conn) iface_proto2.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV6 iface_proto2.add_ip("fe99::215:58ff:fe6e:5", prefix="32") iface_proto2.add_ip("fe80::215:58ff:fe6e:5", prefix="64") iface_proto2.gateway = "1.2.3.4" iface_proto2.dhcp = True iface_proto2.dhcp_peerdns = True iface_proto2.autoconf = True obj.add_protocol(iface_proto1) obj.add_protocol(iface_proto2) self.define_xml(obj)
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
def build_ip_info(self): def build_ip(addr_str): if not addr_str: raise ValueError(_("Please enter an IP address")) ret = addr_str.rsplit("/", 1) address = ret[0] prefix = None if len(ret) > 1: prefix = ret[1] return address, prefix is_manual = self.widget("ip-do-manual").get_active() copy_row = uiutil.get_list_selected_row( self.widget("ip-copy-interface-combo")) v4_mode = self.widget("ipv4-mode").get_active() v4_addr = self.widget("ipv4-address").get_text() v4_gate = self.widget("ipv4-gateway").get_text() v6_mode = self.widget("ipv6-mode").get_active() v6_auto = self.widget("ipv6-autoconf").get_active() v6_gate = self.widget("ipv6-gateway").get_text() v6_addrlist = self.get_config_ipv6_addresses() copy_name = None proto_xml = None ipv4 = None ipv6 = None if not is_manual: copy_vmmiface = copy_row[1] copy_cancopy = copy_row[2] if copy_vmmiface and copy_cancopy: copy_name = copy_vmmiface.get_name() # We always want the inactive protocol XML, which # will list the on disk config, not the run time config, # which doesn't list DHCP proto_xml = copy_vmmiface.get_protocol_xml(inactive=True) else: # Build IPv4 Info if v4_mode != IP_NONE: ipv4 = InterfaceProtocol(self.conn.get_backend()) ipv4.family = "ipv4" ipv4.dhcp = bool(v4_mode == IP_DHCP) if not ipv4.dhcp: addr, prefix = build_ip(v4_addr) if addr: ipv4.add_ip(addr, prefix) if v4_gate: ipv4.gateway = v4_gate # Build IPv6 Info if v6_mode != IP_NONE: ipv6 = InterfaceProtocol(self.conn.get_backend()) ipv6.family = "ipv6" ipv6.dhcp = bool(v6_mode == IP_DHCP) ipv6.autoconf = bool(v6_auto) if not ipv6.dhcp: if v6_gate: ipv6.gateway = v6_gate for v6_addr in v6_addrlist: addr, prefix = build_ip(v6_addr) if addr: ipv6.add_ip(addr, prefix) return [is_manual, copy_name, ipv4, ipv6, proto_xml]
def build_ip_info(self): def build_ip(addr_str): if not addr_str: raise ValueError(_("Please enter an IP address")) ret = addr_str.rsplit("/", 1) address = ret[0] prefix = None if len(ret) > 1: prefix = ret[1] return address, prefix is_manual = self.widget("ip-do-manual").get_active() copy_row = uiutil.get_list_selection( self.widget("ip-copy-interface-combo"), None) v4_mode = self.widget("ipv4-mode").get_active() v4_addr = self.widget("ipv4-address").get_text() v4_gate = self.widget("ipv4-gateway").get_text() v6_mode = self.widget("ipv6-mode").get_active() v6_auto = self.widget("ipv6-autoconf").get_active() v6_gate = self.widget("ipv6-gateway").get_text() v6_addrlist = self.get_config_ipv6_addresses() copy_name = None proto_xml = None ipv4 = None ipv6 = None if not is_manual: if copy_row[1] and copy_row[2]: copy_name = copy_row[1].get_name() proto_xml = copy_row[1].get_protocol_xml() else: # Build IPv4 Info if v4_mode != IP_NONE: ipv4 = InterfaceProtocol(self.conn.get_backend()) ipv4.family = "ipv4" ipv4.dhcp = bool(v4_mode == IP_DHCP) if not ipv4.dhcp: addr, prefix = build_ip(v4_addr) if addr: ipv4.add_ip(addr, prefix) if v4_gate: ipv4.gateway = v4_gate # Build IPv6 Info if v6_mode != IP_NONE: ipv6 = InterfaceProtocol(self.conn.get_backend()) ipv6.family = "ipv6" ipv6.dhcp = bool(v6_mode == IP_DHCP) ipv6.autoconf = bool(v6_auto) if not ipv6.dhcp: if v6_gate: ipv6.gateway = v6_gate for v6_addr in v6_addrlist: addr, prefix = build_ip(v6_addr) if addr: ipv6.add_ip(addr, prefix) return [is_manual, copy_name, ipv4, ipv6, proto_xml]