def refresh(self): """ The refresh method that is called every time the spoke is displayed. It should update the UI elements according to the contents of self.data. :see: pyanaconda.ui.common.UIObject.refresh """ ## Every time we enter, make a list of all the devices that # are not the public interface (user might have changed this) pubif = network.default_route_device() allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\ nm.nm_devices()) privates = filter(lambda x: x != pubif,allifs) idx = self.ifaceCombo.get_active() self.deviceStore.clear() for x in privates: entry=[None,None,None,None] entry[DEVICEIDX] = x entry[TYPEIDX] = "ethernet" entry[MACIDX] = nm.nm_device_perm_hwaddress(x) entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX]) self.deviceStore.append(entry) if len(privates) == 0: entry=[None,None,None,None] entry[DEVICEIDX] = "%s:0" % pubif entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] entry[TYPEIDX] = "virtual" entry[MACIDX] = "" self.deviceStore.append(entry) # Set the active entry, even if we reodered self.ifaceCombo.set_active(idx)
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 refresh(self): """ The refresh method that is called every time the spoke is displayed. It should update the UI elements according to the contents of self.data. :see: pyanaconda.ui.common.UIObject.refresh """ ## Every time we enter, make a list of all the devices that # are not the public interface (user might have changed this) pubif = network.default_route_device() allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\ nm.nm_devices()) privates = filter(lambda x: x != pubif,allifs) idx = self.ifaceCombo.get_active() self.deviceStore.clear() for x in privates: entry=[None,None,None,None] entry[DEVICEIDX] = x entry[TYPEIDX] = "ethernet" entry[MACIDX] = nm.nm_device_valid_hwaddress(x) entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX]) self.deviceStore.append(entry) if len(privates) == 0: entry=[None,None,None,None] entry[DEVICEIDX] = "%s:0" % pubif entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] entry[TYPEIDX] = "virtual" entry[MACIDX] = "" self.deviceStore.append(entry) # Set the active entry, even if we reodered self.ifaceCombo.set_active(idx)
def dumpMissingDefaultIfcfgs(): """ Dump missing default ifcfg file for wired devices. For default auto connections created by NM upon start - which happens in case of missing ifcfg file - rename the connection using device name and dump its ifcfg file. (For server, default auto connections will be turned off in NetworkManager.conf.) The connection id (and consequently ifcfg file) is set to device name. Returns True if any ifcfg file was dumped. """ rv = False for devname in nm.nm_devices(): # for each ethernet device # FIXME add more types (infiniband, bond...?) if not nm.nm_device_type_is_ethernet(devname): continue # if there is no ifcfg file for the device device_cfg = NetworkDevice(netscriptsDir, devname) if os.access(device_cfg.path, os.R_OK): continue try: nm.nm_update_settings_of_device(devname, 'connection', 'id', devname) log.debug("network: dumping ifcfg file for default autoconnection on %s" % devname) nm.nm_update_settings_of_device(devname, 'connection', 'autoconnect', False) log.debug("network: setting autoconnect of %s to False" % devname) except nm.DeviceSettingsNotFoundError as e: log.debug("network: no ifcfg file for %s" % devname) rv = True return rv
def refresh(self): self._nicCombo.remove_all() for devname in nm.nm_devices(): if nm.nm_device_type_is_ethernet(devname): self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname))) self._nicCombo.set_active(0)
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 disableIPV6(rootpath): cfgfile = os.path.normpath(rootpath + ipv6ConfFile) if ('noipv6' in flags.cmdline and all(nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore" for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))): log.info('Disabling ipv6 on target system') with open(cfgfile, "a") as f: f.write("# Anaconda disabling ipv6 (noipv6 option)\n") f.write("net.ipv6.conf.all.disable_ipv6=1\n") f.write("net.ipv6.conf.default.disable_ipv6=1\n")
def disableIPV6(rootpath): cfgfile = os.path.normpath(rootpath + ipv6ConfFile) if ('noipv6' in flags.cmdline and all( nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore" for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))): log.info('Disabling ipv6 on target system') with open(cfgfile, "a") as f: f.write("# Anaconda disabling ipv6 (noipv6 option)\n") f.write("net.ipv6.conf.all.disable_ipv6=1\n") f.write("net.ipv6.conf.default.disable_ipv6=1\n")
def initialize(self): for name in nm_devices(): if nm_device_type_is_ethernet(name): # ignore slaves if nm_device_setting_value(name, "connection", "slave-type"): continue self.supported_devices.append(name) EditTUISpoke.initialize(self) if not self.data.network.seen: self._update_network_data()
def initialize(self): for name in nm.nm_devices(): if nm.nm_device_type_is_ethernet(name): # ignore slaves if nm.nm_device_setting_value(name, "connection", "slave-type"): continue self.supported_devices.append(name) EditTUISpoke.initialize(self) if not self.data.network.seen: self._update_network_data()
def _load_new_devices(self): devices = nm.nm_devices() intf_dumped = network.dumpMissingDefaultIfcfgs() if intf_dumped: log.debug("Dumped interfaces: %s", intf_dumped) for name in devices: if name in self.supported_devices: continue if nm.nm_device_type_is_ethernet(name): # ignore slaves if nm.nm_device_setting_value(name, "connection", "slave-type"): continue self.supported_devices.append(name)
def refresh(self): self._addButton = self.builder.get_object("addButton") self._cancelButton = self.builder.get_object("cancelButton") self._addSpinner = self.builder.get_object("addSpinner") self._errorBox = self.builder.get_object("errorBox") self._nicCombo = self.builder.get_object("nicCombo") self._nicCombo.remove_all() self._dcbCheckbox = self.builder.get_object("dcbCheckbox") self._autoCheckbox = self.builder.get_object("autoCheckbox") for devname in nm.nm_devices(): if nm.nm_device_type_is_ethernet(devname): self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname))) self._nicCombo.set_active(0)
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 dumpMissingDefaultIfcfgs(): """ Dump missing default ifcfg file for wired devices. For default auto connections created by NM upon start - which happens in case of missing ifcfg file - rename the connection using device name and dump its ifcfg file. (For server, default auto connections will be turned off in NetworkManager.conf.) The connection id (and consequently ifcfg file) is set to device name. Returns list of devices for which ifcfg file was dumped. """ rv = [] for devname in nm.nm_devices(): # for each ethernet device # FIXME add more types (infiniband, bond...?) if not nm.nm_device_type_is_ethernet(devname): continue # check that device has connection without ifcfg file try: con_uuid = nm.nm_device_setting_value(devname, "connection", "uuid") except nm.SettingsNotFoundError: continue if find_ifcfg_file_of_device(devname): continue try: nm.nm_update_settings_of_device( devname, [['connection', 'id', devname, None]]) log.debug( "network: dumping ifcfg file for default autoconnection on %s", devname) nm.nm_update_settings_of_device( devname, [['connection', 'autoconnect', False, None]]) log.debug("network: setting autoconnect of %s to False", devname) except nm.SettingsNotFoundError: log.debug("network: no ifcfg file for %s", devname) rv.append(devname) return rv
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 dumpMissingDefaultIfcfgs(): """ Dump missing default ifcfg file for wired devices. For default auto connections created by NM upon start - which happens in case of missing ifcfg file - rename the connection using device name and dump its ifcfg file. (For server, default auto connections will be turned off in NetworkManager.conf.) The connection id (and consequently ifcfg file) is set to device name. Returns list of devices for which ifcfg file was dumped. """ rv = [] for devname in nm.nm_devices(): # for each ethernet device # FIXME add more types (infiniband, bond...?) if not nm.nm_device_type_is_ethernet(devname): continue # check that device has connection without ifcfg file try: con_uuid = nm.nm_device_setting_value(devname, "connection", "uuid") except nm.SettingsNotFoundError: continue if find_ifcfg_file_of_device(devname): continue try: nm.nm_update_settings_of_device(devname, [["connection", "id", devname, None]]) log.debug("network: dumping ifcfg file for default autoconnection on %s", devname) nm.nm_update_settings_of_device(devname, [["connection", "autoconnect", False, None]]) log.debug("network: setting autoconnect of %s to False", devname) except nm.SettingsNotFoundError: log.debug("network: no ifcfg file for %s", devname) rv.append(devname) return rv
def dumpMissingDefaultIfcfgs(): """ Dump missing default ifcfg file for wired devices. Returns list of devices for which ifcfg file was dumped. """ rv = [] for devname in nm.nm_devices(): if not nm.nm_device_type_is_ethernet(devname): continue try: con_uuid = nm.nm_device_setting_value(devname, "connection", "uuid") except nm.SettingsNotFoundError: if find_ifcfg_file_of_device(devname): continue from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() network_data = handler.NetworkData(onboot=False, ipv6="auto") add_connection_for_ksdata(network_data, devname) rv.append(devname) return rv
def setup(self, storage, ksdata, instclass): """ The setup method that should make changes to the runtime environment according to the data stored in this object. :param storage: object storing storage-related information (disks, partitioning, bootloader, etc.) :type storage: blivet.Blivet instance :param ksdata: data parsed from the kickstart file and set in the installation process :type ksdata: pykickstart.base.BaseHandler instance :param instclass: distribution-specific information :type instclass: pyanaconda.installclass.BaseInstallClass """ log = logging.getLogger("anaconda") log.info("ROCKS KS SETUP: %s" % ksdata.__str__()) ## At this point rolls have been selected, the in-memory rocks database ## is set up and cluster information has been added by the user. now ## need to ## A. add the attributes from ksdata.addons.org_rocks_rolls.info ## into the in-memory database ## B. rolls are in ksdata.addons.org_rocks_rolls.rolls ## process the xml files for the rolls specified, then generate ## packages ## We don't have "rolls" if we are a clientInstall if self.clientInstall or ksdata.addons.org_rocks_rolls.info is None: return for row in ksdata.addons.org_rocks_rolls.info: log.info("ROCKS ADD ATTR %s=%s" % (row[2],row[1])) self.addAttr(row[2],row[1]) cmd = ["/opt/rocks/bin/rocks","report","host","attr","pydict=true"] p = subprocess.Popen(cmd,stdout=subprocess.PIPE) attrs = p.stdout.readlines()[0].strip() f = open("/tmp/site.attrs","w") atdict = eval(attrs) for key in atdict.keys(): f.write( "%s:%s\n" % (key,atdict[key]) ) f.close() ## Write out all of the Ethernet devices so that we can load ## Load into the installed FE database. See database-data.xm etherifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\ nm.nm_devices()) ethermacs = map(lambda x: nm.nm_device_valid_hwaddress(x),etherifs) g = open("/tmp/frontend-ifaces.sh","w") g.write("/opt/rocks/bin/rocks config host interface localhost iface='%s' mac='%s' flag='' module=''\n" % \ (",".join(etherifs),",".join(ethermacs))) g.close() cmd = ["/opt/rocks/bin/rocks","list","node", "xml", \ "attrs=%s" % attrs, "basedir=/tmp/rocks/export/profile", "server"] p = subprocess.Popen(cmd,stdout=subprocess.PIPE) nodexml = p.stdout.readlines() cmd = ["/opt/rocks/sbin/kgen","--section=packages"] p = subprocess.Popen(cmd,stdin=subprocess.PIPE, stdout=subprocess.PIPE) out,err = p.communicate(input="".join(nodexml)) pkgs = filter(lambda x: len(x) > 0, out.split("\n")) for pkg in pkgs: if "%" in pkg or "#" in pkg: continue if not pkg in ksdata.packages.packageList: ksdata.packages.packageList.append(pkg) ## Generate the post scripts section log.info("ROCKS GENERATING POST SCRIPTS") cmd = ["/opt/rocks/sbin/kgen","--section=post"] p = subprocess.Popen(cmd,stdin=subprocess.PIPE, stdout=subprocess.PIPE) self.postscripts,err = p.communicate(input="".join(nodexml)) log.info("ROCKS POST SCRIPTS GENERATED") ksparser = kickstart.AnacondaKSParser(ksdata) ksparser.readKickstartFromString(self.postscripts, reset=False) ## Add eula and firstboot stanzas log.info("ROCKS FIRSTBOOT/EULA") ksparser = kickstart.AnacondaKSParser(ksdata) ksparser.readKickstartFromString("eula --agreed", reset=False) ksparser.readKickstartFromString("firstboot --disable", reset=False) log.info("ROCKS FIRSBOOT/EULA END ")
def setup(self, storage, ksdata, instclass): """ The setup method that should make changes to the runtime environment according to the data stored in this object. :param storage: object storing storage-related information (disks, partitioning, bootloader, etc.) :type storage: blivet.Blivet instance :param ksdata: data parsed from the kickstart file and set in the installation process :type ksdata: pykickstart.base.BaseHandler instance :param instclass: distribution-specific information :type instclass: pyanaconda.installclass.BaseInstallClass """ log = logging.getLogger("anaconda") log.info("ROCKS KS SETUP: %s" % ksdata.__str__()) ## At this point rolls have been selected, the in-memory rocks database ## is set up and cluster information has been added by the user. now ## need to ## A. add the attributes from ksdata.addons.org_rocks_rolls.info ## into the in-memory database ## B. rolls are in ksdata.addons.org_rocks_rolls.rolls ## process the xml files for the rolls specified, then generate ## packages ## We don't have "rolls" if we are a clientInstall if self.clientInstall or ksdata.addons.org_rocks_rolls.info is None: return for row in ksdata.addons.org_rocks_rolls.info: log.info("ROCKS ADD ATTR %s=%s" % (row[2], row[1])) self.addAttr(row[2], row[1]) cmd = ["/opt/rocks/bin/rocks", "report", "host", "attr", "pydict=true"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) attrs = p.stdout.readlines()[0].strip() f = open("/tmp/site.attrs", "w") atdict = eval(attrs) for key in atdict.keys(): f.write("%s:%s\n" % (key, atdict[key])) f.close() ## Write out all of the Ethernet devices so that we can load ## Load into the installed FE database. See database-data.xm etherifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\ nm.nm_devices()) ethermacs = map(lambda x: nm.nm_device_valid_hwaddress(x), etherifs) g = open("/tmp/frontend-ifaces.sh", "w") g.write("/opt/rocks/bin/rocks config host interface localhost iface='%s' mac='%s' flag='' module=''\n" % \ (",".join(etherifs),",".join(ethermacs))) g.close() cmd = ["/opt/rocks/bin/rocks","list","node", "xml", \ "attrs=%s" % attrs, "basedir=/tmp/rocks/export/profile", "server"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) nodexml = p.stdout.readlines() cmd = ["/opt/rocks/sbin/kgen", "--section=packages"] p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) out, err = p.communicate(input="".join(nodexml)) pkgs = filter(lambda x: len(x) > 0, out.split("\n")) for pkg in pkgs: if "%" in pkg or "#" in pkg: continue if not pkg in ksdata.packages.packageList: ksdata.packages.packageList.append(pkg) ## Generate the post scripts section log.info("ROCKS GENERATING POST SCRIPTS") cmd = ["/opt/rocks/sbin/kgen", "--section=post"] p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) self.postscripts, err = p.communicate(input="".join(nodexml)) log.info("ROCKS POST SCRIPTS GENERATED") ksparser = kickstart.AnacondaKSParser(ksdata) ksparser.readKickstartFromString(self.postscripts, reset=False) ## Add eula and firstboot stanzas log.info("ROCKS FIRSTBOOT/EULA") ksparser = kickstart.AnacondaKSParser(ksdata) ksparser.readKickstartFromString("eula --agreed", reset=False) ksparser.readKickstartFromString("firstboot --disable", reset=False) log.info("ROCKS FIRSBOOT/EULA END ")
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