當前位置: 首頁>>代碼示例>>Python>>正文


Python Warden.start方法代碼示例

本文整理匯總了Python中freenasUI.common.warden.Warden.start方法的典型用法代碼示例。如果您正苦於以下問題:Python Warden.start方法的具體用法?Python Warden.start怎麽用?Python Warden.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freenasUI.common.warden.Warden的用法示例。


在下文中一共展示了Warden.start方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import start [as 別名]

#.........這裏部分代碼省略.........
        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

        jail_nat = self.cleaned_data.get('jail_nat', None)
        jail_vnet = self.cleaned_data.get('jail_vnet', None)

        jail_set_args = {}
        jail_set_args['jail'] = jail_host
        jail_flags = WARDEN_FLAGS_NONE
        if jail_nat:
            jail_flags |= WARDEN_SET_FLAGS_NAT_ENABLE
        else:
            jail_flags |= WARDEN_SET_FLAGS_NAT_DISABLE

        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:
            # XXXX if NOT LINUX XXXX (revisit this)
            if  (saved_template.jt_arch != 'x86' and saved_template.jt_os != 'Linux'):
                jail_flags |= WARDEN_SET_FLAGS_VNET_ENABLE
            else:
                jail_flags |= WARDEN_SET_FLAGS_VNET_DISABLE

            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
開發者ID:Thomasvamsterdam,項目名稱:freenas,代碼行數:104,代碼來源:forms.py

示例2: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import start [as 別名]

#.........這裏部分代碼省略.........

                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
                    jail_set_args['jflags'] = val

            elif key == 'jail_mac':
                jail_mac_list = [jail.jail_mac for jail in Jails.objects.all()]
                mac_address = generate_randomMAC()
                while mac_address in jail_mac_list:
                    mac_address = generate_randomMAC()

                jail_flags |= WARDEN_SET_FLAGS_MAC
                jail_set_args['mac'] = mac_address

            jail_set_args['flags'] = jail_flags
            try:
                # Do not try to set options if no other options other than
                # jail and flags were set.
                if len(jail_set_args) > 2:
                    w.set(**jail_set_args)
            except Exception as e:
                log.debug('Failed to set jail arguments', exc_info=True)
                self.errors['__all__'] = self.error_class([str(e)])
                return

        jail_nat = self.cleaned_data.get('jail_nat', None)
        jail_vnet = self.cleaned_data.get('jail_vnet', None)
        if jc.jc_ipv4_dhcp or jc.jc_ipv6_autoconf:
            jail_vnet = True

        jail_set_args = {}
        jail_set_args['jail'] = jail_host
        jail_flags = WARDEN_FLAGS_NONE
        if jail_nat:
            jail_flags |= WARDEN_SET_FLAGS_NAT_ENABLE
        else:
            jail_flags |= WARDEN_SET_FLAGS_NAT_DISABLE

        jail_set_args['flags'] = jail_flags
        try:
            w.set(**jail_set_args)
        except Exception as e:
            log.debug('Failed to set jail arguments', exc_info=True)
            self.errors['__all__'] = self.error_class([str(e)])
            return

        jail_set_args = {}
        jail_set_args['jail'] = jail_host
        jail_flags = WARDEN_FLAGS_NONE
        if jail_vnet:
            # XXXX if NOT LINUX XXXX (revisit this)
            if (saved_template.jt_arch != 'x86' and
                    saved_template.jt_os != 'Linux'):
                jail_flags |= WARDEN_SET_FLAGS_VNET_ENABLE
            else:
                jail_flags |= WARDEN_SET_FLAGS_VNET_DISABLE

            jail_set_args['flags'] = jail_flags
            try:
                w.set(**jail_set_args)
            except Exception as e:
                log.debug('Failed to set jail arguments', exc_info=True)
                self.errors['__all__'] = self.error_class([str(e)])
                return

        if self.cleaned_data['jail_autostart']:
            try:
                w.auto(jail=jail_host)
            except Exception as e:
                self.errors['__all__'] = self.error_class([str(e)])
                return

        try:
            w.start(jail=jail_host)
        except Exception as e:
            log.debug('Failed to start jail', exc_info=True)
            self.errors['__all__'] = self.error_class([str(e)])
            return

        # Requery instance so we have everything up-to-date after save
        # See #14686
        self.instance = Jails.objects.get(jail_host=jail_host)
        if self.instance:
            add_media_user_and_group(self.instance.jail_path)
開發者ID:binzyw,項目名稱:freenas,代碼行數:104,代碼來源:forms.py

示例3: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import start [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
開發者ID:ProtoSD,項目名稱:freenas,代碼行數:97,代碼來源:forms.py

示例4: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import start [as 別名]

#.........這裏部分代碼省略.........
        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

                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

        jail_nat = self.cleaned_data.get('jail_nat', None)
        jail_vnet = self.cleaned_data.get('jail_vnet', None)

        jail_set_args = {}
        jail_set_args['jail'] = jail_host
        jail_flags = WARDEN_FLAGS_NONE
        if jail_nat:
            jail_flags |= WARDEN_SET_FLAGS_NAT_ENABLE
        else:
            jail_flags |= WARDEN_SET_FLAGS_NAT_DISABLE

        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:
            if (
                self.cleaned_data['jail_type'] != WARDEN_TYPE_LINUXJAIL
                and
                not self.cleaned_data['jail_32bit']
            ):
                jail_flags |= WARDEN_SET_FLAGS_VNET_ENABLE
            else:
                jail_flags |= WARDEN_SET_FLAGS_VNET_DISABLE

            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
開發者ID:cubieb,項目名稱:freenas,代碼行數:104,代碼來源:forms.py

示例5: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import start [as 別名]

#.........這裏部分代碼省略.........
        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
                    jail_set_args["jflags"] = 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

        jail_nat = self.cleaned_data.get("jail_nat", None)
        jail_vnet = self.cleaned_data.get("jail_vnet", None)
        if jc.jc_ipv4_dhcp or jc.jc_ipv6_autoconf:
            jail_vnet = True

        jail_set_args = {}
        jail_set_args["jail"] = jail_host
        jail_flags = WARDEN_FLAGS_NONE
        if jail_nat:
            jail_flags |= WARDEN_SET_FLAGS_NAT_ENABLE
        else:
            jail_flags |= WARDEN_SET_FLAGS_NAT_DISABLE

        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:
            # XXXX if NOT LINUX XXXX (revisit this)
            if saved_template.jt_arch != "x86" and saved_template.jt_os != "Linux":
                jail_flags |= WARDEN_SET_FLAGS_VNET_ENABLE
            else:
                jail_flags |= WARDEN_SET_FLAGS_VNET_DISABLE

            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
開發者ID:stjernholmco,項目名稱:freenas,代碼行數:104,代碼來源:forms.py


注:本文中的freenasUI.common.warden.Warden.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。