diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-11-15 23:28:13 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-11-15 23:28:13 +0000 |
| commit | 9f3f056bd5ceda5d41508533244f5b509ddcfb0e (patch) | |
| tree | 2f056c66209065caa14cf2677bacb3a10f28a002 /nova/utils.py | |
| parent | a3090f2a3a8a83e25a4a4ded24785a8bb862fe87 (diff) | |
| parent | bcfff3dd530994d3ae22f945f429df3afc954cb0 (diff) | |
Merge "Follow hostname RFCs"
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py index 7723837c9..ec5de7aab 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1061,3 +1061,16 @@ def total_seconds(td): else: return ((td.days * 86400 + td.seconds) * 10 ** 6 + td.microseconds) / 10.0 ** 6 + + +def sanitize_hostname(hostname): + """Return a hostname which conforms to RFC-952 and RFC-1123 specs.""" + if isinstance(hostname, unicode): + hostname = hostname.encode('latin-1', 'ignore') + + hostname = re.sub('[ _]', '-', hostname) + hostname = re.sub('[^\w.-]+', '', hostname) + hostname = hostname.lower() + hostname = hostname.strip('.-') + + return hostname |
