def ovs_networks_stats(stats):
    """ Get OVS networks from RunningConfig and assign them network stats
    dictionaries from underlying devices. Fake bridges and bonds already
    have stats with their names.
    """
    ovs_networks_stats = {}
    running_config = RunningConfig()

    for network, attrs in running_config.networks.items():
        if is_ovs_network(attrs):
            vlan = attrs.get('vlan')
            iface = attrs.get('nic') or attrs.get('bonding')
            if vlan is None:
                # Untagged networks use OVS bridge as their bridge, but Engine
                # expects a bridge with 'network-name' name.  create a copy of
                # top underlying device stats and save it as bridge's stats.
                # NOTE: copy stats of ovsbr0? (now we repots iface's stats)
                ovs_networks_stats[network] = stats[iface]
            else:
                # Engine expects stats entries for vlans named 'iface.id'
                vlan_name = '%s.%s' % (iface, vlan)
                ovs_networks_stats[vlan_name] = stats[network]
                ovs_networks_stats[vlan_name]['name'] = vlan_name

    hooking.log('Updating network stats with OVS networks: %s' %
                ovs_networks_stats)
    return ovs_networks_stats
Exemple #2
0
def ovs_networks_stats(stats):
    """Get OVS networks from RunningConfig and assign them network stats
    dictionaries from underlying devices. Fake bridges and bonds already have
    stats with their names.

    Note, that it takes some time for a new device to appear in stats, so we
    first check if the device we got from running_config is already reported.
    """
    ovs_networks_stats = {}
    running_config = RunningConfig()

    for network, attrs in six.iteritems(running_config.networks):
        if is_ovs_network(attrs):
            vlan = attrs.get('vlan')
            iface = attrs.get('nic') or attrs.get('bonding')
            if vlan is None and iface in stats:
                # Untagged networks use OVS bridge as their bridge, but Engine
                # expects a bridge with 'network-name' name.  create a copy of
                # top underlying device stats and save it as bridge's stats.
                # NOTE: copy stats of ovsbr0? (now we repots iface's stats)
                ovs_networks_stats[network] = stats[iface]
                ovs_networks_stats[network]['name'] = network
            elif network in stats:
                # Engine expects stats entries for vlans named 'iface.id'
                vlan_name = '%s.%s' % (iface, vlan)
                ovs_networks_stats[vlan_name] = stats[network]
                ovs_networks_stats[vlan_name]['name'] = vlan_name

    return ovs_networks_stats
Exemple #3
0
def _process_domxml(tree):
    root = tree.getroot()
    devices = root.find('devices')
    running_config = netconfpersistence.RunningConfig()
    for interface in devices.findall('interface'):
        if interface.get('type') == 'bridge':

            elem_virtualport = interface.find('virtualport')
            elem_source = interface.find('source')

            # 'source bridge' element must exist
            source_bridge = elem_source.get('bridge')
            source_bridge = _find_non_vlan_network(running_config,
                                                   source_bridge)

            net_attrs = running_config.networks.get(source_bridge)
            if net_attrs is None:
                print('Network', source_bridge, 'does not exist',
                      file=sys.stderr)
                sys.exit(1)

            if ovs_utils.is_ovs_network(net_attrs):
                _bind_iface_to_ovs(elem_source, elem_virtualport, interface,
                                   net_attrs)
            else:
                _bind_iface_to_linux_bridge(elem_source, elem_virtualport,
                                            interface, net_attrs,
                                            source_bridge)
def _drop_ovs_nets_config(running_config):
    for net, attrs in list(six.iteritems(running_config.networks)):
        if is_ovs_network(attrs):
            running_config.networks.pop(net)
    for bond, attrs in list(six.iteritems(running_config.bonds)):
        if is_ovs_bond(attrs):
            running_config.bonds.pop(bond)
    running_config.save()
def _drop_ovs_nets_config(running_config):
    for net, attrs in list(six.iteritems(running_config.networks)):
        if is_ovs_network(attrs):
            running_config.networks.pop(net)
    for bond, attrs in list(six.iteritems(running_config.bonds)):
        if is_ovs_bond(attrs):
            running_config.bonds.pop(bond)
    running_config.save()
