Ejemplo n.º 1
0
def _devices_report(ipaddrs, routes):
    devs_report = {'bondings': {}, 'bridges': {}, 'nics': {}, 'vlans': {}}

    devinfo_by_devname = {}
    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = devs_report['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            if dev.isDPDK():
                devinfo = devs_report['nics'][dev.name] = dpdk.info(dev)
            else:
                devinfo = devs_report['nics'][dev.name] = nics.info(dev)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = devs_report['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = devs_report['vlans'][dev.name] = vlans.info(dev)
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))
        devinfo_by_devname[dev.name] = devinfo

    dhcp_info = dhclient.dhcp_info(frozenset(devinfo_by_devname))
    for devname, devinfo in devinfo_by_devname.items():
        devinfo.update(dhcp_info[devname])

    _permanent_hwaddr_info(devs_report)

    return devs_report
Ejemplo n.º 2
0
Archivo: misc.py Proyecto: rexhsu/vdsm
def visible_devs(predicate):
    """Returns a list of visible (vdsm manageable) links for which the
    predicate is True"""
    return [
        dev.name for dev in getLinks()
        if predicate(dev) and not dev.isHidden()
    ]
Ejemplo n.º 3
0
Archivo: cache.py Proyecto: nirs/vdsm
def _devices_report(ipaddrs, routes):
    devs_report = {'bondings': {}, 'bridges': {}, 'nics': {}, 'vlans': {}}

    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = devs_report['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            if dev.isDPDK():
                devinfo = devs_report['nics'][dev.name] = dpdk.info(dev)
            else:
                devinfo = devs_report['nics'][dev.name] = nics.info(dev)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = devs_report['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = devs_report['vlans'][dev.name] = {'iface': dev.device,
                                                        'vlanid': dev.vlanid}
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))

    _permanent_hwaddr_info(devs_report)

    return devs_report
Ejemplo n.º 4
0
Archivo: cache.py Proyecto: nirs/vdsm
def _devices_report(ipaddrs, routes, paddr):
    devs_report = {"bondings": {}, "bridges": {}, "nics": {}, "vlans": {}}

    devinfo_by_devname = {}
    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = devs_report["bridges"][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            devinfo = devs_report["nics"][dev.name] = nics.info(dev, paddr)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = devs_report["bondings"][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = devs_report["vlans"][dev.name] = vlans.info(dev)
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))
        devinfo_by_devname[dev.name] = devinfo

    dhcp_info = dhclient.dhcp_info(frozenset(devinfo_by_devname))
    for devname, devinfo in devinfo_by_devname.items():
        devinfo.update(dhcp_info[devname])

    return devs_report
Ejemplo n.º 5
0
def _devices_report(ipaddrs, routes):
    devs_report = {'bondings': {}, 'bridges': {}, 'nics': {}, 'vlans': {}}

    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = devs_report['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            if dev.isDPDK():
                devinfo = devs_report['nics'][dev.name] = dpdk.info(dev)
            else:
                devinfo = devs_report['nics'][dev.name] = nics.info(dev)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = devs_report['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = devs_report['vlans'][dev.name] = {
                'iface': dev.device,
                'vlanid': dev.vlanid,
            }
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))

    _permanent_hwaddr_info(devs_report)

    return devs_report
Ejemplo n.º 6
0
Archivo: cache.py Proyecto: EdDev/vdsm
def _devices_report(ipaddrs, routes):
    devs_report = {'bondings': {}, 'bridges': {}, 'nics': {}, 'vlans': {}}

    devinfo_by_devname = {}
    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = devs_report['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            if dev.isDPDK():
                devinfo = devs_report['nics'][dev.name] = dpdk.info(dev)
            else:
                devinfo = devs_report['nics'][dev.name] = nics.info(dev)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = devs_report['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = devs_report['vlans'][dev.name] = vlans.info(dev)
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))
        devinfo_by_devname[dev.name] = devinfo

    dhcp_info = dhclient.dhcp_info(frozenset(devinfo_by_devname))
    for devname, devinfo in devinfo_by_devname.items():
        devinfo.update(dhcp_info[devname])

    _permanent_hwaddr_info(devs_report)

    return devs_report
