#NEWLINE# @ _ensure_exists #NEWLINE# def remove( name , stop = False ) : #NEWLINE# #INDENT# "\n    Remove the named container\n\n    .. warning::\n\n        This function will remove all data associated with the container. It\n        will not, however, remove the btrfs subvolumes created by pulling\n        container images (:mod:`nspawn.pull_raw\n        <salt.modules.nspawn.pull_raw>`, :mod:`nspawn.pull_tar\n        <salt.modules.nspawn.pull_tar>`, :mod:`nspawn.pull_dkr\n        <salt.modules.nspawn.pull_dkr>`).\n\n    stop : False\n        If ``True``, the container will be destroyed even if it is\n        running/frozen.\n\n    CLI Examples:\n\n    .. code-block:: bash\n\n        salt '*' nspawn.remove foo\n        salt '*' nspawn.remove foo stop=True\n    " #NEWLINE# if ( ( not stop ) and ( state ( name ) != 'stopped' ) ) : #NEWLINE# #INDENT# raise CommandExecutionError ( "Container '{0}' is not stopped" . format ( name ) ) #NEWLINE# #UNINDENT# def _failed_remove( name , exc ) : #NEWLINE# #INDENT# raise CommandExecutionError ( "Unable to remove container '{0}': {1}" . format ( name , exc ) ) #NEWLINE# #UNINDENT# if ( _sd_version ( ) >= 219 ) : #NEWLINE# #INDENT# ret = _machinectl ( 'remove {0}' . format ( name ) ) #NEWLINE# if ( ret [ 'retcode' ] != 0 ) : #NEWLINE# #INDENT# __context__ [ 'retcode' ] = salt . defaults . exitcodes . EX_UNAVAILABLE #NEWLINE# _failed_remove ( name , ret [ 'stderr' ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# shutil . rmtree ( os . path . join ( _root ( ) , name ) ) #NEWLINE# #UNINDENT# except OSError as exc : #NEWLINE# #INDENT# _failed_remove ( name , exc ) #NEWLINE# #UNINDENT# #UNINDENT# return True