Esempio n. 1
0
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
                    destroyOnMasterRemoval=None):
        if name and nics:  # New bonding or edit bonding.
            slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics),
                                            mtu, _netinfo)
            if name in _netinfo.bondings:
                if _netinfo.ifaceUsers(name):
                    mtu = max(mtu, netinfo.getMtu(name))

                if not options:
                    options = _netinfo.bondings[name]['cfg'].get(
                        'BONDING_OPTS')
        elif name in _netinfo.bondings:  # Implicit bonding.
            if _netinfo.ifaceUsers(name):
                mtu = max(mtu, netinfo.getMtu(name))

            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS')
        else:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING,
                                     'Bonding %s not specified and it is not '
                                     'already on the system' % name)
        if not slaves:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics'
                                     ' for bonding device.')

        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu,
                   destroyOnMasterRemoval=destroyOnMasterRemoval)
Esempio n. 2
0
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
                    destroyOnMasterRemoval=None):
        if name and nics:  # New bonding or edit bonding.
            slaves = cls._objectivizeSlaves(name, configurator, nics, mtu,
                                            _netinfo)
            if name in _netinfo.bondings:
                mtu = max(netinfo.getMtu(name), mtu)
                if not options:
                    options = _netinfo.bondings[name]['cfg'].get(
                        'BONDING_OPTS')
        elif name in _netinfo.bondings:  # Implicit bonding.
            mtu = max(netinfo.getMtu(name), mtu)
            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS')
        else:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING,
                                     'Bonding %s not specified and it is not '
                                     'already on the system' % name)
        if not slaves:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics'
                                     ' for bonding device.')

        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu,
                   destroyOnMasterRemoval=destroyOnMasterRemoval)
Esempio n. 3
0
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
                    destroyOnMasterRemoval=None):
        if nics:  # New bonding or edit bonding.
            slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics),
                                            mtu, _netinfo)
            if name in _netinfo.bondings:
                if _netinfo.ifaceUsers(name):
                    mtu = max(mtu, netinfo.getMtu(name))

                if not options:
                    options = _netinfo.bondings[name]['cfg'].get(
                        'BONDING_OPTS')
        elif name in _netinfo.bondings:  # Implicit bonding.
            if _netinfo.ifaceUsers(name):
                mtu = max(mtu, netinfo.getMtu(name))

            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS')
        else:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Missing required nics on a bonding %s '
                                     'that is unknown to Vdsm ' % name)

        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu,
                   destroyOnMasterRemoval=destroyOnMasterRemoval)
Esempio n. 4
0
def _mtus_bonds(running_config):
    """ Bonding and its slaves should have the same MTU. Check slaves of
    every bonding, if not consistent, set them all the biggest found MTU.
    """
    changes = {}
    for bonding, attrs in iter_ovs_bonds(running_config.bonds):
        slaves = running_config.bonds[bonding].get('nics')
        mtu = max(netinfo.getMtu(bonding),
                  max([netinfo.getMtu(slave) for slave in slaves]))
        _update_mtu_changes(mtu, slaves, changes)
    return changes
def _mtus_bonds(running_config):
    """ Bonding and its slaves should have the same MTU. Check slaves of
    every bonding, if not consistent, set them all the biggest found MTU.
    """
    changes = {}
    for bonding, attrs in iter_ovs_bonds(running_config.bonds):
        slaves = running_config.bonds[bonding].get('nics')
        mtu = max(netinfo.getMtu(bonding),
                  max([netinfo.getMtu(slave) for slave in slaves]))
        _update_mtu_changes(mtu, slaves, changes)
    return changes
Esempio n. 6
0
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo):
        if name and nics:
            slaves = []
            for nic in nics:
                nicVlans = tuple(_netinfo.getVlansForIface(nic))
                nicNet = _netinfo.getNetworkForIface(nic)
                nicBond = _netinfo.getBondingForNic(nic)
                if nicVlans or nicNet or nicBond and nicBond != name:
                    raise ConfigNetworkError(
                        ne.ERR_USED_NIC, 'nic %s already used by %s' %
                        (nic, nicVlans or nicNet or nicBond))
                slaves.append(Nic(nic, configurator, mtu=mtu,
                                  _netinfo=_netinfo))
        elif name in _netinfo.bondings:  # Implicit bonding.
            mtu = max(netinfo.getMtu(name), mtu)
            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS')
        else:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING,
                                     'Bonding %s not specified and it is not '
                                     'already on the system' % name)
        if not slaves:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics'
                                     ' for bonding device.')

        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu)
Esempio n. 7
0
    def configure(self, **opts):
        # in a limited condition, we should not touch the nic config
        if (self.vlan and netinfo.operstate(self.name) == netinfo.OPERSTATE_UP
                and netinfo.ifaceUsed(self.name)
                and self.mtu <= netinfo.getMtu(self.name)):
            return

        self.configurator.configureNic(self, **opts)
