Ejemplo n.º 1
0
def _get_persistence_module():
    persistence = config.get('vars', 'net_persistence')
    if persistence == 'unified':
        return netconfpersistence
    else:
        from .configurators import ifcfg
        return ifcfg
Ejemplo n.º 2
0
Archivo: ifcfg.py Proyecto: oVirt/vdsm
 def __init__(self, net_info, inRollback=False):
     is_unipersistence = config.get('vars', 'net_persistence') == 'unified'
     super(Ifcfg, self).__init__(ConfigWriter(),
                                 net_info,
                                 is_unipersistence,
                                 inRollback)
     self.runningConfig = RunningConfig()
Ejemplo n.º 3
0
def main(*args):
    """
    config-lvm-filter
    Configure LVM filter allowing LVM to access only the local storage
    needed by the hypervisor, but not shared storage owned by Vdsm.

    Return codes:
        0 - Successful completion.
        1 - Exception caught during operation.
        2 - Wrong arguments.
        3 - LVM filter configuration was found to be required but could not be
            completed since there is already another filter configured on the
            host.
        4 - User has chosen not to allow LVM filter reconfiguration, although
            found as required.
    """
    args = parse_args(args)

    print("Analyzing host...")

    config_method = config.get("lvm", "config_method").lower()

    if config_method == "filter":
        return config_with_filter(args)
    elif config_method == "devices":
        return config_with_devices(args)
    else:
        print("Unknown configuration method %s, use either 'filter' or "
              "'devices'." % config_method)
        return CANNOT_CONFIG
Ejemplo n.º 4
0
def _get_persistence_module():
    persistence = config.get('vars', 'net_persistence')
    if persistence == 'unified':
        return netconfpersistence
    else:
        from .configurators import ifcfg
        return ifcfg
Ejemplo n.º 5
0
 def __init__(self, net_info, inRollback=False):
     is_unipersistence = config.get('vars', 'net_persistence') == 'unified'
     super(Ifcfg, self).__init__(ConfigWriter(),
                                 net_info,
                                 is_unipersistence,
                                 inRollback)
     self.runningConfig = RunningConfig()
Ejemplo n.º 6
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 {}
Ejemplo n.º 7
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 {}
Ejemplo n.º 8
0
def init_nets():
    persistence = config.get('vars', 'net_persistence')
    if persistence != 'unified':
        logging.info('Skipping: Unified persistence is not used.')
        return

    if _nets_already_restored(NETS_RESTORED_MARK):
        logging.info('Skipping: Networks were already restored.')
        return

    logging.info('Starting initial network setup.')

    persistent_config = PersistentConfig()

    nets = _persisted_ovs_entries(persistent_config.networks)
    logging.info('Restoring networks configuration: {}'.format(nets))
    _set_blocking_dhcp(nets)

    bonds = _persisted_ovs_entries(persistent_config.bonds)
    logging.info('Restoring bondings configuration: {}'.format(bonds))

    for net, attrs in six.iteritems(nets):
        with _try2execute('IPv6autoconf for {} failed.'.format(net)):
            netswitch.configurator.setup_ipv6autoconf({net: attrs})

    for bond_name, attrs in six.iteritems(bonds):
        with _try2execute('Restoration of bond {} failed.'.format(bond_name)):
            requested_slaves = set(attrs['nics'])
            requested_options = (
                setup.parse_bond_options(attrs['options'])
                if 'options' in attrs
                else None
            )
            with Bond(
                bond_name, slaves=requested_slaves, options=requested_options
            ) as bond:
                bond.create()

    for bond, attrs in six.iteritems(bonds):
        with _try2execute('Setting links up for {} failed.'.format(bond)):
            netswitch.configurator.set_ovs_links_up({}, {bond: attrs}, {})

    for net, attrs in six.iteritems(nets):
        with _try2execute('Setting links up for {} failed.'.format(net)):
            netswitch.configurator.set_ovs_links_up({net: attrs}, {}, {})

    for net, attrs in six.iteritems(nets):
        with _try2execute('IP config for {} failed.'.format(net)):
            netswitch.configurator.setup_ovs_ip_config({net: attrs}, {})

    logging.info('Initial network setup is done.')
