Exemple #1
0
 def _getIfaceConfValues(iface):
     ipv4 = copy.deepcopy(iface.ipv4)
     ipv6 = copy.deepcopy(iface.ipv6)
     mtu = iface.mtu
     nameservers = iface.nameservers
     if ifaceUsed(iface.name):
         confParams = misc.getIfaceCfg(iface.name)
         if not ipv4.address and ipv4.bootproto != "dhcp":
             ipv4.address = confParams.get("IPADDR")
             ipv4.netmask = confParams.get("NETMASK")
             ipv4.gateway = confParams.get("GATEWAY")
             if not ipv4.bootproto:
                 ipv4.bootproto = confParams.get("BOOTPROTO")
         if ipv4.defaultRoute is None and confParams.get("DEFROUTE"):
             ipv4.defaultRoute = _from_ifcfg_bool(confParams["DEFROUTE"])
         if confParams.get("IPV6INIT") == "yes":
             ipv6.address = confParams.get("IPV6ADDR")
             ipv6.gateway = confParams.get("IPV6_DEFAULTGW")
             ipv6.ipv6autoconf = confParams.get("IPV6_AUTOCONF") == "yes"
             ipv6.dhcpv6 = confParams.get("DHCPV6C") == "yes"
         if not iface.mtu:
             mtu = confParams.get("MTU")
             if mtu:
                 mtu = int(mtu)
         if iface.nameservers is None:
             nameservers = [confParams[key] for key in ("DNS1", "DNS2") if key in confParams]
     return ipv4, ipv6, mtu, nameservers
Exemple #2
0
 def _getIfaceConfValues(iface):
     ipv4 = copy.deepcopy(iface.ipv4)
     ipv6 = copy.deepcopy(iface.ipv6)
     mtu = iface.mtu
     nameservers = iface.nameservers
     if ifaceUsed(iface.name):
         confParams = misc.getIfaceCfg(iface.name)
         if not ipv4.address and ipv4.bootproto != 'dhcp':
             ipv4.address = confParams.get('IPADDR')
             ipv4.netmask = confParams.get('NETMASK')
             ipv4.gateway = confParams.get('GATEWAY')
             if not ipv4.bootproto:
                 ipv4.bootproto = confParams.get('BOOTPROTO')
         if ipv4.defaultRoute is None and confParams.get('DEFROUTE'):
             ipv4.defaultRoute = _from_ifcfg_bool(confParams['DEFROUTE'])
         if confParams.get('IPV6INIT') == 'yes':
             ipv6.address = confParams.get('IPV6ADDR')
             ipv6.gateway = confParams.get('IPV6_DEFAULTGW')
             ipv6.ipv6autoconf = confParams.get('IPV6_AUTOCONF') == 'yes'
             ipv6.dhcpv6 = confParams.get('DHCPV6C') == 'yes'
         if not iface.mtu:
             mtu = confParams.get('MTU')
             if mtu:
                 mtu = int(mtu)
         if iface.nameservers is None:
             nameservers = [
                 confParams[key] for key in ('DNS1', 'DNS2')
                 if key in confParams
             ]
     return ipv4, ipv6, mtu, nameservers
Exemple #3
0
 def _ifaceDownAndCleanup(self, iface, remove_even_if_used=False):
     """Returns True iff the iface is to be removed."""
     DynamicSourceRoute.addInterfaceTracking(iface)
     to_be_removed = remove_even_if_used or not ifaceUsed(iface.name)
     if to_be_removed:
         ifdown(iface.name)
     self._removeSourceRoute(iface, StaticSourceRoute)
     return to_be_removed
Exemple #4
0
 def _ifaceDownAndCleanup(self, iface, remove_even_if_used=False):
     """Returns True iff the iface is to be removed."""
     DynamicSourceRoute.addInterfaceTracking(iface)
     to_be_removed = remove_even_if_used or not ifaceUsed(iface.name)
     if to_be_removed:
         ifdown(iface.name)
     self._removeSourceRoute(iface, StaticSourceRoute)
     return to_be_removed
Exemple #5
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 ifaceUsed(self.name)
                and self.mtu <= mtus.getMtu(self.name)):
            return

        self.configurator.configureNic(self, **opts)
Exemple #6
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
                ifaceUsed(self.name) and
                self.mtu <= mtus.getMtu(self.name)):
            return

        self.configurator.configureNic(self, **opts)
