pod_domains.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
def _get_unique_domain_name(basename, domain_id):
    """Returns unique domain name for given basename.
    If basename does not exists in DB with specified domain_id, then it will
    be returned as is.
    Otherwise will be returned basename with random suffix
    """
    pod_domain = PodDomain.query.filter_by(name=basename,
                                           domain_id=domain_id).first()
    if pod_domain is None:
        return basename

    res = None
    # try to get unique random domain name. If it fails for tries limit,
    # then something is going wrong, return None and it will be better to fail
    # in calling code
    tries_limit = 100
    random_suffix_length = 6
    for _ in xrange(tries_limit):
        suffix = randstr(
            symbols=string.lowercase + string.digits,
            length=random_suffix_length)
        new_name = '{0}{1}'.format(basename, suffix)
        pod_domain = PodDomain.query.filter_by(
            name=new_name, domain_id=domain_id).first()
        if pod_domain is None:
            res = new_name
            break
    return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号