本文整理汇总了Python中freenasUI.common.warden.Warden.set方法的典型用法代码示例。如果您正苦于以下问题:Python Warden.set方法的具体用法?Python Warden.set怎么用?Python Warden.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freenasUI.common.warden.Warden
的用法示例。
在下文中一共展示了Warden.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from freenasUI.common.warden import Warden [as 别名]
# 或者: from freenasUI.common.warden.Warden import set [as 别名]
#.........这里部分代码省略.........
)
if jail_ipv6:
jail_flags |= WARDEN_CREATE_FLAGS_IPV6
jail_create_args['ipv6'] = "%s/%s" % (
jail_ipv6, jail_ipv6_prefix
)
jail_flags |= WARDEN_CREATE_FLAGS_LOGFILE
jail_flags |= WARDEN_CREATE_FLAGS_SYSLOG
jail_create_args['logfile'] = self.logfile
jail_create_args['flags'] = jail_flags
createfile = "/var/tmp/.jailcreate"
try:
cf = open(createfile, "a+")
cf.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)
return
if os.path.exists(createfile):
os.unlink(createfile)
for key in (
'jail_bridge_ipv4', 'jail_bridge_ipv6', 'jail_defaultrouter_ipv4',
'jail_defaultrouter_ipv6', 'jail_mac'
):
jail_set_args = {}
jail_set_args['jail'] = jail_host
jail_flags = WARDEN_FLAGS_NONE
val = self.cleaned_data.get(key, None)
if val:
if key == 'jail_bridge_ipv4':
mask = self.cleaned_data.get('jail_bridge_ipv4_netmask', jc_ipv4_netmask)
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV4
jail_set_args['bridge-ipv4'] = "%s/%s" % (val, mask)
elif key == 'jail_bridge_ipv6':
prefix = self.cleaned_data.get('jail_bridge_ipv6_prefix', jc_ipv6_prefix)
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV6
jail_set_args['bridge-ipv6'] = "%s/%s" % (val, prefix)
elif key == 'jail_defaultrouter_ipv4':
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4
jail_set_args['defaultrouter-ipv4'] = val
elif key == 'jail_defaultrouter_ipv6':
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6
jail_set_args['defaultrouter-ipv6'] = val
elif key == 'jail_mac':
jail_flags |= WARDEN_SET_FLAGS_MAC
jail_set_args['mac'] = val
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
示例2: save
# 需要导入模块: from freenasUI.common.warden import Warden [as 别名]
# 或者: from freenasUI.common.warden.Warden import set [as 别名]
def save(self):
jc = self.jc
if not jc.jc_path:
raise MiddlewareError(_("No jail root configured."))
jc_ipv4_netmask = 24
if jc.jc_ipv4_network:
parts = jc.jc_ipv4_network.split('/')
if len(parts) > 1:
jc_ipv4_netmask = parts[1]
jc_ipv6_prefix = 64
if jc.jc_ipv6_network:
parts = jc.jc_ipv6_network.split('/')
if len(parts) > 1:
jc_ipv6_prefix = parts[1]
jail_host = self.cleaned_data.get('jail_host')
jail_ipv4_dhcp = self.cleaned_data.get('jail_ipv4_dhcp')
jail_ipv4 = self.cleaned_data.get('jail_ipv4')
jail_ipv4_netmask = self.cleaned_data.get('jail_ipv4_netmask',
jc_ipv4_netmask)
jail_ipv6_autoconf = self.cleaned_data.get('jail_ipv6_autoconf')
jail_ipv6 = self.cleaned_data.get('jail_ipv6')
jail_ipv6_prefix = self.cleaned_data.get('jail_ipv6_prefix',
jc_ipv6_prefix)
jail_flags = WARDEN_FLAGS_NONE
jail_flags |= WARDEN_CREATE_FLAGS_VANILLA
jail_create_args = {}
jail_create_args['jail'] = jail_host
w = Warden()
template_create_args = {}
jail_type = self.cleaned_data['jail_type']
if not jail_type:
jail_type = 'standard'
# Don't backtrace if template doesn't exist
try:
template = JailTemplate.objects.get(jt_name=jail_type)
except Exception as e:
self.errors['__all__'] = self.error_class([str(e)])
return
template_create_args['nick'] = template.jt_name
template_create_args['tar'] = template.jt_url
template_create_args['flags'] = WARDEN_TEMPLATE_FLAGS_CREATE | \
WARDEN_TEMPLATE_CREATE_FLAGS_NICK | \
WARDEN_TEMPLATE_CREATE_FLAGS_TAR
if template.jt_mtree:
template_create_args['mtree'] = template.jt_mtree
template_create_args['flags'] = template_create_args['flags'] | \
WARDEN_TEMPLATE_CREATE_FLAGS_MTREE
saved_template = template
template = None
template_list_flags = {}
template_list_flags['flags'] = WARDEN_TEMPLATE_FLAGS_LIST
templates = w.template(**template_list_flags)
for t in templates:
if t['nick'] == template_create_args['nick']:
template = t
break
createfile = "/var/tmp/.templatecreate"
if not template:
# If for some reason warden does not list the template but the path
# exists, we shall try to nuke it
template_path = '{}/.warden-template-{}'.format(self.jc.jc_path, jail_type)
if os.path.exists(template_path):
try:
notifier().destroy_zfs_dataset(template_path.replace('/mnt/', ''))
except:
pass
try:
shutil.rmtree(template_path)
except OSError:
pass
try:
cf = open(createfile, "a+")
cf.close()
w.template(**template_create_args)
except Exception as e:
log.debug('Failed to create template', exc_info=True)
self.errors['__all__'] = self.error_class([str(e)])
if os.path.exists(createfile):
os.unlink(createfile)
return
template_list_flags = {}
template_list_flags['flags'] = WARDEN_TEMPLATE_FLAGS_LIST
templates = w.template(**template_list_flags)
for t in templates:
#.........这里部分代码省略.........
示例3: save
# 需要导入模块: from freenasUI.common.warden import Warden [as 别名]
# 或者: from freenasUI.common.warden.Warden import set [as 别名]
def save(self):
try:
jc = JailsConfiguration.objects.order_by("-id")[0]
except Exception as e:
self.errors['__all__'] = self.error_class([_(e.message)])
return
if not jc.jc_path:
self.errors['__all__'] = self.error_class(["No jail root configured."])
return
jail_host = self.cleaned_data.get('jail_host')
jail_ipv4 = self.cleaned_data.get('jail_ipv4')
jail_ipv6 = self.cleaned_data.get('jail_ipv6')
jail_flags = WARDEN_FLAGS_NONE
jail_create_args = { }
jail_create_args['jail'] = jail_host
w = Warden()
# if self.cleaned_data['jail_32bit']:
# jail_flags |= WARDEN_CREATE_FLAGS_32BIT
if self.cleaned_data['jail_source']:
jail_flags |= WARDEN_CREATE_FLAGS_SRC
if self.cleaned_data['jail_ports']:
jail_flags |= WARDEN_CREATE_FLAGS_PORTS
if self.cleaned_data['jail_vanilla']:
jail_flags |= WARDEN_CREATE_FLAGS_VANILLA
if self.cleaned_data['jail_type'] == WARDEN_TYPE_PORTJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_PORTJAIL
elif self.cleaned_data['jail_type'] == WARDEN_TYPE_PLUGINJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_PLUGINJAIL
elif self.cleaned_data['jail_type'] == WARDEN_TYPE_LINUXJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_LINUXJAIL
jail_create_args['script'] = LINUXSCRIPT
if self.cleaned_data['jail_archive']:
if jail_flags & WARDEN_CREATE_FLAGS_LINUXJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_LINUXARCHIVE
else:
jail_flags |= WARDEN_CREATE_FLAGS_ARCHIVE
if jail_ipv4:
jail_flags |= WARDEN_CREATE_FLAGS_IPV4
jail_create_args['ipv4'] = jail_ipv4
if jail_ipv6:
jail_flags |= WARDEN_CREATE_FLAGS_IPV6
jail_create_args['ipv6'] = jail_ipv6
jail_create_args['flags'] = jail_flags
try:
w.create(**jail_create_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
jail_bridge_ipv4 = self.cleaned_data.get('jail_bridge_ipv4')
jail_bridge_ipv6 = self.cleaned_data.get('jail_bridge_ipv6')
if jail_bridge_ipv4:
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV4
jail_set_args['bridge-ipv4'] = jail_bridge_ipv4
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
if self.cleaned_data['jail_autostart']:
try:
w.auto(jail=jail_host)
except Exception as e:
self.errors['__all__'] = self.error_class([_(e.message)])
return
try:
w.start(jail=jail_host)
except Exception as e:
self.errors['__all__'] = self.error_class([_(e.message)])
return
示例4: save
# 需要导入模块: from freenasUI.common.warden import Warden [as 别名]
# 或者: from freenasUI.common.warden.Warden import set [as 别名]
def save(self):
try:
jc = JailsConfiguration.objects.order_by("-id")[0]
except Exception as e:
self.errors['__all__'] = self.error_class([_(e.message)])
return
if not jc.jc_path:
self.errors['__all__'] = self.error_class(
["No jail root configured."]
)
return
jail_host = self.cleaned_data.get('jail_host')
jail_ipv4 = self.cleaned_data.get('jail_ipv4')
jail_ipv6 = self.cleaned_data.get('jail_ipv6')
jail_flags = WARDEN_FLAGS_NONE
jail_create_args = {}
jail_create_args['jail'] = jail_host
w = Warden()
if self.cleaned_data['jail_32bit']:
jail_flags |= WARDEN_CREATE_FLAGS_32BIT
# if self.cleaned_data['jail_source']:
# jail_flags |= WARDEN_CREATE_FLAGS_SRC
# if self.cleaned_data['jail_ports']:
# jail_flags |= WARDEN_CREATE_FLAGS_PORTS
if self.cleaned_data['jail_vanilla']:
jail_flags |= WARDEN_CREATE_FLAGS_VANILLA
if self.cleaned_data['jail_type'] == WARDEN_TYPE_PORTJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_PORTJAIL
elif self.cleaned_data['jail_type'] == WARDEN_TYPE_PLUGINJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_PLUGINJAIL
elif self.cleaned_data['jail_type'] == WARDEN_TYPE_LINUXJAIL:
jail_flags |= WARDEN_CREATE_FLAGS_LINUXJAIL
jail_create_args['script'] = LINUXSCRIPT
# if self.cleaned_data['jail_archive']:
# if jail_flags & WARDEN_CREATE_FLAGS_LINUXJAIL:
# jail_flags |= WARDEN_CREATE_FLAGS_LINUXARCHIVE
# else:
# jail_flags |= WARDEN_CREATE_FLAGS_ARCHIVE
if jail_ipv4:
jail_flags |= WARDEN_CREATE_FLAGS_IPV4
jail_create_args['ipv4'] = jail_ipv4
if jail_ipv6:
jail_flags |= WARDEN_CREATE_FLAGS_IPV6
jail_create_args['ipv6'] = jail_ipv6
jail_flags |= WARDEN_CREATE_FLAGS_LOGFILE
jail_flags |= WARDEN_CREATE_FLAGS_SYSLOG
logfile = "%s/warden.log" % jc.jc_path
jail_create_args['logfile'] = logfile
jail_create_args['flags'] = jail_flags
createfile = "/var/tmp/.jailcreate"
try:
cf = open(createfile, "a+")
cf.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)
return
if os.path.exists(createfile):
os.unlink(createfile)
for key in ('jail_bridge_ipv4', 'jail_bridge_ipv6', \
'jail_defaultrouter_ipv4', 'jail_defaultrouter_ipv6', 'jail_mac'):
jail_set_args = {}
jail_set_args['jail'] = jail_host
jail_flags = WARDEN_FLAGS_NONE
val = self.cleaned_data.get(key, None)
if val:
if key == 'jail_bridge_ipv4':
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV4
jail_set_args['bridge-ipv4'] = val
elif key == 'jail_bridge_ipv6':
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV6
jail_set_args['bridge-ipv6'] = val
elif key == 'jail_defaultrouter_ipv4':
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4
jail_set_args['defaultrouter-ipv4'] = val
elif key == 'jail_defaultrouter_ipv6':
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6
jail_set_args['defaultrouter-ipv6'] = val
#.........这里部分代码省略.........
示例5: save
# 需要导入模块: from freenasUI.common.warden import Warden [as 别名]
# 或者: from freenasUI.common.warden.Warden import set [as 别名]
#.........这里部分代码省略.........
jail_flags |= WARDEN_CREATE_FLAGS_IPV6
jail_create_args["ipv6"] = jail_ipv6
jail_flags |= WARDEN_CREATE_FLAGS_LOGFILE
jail_flags |= WARDEN_CREATE_FLAGS_SYSLOG
jail_create_args["logfile"] = self.logfile
jail_create_args["flags"] = jail_flags
createfile = "/var/tmp/.jailcreate"
try:
cf = open(createfile, "a+")
cf.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)
return
if os.path.exists(createfile):
os.unlink(createfile)
for key in (
"jail_bridge_ipv4",
"jail_bridge_ipv6",
"jail_defaultrouter_ipv4",
"jail_defaultrouter_ipv6",
"jail_mac",
"jail_iface",
"jail_flags",
):
jail_set_args = {}
jail_set_args["jail"] = jail_host
jail_flags = WARDEN_FLAGS_NONE
val = self.cleaned_data.get(key, None)
if val:
if key == "jail_bridge_ipv4":
mask = self.cleaned_data.get("jail_bridge_ipv4_netmask", jc_ipv4_netmask)
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV4
jail_set_args["bridge-ipv4"] = "%s/%s" % (val, mask)
elif key == "jail_bridge_ipv6":
prefix = self.cleaned_data.get("jail_bridge_ipv6_prefix", jc_ipv6_prefix)
jail_flags |= WARDEN_SET_FLAGS_BRIDGE_IPV6
jail_set_args["bridge-ipv6"] = "%s/%s" % (val, prefix)
elif key == "jail_defaultrouter_ipv4":
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV4
jail_set_args["defaultrouter-ipv4"] = val
elif key == "jail_defaultrouter_ipv6":
jail_flags |= WARDEN_SET_FLAGS_DEFAULTROUTER_IPV6
jail_set_args["defaultrouter-ipv6"] = val
elif key == "jail_mac":
jail_flags |= WARDEN_SET_FLAGS_MAC
jail_set_args["mac"] = val
elif key == "jail_iface":
jail_flags |= WARDEN_SET_FLAGS_IFACE
jail_set_args["iface"] = val
elif key == "jail_flags":
jail_flags |= WARDEN_SET_FLAGS_FLAGS