aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/resource_manager.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2019-08-15 19:20:29 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-08-15 19:20:29 +0000
commitba7f5834366d3c1c62726cc3dfdf6381baa9b504 (patch)
tree0b02c6896fc8c4d10043fb20b131798b0e1df46d /src/resource_inventory/resource_manager.py
parent3418c7a7baae772f1bb58e9a827c1e6198dbed54 (diff)
parenta02f1d81f6651ddf5b9353c2e1d7fbf873a19466 (diff)
Merge "Adds Hostname Validator"
Diffstat (limited to 'src/resource_inventory/resource_manager.py')
-rw-r--r--src/resource_inventory/resource_manager.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index 652e4e3..28bed20 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -6,7 +6,7 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
+import re
from dashboard.exceptions import (
ResourceExistenceException,
@@ -172,3 +172,13 @@ class ResourceManager:
self.releaseNetworks(grb, vlan_manager, vlans)
for host in hosts:
self.releaseHost(host)
+
+
+class HostNameValidator(object):
+ regex = r'^[A-Za-z0-9][A-Za-z0-9-]*$'
+ message = "Hostnames can only contain alphanumeric characters and hyphens (-). Hostnames must start with a letter"
+ pattern = re.compile(regex)
+
+ @classmethod
+ def is_valid_hostname(cls, hostname):
+ return len(hostname) < 65 and cls.pattern.fullmatch(hostname) is not None