summaryrefslogtreecommitdiffstats
path: root/utils/src/ooinstall/utils.py
blob: c9e3e25e5b4979b89e06a87163d3c02983dcda0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# pylint: disable=missing-docstring,invalid-name

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"):
            # pylint: disable=logging-format-interpolation
            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("."))