def open_luks(ns, fmt, name, passphrase):
    """
    Open encrypted LUKS format and expose it as a clear-text block device.

    :type fmt: LMIInstance/LMI_EncryptionFormat or string
    :param fmt: The LUKS format to open.
    :type name: string
    :param name: Requested name of the clear-text block device. It will be
            available as /dev/mapper/<name>.
    :type passphrase: string
    :param passphrase: Password to open the encrypted data.
    :rtype: LMIInstance/LMI_LUKSStorageExtent
    :returns: The block device with clear-text data.
    """
    fmt = fs.str2format(ns, fmt)
    service = ns.LMI_ExtentEncryptionConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncOpenEncryptionFormat(
            Format=fmt,
            ElementName=name,
            Passphrase=passphrase)
    if ret != 0:
        if err:
            raise LmiFailed("Cannot open LUKS format: %s." % err)
        values = service.OpenEncryptionFormat.OpenEncryptionFormatValues
        raise LmiFailed("Cannot open LUKS format: %s."
                % (values.value_name(ret),))

    opened = outparams['Extent'].to_instance()
    LOG().info("Opened LUKS on %s as %s", fmt.ElementName, opened.Name)
    return opened
dataset/ETHPy150Open openlmi/openlmi-scripts/commands/storage/lmi/scripts/storage/luks.py/open_luks/original