diff --git a/ipynbsrv/web/templates/web/snippets/container_grid.html b/ipynbsrv/web/templates/web/snippets/container_grid.html
index a49ec22..43e9134 100644
--- a/ipynbsrv/web/templates/web/snippets/container_grid.html
+++ b/ipynbsrv/web/templates/web/snippets/container_grid.html
@@ -5,7 +5,6 @@
{% if ct.is_running %}
{% if ct.is_suspended %}
- }
{% else %}
}
diff --git a/ipynbsrv/web/urls.py b/ipynbsrv/web/urls.py
index fd13ebc..13438ff 100644
--- a/ipynbsrv/web/urls.py
+++ b/ipynbsrv/web/urls.py
@@ -34,6 +34,8 @@
url(r'^container/restart$', 'ipynbsrv.web.views.containers.restart', name='container_restart'),
url(r'^container/start$', 'ipynbsrv.web.views.containers.start', name='container_start'),
url(r'^container/stop$', 'ipynbsrv.web.views.containers.stop', name='container_stop'),
+ url(r'^container/suspend$', 'ipynbsrv.web.views.containers.suspend', name='container_suspend'),
+ url(r'^container/resume$', 'ipynbsrv.web.views.containers.resume', name='container_resume'),
# # /images(s)/...
url(r'^images/$', 'ipynbsrv.web.views.images.index', name='images'),
diff --git a/ipynbsrv/web/views/containers.py b/ipynbsrv/web/views/containers.py
index 524204d..db3e2b5 100644
--- a/ipynbsrv/web/views/containers.py
+++ b/ipynbsrv/web/views/containers.py
@@ -188,7 +188,7 @@ def restart(request):
if container:
try:
client.containers(ct_id).restart.post()
- messages.success(request, "Container is restarting.")
+ messages.success(request, "Container is now restarting.")
except Exception as e:
messages.error(request, api_error_message(e, ""))
else:
@@ -221,7 +221,7 @@ def start(request):
if container:
try:
client.containers(ct_id).start.post()
- messages.success(request, "Container is starting.")
+ messages.success(request, "Container is now starting up.")
except Exception as e:
messages.error(request, api_error_message(e, ""))
else:
@@ -254,7 +254,73 @@ def stop(request):
if container:
try:
client.containers(ct_id).stop.post()
- messages.success(request, "Container stopped successfully.")
+ messages.success(request, "Container is shutting down.")
+ except Exception as e:
+ messages.error(request, api_error_message(e, ""))
+ else:
+ messages.error(request, "Container does not exist.")
+
+ return redirect('containers')
+
+
+@user_passes_test(login_allowed)
+def suspend(request):
+ """
+ Suspend the container.
+ """
+ if request.method != "POST":
+ messages.error(request, "Invalid request method.")
+ return redirect('containers')
+ if 'id' not in request.POST:
+ messages.error(request, "Invalid POST request.")
+ return redirect('containers')
+
+ ct_id = int(request.POST.get('id'))
+
+ client = get_httpclient_instance(request)
+
+ try:
+ container = client.containers(ct_id).get()
+ except HttpNotFoundError:
+ messages.error(request, "Container does not exist.")
+
+ if container:
+ try:
+ client.containers(ct_id).suspend.post()
+ messages.success(request, "Container is going into suspended mode.")
+ except Exception as e:
+ messages.error(request, api_error_message(e, ""))
+ else:
+ messages.error(request, "Container does not exist.")
+
+ return redirect('containers')
+
+
+@user_passes_test(login_allowed)
+def resume(request):
+ """
+ Resume the container
+ """
+ if request.method != "POST":
+ messages.error(request, "Invalid request method.")
+ return redirect('containers')
+ if 'id' not in request.POST:
+ messages.error(request, "Invalid POST request.")
+ return redirect('containers')
+
+ ct_id = int(request.POST.get('id'))
+
+ client = get_httpclient_instance(request)
+
+ try:
+ container = client.containers(ct_id).get()
+ except HttpNotFoundError:
+ messages.error(request, "Container does not exist.")
+
+ if container:
+ try:
+ client.containers(ct_id).resume.post()
+ messages.success(request, "Container is resuming.")
except Exception as e:
messages.error(request, api_error_message(e, ""))
else: