summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMark Washenberger <mark.washenberger@rackspace.com>2011-05-12 22:36:53 -0400
committerMark Washenberger <mark.washenberger@rackspace.com>2011-05-12 22:36:53 -0400
commit2ab50d284146a03a2e12536823b9ede81e2f3691 (patch)
treed12ffd9f33888a1de06c36c0873a3d706f27130d /nova/utils.py
parentdbff37b9ae0893ce209ff0b8c8893987226bd081 (diff)
parent0576766cdf3480ad02159671d2dfc0bdcb154934 (diff)
merge trunk
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/nova/utils.py b/nova/utils.py
index bfcf79216..b55e83e5a 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -232,9 +232,12 @@ def default_flagfile(filename='nova.conf'):
# turn relative filename into an absolute path
script_dir = os.path.dirname(inspect.stack()[-1][1])
filename = os.path.abspath(os.path.join(script_dir, filename))
- if os.path.exists(filename):
- flagfile = ['--flagfile=%s' % filename]
- sys.argv = sys.argv[:1] + flagfile + sys.argv[1:]
+ if not os.path.exists(filename):
+ filename = "./nova.conf"
+ if not os.path.exists(filename):
+ filename = '/etc/nova/nova.conf'
+ flagfile = ['--flagfile=%s' % filename]
+ sys.argv = sys.argv[:1] + flagfile + sys.argv[1:]
def debug(arg):
@@ -709,3 +712,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 ('', '')