Esempio n. 1
0
    def _exists(self):
        devs = scan_netdevs()
        for dev in devs:
            if self._name == dev["name"]:
                return True

        return False
Esempio n. 2
0
    def _exists(self):
        devs = scan_netdevs()
        for dev in devs:
            if self._name == dev["name"]:
                return True

        return False
Esempio n. 3
0
    def get_devices_by_hwaddr(self, hwaddr):
        name_scan = scan_netdevs()
        netdevs = []

        for entry in name_scan:
            if entry["hwaddr"] == normalize_hwaddr(hwaddr):
                netdevs.append(entry)

        return netdevs
Esempio n. 4
0
    def rescan_devices(self):
        self._devices = {}
        devs = scan_netdevs()
        for dev in devs:
            if dev['index'] not in self._devices:
                device = Device(self)
                device.init_netlink(dev['netlink_msg'])

                self._devices[dev['index']] = device
Esempio n. 5
0
    def get_devices_by_devname(self, devname):
        name_scan = scan_netdevs()
        netdevs = []

        for entry in name_scan:
            if entry["name"] == devname:
                netdevs.append(entry)

        return netdevs
Esempio n. 6
0
    def get_devices_by_devname(self, devname):
        name_scan = scan_netdevs()
        netdevs = []

        for entry in name_scan:
            if entry["name"] == devname:
                netdevs.append(entry)

        return netdevs
Esempio n. 7
0
    def get_devices_by_hwaddr(self, hwaddr):
        name_scan = scan_netdevs()
        netdevs = []

        for entry in name_scan:
            if entry["hwaddr"] == normalize_hwaddr(hwaddr):
                netdevs.append(entry)

        return netdevs
Esempio n. 8
0
    def create_device(self, clsname, args=[], kwargs={}):
        devcls = self._device_classes[clsname]

        device = devcls(self, *args, **kwargs)
        device._create()

        devs = scan_netdevs()
        for dev in devs:
            if dev["name"] == device.name:
                device._init_netlink(dev['netlink_msg'])
                self._devices[dev['index']] = device
                return device

        return None
Esempio n. 9
0
    def _generate_name():
        devs = scan_netdevs()

        index = 0
        while True:
            name = "lnstbr%d" % index
            index += 1
            unique = True
            for dev in devs:
                if name == dev["name"]:
                    unique = False
                    break

            if unique:
                return name
Esempio n. 10
0
    def _generate_name():
        devs = scan_netdevs()

        index = 0
        while True:
            name = "lnstbr%d" % index
            index += 1
            unique = True
            for dev in devs:
                if name == dev["name"]:
                    unique = False
                    break

            if unique:
                return name
Esempio n. 11
0
    def rescan_devices(self):
        devices_to_remove = self._devices.keys()
        devs = scan_netdevs()
        for dev in devs:
            if dev['index'] not in self._devices:
                device = None
                for if_id, d in self._tmp_mapping.items():
                    d_cfg = d.get_conf_dict()
                    if d_cfg["name"] == dev["name"]:
                        device = d
                        self._id_mapping[if_id] = dev['index']
                        del self._tmp_mapping[if_id]
                        break
                if device == None:
                    device = Device(self)
                device.init_netlink(dev['netlink_msg'])
                self._devices[dev['index']] = device
            else:
                self._devices[dev['index']].update_netlink(dev['netlink_msg'])
                devices_to_remove.remove(dev['index'])

            self._devices[dev['index']].clear_ips()
            for addr_msg in dev['ip_addrs']:
                self._devices[dev['index']].update_netlink(addr_msg)
        for i in devices_to_remove:
            if self._devices[i].get_netns() != None:
                continue

            dev_name = self._devices[i].get_name()
            logging.debug("Deleting Device with if_index %d, name %s because "\
                          "it doesn't exist anymore." % (i, dev_name))

            del_msg = {"type": "if_deleted",
                       "if_index": i}
            self._server_handler.send_data_to_ctl(del_msg)
            del self._devices[i]

        self._dl_manager.rescan_ports()
        for device in self._devices.values():
            dl_port = self._dl_manager.get_port(device.get_name())
            device.set_devlink(dl_port)
