Permalink
Browse files

Warden updates

- vnet jails are an options now

- add vnet option bindings to python

- make jail creation dialog smaller

- add and use warden logfile as specified during jail creation

- add vnet checkbox
  • Loading branch information...
1 parent b3b3b4e commit 0ac1928d246687bedcb071986bf3fe22a305be94 @jhixson74 jhixson74 committed Jun 7, 2013
View
@@ -63,6 +63,7 @@ class warden_exception(Exception):
WARDEN_KEY_ALIASBRIDGEIP6 = "alias_bridge_ipv6"
WARDEN_KEY_DEFAULTROUTER6 = "defaultrouter_ipv6"
WARDEN_KEY_AUTOSTART = "autostart"
+WARDEN_KEY_VNET = "vnet"
WARDEN_KEY_STATUS = "status"
WARDEN_KEY_TYPE = "type"
@@ -86,6 +87,12 @@ class warden_exception(Exception):
WARDEN_AUTOSTART_ENABLED = "Enabled"
WARDEN_AUTOSTART_DISABLED = "Disabled"
+#
+# Warden jail vnet
+#
+WARDEN_VNET_ENABLED = "Enabled"
+WARDEN_VNET_DISABLED = "Disabled"
+
WARDEN_FLAGS_NONE = warden_arg(0x00000000, None)
@@ -115,9 +122,12 @@ class warden_exception(Exception):
WARDEN_CREATE_FLAGS_PORTJAIL = warden_arg(0x00000080, "--portjail")
WARDEN_CREATE_FLAGS_PLUGINJAIL = warden_arg(0x00000100, "--pluginjail")
WARDEN_CREATE_FLAGS_LINUXJAIL = warden_arg(0x00000200, "--linuxjail", True, "script")
-WARDEN_CREATE_FLAGS_ARCHIVE = warden_arg(0x00000400, "--archive", True, "tar")
-WARDEN_CREATE_FLAGS_LINUXARCHIVE = warden_arg(0x00000800, "--linuxarchive", True, "tar")
-WARDEN_CREATE_FLAGS_VERSION = warden_arg(0x00001000, "--version", True, "string")
+WARDEN_CREATE_FLAGS_ARCHIVE = warden_arg(0x00000400, "--archive", True, "archive")
+WARDEN_CREATE_FLAGS_LINUXARCHIVE = warden_arg(0x00000800, "--linuxarchive", True, "linuxarchive")
+WARDEN_CREATE_FLAGS_VERSION = warden_arg(0x00001000, "--version", True, "version")
+WARDEN_CREATE_FLAGS_TEMPLATE = warden_arg(0x00002000, "--template", True, "template")
+WARDEN_CREATE_FLAGS_SYSLOG = warden_arg(0x00004000, "--syslog")
+WARDEN_CREATE_FLAGS_LOGFILE = warden_arg(0x00008000, "--logfile", True, "logfile")
WARDEN_CREATE_FLAGS = [
WARDEN_CREATE_FLAGS_32BIT,
WARDEN_CREATE_FLAGS_IPV4,
@@ -131,7 +141,10 @@ class warden_exception(Exception):
WARDEN_CREATE_FLAGS_LINUXJAIL,
WARDEN_CREATE_FLAGS_ARCHIVE,
WARDEN_CREATE_FLAGS_LINUXARCHIVE,
- WARDEN_CREATE_FLAGS_VERSION
+ WARDEN_CREATE_FLAGS_VERSION,
+ WARDEN_CREATE_FLAGS_TEMPLATE,
+ WARDEN_CREATE_FLAGS_SYSLOG,
+ WARDEN_CREATE_FLAGS_LOGFILE
]
WARDEN_DETALS = "details"
@@ -161,6 +174,7 @@ class warden_exception(Exception):
WARDEN_GET_FLAGS_DEFAULTROUTER_IPV4 = warden_arg(0x00000100, "defaultrouter-ipv4")
WARDEN_GET_FLAGS_DEFAULTROUTER_IPV6 = warden_arg(0x00000200, "defaultrouter-ipv6")
WARDEN_GET_FLAGS_FLAGS = warden_arg(0x00000400, "flags")
+WARDEN_GET_FLAGS_VNET = warden_arg(0x00000800, "vnet")
WARDEN_GET_FLAGS = [
WARDEN_GET_FLAGS_IPV4,
WARDEN_GET_FLAGS_IPV6,
@@ -172,7 +186,8 @@ class warden_exception(Exception):
WARDEN_GET_FLAGS_ALIAS_BRIDGE_IPV6,
WARDEN_GET_FLAGS_DEFAULTROUTER_IPV4,
WARDEN_GET_FLAGS_DEFAULTROUTER_IPV6,
- WARDEN_GET_FLAGS_FLAGS
+ WARDEN_GET_FLAGS_FLAGS,
+ WARDEN_GET_FLAGS_VNET
]
WARDEN_IMPORT = "import"
@@ -209,6 +224,8 @@ class warden_exception(Exception):
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4 = warden_arg(0x00000100, "defaultrouter-ipv4", True, "defaultrouter-ipv4")
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6 = warden_arg(0x00000200, "defaultrouter-ipv6", True, "defaultrouter-ipv6")
WARDEN_SET_FLAGS_FLAGS = warden_arg(0x00000400, "flags", True, "jflags")
+WARDEN_SET_FLAGS_VNET_ENABLE = warden_arg(0x00000800, "vnet-enable" )
+WARDEN_SET_FLAGS_VNET_DISABLE = warden_arg(0x00001000, "vnet-disable" )
WARDEN_SET_FLAGS = [
WARDEN_SET_FLAGS_IPV4,
WARDEN_SET_FLAGS_IPV6,
@@ -220,7 +237,9 @@ class warden_exception(Exception):
WARDEN_SET_FLAGS_ALIAS_BRIDGE_IPV6,
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4,
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6,
- WARDEN_SET_FLAGS_FLAGS
+ WARDEN_SET_FLAGS_FLAGS,
+ WARDEN_SET_FLAGS_VNET_ENABLE,
+ WARDEN_SET_FLAGS_VNET_DISABLE
]
WARDEN_START = "start"
@@ -241,6 +260,36 @@ class warden_exception(Exception):
WARDEN_TYPE_FLAGS_STANARD
]
+WARDEN_TEMPLATE = "template"
+WARDEN_TEMPLATE_FLAGS_CREATE = warden_arg(0x00000001, "create")
+WARDEN_TEMPLATE_FLAGS_DELETE = warden_arg(0x00000002, "delete")
+WARDEN_TEMPLATE_FLAGS_LIST = warden_arg(0x00000004, "list")
+WARDEN_TEMPLATE_FLAGS = [
+ WARDEN_TEMPLATE_FLAGS_CREATE,
+ WARDEN_TEMPLATE_FLAGS_DELETE,
+ WARDEN_TEMPLATE_FLAGS_LIST
+]
+
+WARDEN_TEMPLATE_CREATE = "create"
+WARDEN_TEMPLATE_CREATE_FLAGS_FBSD = warden_arg(0x00000010, "-fbsd", True, "fbsd")
+WARDEN_TEMPLATE_CREATE_FLAGS_TRUEOS = warden_arg(0x00000020, "-trueos", True, "trueos")
+WARDEN_TEMPLATE_CREATE_FLAGS_ARCH = warden_arg(0x00000040, "-arch", True, "arch")
+WARDEN_TEMPLATE_CREATE_FLAGS_TAR = warden_arg(0x00000080, "-tar", True, "tar")
+WARDEN_TEMPLATE_CREATE_FLAGS_NICK = warden_arg(0x00000100, "-nick", True, "nick")
+WARDEN_TEMPLATE_CREATE_FLAGS = [
+ WARDEN_TEMPLATE_CREATE_FLAGS_FBSD,
+ WARDEN_TEMPLATE_CREATE_FLAGS_TRUEOS,
+ WARDEN_TEMPLATE_CREATE_FLAGS_ARCH,
+ WARDEN_TEMPLATE_CREATE_FLAGS_TAR,
+ WARDEN_TEMPLATE_CREATE_FLAGS_NICK
+]
+
+WARDEN_TEMPLATE_DELETE= "delete"
+WARDEN_TEMPLATE_DELETE_FLAGS = [ ]
+
+WARDEN_TEMPLATE_LIST = "list"
+WARDEN_TEMPLATE_LIST_FLAGS = [ ]
+
WARDEN_ZFSMKSNAP = "zfsmksnap"
WARDEN_ZFSMKSNAP_FLAGS = []
@@ -281,6 +330,7 @@ def __init__(self, **kwargs):
self.alias_bridge_ipv6 = kwargs.get(WARDEN_KEY_ALIASBRIDGEIP6)
self.defaultrouter_ipv6 = kwargs.get(WARDEN_KEY_DEFAULTROUTER6)
self.autostart = kwargs.get(WARDEN_KEY_AUTOSTART)
+ self.vnet = kwargs.get(WARDEN_KEY_VNET)
self.status = kwargs.get(WARDEN_KEY_STATUS)
self.type = kwargs.get(WARDEN_KEY_TYPE)
@@ -560,6 +610,7 @@ def parse(self, thestuff):
'alias-bridge-ipv6': WARDEN_KEY_ALIASBRIDGEIP6,
'defaultrouter-ipv6': WARDEN_KEY_DEFAULTROUTER6,
'autostart': WARDEN_KEY_AUTOSTART,
+ 'vnet': WARDEN_KEY_VNET,
'status': WARDEN_KEY_STATUS,
'type': WARDEN_KEY_TYPE
}
@@ -620,7 +671,16 @@ def __init__(self, flags=WARDEN_FLAGS_NONE, **kwargs):
for wsf in WARDEN_SET_FLAGS:
if flags & wsf:
flags &= ~wsf
- if kwargs.has_key(wsf.argname) and kwargs[wsf.argname] is not None:
+
+ if wsf == WARDEN_SET_FLAGS_VNET_ENABLE:
+ self.args = wsf.string
+ break
+
+ elif wsf == WARDEN_SET_FLAGS_VNET_DISABLE:
+ self.args = wsf.string
+ break
+
+ elif kwargs.has_key(wsf.argname) and kwargs[wsf.argname] is not None:
self.args = wsf.string
break
@@ -676,6 +736,29 @@ def __init__(self, flags=WARDEN_FLAGS_NONE, **kwargs):
WARDEN_TYPE_FLAGS, flags, **kwargs)
+class warden_template(warden_base):
+ def __init__(self, flags=WARDEN_FLAGS_NONE, **kwargs):
+ self.args = ""
+ self.jail = None
+
+ type = None
+ tflags = None
+
+ if flags & WARDEN_TEMPLATE_FLAGS_CREATE:
+ type = WARDEN_TEMPLATE_CREATE
+ tflags = WARDEN_TEMPLATE_CREATE_FLAGS
+ elif flags & WARDEN_TEMPLATE_FLAGS_DELETE:
+ type = WARDEN_TEMPLATE_DELETE
+ tflags = WARDEN_TEMPLATE_DELETE_FLAGS
+ elif flags & WARDEN_TEMPLATE_FLAGS_LIST:
+ type = WARDEN_TEMPLATE_LIST
+ tflags = WARDEN_TEMPLATE_LIST_FLAGS
+
+ cmd = "%s %s" % (WARDEN_TEMPLATE, type)
+ super(warden_template, self).__init__(cmd,
+ tflags, flags, **kwargs)
+
+
class warden_zfsmksnap(warden_base):
def __init__(self, flags=WARDEN_FLAGS_NONE, **kwargs):
self.args = ""
@@ -918,6 +1001,9 @@ def types(self, flags=WARDEN_FLAGS_NONE, **kwargs):
]
return types
+ def template(self, flags=WARDEN_FLAGS_NONE, **kwargs):
+ return self.__call(warden_template(flags, **kwargs))
+
def zfsmksnap(self, flags=WARDEN_FLAGS_NONE, **kwargs):
return self.__call(warden_zfsmksnap(flags, **kwargs))
@@ -812,7 +812,7 @@ require([
} else if (attrs.progressfunc != undefined) {
pbar = new dijit.form.SimpleTextarea({
title: "progress",
- rows: "40",
+ rows: "5",
cols: "80",
style: "width:auto;",
readOnly: true
View
@@ -62,7 +62,8 @@ class JailsFAdmin(BaseFreeAdmin):
'jail_alias_ipv6',
'jail_bridge_ipv6',
'jail_alias_bridge_ipv6',
- 'jail_defaultrouter_ipv6'
+ 'jail_defaultrouter_ipv6',
+ 'jail_vnet'
)
def get_datagrid_columns(self):
View
@@ -59,6 +59,8 @@
WARDEN_CREATE_FLAGS_LINUXARCHIVE,
WARDEN_CREATE_FLAGS_IPV4,
WARDEN_CREATE_FLAGS_IPV6,
+ WARDEN_CREATE_FLAGS_SYSLOG,
+ WARDEN_CREATE_FLAGS_LOGFILE,
WARDEN_SET_FLAGS_IPV4,
WARDEN_SET_FLAGS_IPV6,
WARDEN_SET_FLAGS_ALIAS_IPV4,
@@ -69,6 +71,8 @@
WARDEN_SET_FLAGS_ALIAS_BRIDGE_IPV6,
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4,
WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6,
+ WARDEN_SET_FLAGS_VNET_ENABLE,
+ WARDEN_SET_FLAGS_VNET_DISABLE,
WARDEN_SET_FLAGS_FLAGS,
WARDEN_TYPE_STANDARD,
WARDEN_TYPE_PLUGINJAIL,
@@ -155,6 +159,12 @@ class JailCreateForm(ModelForm):
initial=False
)
+ jail_vnet = forms.BooleanField(
+ label=_("vnet"),
+ required=False,
+ initial=True
+ )
+
# jail_script = forms.CharField(
# label=_("script"),
# required=False
@@ -171,7 +181,8 @@ class JailCreateForm(ModelForm):
'jail_bridge_ipv4',
'jail_ipv6',
'jail_bridge_ipv6',
- 'jail_script'
+ 'jail_script',
+ 'jail_vnet'
]
class Meta:
@@ -338,58 +349,70 @@ def save(self):
jail_flags |= WARDEN_CREATE_FLAGS_IPV6
jail_create_args['ipv6'] = jail_ipv6
- jail_create_args['flags'] = jail_flags
+ jail_flags |= WARDEN_CREATE_FLAGS_LOGFILE
+ jail_flags |= WARDEN_CREATE_FLAGS_SYSLOG
logfile = "%s/warden.log" % jc.jc_path
+ jail_create_args['logfile'] = logfile
- w.logfile = logfile
- w.syslog = True
+ jail_create_args['flags'] = jail_flags
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
jail_bridge_ipv4 = self.cleaned_data.get('jail_bridge_ipv4')
jail_bridge_ipv6 = self.cleaned_data.get('jail_bridge_ipv6')
+ jail_vnet = self.cleaned_data.get('jail_vnet')
+ jail_set_args = { }
+ jail_set_args['jail'] = jail_host
+ jail_flags = WARDEN_FLAGS_NONE
if jail_bridge_ipv4:
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV4
jail_set_args['bridge-ipv4'] = jail_bridge_ipv4
+ jail_set_args['flags'] = jail_flags
+ try:
+ w.set(**jail_set_args)
+ except Exception as e:
+ self.errors['__all__'] = self.error_class([_(e.message)])
+ return
+ jail_set_args = { }
+ jail_set_args['jail'] = jail_host
+ jail_flags = WARDEN_FLAGS_NONE
if jail_bridge_ipv6:
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV6
jail_set_args['bridge-ipv6'] = jail_bridge_ipv6
+ jail_set_args['flags'] = jail_flags
+ try:
+ w.set(**jail_set_args)
+ except Exception as e:
+ self.errors['__all__'] = self.error_class([_(e.message)])
+ return
- jail_set_args['flags'] = jail_flags
-
- try:
- w.set(**jail_set_args)
- except Exception as e:
- self.errors['__all__'] = self.error_class([_(e.message)])
- return
+ jail_set_args = { }
+ jail_set_args['jail'] = jail_host
+ jail_flags = WARDEN_FLAGS_NONE
+ if jail_vnet:
+ jail_flags |= WARDEN_SET_FLAGS_VNET_ENABLE
+ jail_set_args['flags'] = jail_flags
+ try:
+ w.set(**jail_set_args)
+ except Exception as e:
+ self.errors['__all__'] = self.error_class([_(e.message)])
+ return
if self.cleaned_data['jail_autostart']:
try:
@@ -426,6 +449,7 @@ class Meta:
class JailsEditForm(ModelForm):
jail_autostart = forms.BooleanField(label=_("autostart"), required=False)
+ jail_vnet = forms.BooleanField(label=_("vnet"), required=False)
def __set_ro(self, instance, key):
if instance and instance.id:
@@ -487,7 +511,8 @@ def __init__(self, *args, **kwargs):
'jail_alias_ipv6',
'jail_bridge_ipv6',
'jail_alias_bridge_ipv6',
- 'jail_defaultrouter_ipv6'
+ 'jail_defaultrouter_ipv6',
+ 'jail_vnet'
]
instance = getattr(self, 'instance', None)
@@ -552,6 +577,13 @@ def save(self):
flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6
args['defaultrouter-ipv6'] = self.cleaned_data.get(cf)
+ elif cf == 'jail_vnet':
+ if self.cleaned_data.get(cf):
+ flags |= WARDEN_SET_FLAGS_VNET_ENABLE
+ else:
+ flags |= WARDEN_SET_FLAGS_VNET_DISABLE
+ args['vnet-enable'] = self.cleaned_data.get(cf)
+
args['jail'] = jail_host
args['flags'] = flags
Oops, something went wrong.

0 comments on commit 0ac1928

Please sign in to comment.