def _destroy_ovs_libvirt_nets(initial_config, running_config):
    log('Removing OVS and libvirt networks: %s %s' %
        (initial_config, running_config))
    for libvirt_ovs_nets in (iter_ovs_nets(running_config.networks),
                             iter_ovs_nets(initial_config.networks)):
        for net, attrs in libvirt_ovs_nets:
            with suppress(libvirtError):  # network not found
                libvirt.removeNetwork(net)

    destroy_ovs_bridge()
def _destroy_ovs_libvirt_nets(initial_config, running_config):
    log('Removing OVS and libvirt networks: %s %s' % (initial_config,
                                                      running_config))
    for libvirt_ovs_nets in (iter_ovs_nets(running_config.networks),
                             iter_ovs_nets(initial_config.networks)):
        for net, attrs in libvirt_ovs_nets:
            with suppress(libvirtError):  # network not found
                libvirt.removeNetwork(net)

    destroy_ovs_bridge()
def _remove_redundant_ovs_bridge(running_config):
    """ Remove OVS Bridge if there is no OVS net/bond anymore. """
    for net, attr in iter_ovs_nets(running_config.networks):
        return
    for bond, attr in iter_ovs_bonds(running_config.bonds):
        return
    log('Removing redundant OVS bridge')
    destroy_ovs_bridge()
def _remove_redundant_ovs_bridge(running_config):
    """ Remove OVS Bridge if there is no OVS net/bond anymore. """
    for net, attr in iter_ovs_nets(running_config.networks):
        return
    for bond, attr in iter_ovs_bonds(running_config.bonds):
        return
    log('Removing redundant OVS bridge')
    destroy_ovs_bridge()
Example #5
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(interface, routes)
        net_info['iface'] = network
        net_info['bridged'] = True
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Example #6
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(interface, routes)
        net_info['iface'] = network
        # report the network to be bridgeless if this is what Engine expects
        net_info['bridged'] = attrs.get('bridged')
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Example #7
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        vlan = attrs.get('vlan')
        if vlan is not None:
            net_info = _get_net_info(network, routes)
            iface = attrs.get('bonding') or attrs.get('nic')
            net_info['iface'] = iface
            net_info['bridged'] = attrs.get('bridged')
            net_info['vlanid'] = int(vlan)
            ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info
    return ovs_vlans_caps
Example #8
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        vlan = attrs.get('vlan')
        if vlan is not None:
            net_info = _get_net_info(network, routes)
            iface = attrs.get('bonding') or attrs.get('nic')
            net_info['iface'] = iface
            net_info['bridged'] = attrs.get('bridged')
            net_info['vlanid'] = int(vlan)
            ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info
    return ovs_vlans_caps
Example #9
0
def bridges_caps(running_config):
    ovs_bridges_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(interface, routes)
        net_info['bridged'] = True
        net_info['ports'] = _get_ports(network, attrs)
        # TODO netinfo._bridge_options does not work here
        net_info['opts'] = {}
        net_info['stp'] = _get_stp(interface)
        ovs_bridges_caps[network] = net_info
    return ovs_bridges_caps
Example #10
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['iface'] = network
        net_info['bridged'] = True
        net_info['ports'] = _list_ports(interface)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Example #11
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['iface'] = network
        net_info['bridged'] = True
        net_info['ports'] = _list_ports(interface)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
def _mtus_vlans(running_config):
    """ OVS vlans MTUs are automaticaly changed to the lowest MTU of
    underlying devices. However, in VDSM, vlan's MTU is based on network
    settings. In case when current vlan's MTU differs (should be lower than
    a minimal underlying device's MTU), get needed changes.
    """
    changes = {}
    for net, attrs in iter_ovs_nets(running_config.networks):
        mtu = attrs.get('mtu')
        if mtu is not None and 'vlan' in attrs:
            current_mtu = netinfo.mtus.getMtu(net)
            if current_mtu != mtu:
                changes[net] = mtu
    return changes
def _mtus_nics(running_config):
    """ Get MTUs for nics. Bondings MTUs will be changed as a consequence."""
    changes = {}
    for net, attrs in iter_ovs_nets(running_config.networks):
        mtu = attrs.get('mtu')
        if mtu is not None:
            nic = attrs.get('nic')
            bonding = attrs.get('bonding')
            if nic is not None:
                _update_mtu_changes(mtu, [nic], changes)
            elif bonding is not None:
                slaves = running_config.bonds[bonding].get('nics')
                _update_mtu_changes(mtu, slaves, changes)
    return changes
Example #14
0
def _mtus_vlans(running_config):
    """ OVS vlans MTUs are automaticaly changed to the lowest MTU of
    underlying devices. However, in VDSM, vlan's MTU is based on network
    settings. In case when current vlan's MTU differs (should be lower than
    a minimal underlying device's MTU), get needed changes.
    """
    changes = {}
    for net, attrs in iter_ovs_nets(running_config.networks):
        mtu = attrs.get('mtu')
        if mtu is not None and 'vlan' in attrs:
            current_mtu = netinfo.getMtu(net)
            if current_mtu != mtu:
                changes[net] = mtu
    return changes
