#NEWLINE# def receive( uuid , source ) : #NEWLINE# #INDENT# "\n    Receive a vm from a directory\n\n    uuid : string\n        uuid of vm to be received\n    source : string\n        source directory\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' vmadm.receive 186da9ab-7392-4f55-91a5-b8f1fe770543 /opt/backups\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# vmadm = _check_vmadm ( ) #NEWLINE# zfs = _check_zfs ( ) #NEWLINE# if ( not os . path . isdir ( source ) ) : #NEWLINE# #INDENT# ret [ 'Error' ] = 'Source must be a directory or host' #NEWLINE# return ret #NEWLINE# #UNINDENT# if ( not os . path . exists ( os . path . join ( source , '{0}.vmdata' . format ( uuid ) ) ) ) : #NEWLINE# #INDENT# ret [ 'Error' ] = 'Unknow vm with uuid in {0}' . format ( source ) #NEWLINE# return ret #NEWLINE# #UNINDENT# cmd = '{vmadm} receive < {source}' . format ( vmadm = vmadm , source = os . path . join ( source , '{0}.vmdata' . format ( uuid ) ) ) #NEWLINE# res = __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = True ) #NEWLINE# retcode = res [ 'retcode' ] #NEWLINE# if ( ( retcode != 0 ) and ( not res [ 'stderr' ] . endswith ( 'datasets' ) ) ) : #NEWLINE# #INDENT# ret [ 'Error' ] = ( uuid [ 'stderr' ] if ( 'stderr' in res ) else _exit_status ( retcode ) ) #NEWLINE# return ret #NEWLINE# #UNINDENT# vmobj = get ( uuid ) #NEWLINE# if ( 'datasets' not in vmobj ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# log . warning ( 'one or more datasets detected, this is not supported!' ) #NEWLINE# log . warning ( 'trying to restore datasets, mountpoints will need to be set again...' ) #NEWLINE# for dataset in vmobj [ 'datasets' ] : #NEWLINE# #INDENT# name = dataset . split ( '/' ) #NEWLINE# name = name [ ( - 1 ) ] #NEWLINE# cmd = '{zfs} receive {dataset} < {source}' . format ( zfs = zfs , dataset = dataset , source = os . path . join ( source , '{0}-{1}.zfsds' . format ( uuid , name ) ) ) #NEWLINE# res = __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = True ) #NEWLINE# retcode = res [ 'retcode' ] #NEWLINE# if ( retcode != 0 ) : #NEWLINE# #INDENT# ret [ 'Error' ] = ( res [ 'stderr' ] if ( 'stderr' in res ) else _exit_status ( retcode ) ) #NEWLINE# return ret #NEWLINE# #UNINDENT# #UNINDENT# cmd = '{vmadm} install {uuid}' . format ( vmadm = vmadm , uuid = uuid ) #NEWLINE# res = __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = True ) #NEWLINE# retcode = res [ 'retcode' ] #NEWLINE# if ( ( retcode != 0 ) and ( not res [ 'stderr' ] . endswith ( 'datasets' ) ) ) : #NEWLINE# #INDENT# ret [ 'Error' ] = ( res [ 'stderr' ] if ( 'stderr' in res ) else _exit_status ( retcode ) ) #NEWLINE# return ret #NEWLINE# #UNINDENT# return True