Esempio n. 8
0
 def __init__(self, name, configurator, ipconfig=None, mtu=None,
              _netinfo=None):
     if _netinfo is None:
         _netinfo = netinfo.NetInfo()
     if name not in _netinfo.nics:
         raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name)
     super(Nic, self).__init__(name, configurator, ipconfig,
                               mtu=max(mtu, netinfo.getMtu(name)))
Esempio n. 9
0
    def configure(self, **opts):
        # in a limited condition, we should not touch the nic config
        if (self.vlan and
                netinfo.operstate(self.name) == netinfo.OPERSTATE_UP and
                netinfo.ifaceUsed(self.name) and
                self.mtu <= netinfo.getMtu(self.name)):
            return

        self.configurator.configureNic(self, **opts)
Esempio n. 10
0
    def __init__(self, name, configurator, ipv4=None, ipv6=None, blockingdhcp=False, mtu=None, _netinfo=None):
        if _netinfo is None:
            _netinfo = netinfo.NetInfo()
        if name not in _netinfo.nics:
            raise ConfigNetworkError(ne.ERR_BAD_NIC, "unknown nic: %s" % name)

        if _netinfo.ifaceUsers(name):
            mtu = max(mtu, netinfo.getMtu(name))

        super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp, mtu)
Esempio n. 11
0
    def __init__(self, name, configurator, ipconfig=None, mtu=None,
                 _netinfo=None):
        if _netinfo is None:
            _netinfo = netinfo.NetInfo()
        if name not in _netinfo.nics:
            raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name)

        if _netinfo.ifaceUsers(name):
            mtu = max(mtu, netinfo.getMtu(name))

        super(Nic, self).__init__(name, configurator, ipconfig,
                                  mtu=mtu)
Esempio n. 12
0
    def setNewMtu(self, network, bridged, _netinfo=None):
        """
        Set new MTU value to network and its interfaces

        :param network: network name
        :type network: string
        :param bridged: network type (bridged or bridgeless)
        :type bridged: bool

        Update MTU to devices (vlans, bonds and nics)
        or added a new value
        """
        if _netinfo is None:
            _netinfo = netinfo.NetInfo()
        currmtu = None
        if bridged:
            try:
                currmtu = netinfo.getMtu(network)
            except IOError as e:
                if e.errno != os.errno.ENOENT:
                    raise

        nics, delvlan, bonding = \
            _netinfo.getNicsVlanAndBondingForNetwork(network)
        if delvlan is None:
            return

        iface = bonding if bonding else nics[0]
        vlans = _netinfo.getVlansForIface(iface)

        newmtu = None
        for vlan in vlans:
            cf = netinfo.NET_CONF_PREF + iface + '.' + vlan
            mtu = self._getConfigValue(cf, 'MTU')
            if mtu:
                mtu = int(mtu)

            if vlan == delvlan:
                # For VLANed bridgeless networks use MTU of delvlan
                # as current MTU
                if not bridged and mtu:
                    currmtu = mtu
                continue

            newmtu = max(newmtu, mtu)

        # Optimization: if network hasn't custom MTU (currmtu), do nothing
        if currmtu and newmtu != currmtu:
            if bonding:
                self.setBondingMtu(bonding, newmtu)
            else:
                self.setIfaceMtu(nics[0], newmtu)
Esempio n. 13
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
Esempio n. 14
0
    def configure(self, **opts):
        # When the bond is up and we are not changing the configuration that
        # is already applied in any way, we can skip the configuring.
        if (self.vlan and self.name in netinfo.bondings()
                and netinfo.operstate(self.name) == netinfo.OPERSTATE_UP
                and netinfo.ifaceUsed(self.name)
                and self.mtu <= netinfo.getMtu(self.name)
                and self.areOptionsApplied()
                and frozenset(slave.name
                              for slave in self.slaves) == frozenset(
                                  netinfo.slaves(self.name))):
            return

        self.configurator.configureBond(self, **opts)
Esempio n. 15
0
    def configure(self, **opts):
        # When the bond is up and we are not changing the configuration that
        # is already applied in any way, we can skip the configuring.
        if (self.vlan and
            self.name in netinfo.bondings() and
            netinfo.operstate(self.name) == netinfo.OPERSTATE_UP and
            netinfo.NetInfo().ifaceUsers(self.name) and
            self.mtu <= netinfo.getMtu(self.name) and
            self.areOptionsApplied() and
            frozenset(slave.name for slave in self.slaves) ==
                frozenset(netinfo.slaves(self.name))):
                return

        self.configurator.configureBond(self, **opts)
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
Esempio n. 17
0
    def _setNewMtu(self, iface, ifaceVlans):
        """
        Update an interface's MTU when one of its users is removed.

        :param iface: interface object (bond or nic device)
        :type iface: NetDevice instance

        :param ifaceVlans: vlan devices using the interface 'iface'
        :type ifaceVlans: iterable

        """
        ifaceMtu = netinfo.getMtu(iface.name)
        maxMtu = netinfo.getMaxMtu(ifaceVlans, None)
        if maxMtu and maxMtu < ifaceMtu:
            if isinstance(iface, Bond):
                self.configApplier.setBondingMtu(iface.name, maxMtu)
            else:
                self.configApplier.setIfaceMtu(iface.name, maxMtu)
