#NEWLINE# def create_secret( self , usage_type , usage_id , password = None ) : #NEWLINE# #INDENT# "Create a secret.\n\n        :param usage_type: one of 'iscsi', 'ceph', 'rbd' or 'volume'\n                           'rbd' will be converted to 'ceph'.\n        :param usage_id: name of resource in secret\n        :param password: optional secret value to set\n        " #NEWLINE# secret_conf = vconfig . LibvirtConfigSecret ( ) #NEWLINE# secret_conf . ephemeral = False #NEWLINE# secret_conf . private = False #NEWLINE# secret_conf . usage_id = usage_id #NEWLINE# if ( usage_type in ( 'rbd' , 'ceph' ) ) : #NEWLINE# #INDENT# secret_conf . usage_type = 'ceph' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( usage_type == 'iscsi' ) : #NEWLINE# #INDENT# secret_conf . usage_type = 'iscsi' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( usage_type == 'volume' ) : #NEWLINE# #INDENT# secret_conf . usage_type = 'volume' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = _ ( 'Invalid usage_type: %s' ) #NEWLINE# raise exception . NovaException ( ( msg % usage_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# xml = secret_conf . to_xml ( ) #NEWLINE# try : #NEWLINE# #INDENT# LOG . debug ( ( 'Secret XML: %s' % xml ) ) #NEWLINE# conn = self . get_connection ( ) #NEWLINE# secret = conn . secretDefineXML ( xml ) #NEWLINE# if ( self is not None ) : #NEWLINE# #INDENT# secret . setValue ( password ) #NEWLINE# #UNINDENT# return secret #NEWLINE# #UNINDENT# except libvirt . libvirtError : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# LOG . error ( _LE ( 'Error defining a secret with XML: %s' ) , xml )