Beispiel #1
0
def _split_switch_type_entries(entries, running_entries):
    legacy_entries = {}
    ovs_entries = {}

    def store_broken_entry(name, attrs):
        """
        If a network/bond should be removed but its existing entry was not
        found in running config, we have to find out what switch type has to
        be used for removal on our own.

        All we do now is, that we pass orphan entry to legacy swich which is
        (unlike OVS switch) able to remove broken networks/bonds.

        TODO: Try to find out which switch type should be used for broken
        network/bonding removal.
        """
        legacy_entries[name] = attrs

    def store_entry(name, attrs, switch_type):
        if switch_type is None:
            store_broken_entry(name, attrs)
        elif switch_type == legacy_switch.SWITCH_TYPE:
            legacy_entries[name] = attrs
        elif switch_type == ovs_switch.SWITCH_TYPE:
            ovs_entries[name] = attrs
        else:
            raise ne.ConfigNetworkError(
                ne.ERR_BAD_PARAMS, 'Invalid switch type %s' % attrs['switch']
            )

    for name, attrs in six.iteritems(entries):
        if 'remove' in attrs:
            running_attrs = running_entries.get(name, {})
            switch_type = running_attrs.get('switch')

            # When removing a network/bond, we try to determine its switch
            # type from the netinfo report.
            # This is not always possible, specifically with bonds owned by ovs
            # but not successfully deployed (not saved in running config).
            if (
                switch_type == legacy_switch.SWITCH_TYPE
                and bond.Bond(name).exists()
                and not Ifcfg.owned_device(name)
            ):
                # If not owned by Legacy, assume OVS and let it be removed in
                # the OVS way.
                switch_type = ovs_switch.SWITCH_TYPE

        else:
            switch_type = attrs['switch']
        store_entry(name, attrs, switch_type)

    return legacy_entries, ovs_entries
Beispiel #2
0
def _filter_owned_bonds(kconfig_bonds):
    """
    Bonds retrieved from the kernel include both the ones owned by us and the
    ones that are not.
    The filter returns only the owned bonds by examining the ifcfg files
    in case ifcfg persistence is set.
    """
    if config.get('vars', 'net_persistence') == 'ifcfg':
        return {bond_name: bond_attrs
                for bond_name, bond_attrs in six.viewitems(kconfig_bonds)
                if Ifcfg.owned_device(bond_name)}
    return {}
Beispiel #3
0
def _filter_owned_bonds(kconfig_bonds):
    """
    Bonds retrieved from the kernel include both the ones owned by us and the
    ones that are not.
    The filter returns only the owned bonds by examining the ifcfg files
    in case ifcfg persistence is set.
    """
    if config.get('vars', 'net_persistence') == 'ifcfg':
        return {bond_name: bond_attrs
                for bond_name, bond_attrs in six.viewitems(kconfig_bonds)
                if Ifcfg.owned_device(bond_name)}
    return kconfig_bonds
Beispiel #4
0
def _split_switch_type_entries(entries, running_entries):
    legacy_entries = {}
    ovs_entries = {}

    def store_broken_entry(name, attrs):
        """
        If a network/bond should be removed but its existing entry was not
        found in running config, we have to find out what switch type has to
        be used for removal on our own.

        All we do now is, that we pass orphan entry to legacy swich which is
        (unlike OVS switch) able to remove broken networks/bonds.

        TODO: Try to find out which switch type should be used for broken
        network/bonding removal.
        """
        legacy_entries[name] = attrs

    def store_entry(name, attrs, switch_type):
        if switch_type is None:
            store_broken_entry(name, attrs)
        elif switch_type == legacy_switch.SWITCH_TYPE:
            legacy_entries[name] = attrs
        elif switch_type == ovs_switch.SWITCH_TYPE:
            ovs_entries[name] = attrs
        else:
            raise ne.ConfigNetworkError(
                ne.ERR_BAD_PARAMS, 'Invalid switch type %s' % attrs['switch'])

    for name, attrs in six.iteritems(entries):
        if 'remove' in attrs:
            running_attrs = running_entries.get(name, {})
            switch_type = running_attrs.get('switch')

            # When removing a network/bond, we try to determine its switch
            # type from the netinfo report.
            # This is not always possible, specifically with bonds owned by ovs
            # but not successfully deployed (not saved in running config).
            if (switch_type == legacy_switch.SWITCH_TYPE and
                    bond.Bond(name).exists() and
                    not Ifcfg.owned_device(name)):
                # If not owned by Legacy, assume OVS and let it be removed in
                # the OVS way.
                switch_type = ovs_switch.SWITCH_TYPE

        else:
            switch_type = attrs['switch']
        store_entry(name, attrs, switch_type)

    return legacy_entries, ovs_entries