Ejemplo n.º 7
0
def cleanup_leftover_interfaces():
    for interface in getLinks():
        if TEST_NIC_REGEX.match(interface.name):
            logging.warning('Found leftover interface %s', interface)
            try:
                Interface.from_existing_dev_name(interface.name).remove()
            except Exception as e:
                logging.warning('Removal of "%s" failed: %s', interface, e)
Ejemplo n.º 8
0
def _get_links_with_state_down(links):
    return set(
        l.name
        for l in ipwrapper.getLinks()
        if l.name in links
        and _owned_ifcfg(l.name)
        and _onboot_ifcfg(l.name)
        and not l.oper_up
    )
Ejemplo n.º 9
0
    def test_ip_link_wrapper(self, bridge0, nics, bond0, vlan0):
        device_links = ipwrapper.getLinks()
        devices = {device.name: device for device in device_links}

        # Test all devices to be there.
        assert set([bridge0, bond0, vlan0] + nics) <= set(devices)

        assert devices[bridge0].isBRIDGE()
        assert devices[nics[0]].isDUMMY()
        assert devices[nics[1]].isDUMMY()
        assert devices[bond0].isBOND()
        assert devices[vlan0].isVLAN()
Ejemplo n.º 10
0
def _get_interfaces_and_samples():
    links_and_samples = {}
    for link in ipwrapper.getLinks():
        try:
            links_and_samples[link.name] = InterfaceSample(link)
        except IOError as e:
            # this handles a race condition where the device is now no
            # longer exists and netlink fails to fetch it
            if e.errno == errno.ENODEV:
                continue
            raise
    return links_and_samples
Ejemplo n.º 11
0
def _get_interfaces_and_samples():
    links_and_samples = {}
    for link in ipwrapper.getLinks():
        try:
            links_and_samples[link.name] = InterfaceSample(link)
        except IOError as e:
            # this handles a race condition where the device is now no
            # longer exists and netlink fails to fetch it
            if e.errno == errno.ENODEV:
                continue
            raise
    return links_and_samples
Ejemplo n.º 12
0
def _get(vdsmnets=None):
    """
    Generate a networking report for all devices, including data managed by
    libvirt.
    In case vdsmnets is provided, it is used in the report instead of
    retrieving data from libvirt.
    :return: Dict of networking devices with all their details.
    """
    networking = {
        'bondings': {},
        'bridges': {},
        'networks': {},
        'nics': {},
        'vlans': {},
        'dnss': get_host_nameservers()
    }
    paddr = bonding.permanent_address()
    ipaddrs = getIpAddrs()
    routes = get_routes()

    if vdsmnets is None:
        libvirt_nets = libvirt.networks()
        networking['networks'] = libvirtNets2vdsm(libvirt_nets, routes,
                                                  ipaddrs)
    else:
        networking['networks'] = vdsmnets

    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = networking['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            devinfo = networking['nics'][dev.name] = nics.info(dev, paddr)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = networking['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = networking['vlans'][dev.name] = vlans.info(dev)
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))

    for network_name, network_info in six.iteritems(networking['networks']):
        updates = propose_updates_to_reported_dhcp(network_info, networking)
        update_reported_dhcp(updates, networking)
        networking['networks'][network_name].update(LEGACY_SWITCH)

    report_network_qos(networking)
    networking['supportsIPv6'] = ipv6_supported()

    return networking