Example #15
0
def _mtus_nics(running_config):
    """ Get MTUs for nics. Bondings MTUs will be changed as a consequence."""
    changes = {}
    for net, attrs in iter_ovs_nets(running_config.networks):
        mtu = attrs.get('mtu')
        if mtu is not None:
            nic = attrs.get('nic')
            bonding = attrs.get('bonding')
            if nic is not None:
                _update_mtu_changes(mtu, [nic], changes)
            elif bonding is not None:
                slaves = running_config.bonds[bonding].get('nics')
                _update_mtu_changes(mtu, slaves, changes)
    return changes
Example #16
0
def bridges_caps(running_config):
    ovs_bridges_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        # report the network to be bridgeless if this is what Engine expects
        if attrs.get('bridged'):
            interface = network if 'vlan' in attrs else BRIDGE_NAME
            net_info = _get_net_info(interface, routes)
            net_info['bridged'] = True
            net_info['ports'] = _get_ports(network, attrs)
            # TODO netinfo._bridge_options does not work here
            net_info['opts'] = {}
            net_info['stp'] = _get_stp(interface)
            ovs_bridges_caps[network] = net_info
    return ovs_bridges_caps
Example #17
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        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
Example #18
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        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
Example #19
0
def bridges_caps(running_config):
    ovs_bridges_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        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'] = _get_ports(network, attrs)
        # TODO netinfo._bridge_options does not work here
        net_info['opts'] = {}
        net_info['stp'] = _get_stp(interface)
        ovs_bridges_caps[network] = net_info
    return ovs_bridges_caps
Example #20
0
def _update_expected_ip_info(caps, running_config):
    """
    If a network is marked as bridgeless and untagged, we have to report its IP
    info on attached nic/bond.
    """

    def copy_net_info(source, destination):
        KEYS = {'addr', 'gateway', 'netmask', 'dhcpv4', 'ipv4addrs',
                'ipv6addrs', 'ipv6autoconf', 'ipv6gateway', 'dhcpv6'}
        for key in KEYS:
            destination[key] = source[key]

    for network, attrs in iter_ovs_nets(running_config.networks):
        if not attrs.get('bridged', True) and 'vlan' not in attrs:
            bond = attrs.get('bond')
            nic = attrs.get('nic')
            if bond is not None:
                copy_net_info(
                    caps['networks'][network], caps['bondings'][bond])
            elif nic is not None:
                copy_net_info(caps['networks'][network], caps['nics'][nic])
Example #21
0
def networks_caps(running_config):
    def get_engine_expected_top_dev(net, attrs):
        """Return top device (iface) expected by Engine."""
        nic_bond = attrs.get('bonding') or attrs.get('nic')
        vlan = attrs.get('vlan')
        return (net if attrs.get('bridged', True) else '%s.%s' %
                (nic_bond, vlan) if vlan is not None else nic_bond)

    ovs_networks_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        actual_top_dev = network if 'vlan' in attrs else BRIDGE_NAME
        expected_top_dev = get_engine_expected_top_dev(network, attrs)
        net_info = _get_net_info(actual_top_dev, routes)
        net_info['iface'] = expected_top_dev
        # report the network to be bridgeless if this is what Engine expects
        net_info['bridged'] = attrs.get('bridged')
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(actual_top_dev)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Example #22
0
def _update_expected_ip_info(caps, running_config):
    """
    If a network is marked as bridgeless and untagged, we have to report its IP
    info on attached nic/bond.
    """
    def copy_net_info(source, destination):
        KEYS = {
            'addr', 'gateway', 'netmask', 'dhcpv4', 'ipv4addrs', 'ipv6addrs',
            'ipv6autoconf', 'ipv6gateway', 'dhcpv6'
        }
        for key in KEYS:
            destination[key] = source[key]

    for network, attrs in iter_ovs_nets(running_config.networks):
        if not attrs.get('bridged', True) and 'vlan' not in attrs:
            bond = attrs.get('bond')
            nic = attrs.get('nic')
            if bond is not None:
                copy_net_info(caps['networks'][network],
                              caps['bondings'][bond])
            elif nic is not None:
                copy_net_info(caps['networks'][network], caps['nics'][nic])
Example #23
0
def networks_caps(running_config):

    def get_engine_expected_top_dev(net, attrs):
        """Return top device (iface) expected by Engine."""
        nic_bond = attrs.get('bonding') or attrs.get('nic')
        vlan = attrs.get('vlan')
        return (net if attrs.get('bridged', True)
                else '%s.%s' % (nic_bond, vlan) if vlan is not None
                else nic_bond)

    ovs_networks_caps = {}
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        actual_top_dev = network if 'vlan' in attrs else BRIDGE_NAME
        expected_top_dev = get_engine_expected_top_dev(network, attrs)
        net_info = _get_net_info(actual_top_dev, routes)
        net_info['iface'] = expected_top_dev
        # report the network to be bridgeless if this is what Engine expects
        net_info['bridged'] = attrs.get('bridged')
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(actual_top_dev)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
def _get_untagged_net(running_config):
    for network, attrs in iter_ovs_nets(running_config.networks):
        if 'vlan' not in attrs:
            return network
    return None
def _get_untagged_net(running_config):
    for network, attrs in iter_ovs_nets(running_config.networks):
        if 'vlan' not in attrs:
            return network
    return None