def find_ifcfg_file_of_device(devname, root_path=""): ifcfg_path = None if devname not in nm.nm_devices(): return None if nm.nm_device_type_is_wifi(devname): ssid = nm.nm_device_active_ssid(devname) if ssid: ifcfg_path = find_ifcfg_file([("ESSID", ssid)]) elif nm.nm_device_type_is_bond(devname): ifcfg_path = find_ifcfg_file([("DEVICE", devname)]) elif nm.nm_device_type_is_team(devname): ifcfg_path = find_ifcfg_file([("DEVICE", devname)]) elif nm.nm_device_type_is_vlan(devname): ifcfg_path = find_ifcfg_file([("DEVICE", devname)]) elif nm.nm_device_type_is_ethernet(devname): try: hwaddr = nm.nm_device_hwaddress(devname) except nm.PropertyNotFoundError: hwaddr = None if hwaddr: hwaddr_check = lambda mac: mac.upper() == hwaddr.upper() nonempty = lambda x: x # slave configration created in GUI takes precedence ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("MASTER", nonempty)], root_path) if not ifcfg_path: ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("TEAM_MASTER", nonempty)], root_path) if not ifcfg_path: ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)], root_path) if not ifcfg_path: ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path) return ifcfg_path
def ksdata_from_ifcfg(devname): if nm.nm_device_is_slave(devname): return None ifcfg_path = None # Find ifcfg file for the device. # If the device is active, use uuid of its active connection. uuid = nm.nm_device_active_con_uuid(devname) if uuid: ifcfg_path = find_ifcfg_file([("UUID", uuid)]) else: # If not, look it up by other values depending on its type if nm.nm_device_type_is_ethernet(devname): ifcfg_path = find_ifcfg_file_of_device(devname) elif nm.nm_device_type_is_wifi(devname): ssid = nm.nm_device_active_ssid(devname) if ssid: ifcfg_path = find_ifcfg_file([("ESSID", ssid)]) elif nm.nm_device_type_is_bond(devname): ifcfg_path = find_ifcfg_file([("DEVICE", devname)]) elif nm.nm_device_type_is_vlan(devname): ifcfg_path = find_ifcfg_file([("DEVICE", devname)]) if not ifcfg_path: return None ifcfg = IfcfgFile(ifcfg_path) ifcfg.read() nd = ifcfg_to_ksdata(ifcfg, devname) if not nd: return None if nm.nm_device_type_is_ethernet(devname): nd.device = devname elif nm.nm_device_type_is_wifi(devname): nm.device = "" elif nm.nm_device_type_is_bond(devname): nd.device = devname elif nm.nm_device_type_is_vlan(devname): nd.device = devname.split(".")[0] return nd
def ksdata_from_ifcfg(devname, uuid=None): if devname not in nm.nm_devices(): return None if nm.nm_device_is_slave(devname): return None if nm.nm_device_type_is_wifi(devname): # wifi from kickstart is not supported yet return None if not uuid: # Find ifcfg file for the device. # If the device is active, use uuid of its active connection. uuid = nm.nm_device_active_con_uuid(devname) if uuid: ifcfg_path = find_ifcfg_file([("UUID", uuid)]) else: # look it up by other values depending on its type ifcfg_path = find_ifcfg_file_of_device(devname) if not ifcfg_path: return None ifcfg = IfcfgFile(ifcfg_path) ifcfg.read() nd = ifcfg_to_ksdata(ifcfg, devname) if not nd: return None if nm.nm_device_type_is_ethernet(devname): nd.device = devname elif nm.nm_device_type_is_wifi(devname): nm.device = "" elif nm.nm_device_type_is_bond(devname): nd.device = devname elif nm.nm_device_type_is_team(devname): nd.device = devname elif nm.nm_device_type_is_vlan(devname): if devname != default_ks_vlan_interface_name(nd.device, nd.vlanid): nd.interfacename = devname return nd
def ksdata_from_ifcfg(devname, uuid=None): if nm.nm_device_is_slave(devname): return None if nm.nm_device_type_is_wifi(devname): # wifi from kickstart is not supported yet return None if not uuid: # Find ifcfg file for the device. # If the device is active, use uuid of its active connection. uuid = nm.nm_device_active_con_uuid(devname) if uuid: ifcfg_path = find_ifcfg_file([("UUID", uuid)]) else: # look it up by other values depending on its type ifcfg_path = find_ifcfg_file_of_device(devname) if not ifcfg_path: return None ifcfg = IfcfgFile(ifcfg_path) ifcfg.read() nd = ifcfg_to_ksdata(ifcfg, devname) if not nd: return None if nm.nm_device_type_is_ethernet(devname): nd.device = devname elif nm.nm_device_type_is_wifi(devname): nm.device = "" elif nm.nm_device_type_is_bond(devname): nd.device = devname elif nm.nm_device_type_is_team(devname): nd.device = devname elif nm.nm_device_type_is_vlan(devname): if devname != default_ks_vlan_interface_name(nd.device, nd.vlanid): nd.interfacename = devname return nd
def status_message(): """ A short string describing which devices are connected. """ msg = _("Unknown") state = nm.nm_state() if state == NetworkManager.State.CONNECTING: msg = _("Connecting...") elif state == NetworkManager.State.DISCONNECTING: msg = _("Disconnecting...") else: active_devs = nm.nm_activated_devices() if active_devs: slaves = {} ssids = {} # first find slaves and wireless aps for devname in active_devs: slaves[devname] = nm.nm_device_slaves(devname) or [] if nm.nm_device_type_is_wifi(devname): ssids[devname] = nm.nm_device_active_ssid(devname) or "" all_slaves = set(itertools.chain.from_iterable(slaves.values())) nonslaves = [dev for dev in active_devs if dev not in all_slaves] if len(nonslaves) == 1: devname = nonslaves[0] if nm.nm_device_type_is_ethernet(devname): msg = _("Wired (%(interface_name)s) connected") % {"interface_name": devname} elif nm.nm_device_type_is_wifi(devname): msg = _("Wireless connected to %(access_point)s") % {"access_point": ssids[devname]} elif nm.nm_device_type_is_bond(devname): msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") % { "interface_name": devname, "list_of_slaves": ",".join(slaves[devname]), } elif nm.nm_device_type_is_team(devname): msg = _("Team%(interface_name)s (%(list_of_slaves)s) connected") % { "interface_name": devname, "list_of_slaves": ",".join(slaves[devname]), } elif nm.nm_device_type_is_vlan(devname): parent = nm.nm_device_setting_value(devname, "vlan", "parent") vlanid = nm.nm_device_setting_value(devname, "vlan", "id") msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") % { "interface_name": devname, "parent_device": parent, "vlanid": vlanid, } elif len(nonslaves) > 1: devlist = [] for devname in nonslaves: if nm.nm_device_type_is_ethernet(devname): devlist.append("%s" % devname) elif nm.nm_device_type_is_wifi(devname): devlist.append("%s" % ssids[devname]) elif nm.nm_device_type_is_bond(devname): devlist.append("%s (%s)" % (devname, ",".join(slaves[devname]))) elif nm.nm_device_type_is_team(devname): devlist.append("%s (%s)" % (devname, ",".join(slaves[devname]))) elif nm.nm_device_type_is_vlan(devname): devlist.append("%s" % devname) msg = _("Connected: %(list_of_interface_names)s") % {"list_of_interface_names": ", ".join(devlist)} else: msg = _("Not connected") if not nm.nm_devices(): msg = _("No network devices available") return msg
def status_message(): """ A short string describing which devices are connected. """ msg = _("Unknown") state = nm.nm_state() if state == NetworkManager.State.CONNECTING: msg = _("Connecting...") elif state == NetworkManager.State.DISCONNECTING: msg = _("Disconnecting...") else: active_devs = nm.nm_activated_devices() if active_devs: slaves = {} ssids = {} # first find slaves and wireless aps for devname in active_devs: slaves[devname] = nm.nm_device_slaves(devname) or [] if nm.nm_device_type_is_wifi(devname): ssids[devname] = nm.nm_device_active_ssid(devname) or "" all_slaves = set(itertools.chain.from_iterable(slaves.values())) nonslaves = [dev for dev in active_devs if dev not in all_slaves] if len(nonslaves) == 1: devname = nonslaves[0] if nm.nm_device_type_is_ethernet(devname): msg = _("Wired (%(interface_name)s) connected") \ % {"interface_name": devname} elif nm.nm_device_type_is_wifi(devname): msg = _("Wireless connected to %(access_point)s") \ % {"access_point" : ssids[devname]} elif nm.nm_device_type_is_bond(devname): msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") \ % {"interface_name": devname, \ "list_of_slaves": ",".join(slaves[devname])} elif nm.nm_device_type_is_team(devname): msg = _("Team%(interface_name)s (%(list_of_slaves)s) connected") \ % {"interface_name": devname, \ "list_of_slaves": ",".join(slaves[devname])} elif nm.nm_device_type_is_vlan(devname): parent = nm.nm_device_setting_value( devname, "vlan", "parent") vlanid = nm.nm_device_setting_value(devname, "vlan", "id") msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") \ % {"interface_name": devname, "parent_device": parent, "vlanid": vlanid} elif len(nonslaves) > 1: devlist = [] for devname in nonslaves: if nm.nm_device_type_is_ethernet(devname): devlist.append("%s" % devname) elif nm.nm_device_type_is_wifi(devname): devlist.append("%s" % ssids[devname]) elif nm.nm_device_type_is_bond(devname): devlist.append("%s (%s)" % (devname, ",".join(slaves[devname]))) elif nm.nm_device_type_is_team(devname): devlist.append("%s (%s)" % (devname, ",".join(slaves[devname]))) elif nm.nm_device_type_is_vlan(devname): devlist.append("%s" % devname) msg = _("Connected: %(list_of_interface_names)s") \ % {"list_of_interface_names": ", ".join(devlist)} else: msg = _("Not connected") if not nm.nm_devices(): msg = _("No network devices available") return msg