Ejemplo n.º 13
0
def wait_for_device(name, timeout=1):
    """
    Wait for a network device to appear in a given timeout. If the device is
    not created by then, raise a ConfigNetworkError.
    """
    with monitor.Monitor(timeout=timeout, groups=('link',),
                         silent_timeout=True) as mon:
        if name in (link.name for link in ipwrapper.getLinks()):
            return
        for event in mon:
            if event.get('name') == name and event.get('event') == 'new_link':
                return
    raise ConfigNetworkError(ERR_FAILED_IFUP, 'Device %s was not created '
                             'during a %ss timeout.' % (name, timeout))
Ejemplo n.º 14
0
def _lldp_init():
    """"
    Enables receiving of LLDP frames for all nics. If sending or receiving
    LLDP frames is already enabled on a nic, it is not modified.
    """
    if Lldp.is_active():
        for device in (link for link in getLinks() if link.isNIC()):
            if not Lldp.is_lldp_enabled_on_iface(device.name):
                try:
                    Lldp.enable_lldp_on_iface(device.name)
                except lldp.EnableLldpError:
                    logging.warning('Ignoring failure to enable LLDP on %s',
                                    device.name, exc_info=True)
    else:
        logging.warning('LLDP is inactive, skipping LLDP initialization')
Ejemplo n.º 15
0
def wait_for_device(name, timeout=1):
    """
    Wait for a network device to appear in a given timeout. If the device is
    not created by then, raise a ConfigNetworkError.
    """
    with monitor.Monitor(timeout=timeout,
                         groups=('link', ),
                         silent_timeout=True) as mon:
        if name in (link.name for link in ipwrapper.getLinks()):
            return
        for event in mon:
            if event.get('name') == name and event.get('event') == 'new_link':
                return
    raise ConfigNetworkError(
        ERR_FAILED_IFUP, 'Device %s was not created '
        'during a %ss timeout.' % (name, timeout))
Ejemplo n.º 16
0
def _get(vdsmnets=None):
    """
    Generate a networking report for all devices, including data managed by
    libvirt.
    In case vdsmnets is provided, it is used in the report instead of
    retrieving data from libvirt.
    :return: Dict of networking devices with all their details.
    """
    networking = {'bondings': {}, 'bridges': {}, 'networks': {}, 'nics': {},
                  'vlans': {}, 'dnss': get_host_nameservers()}
    paddr = bonding.permanent_address()
    ipaddrs = getIpAddrs()
    routes = get_routes()

    if vdsmnets is None:
        libvirt_nets = libvirt.networks()
        networking['networks'] = libvirtNets2vdsm(libvirt_nets, routes,
                                                  ipaddrs)
    else:
        networking['networks'] = vdsmnets

    for dev in (link for link in getLinks() if not link.isHidden()):
        if dev.isBRIDGE():
            devinfo = networking['bridges'][dev.name] = bridges.info(dev)
        elif dev.isNICLike():
            devinfo = networking['nics'][dev.name] = nics.info(dev, paddr)
            devinfo.update(bonding.get_bond_slave_agg_info(dev.name))
        elif dev.isBOND():
            devinfo = networking['bondings'][dev.name] = bonding.info(dev)
            devinfo.update(bonding.get_bond_agg_info(dev.name))
            devinfo.update(LEGACY_SWITCH)
        elif dev.isVLAN():
            devinfo = networking['vlans'][dev.name] = vlans.info(dev)
        else:
            continue
        devinfo.update(_devinfo(dev, routes, ipaddrs))

    for network_name, network_info in six.iteritems(networking['networks']):
        updates = propose_updates_to_reported_dhcp(network_info, networking)
        update_reported_dhcp(updates, networking)
        networking['networks'][network_name].update(LEGACY_SWITCH)

    report_network_qos(networking)
    networking['supportsIPv6'] = ipv6_supported()

    return networking
