def _unconfigure(interface):
    """
    Remove config file for specified interface
    """
    filename = _get_config_name(interface)
    if os.path.exists(filename):
        utils.unpersist(filename)
        utils.rmFile(filename)
def _unconfigure(interface):
    """
    Remove config file for specified interface
    """
    filename = _get_config_name(interface)
    if os.path.exists(filename):
        utils.unpersist(filename)
        utils.rmFile(filename)
Exemple #3
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
Exemple #4
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
Exemple #5
0
def configure():
    """
    Set up the multipath daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """

    if os.path.exists(_CONF_FILE):
        backup = _CONF_FILE + '.' + time.strftime("%Y%m%d%H%M")
        shutil.copyfile(_CONF_FILE, backup)
        sys.stdout.write("Backup previous multipath.conf to %r\n" % backup)
        utils.persist(backup)

    with tempfile.NamedTemporaryFile(mode="wb",
                                     prefix=os.path.basename(_CONF_FILE) +
                                     ".tmp",
                                     dir=os.path.dirname(_CONF_FILE),
                                     delete=False) as f:
        try:
            f.write(_CONF_DATA)
            f.flush()
            if selinux.is_selinux_enabled():
                selinux.restorecon(f.name)
            os.chmod(f.name, 0o644)
            # On ovirt node multipath.conf is a bind mount and rename will fail
            # if we do not unpersist first, making this non-atomic.
            utils.unpersist(_CONF_FILE)
            os.rename(f.name, _CONF_FILE)
        except:
            os.unlink(f.name)
            raise

    utils.persist(_CONF_FILE)

    # Flush all unused multipath device maps
    commands.execCmd([constants.EXT_MULTIPATH, "-F"])

    try:
        service.service_reload("multipathd")
    except service.ServiceOperationError:
        status = service.service_status("multipathd", False)
        if status == 0:
            raise
Exemple #6
0
def configure():
    """
    Set up the multipath daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """

    if os.path.exists(_CONF_FILE):
        backup = _CONF_FILE + '.' + time.strftime("%Y%m%d%H%M")
        shutil.copyfile(_CONF_FILE, backup)
        sys.stdout.write("Backup previous multipath.conf to %r\n" % backup)
        utils.persist(backup)

    with tempfile.NamedTemporaryFile(
            mode="wb",
            prefix=os.path.basename(_CONF_FILE) + ".tmp",
            dir=os.path.dirname(_CONF_FILE),
            delete=False) as f:
        try:
            f.write(_CONF_DATA)
            f.flush()
            if selinux.is_selinux_enabled():
                selinux.restorecon(f.name)
            os.chmod(f.name, 0o644)
            # On ovirt node multipath.conf is a bind mount and rename will fail
            # if we do not unpersist first, making this non-atomic.
            utils.unpersist(_CONF_FILE)
            os.rename(f.name, _CONF_FILE)
        except:
            os.unlink(f.name)
            raise

    utils.persist(_CONF_FILE)

    # Flush all unused multipath device maps
    commands.execCmd([constants.EXT_MULTIPATH, "-F"])

    try:
        service.service_reload("multipathd")
    except service.ServiceOperationError:
        status = service.service_status("multipathd", False)
        if status == 0:
            raise