Permalink
Browse files

Display the progress of jail creation when jails are being created

  • Loading branch information...
1 parent a004ca2 commit 1d2bddd71eae554a5865b5226a102b660db252e6 @jhixson74 jhixson74 committed Jun 6, 2013
@@ -651,6 +651,23 @@ require([
}
+ checkProgress = function(pbar, url, uuid, iter) {
+ if(!iter) iter = 0;
+ xhr.get(url, {
+ headers: {"X-Progress-ID": uuid}
+ }).then(function(data) {
+ var obj = JSON.parse(data);
+ if (obj.size > 0) {
+ pbar.set('value', obj.data);
+ }
+ if (obj.state != 'done') {
+ setTimeout(function() {
+ checkProgress(pbar, url, uuid, iter + 1);
+ }, 1000);
+ }
+ });
+ };
+
checkProgressBar = function(pbar, url, uuid, iter) {
var progress_url;
if(typeof(url) == 'string') {
@@ -684,7 +701,6 @@ require([
}
doSubmit = function(attrs) {
-
var pbar, uuid, multipart, rnode, newData;
if(!attrs) {
@@ -793,6 +809,17 @@ require([
rnode._size();
rnode._position();
+ } else if (attrs.progressfunc != undefined) {
+ pbar = new dijit.form.SimpleTextarea({
+ title: "progress",
+ rows: "40",
+ cols: "80",
+ style: "width:auto;",
+ readOnly: true
+ }).placeAt(attrs.form.domNode);
+
+ rnode._size();
+ rnode._position();
}
if( multipart ) {
@@ -822,8 +849,10 @@ require([
if (attrs.progressbar != undefined) {
checkProgressBar(pbar, attrs.progressbar, uuid);
+ } else if(attrs.progressfunc != undefined &&
+ attrs.progressurl != undefined) {
+ checkProgress(pbar, attrs.progressurl, uuid);
}
-
}
checkNumLog = function(unselected) {
View
@@ -210,6 +210,10 @@ def __init__(self, *args, **kwargs):
except:
pass
+ logfile = "%s/warden.log" % jc.jc_path
+ if os.path.exists(logfile):
+ os.unlink(logfile)
+
#
# Reserve the first 25 addresses
#
@@ -303,13 +307,6 @@ def save(self):
w = Warden()
- logfile = "%s/warden.log" % jc.jc_path
- if os.access(logfile, os.F_OK):
- os.unlink(logfile)
-
- w.logfile = logfile
- w.syslog = True
-
# if self.cleaned_data['jail_32bit']:
# jail_flags |= WARDEN_CREATE_FLAGS_32BIT
if self.cleaned_data['jail_source']:
@@ -343,12 +340,34 @@ def save(self):
jail_create_args['flags'] = jail_flags
+ logfile = "%s/warden.log" % jc.jc_path
+
+ w.logfile = logfile
+ w.syslog = True
+
+ createfile = "/var/tmp/.jailcreate"
try:
+ cf = open(createfile, "a+")
+ cf.close()
+ if os.path.exists(logfile):
+ os.unlink(logfile)
+ lf = open(logfile, "a+")
+ lf.close()
w.create(**jail_create_args)
+
except Exception as e:
self.errors['__all__'] = self.error_class([_(e.message)])
+ if os.path.exists(createfile):
+ os.unlink(createfile)
+ if os.path.exists(logfile):
+ os.unlink(logfile)
return
+ if os.path.exists(createfile):
+ os.unlink(createfile)
+ if os.path.exists(logfile):
+ os.unlink(logfile)
+
jail_set_args = { }
jail_set_args['jail'] = jail_host
jail_flags = WARDEN_FLAGS_NONE
View
@@ -39,5 +39,6 @@
url(r'^import/$', 'jail_import', name="jail_import"),
url(r'^start/(?P<id>\d+)$', 'jail_start', name="jail_start"),
url(r'^stop/(?P<id>\d+)$', 'jail_stop', name="jail_stop"),
+ url(r'^progress/$', 'jail_progress', name="jail_progress"),
)
View
@@ -25,6 +25,11 @@
#
#####################################################################
import logging
+import os
+import stat
+import string
+import threading
+import time
from django.http import HttpResponse
from django.shortcuts import render
@@ -34,6 +39,7 @@
from freenasUI.freeadmin.views import JsonResp
from freenasUI.middleware.notifier import notifier
from freenasUI.jails import forms, models
+from freenasUI.common.pipesubr import pipeopen
from freenasUI.common.warden import (
Warden,
WARDEN_STATUS_RUNNING,
@@ -236,6 +242,36 @@ def jail_export(request, id):
return response
+
+def jail_progress(request):
+ data = {
+ 'size': 0,
+ 'data': '',
+ 'state': 'running'
+ }
+
+ jc = models.JailsConfiguration.objects.order_by("-id")[0]
+ logfile = '%s/warden.log' % jc.jc_path
+
+ if os.path.exists(logfile):
+ f = open(logfile, "r")
+ buf = f.readlines()
+ f.close()
+
+ size = len(buf)
+ if size > 0:
+ buf = string.join(buf)
+ size = len(buf)
+
+ data['size'] = size
+ data['data'] = buf
+
+ if not os.path.exists("/var/tmp/.jailcreate"):
+ data['state'] = 'done'
+
+ return HttpResponse(simplejson.dumps(data), mimetype="application/json")
+
+
def jail_import(request):
log.debug("XXX: jail_import()")
return render(request, 'jails/import.html', { })
@@ -0,0 +1,12 @@
+{% extends "freeadmin/generic_model_add.html" %}
+{% block post_form %}
+<script type="dojo/on" data-dojo-event="submit" data-dojo-args="e">
+ doSubmit({
+ form: this,
+ event: e,
+ url: '{{ request.path }}',
+ progressurl: '/jails/progress/',
+ progressfunc: checkProgress
+ });
+</script>
+{% endblock %}
@@ -174,12 +174,12 @@ if [ "${PLUGINJAIL}" = "YES" -a ! -e "${WORLDCHROOT}" ] ; then
clean_exit()
{
cd /
- zfs destroy -R "${tank}${clonep}"
+ zfs destroy -fR "${tank}${clonep}"
rm -rf "${pjdir}" >/dev/null 2>&1
warden_exit "Failed to setup chroot"
}
- trap clean_exit 2 3 6 9
+ trap clean_exit 2 3 6 9 15
warden_print zfs clone ${tank}${zfsp}@clean ${tank}${clonep}
@@ -194,9 +194,9 @@ if [ "${PLUGINJAIL}" = "YES" -a ! -e "${WORLDCHROOT}" ] ; then
bootstrap_pkgng "${pjdir}" "pluginjail"
if [ "$?" != "0" ] ; then
- warden_print zfs destroy -R "${tank}${clonep}"
+ warden_print zfs destroy -fR "${tank}${clonep}"
- zfs destroy -R "${tank}${clonep}"
+ zfs destroy -fR "${tank}${clonep}"
rm -rf "${pjdir}" >/dev/null 2>&1
warden_exit "bootstrap_pkng for ${pjdir} failed"
fi
@@ -205,14 +205,14 @@ if [ "${PLUGINJAIL}" = "YES" -a ! -e "${WORLDCHROOT}" ] ; then
zfs snapshot ${tank}${clonep}@clean
if [ $? -ne 0 ] ; then
- warden_print zfs destroy -R "${tank}${clonep}"
+ warden_print zfs destroy -fR "${tank}${clonep}"
- zfs destroy -R "${tank}${clonep}"
+ zfs destroy -fR "${tank}${clonep}"
rm -rf "${pjdir}" >/dev/null 2>&1
warden_exit "Failed creating clean ZFS pluginjail snapshot"
fi
- trap 2 3 6 9
+ trap 2 3 6 9 15
# We're on UFS :-(
else
Oops, something went wrong.

0 comments on commit 1d2bddd

Please sign in to comment.