예제 #1
0
def upgrade_cib(cib, runner):
    """
    Upgrade CIB to the latest schema of installed pacemaker. Returns upgraded
    CIB as string.
    Raises LibraryError on any failure.

    cib -- cib etree
    runner -- CommandRunner
    """
    temp_file = None
    try:
        temp_file = tempfile.NamedTemporaryFile("w+", suffix=".pcs")
        temp_file.write(etree.tostring(cib).decode())
        temp_file.flush()
        stdout, stderr, retval = runner.run(
            [
                os.path.join(settings.pacemaker_binaries, "cibadmin"),
                "--upgrade", "--force"
            ],
            env_extend={"CIB_file": temp_file.name})

        if retval != 0:
            temp_file.close()
            raise LibraryError(
                reports.cib_upgrade_failed(join_multilines([stderr, stdout])))

        temp_file.seek(0)
        return etree.fromstring(temp_file.read())
    except (EnvironmentError, etree.XMLSyntaxError,
            etree.DocumentInvalid) as e:
        raise LibraryError(reports.cib_upgrade_failed(str(e)))
    finally:
        if temp_file:
            temp_file.close()
예제 #2
0
파일: tools.py 프로젝트: wyatt88/pcs
def upgrade_cib(cib, runner):
    """
    Upgrade CIB to the latest schema of installed pacemaker. Returns upgraded
    CIB as string.
    Raises LibraryError on any failure.

    cib -- cib etree
    runner -- CommandRunner
    """
    temp_file = tempfile.NamedTemporaryFile("w+", suffix=".pcs")
    temp_file.write(etree.tostring(cib).decode())
    temp_file.flush()
    output, retval = runner.run(
        [
            os.path.join(settings.pacemaker_binaries, "cibadmin"),
            "--upgrade",
            "--force"
        ],
        env_extend={"CIB_file": temp_file.name}
    )

    if retval != 0:
        temp_file.close()
        LibraryError(reports.cib_upgrade_failed(output))

    try:
        temp_file.seek(0)
        return etree.fromstring(temp_file.read())
    except (EnvironmentError, etree.XMLSyntaxError, etree.DocumentInvalid) as e:
        LibraryError(reports.cib_upgrade_failed(str(e)))
    finally:
        temp_file.close()
예제 #3
0
파일: live.py 프로젝트: bgistone/pcs
def ensure_cib_version(runner, cib, version):
    """
    This method ensures that specified cib is verified by pacemaker with
    version 'version' or newer. If cib doesn't correspond to this version,
    method will try to upgrade cib.
    Returns cib which was verified by pacemaker version 'version' or later.
    Raises LibraryError on any failure.

    CommandRunner runner
    etree cib cib tree
    tuple version tuple of integers (<major>, <minor>, <revision>)
    """
    current_version = get_pacemaker_version_by_which_cib_was_validated(cib)
    if current_version >= version:
        return None

    _upgrade_cib(runner)
    new_cib_xml = get_cib_xml(runner)

    try:
        new_cib = parse_cib_xml(new_cib_xml)
    except (etree.XMLSyntaxError, etree.DocumentInvalid) as e:
        raise LibraryError(reports.cib_upgrade_failed(str(e)))

    current_version = get_pacemaker_version_by_which_cib_was_validated(new_cib)
    if current_version >= version:
        return new_cib

    raise LibraryError(
        reports.unable_to_upgrade_cib_to_required_version(
            current_version, version))
예제 #4
0
def ensure_cib_version(runner, cib, version):
    """
    This method ensures that specified cib is verified by pacemaker with
    version 'version' or newer. If cib doesn't correspond to this version,
    method will try to upgrade cib.
    Returns cib which was verified by pacemaker version 'version' or later.
    Raises LibraryError on any failure.

    CommandRunner runner
    etree cib cib tree
    tuple version tuple of integers (<major>, <minor>, <revision>)
    """
    current_version = get_pacemaker_version_by_which_cib_was_validated(cib)
    if current_version >= version:
        return None

    _upgrade_cib(runner)
    new_cib_xml = get_cib_xml(runner)

    try:
        new_cib = parse_cib_xml(new_cib_xml)
    except (etree.XMLSyntaxError, etree.DocumentInvalid) as e:
        raise LibraryError(reports.cib_upgrade_failed(str(e)))

    current_version = get_pacemaker_version_by_which_cib_was_validated(new_cib)
    if current_version >= version:
        return new_cib

    raise LibraryError(reports.unable_to_upgrade_cib_to_required_version(
        current_version, version
    ))
