Skip to content

Commit

Permalink
Display the progress of jail creation when jails are being created
Browse files Browse the repository at this point in the history
  • Loading branch information
John Hixson committed Jun 6, 2013
1 parent a004ca2 commit 1d2bddd
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 52 deletions.
33 changes: 31 additions & 2 deletions gui/freeadmin/static/lib/js/freeadmin.js
Expand Up @@ -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') {
Expand Down Expand Up @@ -684,7 +701,6 @@ require([
}

doSubmit = function(attrs) {

var pbar, uuid, multipart, rnode, newData;

if(!attrs) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 26 additions & 7 deletions gui/jails/forms.py
Expand Up @@ -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
#
Expand Down Expand Up @@ -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']:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gui/jails/urls.py
Expand Up @@ -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"),
)

36 changes: 36 additions & 0 deletions gui/jails/views.py
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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', { })
Expand Down
12 changes: 12 additions & 0 deletions gui/templates/jails/jails_add.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 %}
14 changes: 7 additions & 7 deletions src/pcbsd/warden/scripts/backend/createjail.sh
Expand Up @@ -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}

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1d2bddd

Please sign in to comment.