Ejemplo n.º 9
0
def init_nets():
    persistence = config.get('vars', 'net_persistence')
    if persistence != 'unified':
        logging.info('Skipping: Unified persistence is not used.')
        return

    if _nets_already_restored(NETS_RESTORED_MARK):
        logging.info('Skipping: Networks were already restored.')
        return

    logging.info('Starting initial network setup.')

    persistent_config = PersistentConfig()

    nets = _persisted_ovs_entries(persistent_config.networks)
    logging.info('Restoring networks configuration: {}'.format(nets))
    _set_blocking_dhcp(nets)

    bonds = _persisted_ovs_entries(persistent_config.bonds)
    logging.info('Restoring bondings configuration: {}'.format(bonds))

    for net, attrs in six.iteritems(nets):
        with _try2execute('IPv6autoconf for {} failed.'.format(net)):
            netswitch.configurator.setup_ipv6autoconf({net: attrs})

    for bond_name, attrs in six.iteritems(bonds):
        with _try2execute('Restoration of bond {} failed.'.format(bond_name)):
            requested_slaves = set(attrs['nics'])
            requested_options = (setup.parse_bond_options(attrs['options'])
                                 if 'options' in attrs else None)
            with Bond(bond_name, slaves=requested_slaves,
                      options=requested_options) as bond:
                bond.create()

    for bond, attrs in six.iteritems(bonds):
        with _try2execute('Setting links up for {} failed.'.format(bond)):
            netswitch.configurator.set_ovs_links_up({}, {bond: attrs}, {})

    for net, attrs in six.iteritems(nets):
        with _try2execute('Setting links up for {} failed.'.format(net)):
            netswitch.configurator.set_ovs_links_up({net: attrs}, {}, {})

    for net, attrs in six.iteritems(nets):
        with _try2execute('IP config for {} failed.'.format(net)):
            netswitch.configurator.setup_ovs_ip_config({net: attrs}, {})

    logging.info('Initial network setup is done.')
Ejemplo n.º 10
0
def restore(force):
    if not force and _nets_already_restored(NETS_RESTORED_MARK):
        logging.info('networks already restored. doing nothing.')
        return

    _restore_sriov_numvfs()
    unified = config.get('vars', 'net_persistence') == 'unified'
    logging.info('starting network restoration.')
    try:
        if unified:
            unified_restoration()
        else:
            ifcfg_restoration()
            _copy_persistent_over_running_config()
    except Exception:
        logging.exception('%s restoration failed.',
                          'unified' if unified else 'ifcfg')
        raise
    else:
        logging.info('restoration completed successfully.')

    touch_file(NETS_RESTORED_MARK)
Ejemplo n.º 11
0
def restore(force):
    if not force and _nets_already_restored(NETS_RESTORED_MARK):
        logging.info('networks already restored. doing nothing.')
        return

    _restore_sriov_config()
    unified = config.get('vars', 'net_persistence') == 'unified'
    logging.info('starting network restoration.')
    try:
        if unified:
            unified_restoration()
        else:
            ifcfg_restoration()
            _copy_persistent_over_running_config()
    except Exception:
        logging.exception('%s restoration failed.',
                          'unified' if unified else 'ifcfg')
        raise
    else:
        logging.info('restoration completed successfully.')

    touch_file(NETS_RESTORED_MARK)
Ejemplo n.º 12
0
DEFAULT_GENERATION = 0
MAX_GENERATION = 999  # Since this is represented in ASCII, limit to 3 places

# Block volume metadata tags
TAG_PREFIX_MD = "MD_"
TAG_PREFIX_IMAGE = "IU_"
TAG_PREFIX_PARENT = "PU_"
TAG_VOL_UNINIT = "OVIRT_VOL_INITIALIZING"
VOLUME_TAGS = [TAG_PREFIX_PARENT,
               TAG_PREFIX_IMAGE,
               TAG_PREFIX_MD]

SUPPORTED_BLOCKSIZE = (512,)

# This is the domain version translation list
# DO NOT CHANGE OLD VALUES ONLY APPEND
DOMAIN_VERSIONS = (0, 2, 3, 4, 5)

# This contains the domains versions that this VDSM
# accepts currently its all of the version but in the
# future we might slice it (eg. tuple(DOMAIN_VERSION[1:]))
SUPPORTED_DOMAIN_VERSIONS = DOMAIN_VERSIONS

P_VDSM_LIB = os.path.join(constants.P_VDSM_LIB, 'storage/')
P_VDSM_STORAGE = os.path.join(constants.P_VDSM_RUN, 'storage/')

# Storage repository
DOMAIN_MNT_POINT = 'mnt'
REPO_DATA_CENTER = config.get('irs', 'repository')
REPO_MOUNT_DIR = os.path.join(REPO_DATA_CENTER, DOMAIN_MNT_POINT)
Ejemplo n.º 13
0
VOLUME_TAGS = [TAG_PREFIX_PARENT, TAG_PREFIX_IMAGE, TAG_PREFIX_MD]

SUPPORTED_BLOCKSIZE = (512, )

# This is the domain version translation list
# DO NOT CHANGE OLD VALUES ONLY APPEND
DOMAIN_VERSIONS = (0, 2, 3, 4, 5)

# This contains the domains versions that this VDSM
# accepts currently its all of the version but in the
# future we might slice it (eg. tuple(DOMAIN_VERSION[1:]))
SUPPORTED_DOMAIN_VERSIONS = DOMAIN_VERSIONS

P_VDSM_LIB = os.path.join(constants.P_VDSM_LIB, 'storage/')
P_VDSM_STORAGE = os.path.join(constants.P_VDSM_RUN, 'storage/')

# Storage repository
DOMAIN_MNT_POINT = 'mnt'
REPO_DATA_CENTER = config.get('irs', 'repository')
REPO_MOUNT_DIR = os.path.join(REPO_DATA_CENTER, DOMAIN_MNT_POINT)

# TODO: Consider totally removing it in the future.
# Global process pool name.
GLOBAL_OOP = 'Global'

# Job statuses for external lease metadata
JOB_STATUS_PENDING = "PENDING"
JOB_STATUS_FAILED = "FAILED"
JOB_STATUS_SUCCEEDED = "SUCCEEDED"
JOB_STATUS_FENCED = "FENCED"
Ejemplo n.º 14
0
def getEthtoolOpts(name):
    try:
        opts = config.get('vars', 'ethtool_opts.' + name)
    except configparser.NoOptionError:
        opts = config.get('vars', 'ethtool_opts')
    return opts
Ejemplo n.º 15
0
class Link(object):
    """Represents link information obtained from iproute2"""

    _fakeNics = config.get('vars', 'fake_nics').split(',')
    _hiddenBonds = config.get('vars', 'hidden_bonds').split(',')
    _hiddenNics = config.get('vars', 'hidden_nics').split(',')
    _hiddenVlans = config.get('vars', 'hidden_vlans').split(',')

    def __init__(self,
                 address,
                 index,
                 linkType,
                 mtu,
                 name,
                 qdisc,
                 state,
                 vlanid=None,
                 vlanprotocol=None,
                 master=None,
                 device=None,
                 **kwargs):
        self.address = address
        self.index = index
        self.type = linkType
        self.mtu = mtu
        self.name = name
        self.qdisc = qdisc
        self.state = state
        self.master = master
        if vlanid is not None:
            self.vlanid = vlanid
        if vlanprotocol is not None:
            self.vlanprotocol = vlanprotocol
        if device is not None:
            self.device = device
        for key, value in kwargs.items():
            setattr(self, key, value)

    def __repr__(self):
        return '%s: %s(%s) %s' % (
            self.index,
            self.name,
            self.type,
            self.address,
        )

    @classmethod
    def fromDict(cls, data):
        data['linkType'] = (data['type'] if 'type' in data else
                            cls._detectType(data['name']))
        return cls(**data)

    @staticmethod
    def _detectType(name):
        """Returns the LinkType for the specified device."""
        # TODO: Add support for virtual functions
        detectedType = None
        try:
            driver = ethtool.driver_name(name)
        except IOError as ioe:
            if ioe.errno == errno.EOPNOTSUPP:
                if name == 'lo':
                    detectedType = LinkType.LOOPBACK
                else:
                    detectedType = LinkType.DUMMY
                return detectedType
            else:
                raise  # Reraise other errors like ENODEV
        if driver in (
                LinkType.BRIDGE,
                LinkType.MACVLAN,
                LinkType.TUN,
                LinkType.OVS,
                LinkType.TEAM,
                LinkType.VETH,
        ):
            detectedType = driver
        elif driver == 'bonding':
            detectedType = LinkType.BOND
        elif 'VLAN' in driver or 'vlan' in driver:
            detectedType = LinkType.VLAN
        elif os.path.exists('/sys/class/net/%s/device/physfn/' % name):
            detectedType = LinkType.VF
        else:
            detectedType = LinkType.NIC
        return detectedType

    def isBOND(self):
        return self.type == LinkType.BOND

    def isBRIDGE(self):
        return self.type == LinkType.BRIDGE

    def isDUMMY(self):
        return self.type == LinkType.DUMMY

    def isDPDK(self):
        return self.type == LinkType.DPDK

    def isNIC(self):
        return self.type == LinkType.NIC

    def isVETH(self):
        return self.type == LinkType.VETH

    def isVF(self):
        return self.type == LinkType.VF

    def isVLAN(self):
        return self.type == LinkType.VLAN

    def isMACVLAN(self):
        return self.type == LinkType.MACVLAN

    def isFakeNIC(self):
        """
        Returns True iff vdsm config marks the DUMMY or VETH dev to be reported
        as NIC.
        """
        if self.isDUMMY() or self.isVETH() or self.isMACVLAN():
            return _any_fnmatch(self.name, self._fakeNics)
        return False

    def isNICLike(self):
        return self.isNIC() or self.isVF() or self.isFakeNIC() or self.isDPDK()

    def isHidden(self):
        """Returns True iff vdsm config hides the device."""
        if self.isVLAN():
            return _any_fnmatch(self.name, self._hiddenVlans)
        elif self.isNICLike():
            return (_any_fnmatch(self.name, self._hiddenNics)
                    or (self.master and _bondExists(self.master)
                        and _any_fnmatch(self.master, self._hiddenBonds))
                    or (self.isVF() and self._isVFhidden()))
        elif self.isBOND():
            return _any_fnmatch(self.name, self._hiddenBonds)
        elif self.isBRIDGE():
            return self.name == DUMMY_BRIDGE
        return False

    def _isVFhidden(self):
        if self.address == '00:00:00:00:00:00':
            if self._is_vmfex():
                return True
        # We hide a VF if there exists a macvtap device with the same address.
        # We assume that such VFs are used by a VM and should not be reported
        # as host nics
        for path in iglob('/sys/class/net/*/address'):
            dev = os.path.basename(os.path.dirname(path))
            if (dev != self.name and _read_stripped(path) == self.address
                    and self._detectType(dev) == LinkType.MACVLAN):
                return True
        return False

    def _is_vmfex(self):
        return ethtool.driver_name(self.name) == 'enic'

    @property
    def oper_up(self):
        if dpdk.is_dpdk(self.name):
            return dpdk.is_oper_up(self.name)
        return bool(
            link.get_link(self.name)['flags'] & libnl.IfaceStatus.IFF_RUNNING)

    def get_promisc(self):
        return bool(
            link.get_link(self.name)['flags'] & libnl.IfaceStatus.IFF_PROMISC)

    def set_promisc(self, value):
        """Takes a boolean to enable/disable Link promiscuity"""
        promisc = 'on' if value else 'off'
        linkSet(self.name, ['promisc', promisc])

    promisc = property(get_promisc, set_promisc, None, 'Link promiscuity flag')
