Example #1
0
def _print_recommended_filter(wanted_filter):
    print("This is the recommended LVM filter for this host:")
    print()
    print("  " + lvmfilter.format_option(wanted_filter))
    print()
    print("""\
This filter allows LVM to access the local devices used by the
hypervisor, but not shared storage owned by Vdsm. If you add a new
device to the volume group, you will need to edit the filter manually.
    """)
Example #2
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.
    """

    print("Analyzing host...")

    mounts = lvmfilter.find_lvm_mounts()
    wanted_filter = lvmfilter.build_filter(mounts)

    with lvmconf.LVMConfig() as config:
        current_filter = config.getlist("devices", "filter")

    advice = lvmfilter.analyze(current_filter, wanted_filter)

    # This is the expected condition on a correctly configured host.
    if advice.action == lvmfilter.UNNEEDED:
        print("LVM filter is already configured for Vdsm")
        return

    # We need to configure LVM filter.

    print("Found these mounted logical volumes on this host:")
    print()

    for mnt in mounts:
        print("  logical volume: ", mnt.lv)
        print("  mountpoint:     ", mnt.mountpoint)
        print("  devices:        ", ", ".join(mnt.devices))
        print()

    print("This is the recommended LVM filter for this host:")
    print()
    print("  " + lvmfilter.format_option(wanted_filter))
    print()
    print("""\
This filter allows LVM to access the local devices used by the
hypervisor, but not shared storage owned by Vdsm. If you add a new
device to the volume group, you will need to edit the filter manually.
""")

    if current_filter:
        print("This is the current LVM filter:")
        print()
        print("  " + lvmfilter.format_option(current_filter))
        print()

    if advice.action == lvmfilter.CONFIGURE:

        if not confirm("Configure LVM filter? [yes,NO] "):
            return

        with lvmconf.LVMConfig() as config:
            config.setlist("devices", "filter", advice.filter)
            config.save()

        print("""\
Configuration completed successfully!

Please reboot to verify the LVM configuration.
""")

    elif advice.action == lvmfilter.RECOMMEND:

        print("""\
WARNING: The current LVM filter does not match the recommended filter,
Vdsm cannot configure the filter automatically.

Please edit /etc/lvm/lvm.conf and set the 'filter' option in the
'devices' section to the recommended value.

It is recommend to reboot after changing LVM filter.
""")
Example #3
0
def _print_current_filter(current_filter):
    print("This is the current LVM filter:")
    print()
    print("  " + lvmfilter.format_option(current_filter))
    print()
Example #4
0
def test_format_option():
    lvm_filter = ["a|^/dev/sda2$|", "r|.*|"]
    expected = 'filter = [ "a|^/dev/sda2$|", "r|.*|" ]'
    assert lvmfilter.format_option(lvm_filter) == expected
Example #5
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.
    """

    print("Analyzing host...")

    mounts = lvmfilter.find_lvm_mounts()
    wanted_filter = lvmfilter.build_filter(mounts)

    with lvmconf.LVMConfig() as config:
        current_filter = config.getlist("devices", "filter")

    advice = lvmfilter.analyze(current_filter, wanted_filter)

    # This is the expected condition on a correctly configured host.
    if advice.action == lvmfilter.UNNEEDED:
        print("LVM filter is already configured for Vdsm")
        return

    # We need to configure LVM filter.

    print("Found these mounted logical volumes on this host:")
    print()

    for mnt in mounts:
        print("  logical volume: ", mnt.lv)
        print("  mountpoint:     ", mnt.mountpoint)
        print("  devices:        ", ", ".join(mnt.devices))
        print()

    print("This is the recommended LVM filter for this host:")
    print()
    print("  " + lvmfilter.format_option(wanted_filter))
    print()
    print("""\
This filter allows LVM to access the local devices used by the
hypervisor, but not shared storage owned by Vdsm. If you add a new
device to the volume group, you will need to edit the filter manually.
""")

    if current_filter:
        print("This is the current LVM filter:")
        print()
        print("  " + lvmfilter.format_option(current_filter))
        print()

    if advice.action == lvmfilter.CONFIGURE:

        if not common.confirm("Configure LVM filter? [yes,NO] "):
            return

        with lvmconf.LVMConfig() as config:
            config.setlist("devices", "filter", advice.filter)
            config.save()

        print("""\
Configuration completed successfully!

Please reboot to verify the LVM configuration.
""")

    elif advice.action == lvmfilter.RECOMMEND:

        print("""\
WARNING: The current LVM filter does not match the recommended filter,
Vdsm cannot configure the filter automatically.

Please edit /etc/lvm/lvm.conf and set the 'filter' option in the
'devices' section to the recommended value.

It is recommend to reboot after changing LVM filter.
""")
Example #6
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...")

    mounts = lvmfilter.find_lvm_mounts()
    wanted_filter = lvmfilter.build_filter(mounts)
    wanted_wwids = lvmfilter.find_wwids(mounts)

    with lvmconf.LVMConfig() as config:
        current_filter = config.getlist("devices", "filter")

    current_wwids = mpathconf.read_blacklist()

    advice = lvmfilter.analyze(
        current_filter,
        wanted_filter,
        current_wwids,
        wanted_wwids)

    # This is the expected condition on a correctly configured host.
    if advice.action == lvmfilter.UNNEEDED:
        print("LVM filter is already configured for Vdsm")
        return

    # We need to configure LVM filter.

    print("Found these mounted logical volumes on this host:")
    print()

    for mnt in mounts:
        print("  logical volume: ", mnt.lv)
        print("  mountpoint:     ", mnt.mountpoint)
        print("  devices:        ", ", ".join(mnt.devices))
        print()

    print("This is the recommended LVM filter for this host:")
    print()
    print("  " + lvmfilter.format_option(wanted_filter))
    print()
    print("""\
This filter allows LVM to access the local devices used by the
hypervisor, but not shared storage owned by Vdsm. If you add a new
device to the volume group, you will need to edit the filter manually.
""")

    if current_filter:
        print("This is the current LVM filter:")
        print()
        print("  " + lvmfilter.format_option(current_filter))
        print()

    if advice.wwids:
        print("To use the recommended filter we need to add multipath")
        print("blacklist in /etc/multipath/conf.d/vdsm_blacklist.conf:")
        print()
        print(textwrap.indent(mpathconf.format_blacklist(advice.wwids), "  "))
        print()

    if advice.action == lvmfilter.CONFIGURE:

        if not args.assume_yes:
            if not common.confirm("Configure host? [yes,NO] "):
                return NEEDS_CONFIG

        mpathconf.configure_blacklist(advice.wwids)

        with lvmconf.LVMConfig() as config:
            config.setlist("devices", "filter", advice.filter)
            config.save()

        print("""\
Configuration completed successfully!

Please reboot to verify the configuration.
""")

    elif advice.action == lvmfilter.RECOMMEND:

        print("""\
WARNING: The current LVM filter does not match the recommended filter,
Vdsm cannot configure the filter automatically.

Please edit /etc/lvm/lvm.conf and set the 'filter' option in the
'devices' section to the recommended value.

Make sure /etc/multipath/conf.d/vdsm_blacklist.conf is set with the
recommended 'blacklist' section.

It is recommended to reboot to verify the new configuration.
""")
        return CANNOT_CONFIG
Example #7
0
def test_format_option():
    lvm_filter = ["a|^/dev/sda2$|", "r|.*|"]
    expected = 'filter = [ "a|^/dev/sda2$|", "r|.*|" ]'
    assert lvmfilter.format_option(lvm_filter) == expected