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


Python Warden.template方法代碼示例

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


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

示例1: delete

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [as 別名]
    def delete(self, force=False):
        ninstances = self.jt_instances
        if ninstances != 0:
            raise MiddlewareError(
                _("Template must have 0 instances!")
            )

        template = self.jt_name
        jc = JailsConfiguration.objects.all()[0]
        if not jc:
            raise MiddlewareError(
                _("Jail root is not configured!")
            )

        tdir = os.path.realpath("%s/.warden-template-%s" % (jc.jc_path, template))
        if not os.path.exists(tdir):
            super(JailTemplate, self).delete()
            return

        try:
            w = Warden()
            template_delete_args = {}
            template_delete_args['flags'] = WARDEN_TEMPLATE_FLAGS_DELETE
            template_delete_args['template'] = self.jt_name
            w.template(**template_delete_args)
            super(JailTemplate, self).delete()

        except Exception as e:
            raise MiddlewareError(_(e))
開發者ID:anilh889,項目名稱:freenas,代碼行數:31,代碼來源:models.py

示例2: delete

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [as 別名]
    def delete(self, force=False):
        ninstances = self.jt_instances
        if ninstances != 0: 
            raise MiddlewareError(
                _("Template must have 0 instances!")
            )

        try:
            w = Warden()
            template_delete_args = {}
            template_delete_args['flags'] = WARDEN_TEMPLATE_FLAGS_DELETE
            template_delete_args['template'] = self.jt_name  
            w.template(**template_delete_args)
            super(JailTemplate, self).delete()

        except Except as e:
            raise MiddlewareError(_(e))
開發者ID:CsMAr51,項目名稱:freenas,代碼行數:19,代碼來源:models.py

示例3: jt_instances

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [as 別名]
    def jt_instances(self):
        instances = 0

        w = Warden()

        template = None
        template_list_args = {}
        template_list_args['flags'] = WARDEN_TEMPLATE_FLAGS_LIST
        templates = w.template(**template_list_args)
        for t in templates:
            if t['nick'] == self.jt_name:
                template = t
                break

        if template:
            instances = t['instances']

        return instances
開發者ID:CsMAr51,項目名稱:freenas,代碼行數:20,代碼來源:models.py

示例4: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [as 別名]
    def save(self):
        try:
            jc = JailsConfiguration.objects.order_by("-id")[0]
        except Exception as e:
            raise MiddlewareError(e.message)

        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 = self.cleaned_data.get('jail_ipv4')
        jail_ipv4_netmask = self.cleaned_data.get('jail_ipv4_netmask', jc_ipv4_netmask)

        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_create_args = {}
        jail_create_args['jail'] = jail_host

        w = Warden()

#        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

        template_create_args = {}

        jail_type = self.cleaned_data['jail_type']
        template = JailTemplate.objects.get(jt_name=jail_type)
        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

        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:
            try:
                cf = open(createfile, "a+")
                cf.close()
                w.template(**template_create_args)

            except Exception as e:
                self.errors['__all__'] = self.error_class([_(e.message)])
                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:
                if t['nick'] == template_create_args['nick']:
                    template = t
                    break

        if not template:
            self.errors['__all__'] = self.error_class([
                _('Unable to find template!')
            ])
            return

        if template['type'] == 'Linux':
            jail_flags |= WARDEN_CREATE_FLAGS_LINUXJAIL
        if template['arch'] == 'i386' and self.arch == 'x64':
            jail_flags |= WARDEN_CREATE_FLAGS_32BIT

        jail_flags |= WARDEN_CREATE_FLAGS_TEMPLATE
        jail_create_args['template'] = template_create_args['nick']

        if jail_ipv4:
            jail_flags |= WARDEN_CREATE_FLAGS_IPV4
            jail_create_args['ipv4'] = "%s/%s" % (
#.........這裏部分代碼省略.........
開發者ID:Thomasvamsterdam,項目名稱:freenas,代碼行數:103,代碼來源:forms.py

示例5: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [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:
#.........這裏部分代碼省略.........
開發者ID:binzyw,項目名稱:freenas,代碼行數:103,代碼來源:forms.py

示例6: save

# 需要導入模塊: from freenasUI.common.warden import Warden [as 別名]
# 或者: from freenasUI.common.warden.Warden import template [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"
        template = JailTemplate.objects.get(jt_name=jail_type)
        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:
            try:
                cf = open(createfile, "a+")
                cf.close()
                w.template(**template_create_args)

            except Exception as e:
                self.errors["__all__"] = self.error_class([_(e.message)])
                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:
                if t["nick"] == template_create_args["nick"]:
                    template = t
                    break

        if not template:
            self.errors["__all__"] = self.error_class([_("Unable to find template!")])
            return

        if template["type"] == "Linux":
            jail_flags |= WARDEN_CREATE_FLAGS_LINUXJAIL
        if template["arch"] == "i386" and self.arch == "x64":
            jail_flags |= WARDEN_CREATE_FLAGS_32BIT

        jail_flags |= WARDEN_CREATE_FLAGS_TEMPLATE
        jail_create_args["template"] = template_create_args["nick"]

        if jail_ipv4_dhcp:
            jail_ipv4 = "DHCP"

        if jail_ipv4:
            if jail_ipv4 != "DHCP":
                jail_ipv4 = "%s/%s" % (jail_ipv4, jail_ipv4_netmask)

            jail_flags |= WARDEN_CREATE_FLAGS_IPV4
#.........這裏部分代碼省略.........
開發者ID:stjernholmco,項目名稱:freenas,代碼行數:103,代碼來源:forms.py


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