Exemple #1
0
def _getNetInfo(iface, bridged, routes, ipaddrs):
    """Returns a dictionary of properties about the network's interface status.
    Raises a NetworkIsMissing if the iface does not exist."""
    data = {}
    try:
        if bridged:
            data.update({'ports': bridges.ports(iface),
                         'stp': bridges.stp_state(iface)})
        else:
            # ovirt-engine-3.1 expects to see the "interface" attribute iff the
            # network is bridgeless. Please remove the attribute and this
            # comment when the version is no longer supported.
            data['interface'] = iface

        gateway = get_gateway(routes, iface)
        ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
            iface, ipaddrs, gateway)

        data.update({'iface': iface, 'bridged': bridged,
                     'addr': ipv4addr, 'netmask': ipv4netmask,
                     'ipv4addrs': ipv4addrs,
                     'ipv6addrs': ipv6addrs,
                     'ipv6autoconf': is_ipv6_local_auto(iface),
                     'gateway': gateway,
                     'ipv6gateway': get_gateway(routes, iface, family=6),
                     'ipv4defaultroute': is_default_route(gateway),
                     'mtu': link_iface.get_mtu(iface)})
    except (IOError, OSError) as e:
        if e.errno == errno.ENOENT or e.errno == errno.ENODEV:
            logging.info('Obtaining info for net %s.', iface, exc_info=True)
            raise NetworkIsMissing('Network %s was not found' % iface)
        else:
            raise
    return data
Exemple #2
0
    def configure(self, **opts):
        # in a limited condition, we should not touch the nic config
        if (self.vlan and nics.operstate(self.name) == nics.OPERSTATE_UP
                and self.configurator.net_info.ifaceUsers(self.name)
                and self.mtu <= link_iface.get_mtu(self.name)):
            return

        self.configurator.configureNic(self, **opts)
Exemple #3
0
def _update_mtu_for_an_existing_bridge(dev_name, configurator, mtu):
    # When the MTU changes to the default MTU, reading the existing MTU on the
    # bridge is misleading, as with the latest OS, when no ports are connected
    # to it, it will fall down to the default.
    # In such a scenario, the ifcfg file still needs to be updated.
    if mtu != link_iface.get_mtu(dev_name):
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
        _update_bridge_ports_mtu(dev_name, mtu)
    elif mtu == link_iface.DEFAULT_MTU:
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
Exemple #4
0
    def objectivize(cls,
                    name,
                    configurator,
                    options,
                    nics,
                    mtu,
                    _netinfo,
                    on_removal_just_detach_from_network=False):

        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, link_iface.get_mtu(name))

                if not options:
                    options = _netinfo.bondings[name].get('opts')
                    options = Bond._dict2list(options)
        elif name in _netinfo.bondings:  # Implicit bonding.
            if _netinfo.ifaceUsers(name):
                mtu = max(mtu, link_iface.get_mtu(name))

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

        detach = on_removal_just_detach_from_network  # argument is too long
        return cls(name,
                   configurator,
                   slaves=slaves,
                   options=options,
                   mtu=mtu,
                   on_removal_just_detach_from_network=detach)
Exemple #5
0
def _get_iface_info(iface, addresses, routes):
    ipv4gateway = get_gateway(routes, iface, family=4)
    ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
        iface, addresses, ipv4gateway)
    is_dhcpv4 = dhclient.is_active(iface, family=4)
    is_dhcpv6 = dhclient.is_active(iface, family=6)

    return {'mtu': get_mtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs,
            'gateway': ipv4gateway, 'netmask': ipv4netmask,
            'ipv4defaultroute': is_default_route(ipv4gateway),
            'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs,
            'ipv6gateway': get_gateway(routes, iface, family=6),
            'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
Exemple #6
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

        :return mtu value that was applied
        """
        ifaceMtu = link_iface.get_mtu(iface.name)
        ifaces = tuple(ifaceVlans)
        maxMtu = (max(link_iface.get_mtu(dev)
                      for dev in ifaces) if ifaces else None)
        if maxMtu and maxMtu < ifaceMtu:
            if isinstance(iface, Bond):
                self.configApplier.setBondingMtu(iface.name, maxMtu)
            else:
                self.configApplier.setIfaceMtu(iface.name, maxMtu)
        return maxMtu
Exemple #7
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 bonding.bondings()
                and (not self.configurator.unifiedPersistence
                     or self.name in self.configurator.runningConfig.bonds)
                and nics.operstate(self.name) == nics.OPERSTATE_UP
                and self.configurator.net_info.ifaceUsers(self.name)
                and self.mtu <= link_iface.get_mtu(self.name)
                and self.areOptionsApplied()
                and frozenset(slave.name
                              for slave in self.slaves) == frozenset(
                                  link_bond.Bond(self.name).slaves)):
            return

        self.configurator.configureBond(self, **opts)
Exemple #8
0
    def __init__(self,
                 name,
                 configurator,
                 ipv4=None,
                 ipv6=None,
                 blockingdhcp=False,
                 mtu=None,
                 _netinfo=None):
        if _netinfo is None:
            _netinfo = CachingNetInfo()
        if name not in _netinfo.nics:
            raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name)

        if _netinfo.ifaceUsers(name):
            mtu = max(mtu, link_iface.get_mtu(name))

        super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp,
                                  mtu)