Esempio n. 18
0
    def _setNewMtu(self, iface, ifaceVlans):
        """
        Update an interface's MTU when one of its users is removed.

        :param iface: interface object (bond or nic device)
        :type iface: NetDevice instance

        :param ifaceVlans: vlan devices using the interface 'iface'
        :type ifaceVlans: iterable

        """
        ifaceMtu = netinfo.getMtu(iface.name)
        maxMtu = netinfo.getMaxMtu(ifaceVlans, None)
        if maxMtu and maxMtu < ifaceMtu:
            if isinstance(iface, Bond):
                self.configApplier.setBondingMtu(iface.name, maxMtu)
            else:
                self.configApplier.setIfaceMtu(iface.name, maxMtu)
Esempio n. 19
0
def _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes):
    mtu = netinfo.getMtu(interface)
    addr, netmask, ipv4addrs, ipv6addrs = netinfo.getIpInfo(interface)
    dhcpv4 = netinfo._dhcp_used(interface, dhcpv4ifaces, attrs)
    dhcpv6 = netinfo._dhcp_used(interface, dhcpv6ifaces, attrs, family=6)
    gateway = netinfo._get_gateway(routes, interface)
    ipv6gateway = netinfo._get_gateway(routes, interface, family=6)
    return {
        "mtu": str(mtu),
        "addr": addr,
        "gateway": gateway,
        "netmask": netmask,
        "dhcpv4": dhcpv4,
        "ipv4addrs": ipv4addrs,
        "ipv6addrs": ipv6addrs,
        "ipv6gateway": ipv6gateway,
        "dhcpv6": dhcpv6,
        "cfg": {"BOOTPROTO": "dhcp" if dhcpv4 else "none"},
    }
Esempio n. 20
0
def _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes):
    mtu = netinfo.getMtu(interface)
    addr, netmask, ipv4addrs, ipv6addrs = netinfo.getIpInfo(interface)
    dhcpv4 = netinfo._dhcp_used(interface, dhcpv4ifaces, attrs)
    dhcpv6 = netinfo._dhcp_used(interface, dhcpv6ifaces, attrs,
                                family=6)
    gateway = netinfo._get_gateway(routes, interface)
    ipv6gateway = netinfo._get_gateway(routes, interface, family=6)
    return {
        'mtu': str(mtu),
        'addr': addr,
        'gateway': gateway,
        'netmask': netmask,
        'dhcpv4': dhcpv4,
        'ipv4addrs': ipv4addrs,
        'ipv6addrs': ipv6addrs,
        'ipv6gateway': ipv6gateway,
        'dhcpv6': dhcpv6,
        'cfg': {'BOOTPROTO': 'dhcp' if dhcpv4 else 'none'}}
Esempio n. 21
0
def _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes):
    mtu = netinfo.getMtu(interface)
    addr, netmask, ipv4addrs, ipv6addrs = netinfo.getIpInfo(interface)
    dhcpv4 = netinfo._dhcp_used(interface, dhcpv4ifaces, attrs)
    dhcpv6 = netinfo._dhcp_used(interface, dhcpv6ifaces, attrs, family=6)
    gateway = netinfo._get_gateway(routes, interface)
    ipv6gateway = netinfo._get_gateway(routes, interface, family=6)
    return {
        'mtu': str(mtu),
        'addr': addr,
        'gateway': gateway,
        'netmask': netmask,
        'dhcpv4': dhcpv4,
        'ipv4addrs': ipv4addrs,
        'ipv6addrs': ipv6addrs,
        'ipv6gateway': ipv6gateway,
        'dhcpv6': dhcpv6,
        'cfg': {
            'BOOTPROTO': 'dhcp' if dhcpv4 else 'none'
        }
    }
Esempio n. 22
0
def _update_mtu_changes(mtu, devices, changes):
    for device in devices:
        current_mtu = netinfo.getMtu(device)
        mtu = max(mtu, changes.get(device), current_mtu)
        if mtu != current_mtu:
            changes[device] = mtu
def _update_mtu_changes(mtu, devices, changes):
    for device in devices:
        current_mtu = netinfo.getMtu(device)
        mtu = max(mtu, changes.get(device), current_mtu)
        if mtu != current_mtu:
            changes[device] = mtu