#NEWLINE# def import_key( kwargs = None , call = None ) : #NEWLINE# #INDENT# '\n    List the keys available\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt-cloud -f import_key joyent keyname=mykey keyfile=/tmp/mykey.pub\n    ' #NEWLINE# if ( call != 'function' ) : #NEWLINE# #INDENT# log . error ( 'The import_key function must be called with -f or --function.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( not kwargs ) : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( 'keyname' not in kwargs ) : #NEWLINE# #INDENT# log . error ( 'A keyname is required.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( 'keyfile' not in kwargs ) : #NEWLINE# #INDENT# log . error ( 'The location of the SSH keyfile is required.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( not os . path . isfile ( kwargs [ 'keyfile' ] ) ) : #NEWLINE# #INDENT# log . error ( 'The specified keyfile ({0}) does not exist.' . format ( kwargs [ 'keyfile' ] ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# with salt . utils . fopen ( kwargs [ 'keyfile' ] , 'r' ) as fp_ : #NEWLINE# #INDENT# kwargs [ 'key' ] = fp_ . read ( ) #NEWLINE# #UNINDENT# send_data = { #NEWLINE# #INDENT# 'name' : kwargs [ 'keyname' ] , #NEWLINE# 'key' : kwargs [ 'key' ] , #NEWLINE# #UNINDENT# } #NEWLINE# kwargs [ 'data' ] = json . dumps ( send_data ) #NEWLINE# ( rcode , data ) = query ( command = 'my/keys' , method = 'POST' , data = kwargs [ 'data' ] ) #NEWLINE# log . debug ( pprint . pformat ( data ) ) #NEWLINE# return { #NEWLINE# #INDENT# 'keys' : { #NEWLINE# #INDENT# data [ 'name' ] : data [ 'key' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# }