Esempio n. 1
0
 def _isLibvirtInterface(device):
     try:
         networks = libvirt.networks()
     except libvirtError:  # libvirt might not be started or it just fails
         logging.error('Libvirt failed to answer. It might be the case that'
                       ' this script is being run before libvirt startup. '
                       ' Thus, check if vdsm owns %s an alternative way' %
                       device)
         return DynamicSourceRoute._isLibvirtInterfaceFallback(device)
     trackedInterfaces = [network.get('bridge') or network.get('iface')
                          for network in networks.itervalues()]
     return device in trackedInterfaces
Esempio n. 2
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
Esempio n. 3
0
def ifaceUsed(iface):
    """Lightweight implementation of bool(Netinfo.ifaceUsers()) that does not
    require a NetInfo object."""
    if os.path.exists(os.path.join(netinfo.NET_PATH, iface, 'brport')):
        return True  # Is it a port
    for linkDict in nl_link.iter_links():
        if linkDict['name'] == iface and 'master' in linkDict:  # Is it a slave
            return True
        if linkDict.get('device') == iface and linkDict.get('type') == 'vlan':
            return True  # it backs a VLAN
    for net_attr in six.itervalues(libvirt.networks()):
        if net_attr.get('iface') == iface:
            return True
    return False
Esempio n. 4
0
File: cache.py Progetto: rexhsu/vdsm
def ifaceUsed(iface):
    """Lightweight implementation of bool(Netinfo.ifaceUsers()) that does not
    require a NetInfo object."""
    if os.path.exists(os.path.join(netinfo.NET_PATH, iface, 'brport')):
        return True  # Is it a port
    for linkDict in nl_link.iter_links():
        if linkDict['name'] == iface and 'master' in linkDict:  # Is it a slave
            return True
        if linkDict.get('device') == iface and linkDict.get('type') == 'vlan':
            return True  # it backs a VLAN
    for net_attr in six.itervalues(libvirt.networks()):
        if net_attr.get('iface') == iface:
            return True
    return False
Esempio n. 5
0
 def _isLibvirtInterface(device):
     try:
         networks = libvirt.networks()
     except libvirtError:  # libvirt might not be started or it just fails
         logging.error('Libvirt failed to answer. It might be the case that'
                       ' this script is being run before libvirt startup. '
                       ' Thus, check if vdsm owns %s an alternative way' %
                       device)
         return DynamicSourceRoute._isLibvirtInterfaceFallback(device)
     trackedInterfaces = [
         network.get('bridge') or network.get('iface')
         for network in networks.itervalues()
     ]
     return device in trackedInterfaces
Esempio n. 6
0
File: cache.py Progetto: 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
Esempio n. 7
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
Esempio n. 8
0
def libvirt_networks():
    """Report libvirt known networks"""
    return libvirt.networks()
Esempio n. 9
0
File: api.py Progetto: igoihman/vdsm
def libvirt_networks():
    """Report libvirt known networks"""
    return libvirt.networks()