Commit c2c3913d by Kálmán Viktor

dashboard: add screenshot

parent 31f77d82
......@@ -654,3 +654,12 @@ textarea[name="list-new-namelist"] {
80% { -webkit-transform: scale(1); }
100% { -webkit-transform: scale(1); }
}
.btn-toolbar {
margin-bottom: 5px;
}
#vm-console-screenshot {
display: none;
}
......@@ -264,6 +264,19 @@ $(function() {
return false;
});
// screenshot
$("#getScreenshotButton").click(function() {
var vm = $(this).data("vm-pk");
var ct = $("#vm-console-screenshot");
ct.slideDown();
var img = $("img", ct).prop("src", '/dashboard/vm/' + vm + '/screenshot/');
});
// screenshot close
$("#vm-console-screenshot button").click(function() {
$(this).parent("div").slideUp();
});
});
......
{% load i18n %}
<div class="btn-toolbar">
<button id="sendCtrlAltDelButton" class="btn btn-danger small">{% trans "Send Ctrl+Alt+Del" %}</button>
<button id="sendPasswordButton" class="btn btn-default small">{% trans "Type password" %}</button>
<button id="sendCtrlAltDelButton" class="btn btn-danger btn-sm">{% trans "Send Ctrl+Alt+Del" %}</button>
<button id="sendPasswordButton" class="btn btn-default btn-sm">{% trans "Type password" %}</button>
<button id="getScreenshotButton" class="btn btn-info btn-sm pull-right" data-vm-pk="{{ instance.pk }}"><i class="icon-picture"></i> {% trans "Screenshot" %}</button>
</div>
<div class="alert alert-info" id="noVNC_status">
</div>
<div id="vm-console-screenshot">
<button class="btn btn-danger btn-sm pull-right">Close</button>
<h3>{% trans "Screenshot" %}</h3>
<img />
<hr />
</div>
<canvas id="noVNC_canvas" width="640px" height="20px">Canvas not supported.
</canvas>
......
......@@ -33,6 +33,7 @@ from .views import (
GroupRemoveAclUserView, GroupRemoveAclGroupView, GroupRemoveUserView,
GroupCreate,
TemplateChoose,
get_vm_screenshot
)
urlpatterns = patterns(
......@@ -83,6 +84,8 @@ urlpatterns = patterns(
name='dashboard.views.vm-renew'),
url(r'^vm/activity/(?P<pk>\d+)/$', InstanceActivityDetail.as_view(),
name='dashboard.views.vm-activity'),
url(r'^vm/(?P<pk>\d+)/screenshot/$', get_vm_screenshot,
name='dashboard.views.vm-get-screenshot'),
url(r'^node/list/$', NodeList.as_view(), name='dashboard.views.node-list'),
url(r'^node/(?P<pk>\d+)/$', NodeDetailView.as_view(),
......
......@@ -2590,3 +2590,16 @@ class InterfaceDeleteView(DeleteView):
if redirect:
return redirect
self.object.instance.get_absolute_url()
@require_GET
def get_vm_screenshot(request, pk):
instance = get_object_or_404(Instance, pk=pk)
try:
image = instance.screenshot(instance=instance,
user=request.user).getvalue()
except:
# TODO handle this better
raise Http404()
return HttpResponse(image, mimetype="image/png")
......@@ -913,3 +913,9 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
i.is_abortable_for_user = partial(i.is_abortable_for,
user=user)
return acts
def get_screenshot(self, timeout=5):
queue_name = self.get_remote_queue_name('vm')
return vm_tasks.screenshot.apply_async(args=[self.vm_name],
queue=queue_name
).get(timeout=timeout)
......@@ -534,3 +534,22 @@ class FlushOperation(NodeOperation):
register_operation(FlushOperation)
class ScreenshotOperation(InstanceOperation):
activity_code_suffix = 'screenshot'
id = 'screenshot'
name = _("screenshot")
description = _("Get screenshot")
acl_level = "owner"
def check_precond(self):
super(ScreenshotOperation, self).check_precond()
if self.instance.status not in ['RUNNING']:
raise self.instance.WrongStateError(self.instance)
def _operation(self, instance, user):
return self.instance.get_screenshot(timeout=20)
register_operation(ScreenshotOperation)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment