Esempio n. 1
0
def rotateFiles(directory, prefixName, gen, cp=False, persist=False):
    log.debug("dir: %s, prefixName: %s, versions: %s" %
              (directory, prefixName, gen))
    gen = int(gen)
    files = os.listdir(directory)
    files = glob.glob("%s*" % prefixName)
    fd = {}
    for fname in files:
        name = fname.rsplit('.', 1)
        try:
            ind = int(name[1])
        except ValueError:
            name[0] = fname
            ind = 0
        except IndexError:
            ind = 0
        except:
            continue
        if ind < gen:
            fd[ind] = {'old': fname, 'new': name[0] + '.' + str(ind + 1)}

    keys = fd.keys()
    keys.sort(reverse=True)
    log.debug("versions found: %s" % (keys))

    for key in keys:
        oldName = os.path.join(directory, fd[key]['old'])
        newName = os.path.join(directory, fd[key]['new'])
        if utils.isOvirtNode() and persist and not cp:
            try:
                execCmd([constants.EXT_UNPERSIST, oldName],
                        sudo=True)
                execCmd([constants.EXT_UNPERSIST, newName],
                        sudo=True)
            except:
                pass
        try:
            if cp:
                execCmd([constants.EXT_CP, oldName, newName], sudo=True)
                if (utils.isOvirtNode() and
                        persist and not os.path.exists(newName)):
                    execCmd([constants.EXT_PERSIST, newName],
                            sudo=True)

            else:
                os.rename(oldName, newName)
        except:
            pass
        if utils.isOvirtNode() and persist and not cp:
            try:
                execCmd([constants.EXT_PERSIST, newName],
                        sudo=True)
            except:
                pass
Esempio n. 2
0
def rotateFiles(directory, prefixName, gen, cp=False, persist=False):
    log.debug("dir: %s, prefixName: %s, versions: %s" %
              (directory, prefixName, gen))
    gen = int(gen)
    files = os.listdir(directory)
    files = glob.glob("%s*" % prefixName)
    fd = {}
    for fname in files:
        name = fname.rsplit('.', 1)
        try:
            ind = int(name[1])
        except ValueError:
            name[0] = fname
            ind = 0
        except IndexError:
            ind = 0
        except:
            continue
        if ind < gen:
            fd[ind] = {'old': fname, 'new': name[0] + '.' + str(ind + 1)}

    keys = fd.keys()
    keys.sort(reverse=True)
    log.debug("versions found: %s" % (keys))

    for key in keys:
        oldName = os.path.join(directory, fd[key]['old'])
        newName = os.path.join(directory, fd[key]['new'])
        if utils.isOvirtNode() and persist and not cp:
            try:
                utils.unpersist(oldName)
                utils.unpersist(newName)
            except:
                pass
        try:
            if cp:
                execCmd([constants.EXT_CP, oldName, newName], sudo=True)
                if (utils.isOvirtNode() and persist
                        and not os.path.exists(newName)):
                    utils.persist(newName)

            else:
                os.rename(oldName, newName)
        except:
            pass
        if utils.isOvirtNode() and persist and not cp:
            try:
                utils.persist(newName)
            except:
                pass
Esempio n. 3
0
File: ifcfg.py Progetto: mykaul/vdsm
 def _removeFile(filename):
     """Remove file (directly or using oVirt node's library)"""
     if utils.isOvirtNode():
         node_fs.Config().delete(filename)  # unpersists and shreds the file
     else:
         utils.rmFile(filename)
     logging.debug("Removed file %s", filename)
Esempio n. 4
0
    def writeConfFile(self, fileName, configuration):
        '''Backs up the previous contents of the file referenced by fileName
        writes the new configuration and sets the specified access mode.'''
        self._backup(fileName)
        configuration = self.CONFFILE_HEADER + '\n' + configuration

        logging.debug('Writing to file %s configuration:\n%s', fileName,
                      configuration)
        with open(fileName, 'w') as confFile:
            confFile.write(configuration)
        os.chmod(fileName, 0o664)

        try:
            # filname can be of 'unicode' type. restorecon calls into a C API
            # that needs a char *. Thus, it is necessary to encode unicode to
            # a utf-8 string.
            selinux.restorecon(fileName.encode('utf-8'))
        except:
            logging.debug(
                'ignoring restorecon error in case '
                'SElinux is disabled',
                exc_info=True)

        # make sure that ifcfg files are always persisted by the node
        if self.unifiedPersistence and utils.isOvirtNode():
            node_fs.Config().persist(fileName)
Esempio n. 5
0
 def _removeFile(filename):
     """Remove file (directly or using oVirt node's library)"""
     if utils.isOvirtNode():
         node_fs.Config().delete(filename)  # unpersists and shreds the file
     else:
         utils.rmFile(filename)
     logging.debug("Removed file %s", filename)
Esempio n. 6
0
def configure():
    script = (str(_SASLPASSWD2), '-p', '-a', 'libvirt', SASL_USERNAME)
    rc, _, err = commands.execCmd(script, data=libvirt_password())
    if rc != 0:
        raise RuntimeError("Set password failed: %s" % (err,))
    if utils.isOvirtNode():
        # It seems that all /etc/libvirt folder is persisted in node,
        # but better to persist the db file explicitly
        utils.persist(_LIBVIRT_SASLDB)
