当前位置: 首页>>代码示例>>Python>>正文


Python Domain.purgeable方法代码示例

本文整理汇总了Python中mozdns.domain.models.Domain.purgeable方法的典型用法代码示例。如果您正苦于以下问题:Python Domain.purgeable方法的具体用法?Python Domain.purgeable怎么用?Python Domain.purgeable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mozdns.domain.models.Domain的用法示例。


在下文中一共展示了Domain.purgeable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ensure_domain

# 需要导入模块: from mozdns.domain.models import Domain [as 别名]
# 或者: from mozdns.domain.models.Domain import purgeable [as 别名]
def ensure_domain(name, purgeable=False, inherit_soa=False, force=False):
    """This function will take ``domain_name`` and make sure that a domain with
    that name exists. If this function creates a domain it will set the
    domain's purgeable flag to the value of the named arguement ``purgeable``.
    See the doc page about Labels and Domains for other information about this
    function.

    This function will attempt to prevent you from:
        * creating a new TLD
        * creating a domain that would be a child of a delegated domain
        * creating a domain that wouldn't exist in an existing zone (it
            wouldn't have an SOA)

    You can override these constrains by setting the ``force`` named argument
    to ``True``.

    By default if a domain's parent has an SOA, the new domain will not inherit
    that SOA. You can cause the domain to inherit the SOA by passing the named
    argument ``inherit_soa`` as ``True``. For example, the function
    :func:`ensure_label_domain` passes ``inherit_soa=True``.

    If a domain already exists with a name equal to ``name`` it is immediately
    returned. It is up to the caller to ensure that ``purgeable`` is set if it
    is needed.
    """
    try:
        domain = Domain.objects.get(name=name)
        return domain
    except ObjectDoesNotExist:
        pass

    # Looks like we are creating some domains. Make sure the first domain we
    # create is under a domain that has a non-None SOA reference.
    parts = list(reversed(name.split('.')))

    if not force:
        domain_name = ''
        leaf_domain = None
        # Find the leaf domain.
        for i in range(len(parts)):
            domain_name = parts[i] + '.' + domain_name
            domain_name = domain_name.strip('.')
            try:
                tmp_domain = Domain.objects.get(name=domain_name)
                # It got here so we know we found a domain.
                leaf_domain = tmp_domain
            except ObjectDoesNotExist:
                continue

        if not leaf_domain:
            raise ValidationError(
                "Creating this record would cause the "
                "creation of a new TLD. Please contact "
                "http://www.icann.org/ for more information.")
        if leaf_domain.delegated:
            raise ValidationError(
                "Creating this record would cause the "
                "creation of a domain that would be a child of a "
                "delegated domain.")
        if not leaf_domain.soa:
            raise ValidationError(
                "Creating this record would cause the "
                "creation of a domain that would not be in an existing "
                "DNS zone.")

    domain_name = ''
    # We know the end domain doesn't exist, so we build it up incrementally
    # starting at the very right most parent domain. If we find that a parent
    # domain already exists we continue until we find the domain that doesn't
    # exist.
    for i in range(len(parts)):
        domain_name = parts[i] + '.' + domain_name
        domain_name = domain_name.strip('.')
        if Domain.objects.filter(name=domain_name).exists():
            continue

        # We are about to create a domain that previously didn't exist!
        clobber_querysets = get_clobbered(domain_name)
        # Don't use get_or_create here because we need to pass certain kwargs
        # to clean()
        domain = Domain(name=domain_name)
        # we know the clobber_querysets may conflict, but we will handle
        # resolving the conflict later in this function

        if purgeable:
            domain.purgeable = True

        domain.clean(ignore_conflicts=True)  # master domain is set here

        if (inherit_soa and domain.master_domain and
                domain.master_domain.soa is not None):
            domain.soa = domain.master_domain.soa

        # get the domain in the db so we can save the clobbered objects
        domain.save(do_full_clean=False)

        # update the objects that initially conflicted with this domain
        for qs in clobber_querysets:
            qs.update(domain=domain, label='')

#.........这里部分代码省略.........
开发者ID:Marlburo,项目名称:inventory,代码行数:103,代码来源:utils.py


注:本文中的mozdns.domain.models.Domain.purgeable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。