<s> """<STR_LIT>""" <EOL> from lmi . scripts . common import get_logger <EOL> from lmi . scripts . common . errors import LmiFailed <EOL> from lmi . scripts . storage import common , fs <EOL> LOG = get_logger ( __name__ ) <EOL> def get_luks_list ( ns ) : <EOL> """<STR_LIT>""" <EOL> for fmt in ns . LMI_EncryptionFormat . instances ( ) : <EOL> yield fmt <EOL> def create_luks ( ns , device , passphrase ) : <EOL> """<STR_LIT>""" <EOL> device = common . str2device ( ns , device ) <EOL> service = ns . LMI_ExtentEncryptionConfigurationService . first_instance ( ) <EOL> ( ret , outparams , err ) = service . SyncCreateEncryptionFormat ( <EOL> InExtent = device , <EOL> Passphrase = passphrase ) <EOL> if ret != <NUM_LIT:0> : <EOL> if err : <EOL> raise LmiFailed ( "<STR_LIT>" % err ) <EOL> values = service . CreateEncryptionFormat . CreateEncryptionFormatValues <EOL> raise LmiFailed ( "<STR_LIT>" <EOL> % ( values . value_name ( ret ) , ) ) <EOL> LOG ( ) . info ( "<STR_LIT>" , device . Name ) <EOL> return outparams [ '<STR_LIT>' ] <EOL> def open_luks ( ns , fmt , name , passphrase ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> service = ns . LMI_ExtentEncryptionConfigurationService . first_instance ( ) <EOL> ( ret , outparams , err ) = service . SyncOpenEncryptionFormat ( <EOL> Format = fmt , <EOL> ElementName = name , <EOL> Passphrase = passphrase ) <EOL> if ret != <NUM_LIT:0> : <EOL> if err : <EOL> raise LmiFailed ( "<STR_LIT>" % err ) <EOL> values = service . OpenEncryptionFormat . OpenEncryptionFormatValues <EOL> raise LmiFailed ( "<STR_LIT>" <EOL> % ( values . value_name ( ret ) , ) ) <EOL> opened = outparams [ '<STR_LIT>' ] . to_instance ( ) <EOL> LOG ( ) . info ( "<STR_LIT>" , fmt . ElementName , opened . Name ) <EOL> return opened <EOL> def close_luks ( ns , fmt ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> service = ns . LMI_ExtentEncryptionConfigurationService . first_instance ( ) <EOL> ( ret , outparams , err ) = service . SyncCloseEncryptionFormat ( Format = fmt ) <EOL> if ret != <NUM_LIT:0> : <EOL> if err : <EOL> raise LmiFailed ( "<STR_LIT>" % err ) <EOL> values = service . CloseEncryptionFormat . CloseEncryptionFormatValues <EOL> raise LmiFailed ( "<STR_LIT>" <EOL> % ( values . value_name ( ret ) , ) ) <EOL> LOG ( ) . info ( "<STR_LIT>" , fmt . ElementName ) <EOL> def add_luks_passphrase ( ns , fmt , passphrase , new_passphrase ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> service = ns . LMI_ExtentEncryptionConfigurationService . first_instance ( ) <EOL> ( ret , outparams , err ) = service . AddPassphrase ( <EOL> Format = fmt , <EOL> Passphrase = passphrase , <EOL> NewPassphrase = new_passphrase ) <EOL> if ret != <NUM_LIT:0> : <EOL> if err : <EOL> raise LmiFailed ( "<STR_LIT>" % err ) <EOL> values = service . AddPassphrase . AddPassphraseValues <EOL> raise LmiFailed ( "<STR_LIT>" <EOL> % ( values . value_name ( ret ) , ) ) <EOL> LOG ( ) . info ( "<STR_LIT>" , fmt . ElementName ) <EOL> def delete_luks_passphrase ( ns , fmt , passphrase ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> service = ns . LMI_ExtentEncryptionConfigurationService . first_instance ( ) <EOL> ( ret , outparams , err ) = service . DeletePassphrase ( <EOL> Format = fmt , <EOL> Passphrase = passphrase ) <EOL> if ret != <NUM_LIT:0> : <EOL> if err : <EOL> raise LmiFailed ( "<STR_LIT>" % err ) <EOL> values = service . DeletePassphrase . DeletePassphraseValues <EOL> raise LmiFailed ( "<STR_LIT>" <EOL> % ( values . value_name ( ret ) , ) ) <EOL> LOG ( ) . info ( "<STR_LIT>" , fmt . ElementName ) <EOL> def get_luks_device ( ns , fmt ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> crypttext_device = fmt . first_associator ( <EOL> AssocClass = "<STR_LIT>" , <EOL> Role = "<STR_LIT>" ) <EOL> device = crypttext_device . first_associator ( <EOL> AssocClass = "<STR_LIT>" , <EOL> Role = "<STR_LIT>" ) <EOL> return device <EOL> def get_passphrase_count ( ns , fmt ) : <EOL> """<STR_LIT>""" <EOL> fmt = fs . str2format ( ns , fmt ) <EOL> count = reduce ( lambda a , b : a + b , fmt . SlotStatus ) <EOL> return count </s>
