Example #1
0
    def update(self):
        ifcfglog.debug("Network.update() called")

        self.netdevices = {}
        self.ksdevice = None

        if flags.imageInstall:
            return

        # populate self.netdevices
        devhash = isys.getDeviceProperties(dev=None)
        for iface in devhash.keys():
            if isys.isWirelessDevice(iface):
                device = WirelessNetworkDevice(iface)
            else:
                device = NetworkDevice(netscriptsDir, iface)
                if os.access(device.path, os.R_OK):
                    device.loadIfcfgFile()
                else:
                    device.setDefaultConfig()

            # TODORV - the last iface in loop wins, might be ok,
            #          not worthy of special juggling
            if device.get('HOSTNAME'):
                self.hostname = device.get('HOSTNAME')

            device.description = isys.getNetDevDesc(iface)

            self.netdevices[iface] = device


        ksdevice = flags.cmdline.get('ksdevice', None)
        if ksdevice:
            bootif_mac = None
            if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline:
                bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper()
            # sort for ksdevice=link (to select the same device as in initrd))
            for dev in sorted(self.netdevices):
                mac = self.netdevices[dev].get('HWADDR').upper()
                if ksdevice == 'link' and isys.getLinkStatus(dev):
                    self.ksdevice = dev
                    break
                elif ksdevice == 'bootif':
                    if bootif_mac == mac:
                        self.ksdevice = dev
                        break
                elif ksdevice == dev:
                    self.ksdevice = dev
                    break
                elif ':' in ksdevice:
                    if ksdevice.upper() == mac:
                        self.ksdevice = dev
                        break
Example #2
0
def getSSIDs(devices_to_scan=None):

    rv = {}
    bus = dbus.SystemBus()
    nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
    device_paths = nm.get_dbus_method("GetDevices")()

    for device_path in device_paths:

        device = bus.get_object(isys.NM_SERVICE, device_path)
        device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
        # interface name, eg. "eth0", "wlan0"
        dev = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))

        if (isys.isWirelessDevice(dev) and
            (not devices_to_scan or dev in devices_to_scan)):

            i = 0
            log.info("scanning APs for %s" % dev)
            while i < 5:
                ap_paths = device.GetAccessPoints(dbus_interface='org.freedesktop.NetworkManager.Device.Wireless')
                if ap_paths:
                    break
                time.sleep(0.5)
                i += 0.5

            ssids = []
            for ap_path in ap_paths:
                ap = bus.get_object(isys.NM_SERVICE, ap_path)
                ap_props = dbus.Interface(ap, isys.DBUS_PROPS_IFACE)
                ssid_bytearray = ap_props.Get(isys.NM_ACCESS_POINT_IFACE, "Ssid")
                ssid = "".join((str(b) for b in ssid_bytearray))
                ssids.append(ssid)
            log.info("APs found for %s: %s" % (dev, str(ssids)))
            # XXX there can be duplicates in a list, but maybe
            # we want to keep them when/if we differentiate on something
            # more then just ssids; for now, remove them
            rv[dev]=list(set(ssids))

    return rv
Example #3
0
def getSSIDs(devices_to_scan=None):

    rv = {}
    bus = dbus.SystemBus()
    nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
    device_paths = nm.get_dbus_method("GetDevices")()

    for device_path in device_paths:

        device = bus.get_object(isys.NM_SERVICE, device_path)
        device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
        # interface name, eg. "eth0", "wlan0"
        dev = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))

        if (isys.isWirelessDevice(dev) and
            (not devices_to_scan or dev in devices_to_scan)):

            i = 0
            log.info("scanning APs for %s" % dev)
            while i < 5:
                ap_paths = device.GetAccessPoints(dbus_interface='org.freedesktop.NetworkManager.Device.Wireless')
                if ap_paths:
                    break
                time.sleep(0.5)
                i += 0.5

            ssids = []
            for ap_path in ap_paths:
                ap = bus.get_object(isys.NM_SERVICE, ap_path)
                ap_props = dbus.Interface(ap, isys.DBUS_PROPS_IFACE)
                ssid_bytearray = ap_props.Get(isys.NM_ACCESS_POINT_IFACE, "Ssid")
                ssid = "".join((str(b) for b in ssid_bytearray))
                ssids.append(ssid)
            log.info("APs found for %s: %s" % (dev, str(ssids)))
            # XXX there can be duplicates in a list, but maybe
            # we want to keep them when/if we differentiate on something
            # more then just ssids; for now, remove them
            rv[dev]=list(set(ssids))

    return rv
Example #4
0
 def hasWirelessDev(self):
     for dev in self.netdevices:
         if isys.isWirelessDevice(dev):
             return True
     return False
Example #5
0
 def hasWirelessDev(self):
     for dev in self.netdevices:
         if isys.isWirelessDevice(dev):
             return True
     return False
Example #6
0
 def controlWireless(self):
     for devname, device in self.netdevices.items():
         if isys.isWirelessDevice(devname):
             device.set(('NM_CONTROLLED', 'yes'))