summaryrefslogtreecommitdiffstats
path: root/utils/src/ooinstall/utils.py
blob: 85a77c75e3cc22b32d64fa8ff5e05cd89529f655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import logging
import re


installer_log = logging.getLogger('installer')


def debug_env(env):
    for k in sorted(env.keys()):
        if k.startswith("OPENSHIFT") or k.startswith("ANSIBLE") or k.startswith("OO"):
            installer_log.debug("{key}: {value}".format(
                key=k, value=env[k]))


def is_valid_hostname(hostname):
    if not hostname or len(hostname) > 255:
        return False
    if hostname[-1] == ".":
        hostname = hostname[:-1]  # strip exactly one dot from the right, if present
    allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
    return all(allowed.match(x) for x in hostname.split("."))