예제 #5
0
파일: live.py 프로젝트: bgistone/pcs
def _upgrade_cib(runner):
    """
    Upgrade CIB to the latest schema available locally or clusterwise.
    CommandRunner runner
    """
    stdout, stderr, retval = runner.run(
        [__exec("cibadmin"), "--upgrade", "--force"])
    # If we are already on the latest schema available, do not consider it an
    # error. We do not know here what version is required. The caller however
    # knows and is responsible for dealing with it.
    if retval not in (0, __EXITCODE_CIB_SCHEMA_IS_THE_LATEST_AVAILABLE):
        raise LibraryError(
            reports.cib_upgrade_failed(join_multilines([stderr, stdout])))
예제 #6
0
def _upgrade_cib(runner):
    """
    Upgrade CIB to the latest schema available locally or clusterwise.
    CommandRunner runner
    """
    stdout, stderr, retval = runner.run(
        [__exec("cibadmin"), "--upgrade", "--force"])
    # If we are already on the latest schema available, cibadmin exits with 0.
    # That is fine. We do not know here what version is required anyway. The
    # caller knows that and is responsible for dealing with it.
    if retval != 0:
        raise LibraryError(
            reports.cib_upgrade_failed(join_multilines([stderr, stdout])))
예제 #7
0
def _upgrade_cib(runner):
    """
    Upgrade CIB to the latest schema available locally or clusterwise.
    CommandRunner runner
    """
    stdout, stderr, retval = runner.run(
        [__exec("cibadmin"), "--upgrade", "--force"]
    )
    # If we are already on the latest schema available, do not consider it an
    # error. We do not know here what version is required. The caller however
    # knows and is responsible for dealing with it.
    if retval not in (0, __EXITCODE_CIB_SCHEMA_IS_THE_LATEST_AVAILABLE):
        raise LibraryError(
            reports.cib_upgrade_failed(join_multilines([stderr, stdout]))
        )
예제 #8
0
파일: live.py 프로젝트: tomjelinek/pcs
def _upgrade_cib(runner):
    """
    Upgrade CIB to the latest schema available locally or clusterwise.
    CommandRunner runner
    """
    stdout, stderr, retval = runner.run(
        [__exec("cibadmin"), "--upgrade", "--force"]
    )
    # If we are already on the latest schema available, cibadmin exits with 0.
    # That is fine. We do not know here what version is required anyway. The
    # caller knows that and is responsible for dealing with it.
    if retval != 0:
        raise LibraryError(
            reports.cib_upgrade_failed(join_multilines([stderr, stdout]))
        )
예제 #9
0
def upgrade_cib(runner, cib_file_path=None):
    """
    Upgrade CIB to the latest schema available locally or clusterwise.
    CommandRunner runner
    string cib_file_path run on specified file or live cluster if None
    """
    environment = dict()
    if cib_file_path:
        environment["CIB_file"] = cib_file_path
    stdout, stderr, retval = runner.run([
        os.path.join(settings.pacemaker_binaries, "cibadmin"),
        "--upgrade",
        "--force",
    ],
                                        env_extend=environment)
    if retval != 0:
        raise LibraryError(
            reports.cib_upgrade_failed(join_multilines([stderr, stdout])))
예제 #10
0
def upgrade_cib_file(cib, runner):
    """
    Upgrade CIB to the latest schema of installed pacemaker. Returns upgraded
    CIB as string.
    Raises LibraryError on any failure.

    cib -- cib etree
    runner -- CommandRunner
    """
    temp_file = None
    try:
        temp_file = tempfile.NamedTemporaryFile("w+", suffix=".pcs")
        temp_file.write(etree.tostring(cib).decode())
        temp_file.flush()
        upgrade_cib(runner, temp_file.name)
        temp_file.seek(0)
        return temp_file.read()
    except EnvironmentError as e:
        raise LibraryError(reports.cib_upgrade_failed(str(e)))
    finally:
        if temp_file:
            temp_file.close()