@_ensure_exists
def remove(name, stop=False):
    if not stop and state(name) != 'stopped':
        raise CommandExecutionError(
            'Container \'{0}\' is not stopped'.format(name)
        )

    def _failed_remove(name, exc):
        raise CommandExecutionError(
            'Unable to remove container \'{0}\': {1}'.format(name, exc)
        )

    if _sd_version() >= 219:
        ret = _machinectl('remove {0}'.format(name))
        if ret['retcode'] != 0:
            __context__['retcode'] = salt.defaults.exitcodes.EX_UNAVAILABLE
            _failed_remove(name, ret['stderr'])
    else:
        try:
            shutil.rmtree(os.path.join(_root(), name))
        except OSError as exc:
            _failed_remove(name, exc)
    return True


# Compatibility between LXC and nspawn
Remove the named container
dataset/ETHPy150Open saltstack/salt/salt/modules/nspawn.py/remove