def _validate_net_configuration(net, attrs, running_config, netinfo):
    nic = attrs.get('nic')
    bonding = attrs.get('bonding')
    vlan = attrs.get('vlan')
    bridged = attrs.get('bridged', True)
    stp = attrs.get('stp', False)

    if not bridged:
        raise Exception('OVS does not support bridgeless networks')
    if bonding in running_config.bonds:
        if not is_ovs_bond(running_config.bonds[bonding]):
            raise Exception('%s is not OVS bonding' % bonding)
    if nic is not None and nic not in netinfo.nics:
        raise Exception('Nic %s does not exist' % nic)
    if vlan is not None and bonding is None and nic is None:
        raise Exception('You can not create a nicless/bondless vlan')

    for existing_net, existing_attrs in six.iteritems(running_config.networks):
        if (existing_net != net and
                existing_attrs.get('nic') == nic and
                existing_attrs.get('bond') == bonding and
                existing_attrs.get('vlan') == vlan):
            raise Exception('%s is already used by network %s' %
                            ((nic or bonding), existing_net))
    if vlan is None:
        untagged_net = _get_untagged_net(running_config)
        if untagged_net not in (None, net):
            raise Exception('Untagged network already defined with name %s' %
                            untagged_net)
        if rget(attrs, ('custom', 'ovs_aa_sid')) is not None:
            raise Exception('Cannot define aa-mapping on untagged network')
    if stp and vlan is not None:
        raise Exception('STP could be set only on untagged networks')
def _validate_net_configuration(net, attrs, running_config, netinfo):
    nic = attrs.get('nic')
    bonding = attrs.get('bonding')
    vlan = attrs.get('vlan')
    bridged = attrs.get('bridged', True)
    stp = attrs.get('stp', False)

    if not bridged:
        raise Exception('OVS does not support bridgeless networks')
    if bonding in running_config.bonds:
        if not is_ovs_bond(running_config.bonds[bonding]):
            raise Exception('%s is not OVS bonding' % bonding)
    if nic is not None and nic not in netinfo.nics:
        raise Exception('Nic %s does not exist' % nic)
    if vlan is not None and bonding is None and nic is None:
        raise Exception('You can not create a nicless/bondless vlan')

    for existing_net, existing_attrs in six.iteritems(running_config.networks):
        if (existing_net != net and
                existing_attrs.get('nic') == nic and
                existing_attrs.get('bond') == bonding and
                existing_attrs.get('vlan') == vlan):
            raise Exception('%s is already used by network %s' %
                            ((nic or bonding), existing_net))
    if vlan is None:
        untagged_net = _get_untagged_net(running_config)
        if untagged_net not in (None, net):
            raise Exception('Untagged network already defined with name %s' %
                            untagged_net)
    if stp and vlan is not None:
        raise Exception('STP could be set only on untagged networks')
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()
Exemple #5
0
def bondings_caps(running_config):
    ovs_bonding_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces()
    routes = netinfo._get_routes()
    for bonding, attrs in running_config.bonds.items():
        if is_ovs_bond(attrs):
            options = get_bond_options(attrs.get("options"), keep_custom=True)
            net_info = _get_net_info(attrs, bonding, dhcpv4ifaces, dhcpv6ifaces, routes)
            net_info["slaves"] = attrs.get("nics")
            net_info["active_slave"] = _get_active_slave(bonding)
            net_info["opts"] = options
            ovs_bonding_caps[bonding] = net_info
    return ovs_bonding_caps
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