Ejemplo n.º 17
0
    def testIpLinkWrapper(self):
        """Tests that the created devices are properly parsed by the ipwrapper
        Link class."""
        BIG_MTU = 2000
        VLAN_NAME = '%s.%s' % (BONDING_NAME, VLAN_ID)
        with dummyIf(2) as nics:
            status, msg = self.setupNetworks(
                {
                    NETWORK_NAME: {
                        'bonding': BONDING_NAME,
                        'bridged': True,
                        'vlan': VLAN_ID,
                        'mtu': BIG_MTU
                    }
                }, {BONDING_NAME: {
                    'nics': nics
                }}, NOCHK)
            self.assertEqual(status, SUCCESS, msg)
            deviceLinks = getLinks()
            deviceNames = [device.name for device in deviceLinks]

            # Test all devices to be there.
            self.assertIn(NETWORK_NAME, deviceNames)
            self.assertIn(BONDING_NAME, deviceNames)
            self.assertIn(nics[0], deviceNames)
            self.assertIn(nics[1], deviceNames)
            self.assertIn(VLAN_NAME, deviceNames)

            for device in deviceLinks:
                if device.name == NETWORK_NAME:
                    self.assertEqual(device.type, LinkType.BRIDGE)
                elif device.name in nics:
                    self.assertEqual(device.type, LinkType.DUMMY)
                elif device.name == VLAN_NAME:
                    self.assertEqual(device.type, LinkType.VLAN)
                elif device.name == BONDING_NAME:
                    self.assertEqual(device.type, LinkType.BOND)
                    self.assertEqual(device.mtu, BIG_MTU)

            # Cleanup
            status, msg = self.setupNetworks({NETWORK_NAME: {
                'remove': True
            }}, {BONDING_NAME: {
                'remove': True
            }}, NOCHK)
            self.assertEqual(status, SUCCESS, msg)
Ejemplo n.º 18
0
def _delTarget(network, parent, target):
    fs = list(filters(network, parent))
    if fs:
        filt = fs[0]
    else:
        return []

    devices = set(link.name for link in ipwrapper.getLinks())
    acts = [act for act in filt.actions
            if act.target in devices and act.target != target]

    if acts:
        filt = Filter(prio=filt.prio, handle=filt.handle, actions=acts)
        _filter_replace(network, parent, filt)
    else:
        tc_filter.delete(network, filt.prio, parent=parent)
    return acts
Ejemplo n.º 19
0
def _delTarget(network, parent, target):
    fs = list(filters(network, parent))
    if fs:
        filt = fs[0]
    else:
        return []

    devices = set(link.name for link in ipwrapper.getLinks())
    acts = [act for act in filt.actions
            if act.target in devices and act.target != target]

    if acts:
        filt = Filter(prio=filt.prio, handle=filt.handle, actions=acts)
        _filter_replace(network, parent, filt)
    else:
        tc_filter.delete(network, filt.prio, parent=parent)
    return acts
Ejemplo n.º 20
0
def _lldp_init():
    """"
    Enables receiving of LLDP frames for all nics. If sending or receiving
    LLDP frames is already enabled on a nic, it is not modified.
    """
    if not config.getboolean('vars', 'enable_lldp'):
        logging.warning('LLDP is disabled')
        return

    if Lldp.is_active():
        for device in (link for link in getLinks() if link.isNIC()):
            if not Lldp.is_lldp_enabled_on_iface(device.name):
                try:
                    Lldp.enable_lldp_on_iface(device.name)
                except lldp.EnableLldpError:
                    logging.warning('Ignoring failure to enable LLDP on %s',
                                    device.name, exc_info=True)
    else:
        logging.warning('LLDP is inactive, skipping LLDP initialization')
Ejemplo n.º 21
0
def _get_links_with_state_down(links):
    return set(l.name for l in ipwrapper.getLinks() if
               l.name in links and
               _owned_ifcfg(l.name) and
               _onboot_ifcfg(l.name) and
               not l.oper_up)
Ejemplo n.º 22
0
def visible_devs(predicate):
    """Returns a list of visible (vdsm manageable) links for which the
    predicate is True"""
    return [dev.name for dev in getLinks() if predicate(dev) and
            not dev.isHidden()]