Esempio n. 7
0
def _removeFile(content, vdsmConfiguration):
    """
    delete a file if it exists.
    """
    if utils.isOvirtNode():
        NodeCfg().delete(content['path'])
    else:
        try:
            os.unlink(content['path'])
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
Esempio n. 8
0
def configure():
    if utils.isOvirtNode():
        if not os.path.exists(constants.P_VDSM_CERT):
            raise InvalidRun("vdsm: Missing certificate, vdsm not registered")
        validate_ovirt_certs()

    # Remove a previous configuration (if present)
    removeConf()

    vdsmConfiguration = {
        'ssl_enabled': config.getboolean('vars', 'ssl'),
        'sanlock_enabled': constants.SANLOCK_ENABLED,
        'libvirt_selinux': constants.LIBVIRT_SELINUX
    }

    # write configuration
    for cfile, content in FILES.items():
        content['configure'](content, vdsmConfiguration)
Esempio n. 9
0
    def writeConfFile(self, fileName, configuration):
        """Backs up the previous contents of the file referenced by fileName
        writes the new configuration and sets the specified access mode."""
        self._backup(fileName)
        configuration = self.CONFFILE_HEADER + "\n" + configuration

        logging.debug("Writing to file %s configuration:\n%s", fileName, configuration)
        with open(fileName, "w") as confFile:
            confFile.write(configuration)
        os.chmod(fileName, 0o664)

        try:
            # filname can be of 'unicode' type. restorecon calls into a C API
            # that needs a char *. Thus, it is necessary to encode unicode to
            # a utf-8 string.
            selinux.restorecon(fileName.encode("utf-8"))
        except:
            logging.debug("ignoring restorecon error in case " "SElinux is disabled", exc_info=True)

        # make sure that ifcfg files are always persisted by the node
        if self.unifiedPersistence and utils.isOvirtNode():
            node_fs.Config().persist(fileName)
Esempio n. 10
0
def configure():
    _exec_vdsm_gencerts()
    if isOvirtNode():
        validate_ovirt_certs()
Esempio n. 11
0
File: ifcfg.py Progetto: mykaul/vdsm
from vdsm.config import config
from vdsm import commands
from vdsm import cmdutils
from vdsm import constants
from vdsm import dsaversion
from vdsm import hooks
from vdsm import ipwrapper
from vdsm.netinfo import (bonding as netinfo_bonding, mtus, nics, vlans, misc,
                          NET_PATH)
from vdsm.netinfo.cache import ifaceUsed
from vdsm import sysctl
from vdsm import utils
from vdsm.netconfpersistence import RunningConfig, PersistentConfig
from vdsm.netlink import monitor

if utils.isOvirtNode():
    from ovirt.node.utils import fs as node_fs

from . import Configurator, dhclient, getEthtoolOpts, libvirt, wait_for_device
from ..errors import ConfigNetworkError, ERR_FAILED_IFUP
from ..models import Nic, Bridge, IPv4, IPv6
from ..sourceroute import StaticSourceRoute, DynamicSourceRoute
from ..utils import remove_custom_bond_option

NET_CONF_DIR = '/etc/sysconfig/network-scripts/'
NET_CONF_BACK_DIR = constants.P_VDSM_LIB + 'netconfback/'
NET_CONF_PREF = NET_CONF_DIR + 'ifcfg-'
NET_LOGICALNET_CONF_BACK_DIR = NET_CONF_BACK_DIR + 'logicalnetworks/'


def is_available():
Esempio n. 12
0
from vdsm import dsaversion
from vdsm import hooks
from vdsm import sysctl
from vdsm import utils

from vdsm.network import ipwrapper
from vdsm.network import libvirt
from vdsm.network.ip import address
from vdsm.network.ip import dhclient
from vdsm.network.netconfpersistence import RunningConfig, PersistentConfig
from vdsm.network.netinfo import (bonding as netinfo_bonding, mtus, nics,
                                  vlans, misc, NET_PATH)
from vdsm.network.netinfo.cache import ifaceUsed
from vdsm.network.netlink import monitor

if utils.isOvirtNode():
    from ovirt.node.utils import fs as node_fs

from . import Configurator, getEthtoolOpts
from ..errors import ConfigNetworkError, ERR_FAILED_IFUP
from ..models import Nic, Bridge
from ..sourceroute import StaticSourceRoute, DynamicSourceRoute
from ..utils import remove_custom_bond_option

NET_CONF_DIR = '/etc/sysconfig/network-scripts/'
NET_CONF_BACK_DIR = constants.P_VDSM_LIB + 'netconfback/'
NET_CONF_PREF = NET_CONF_DIR + 'ifcfg-'
NET_LOGICALNET_CONF_BACK_DIR = NET_CONF_BACK_DIR + 'logicalnetworks/'


def is_available():
Esempio n. 13
0
def configure():
    _exec_vdsm_gencerts()
    if isOvirtNode():
        validate_ovirt_certs()
Esempio n. 14
0
def persistFile(name):
    if utils.isOvirtNode():
        execCmd([constants.EXT_PERSIST, name], sudo=True)
Esempio n. 15
0
def persistFile(name):
    if utils.isOvirtNode():
        execCmd([constants.EXT_PERSIST, name], sudo=True)