Exemple #7
0
def _uses_classes(device, root_qdisc_handle=None):
    """Returns true iff there's traffic classes in the device, ignoring the
    root class and a default unused class"""
    if root_qdisc_handle is None:
        root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
        root_qdisc_handle = root_qdisc['handle']
    classes = [cls for cls in tc.classes(device, parent=root_qdisc_handle) if
               not cls.get('root')]
    return (classes and
            not(len(classes) == 1 and not ifaceUsed(device) and
                classes[0]['handle'] == root_qdisc_handle + _DEFAULT_CLASSID))
Exemple #8
0
def _uses_classes(device, root_qdisc_handle=None):
    """Returns true iff there's traffic classes in the device, ignoring the
    root class and a default unused class"""
    if root_qdisc_handle is None:
        root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
        root_qdisc_handle = root_qdisc['handle']
    classes = [cls for cls in tc.classes(device, parent=root_qdisc_handle) if
               not cls.get('root')]
    return (classes and
            not(len(classes) == 1 and not ifaceUsed(device) and
                classes[0]['handle'] == root_qdisc_handle + _DEFAULT_CLASSID))
Exemple #9
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 ifaceUsed(self.name) and self.mtu <= mtus.getMtu(self.name)
                and self.areOptionsApplied()
                and frozenset(slave.name
                              for slave in self.slaves) == frozenset(
                                  bonding.slaves(self.name))):
            return

        self.configurator.configureBond(self, **opts)
Exemple #10
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
            ifaceUsed(self.name) and
            self.mtu <= mtus.getMtu(self.name) and
            self.areOptionsApplied() and
            frozenset(slave.name for slave in self.slaves) ==
                frozenset(bonding.slaves(self.name))):
                return

        self.configurator.configureBond(self, **opts)
Exemple #11
0
    def removeBond(self, bonding):
        toBeRemoved = not ifaceUsed(bonding.name)

        if toBeRemoved:
            if bonding.master is None:
                self.configApplier.removeIpConfig(bonding)
                DynamicSourceRoute.addInterfaceTracking(bonding)
                self._removeSourceRoute(bonding, DynamicSourceRoute)

            if bonding.on_removal_just_detach_from_network:
                self.configApplier.setIfaceMtu(bonding.name,  mtus.DEFAULT_MTU)
                self.configApplier.ifdown(bonding)
            else:
                self._destroyBond(bonding)
                self.runningConfig.removeBonding(bonding.name)
        else:
            self._setNewMtu(bonding, vlans.vlan_devs_for_iface(bonding.name))
Exemple #12
0
    def removeNic(self, nic, remove_even_if_used=False):
        """
        Remove a nic from the kernel. By default, do nothing if the nic is used
        When remove_even_if_used=True, remove the nic anyway
        # FIXME the caller of this method is responsible to remove
        # the nic from its users (such as bond)
        """
        toBeRemoved = not ifaceUsed(nic.name) or remove_even_if_used

        if toBeRemoved:
            if nic.master is None:
                self.configApplier.removeIpConfig(nic)
                DynamicSourceRoute.addInterfaceTracking(nic)
                self._removeSourceRoute(nic, DynamicSourceRoute)
            else:
                self.configApplier.setIfaceMtu(nic.name, mtus.DEFAULT_MTU)
                self.configApplier.ifdown(nic)
        else:
            self._setNewMtu(nic, vlans.vlan_devs_for_iface(nic.name))
Exemple #13
0
 def _getIfaceConfValues(iface):
     ipv4 = copy.deepcopy(iface.ipv4)
     ipv6 = copy.deepcopy(iface.ipv6)
     mtu = iface.mtu
     if ifaceUsed(iface.name):
         confParams = misc.getIfaceCfg(iface.name)
         if not ipv4.address and ipv4.bootproto != 'dhcp':
             ipv4.address = confParams.get('IPADDR')
             ipv4.netmask = confParams.get('NETMASK')
             ipv4.gateway = confParams.get('GATEWAY')
             if not ipv4.bootproto:
                 ipv4.bootproto = confParams.get('BOOTPROTO')
         if ipv4.defaultRoute is None and confParams.get('DEFROUTE'):
             ipv4.defaultRoute = _from_ifcfg_bool(confParams['DEFROUTE'])
         if confParams.get('IPV6INIT') == 'yes':
             ipv6.address = confParams.get('IPV6ADDR')
             ipv6.gateway = confParams.get('IPV6_DEFAULTGW')
             ipv6.ipv6autoconf = confParams.get('IPV6_AUTOCONF') == 'yes'
             ipv6.dhcpv6 = confParams.get('DHCPV6C') == 'yes'
         if not iface.mtu:
             mtu = confParams.get('MTU')
             if mtu:
                 mtu = int(mtu)
     return ipv4, ipv6, mtu