Esempio n. 12
0
    def rescan_devices(self):
        devices_to_remove = self._devices.keys()
        devs = scan_netdevs()
        for dev in devs:
            if dev['index'] not in self._devices:
                device = None
                for if_id, d in self._tmp_mapping.items():
                    d_cfg = d.get_conf_dict()
                    if d_cfg["name"] == dev["name"]:
                        device = d
                        self._id_mapping[if_id] = dev['index']
                        del self._tmp_mapping[if_id]
                        break
                if device == None:
                    device = Device(self)
                device.init_netlink(dev['netlink_msg'])
                self._devices[dev['index']] = device
            else:
                self._devices[dev['index']].update_netlink(dev['netlink_msg'])
                devices_to_remove.remove(dev['index'])

            self._devices[dev['index']].clear_ips()
            for addr_msg in dev['ip_addrs']:
                self._devices[dev['index']].update_netlink(addr_msg)
        for i in devices_to_remove:
            if self._devices[i].get_netns() != None:
                continue

            dev_name = self._devices[i].get_name()
            logging.debug("Deleting Device with if_index %d, name %s because "\
                          "it doesn't exist anymore." % (i, dev_name))

            del_msg = {"type": "if_deleted",
                       "if_index": i}
            self._server_handler.send_data_to_ctl(del_msg)
            del self._devices[i]

        self._dl_manager.rescan_ports()
        for device in self._devices.values():
            dl_port = self._dl_manager.get_port(device.get_name())
            device.set_devlink(dl_port)
Esempio n. 13
0
    def rescan_devices(self):
        devices_to_remove = self._devices.keys()
        devs = scan_netdevs()
        for dev in devs:
            if dev['index'] not in self._devices:
                device = self._device_classes["Device"](self)
                device._init_netlink(dev['netlink_msg'])
                self._devices[dev['index']] = device

                update_msg = {"type": "dev_created",
                              "dev_data": device._get_if_data()}
                self._server_handler.send_data_to_ctl(update_msg)
            else:
                self._devices[dev['index']]._update_netlink(dev['netlink_msg'])
                try:
                    devices_to_remove.remove(dev['index'])
                except ValueError:
                    # we may have multiple updates for the same device, it's
                    # okay not to find the device in devices_to_remove
                    pass

            self._devices[dev['index']]._clear_ips()
            for addr_msg in dev['ip_addrs']:
                self._devices[dev['index']]._update_netlink(addr_msg)
        for i in devices_to_remove:
            dev_name = self._devices[i].name
            logging.debug("Deleting Device with if_index %d, name %s because "\
                          "it doesn't exist anymore." % (i, dev_name))

            self._devices[i]._deleted = True
            del self._devices[i]

            del_msg = {"type": "dev_deleted",
                       "if_index": i}
            self._server_handler.send_data_to_ctl(del_msg)

        self._dl_manager.rescan_ports()
        for device in self._devices.values():
            dl_port = self._dl_manager.get_port(device.name)
            device._set_devlink(dl_port)
Esempio n. 14
0
 def __init__(self):
     self._scan = scan_netdevs()
Esempio n. 15
0
def _dev_exists(hwaddr):
    devnames = scan_netdevs()
    for dev in devnames:
        if dev["hwaddr"] == hwaddr:
            return True
Esempio n. 16
0
 def rescan_netdevs(self):
     self._scan = scan_netdevs()
Esempio n. 17
0
 def rescan_netdevs(self):
     self._scan = scan_netdevs()
Esempio n. 18
0
 def __init__(self):
     self._scan = scan_netdevs()
Esempio n. 19
0
def _dev_exists(hwaddr):
    devnames = scan_netdevs()
    for dev in devnames:
        if dev["hwaddr"] == hwaddr:
            return True