Пример #1
0
def _get(vdsmnets=None):
    """
    Generate a networking report for all devices.
    In case vdsmnets is provided, it is used in the report instead of
    retrieving data from the running config.
    :return: Dict of networking devices with all their details.
    """
    ipaddrs = getIpAddrs()
    routes = get_routes()

    devices_info = _devices_report(ipaddrs, routes)
    nets_info = _networks_report(vdsmnets, routes, ipaddrs, devices_info)

    add_qos_info_to_devices(nets_info, devices_info)

    flat_devs_info = _get_flat_devs_info(devices_info)
    devices = _get_dev_names(nets_info, flat_devs_info)
    extra_info = {}
    if nmstate.is_nmstate_backend():
        extra_info.update(_get_devices_info_from_nmstate(devices))
    else:
        extra_info.update(dhclient.dhcp_info(devices))

    _update_caps_info(nets_info, flat_devs_info, extra_info)

    networking_report = {'networks': nets_info}
    networking_report.update(devices_info)
    if nmstate.is_nmstate_backend():
        networking_report['nameservers'] = nmstate.show_nameservers()
    else:
        networking_report['nameservers'] = dns.get_host_nameservers()
    networking_report['supportsIPv6'] = ipv6_supported()

    return networking_report
Пример #2
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
Пример #3
0
Файл: cache.py Проект: 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
Пример #4
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
Пример #5
0
 def test_daemon_cmdline_with_last_arg_as_hostname(self):
     """
     In most cases, the dhclient is executed with a cmdline that locates
     the device name at the last argument. However, an exception has been
     detected with DHCPv6 from ifcfg initscripts, in which the last argument
     is the host name and the device name is placed just before it.
     """
     dhcp_info = dhclient.dhcp_info(devices=(DEVNAME, ))
     expected = {DEVNAME: {dhclient.DHCP4: False, dhclient.DHCP6: True}}
     assert expected == dhcp_info
Пример #6
0
 def test_daemon_cmdline_with_last_arg_as_hostname(self):
     """
     In most cases, the dhclient is executed with a cmdline that locates
     the device name at the last argument. However, an exception has been
     detected with DHCPv6 from ifcfg initscripts, in which the last argument
     is the host name and the device name is placed just before it.
     """
     dhcp_info = dhclient.dhcp_info(devices=(DEVNAME,))
     expected = {DEVNAME: {dhclient.DHCP4: False, dhclient.DHCP6: True}}
     self.assertEqual(expected, dhcp_info)
Пример #7
0
def _update_dhcp_info(nets_info, devices_info):
    """Update DHCP info for both networks and devices"""

    net_ifaces = {net_info['iface'] for net_info in six.viewvalues(nets_info)}
    flat_devs_info = {
        devname: devinfo
        for sub_devs in six.viewvalues(devices_info)
        for devname, devinfo in six.viewitems(sub_devs)
    }
    dhcp_info = dhclient.dhcp_info(net_ifaces | frozenset(flat_devs_info))

    for net_info in six.viewvalues(nets_info):
        net_info.update(dhcp_info[net_info['iface']])

    for devname, devinfo in six.viewitems(flat_devs_info):
        devinfo.update(dhcp_info[devname])
Пример #8
0
Файл: cache.py Проект: nirs/vdsm
def _update_dhcp_info(nets_info, devices_info):
    """Update DHCP info for both networks and devices"""

    net_ifaces = {net_info['iface'] for net_info in six.viewvalues(nets_info)}
    flat_devs_info = {
        devname: devinfo
        for sub_devs in six.viewvalues(devices_info)
        for devname, devinfo in six.viewitems(sub_devs)
    }
    dhcp_info = dhclient.dhcp_info(net_ifaces | frozenset(flat_devs_info))

    for net_info in six.viewvalues(nets_info):
        net_info.update(dhcp_info[net_info['iface']])

    for devname, devinfo in six.viewitems(flat_devs_info):
        devinfo.update(dhcp_info[devname])
Пример #9
0
Файл: cache.py Проект: nirs/vdsm
def _networks_report(vdsmnets, routes, ipaddrs, devices_info):
    if vdsmnets is None:
        nets_info = libvirtNets2vdsm(libvirt.networks(), routes, ipaddrs)
    else:
        nets_info = vdsmnets

    ifaces = {net_info["iface"] for net_info in six.itervalues(nets_info)}
    dhcp_info = dhclient.dhcp_info(ifaces)

    for network_info in six.itervalues(nets_info):
        network_info.update(dhcp_info[network_info["iface"]])
        network_info.update(LEGACY_SWITCH)

    report_network_qos(nets_info, devices_info)

    return nets_info
Пример #10
0
def _networks_report(vdsmnets, routes, ipaddrs, devices_info):
    if vdsmnets is None:
        running_nets = RunningConfig().networks
        nets_info = networks_base_info(running_nets, routes, ipaddrs)
    else:
        nets_info = vdsmnets

    ifaces = {net_info['iface'] for net_info in six.itervalues(nets_info)}
    dhcp_info = dhclient.dhcp_info(ifaces)

    for network_info in six.itervalues(nets_info):
        network_info.update(dhcp_info[network_info['iface']])
        network_info.update(LEGACY_SWITCH)

    report_network_qos(nets_info, devices_info)

    return nets_info
Пример #11
0
def _networks_report(vdsmnets, routes, ipaddrs, devices_info):
    if vdsmnets is None:
        running_nets = RunningConfig().networks
        nets_info = networks_base_info(running_nets, routes, ipaddrs)
    else:
        nets_info = vdsmnets

    ifaces = {net_info['iface'] for net_info in six.itervalues(nets_info)}
    dhcp_info = dhclient.dhcp_info(ifaces)

    for network_info in six.itervalues(nets_info):
        network_info.update(dhcp_info[network_info['iface']])
        network_info.update(LEGACY_SWITCH)

    report_network_qos(nets_info, devices_info)

    return nets_info