summaryrefslogtreecommitdiffstats
path: root/utils/src/ooinstall/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src/ooinstall/utils.py')
-rw-r--r--utils/src/ooinstall/utils.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/utils/src/ooinstall/utils.py b/utils/src/ooinstall/utils.py
index eb27a57e4..85a77c75e 100644
--- a/utils/src/ooinstall/utils.py
+++ b/utils/src/ooinstall/utils.py
@@ -1,4 +1,6 @@
import logging
+import re
+
installer_log = logging.getLogger('installer')
@@ -8,3 +10,12 @@ def debug_env(env):
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("."))