def _check_iface(name, typ, child_names): libvirtobj = conn.interfaceLookupByName(name) xmlobj = Interface(conn, parsexml=libvirtobj.XMLDesc(0)) self.assertEqual(xmlobj.name, name) self.assertEqual(xmlobj.type, typ) self.assertEqual({i.name for i in xmlobj.interfaces}, set(child_names))
def build_ip(addr_str): if not addr_str: return None ret = addr_str.rsplit("/", 1) ip = Interface.InterfaceProtocolIPAddress(ret[0]) if len(ret) > 1: ip.prefix = ret[1] return ip
def get_default_name(self): itype = self.get_config_interface_type() name = _("No interface selected") if itype == Interface.INTERFACE_TYPE_BRIDGE: name = Interface.find_free_name(self.conn.get_backend(), "br") elif itype == Interface.INTERFACE_TYPE_BOND: name = Interface.find_free_name(self.conn.get_backend(), "bond") else: ifaces = self.get_config_selected_interfaces() if len(ifaces) > 0: iface = ifaces[0][INTERFACE_ROW_NAME] if itype == Interface.INTERFACE_TYPE_VLAN: tag = uiutil.spin_get_helper(self.widget("vlan-tag")) name = "%s.%s" % (iface, int(tag)) elif itype == Interface.INTERFACE_TYPE_ETHERNET: name = iface return name
def _m(_n): xml = self.conn.interfaceLookupByName(_n).XMLDesc(0) return Interface(self.conn, parsexml=xml)
def build_interface(self, interface_type, name): iobj = Interface(self.conn) iobj.type = interface_type iobj.name = name return iobj
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 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)
def build_interface(self, interface_type, name): iclass = Interface.interface_class_for_type(interface_type) iobj = iclass(name, conn) return iobj
virtimage = virtinst.ImageParser.parse_file("tests/image-xml/image.xml") volinst = virtinst.Storage.StorageVolume(conn=testconn, pool_name="default-pool", name="val-vol", capacity=1) tmppool = testconn.storagePoolLookupByName("inactive-pool") tmppool.destroy() iface_proto1 = Interface.InterfaceProtocol.protocol_class_for_family( Interface.InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4)() iface_proto2 = Interface.InterfaceProtocol.protocol_class_for_family( Interface.InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV6)() iface_ip1 = Interface.InterfaceProtocolIPAddress("129.63.1.2") iface_ip2 = Interface.InterfaceProtocolIPAddress("fe80::215:58ff:fe6e:5", prefix="64") args = { 'guest' : { 'name' : { 'invalid' : ['123456789', 'im_invalid!', '', 0, 'verylongnameverylongnameverylongnamevery' 'longnameveryvery', "test" # In use, ], 'valid' : ['Valid_name.01'] }, 'memory' : { 'invalid' : [-1, 0, ''], 'valid' : [200, 2000] },
def build_ip_info(self): def get_row(widget): combo = widget.get_model() active = widget.get_active() if active == -1: return None return combo[active] def build_ip(addr_str): if not addr_str: return None ret = addr_str.rsplit("/", 1) ip = Interface.InterfaceProtocolIPAddress(ret[0]) if len(ret) > 1: ip.prefix = ret[1] return ip is_manual = self.widget("ip-do-manual").get_active() copy_row = get_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: 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 = Interface.InterfaceProtocolIPv4() ipv4.dhcp = bool(v4_mode == IP_DHCP) if not ipv4.dhcp: if v4_addr: ipv4.ips.append(build_ip(v4_addr)) if v4_gate: ipv4.gateway = v4_gate # Build IPv6 Info if v6_mode != IP_NONE: ipv6 = Interface.InterfaceProtocolIPv6() ipv6.dhcp = bool(v6_mode == IP_DHCP) ipv6.autoconf = bool(v6_auto) if not ipv6.dhcp: if v6_gate: ipv6.gateway = v6_gate if v6_addrlist: ipv6.ips = [build_ip(i) for i in v6_addrlist] return [is_manual, copy_name, ipv4, ipv6, proto_xml]
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)
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