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 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 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]