summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorCerberus <matt.dietz@rackspace.com>2011-05-10 15:42:08 -0500
committerCerberus <matt.dietz@rackspace.com>2011-05-10 15:42:08 -0500
commit90d7e6771cf28725a6b4296b44e5d078f2ed9544 (patch)
treeb4e5686befe36bd81d64b317abefe7e2903031ce /nova/utils.py
parent3d756a8343845acfead201621a6d658c8ac616fb (diff)
parent21f18f77e7d729107742fa9157b531ce56f3272a (diff)
Merge from trunk
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index bfcf79216..80bf1197f 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -709,3 +709,33 @@ def check_isinstance(obj, cls):
raise Exception(_('Expected object of type: %s') % (str(cls)))
# TODO(justinsb): Can we make this better??
return cls() # Ugly PyLint hack
+
+
+def parse_server_string(server_str):
+ """
+ Parses the given server_string and returns a list of host and port.
+ If it's not a combination of host part and port, the port element
+ is a null string. If the input is invalid expression, return a null
+ list.
+ """
+ try:
+ # First of all, exclude pure IPv6 address (w/o port).
+ if netaddr.valid_ipv6(server_str):
+ return (server_str, '')
+
+ # Next, check if this is IPv6 address with a port number combination.
+ if server_str.find("]:") != -1:
+ (address, port) = server_str.replace('[', '', 1).split(']:')
+ return (address, port)
+
+ # Third, check if this is a combination of an address and a port
+ if server_str.find(':') == -1:
+ return (server_str, '')
+
+ # This must be a combination of an address and a port
+ (address, port) = server_str.split(':')
+ return (address, port)
+
+ except:
+ LOG.debug(_('Invalid server_string: %s' % server_str))
+ return ('', '')