Ejemplo n.º 16
0
from vdsm.common import errors
from vdsm.common import osutils
from vdsm.common.compat import subprocess
from vdsm.common.config import config
from vdsm.common.password import ProtectedPassword
from vdsm.common.time import monotonic_time

log = logging.getLogger("procutils")

# receive() source names
OUT = "out"
ERR = "err"

_ANY_CPU = ["0-%d" % (os.sysconf('SC_NPROCESSORS_CONF') - 1)]
_SUDO_NON_INTERACTIVE_FLAG = "-n"
_USING_CPU_AFFINITY = config.get('vars', 'cpu_affinity') != ""


class CommandPath(object):
    def __init__(self, name, *args, **kwargs):
        self.name = name
        self.paths = args
        self._cmd = None
        self._search_path = kwargs.get('search_path', True)

    @property
    def cmd(self):
        if not self._cmd:
            for path in self.paths:
                if os.path.exists(path):
                    self._cmd = path
Ejemplo n.º 17
0
def getEthtoolOpts(name):
    try:
        opts = config.get('vars', 'ethtool_opts.' + name)
    except configparser.NoOptionError:
        opts = config.get('vars', 'ethtool_opts')
    return opts
Ejemplo n.º 18
0
from vdsm.common import osutils
from vdsm.common.compat import subprocess
from vdsm.common.config import config
from vdsm.common.time import monotonic_time

SYSTEMD_RUN = "/usr/bin/systemd-run"

log = logging.getLogger("procutils")

# receive() source names
OUT = "out"
ERR = "err"

_ANY_CPU = ["0-%d" % (os.sysconf('SC_NPROCESSORS_CONF') - 1)]
_SUDO_NON_INTERACTIVE_FLAG = "-n"
_USING_CPU_AFFINITY = config.get('vars', 'cpu_affinity') != ""


class CommandPath(object):
    def __init__(self, name, *args, **kwargs):
        self.name = name
        self.paths = args
        self._cmd = None
        self._search_path = kwargs.get('search_path', True)

    @property
    def cmd(self):
        if not self._cmd:
            for path in self.paths:
                if os.path.exists(path):
                    self._cmd = path