def _separate_ovs_nets_bonds(nets, bonds, running_config):
    """ Get a dictionaries of nets and bonds to be handled by OVS hook and
    those to be handled by standard configurator.
    """
    ovs_nets = {}
    non_ovs_nets = {}
    ovs_bonds = {}
    non_ovs_bonds = {}
    for net, attrs in six.iteritems(nets):
        if (('remove' in attrs and net in running_config.networks and
                is_ovs_network(running_config.networks[net])) or
                is_ovs_network(attrs)):
            ovs_nets[net] = attrs
        else:
            non_ovs_nets[net] = attrs
    for bond, attrs in six.iteritems(bonds):
        if (('remove' in attrs and bond in running_config.bonds and
                is_ovs_bond(running_config.bonds[bond])) or
                is_ovs_bond(attrs)):
            ovs_bonds[bond] = attrs
        else:
            non_ovs_bonds[bond] = attrs
    return ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds
def _separate_ovs_nets_bonds(nets, bonds, running_config):
    """ Get a dictionaries of nets and bonds to be handled by OVS hook and
    those to be handled by standard configurator.
    """
    ovs_nets = {}
    non_ovs_nets = {}
    ovs_bonds = {}
    non_ovs_bonds = {}
    for net, attrs in six.iteritems(nets):
        if (('remove' in attrs and net in running_config.networks
             and is_ovs_network(running_config.networks[net]))
                or is_ovs_network(attrs)):
            ovs_nets[net] = attrs
        else:
            non_ovs_nets[net] = attrs
    for bond, attrs in six.iteritems(bonds):
        if (('remove' in attrs and bond in running_config.bonds
             and is_ovs_bond(running_config.bonds[bond]))
                or is_ovs_bond(attrs)):
            ovs_bonds[bond] = attrs
        else:
            non_ovs_bonds[bond] = attrs
    return ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds
Exemple #8
0
def bridges_caps(running_config):
    ovs_bridges_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in running_config.networks.items():
        if is_ovs_network(attrs):
            interface = network if "vlan" in attrs else BRIDGE_NAME
            net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes)
            net_info["bridged"] = True
            net_info["ports"] = []  # TODO attached nics + vms nets
            net_info["opts"] = {}  # TODO netinfo.bridgeOpts does not work here
            net_info["stp"] = _get_stp(interface)
            ovs_bridges_caps[network] = net_info
    return ovs_bridges_caps
Exemple #9
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in running_config.networks.items():
        if is_ovs_network(attrs):
            vlan = attrs.get("vlan")
            if vlan is not None:
                net_info = _get_net_info(attrs, network, dhcpv4ifaces, dhcpv6ifaces, routes)
                iface = attrs.get("bonding") or attrs.get("nic")
                net_info["iface"] = iface
                net_info["bridged"] = True
                net_info["vlanid"] = vlan
                ovs_vlans_caps["%s.%s" % (iface, vlan)] = net_info
    return ovs_vlans_caps
def ovs_device(domxml):
    """ Modify interface XML in Libvirt to proper OVS configuration if OVS
    network is set as a source.
    """
    running_config = RunningConfig()

    iface = domxml.getElementsByTagName('interface')[0]
    source = iface.getElementsByTagName('source')[0]
    source_bridge = source.getAttribute('bridge')

    network = running_config.networks.get(source_bridge)
    if network is None:
        hooking.exit_hook('Network %s does not exist' % source_bridge)

    if is_ovs_network(network):
        virtualport = domxml.createElement('virtualport')
        virtualport.setAttribute('type', 'openvswitch')
        iface.appendChild(virtualport)
        if network.get('vlan') is None:
            source.setAttribute('bridge', BRIDGE_NAME)
Exemple #11
0
def ovs_device(domxml):
    """ Modify interface XML in Libvirt to proper OVS configuration if OVS
    network is set as a source.
    """
    running_config = RunningConfig()

    iface = domxml.getElementsByTagName('interface')[0]
    source = iface.getElementsByTagName('source')[0]
    source_bridge = source.getAttribute('bridge')

    network = running_config.networks.get(source_bridge)
    if network is None:
        hooking.exit_hook('Network %s does not exist' % source_bridge)

    if is_ovs_network(network):
        virtualport = domxml.createElement('virtualport')
        virtualport.setAttribute('type', 'openvswitch')
        iface.appendChild(virtualport)
        if network.get('vlan') is None:
            source.setAttribute('bridge', BRIDGE_NAME)