summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
committerJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
commitd8f8d121a00173cb3f5fb5e496cc010dc179cf19 (patch)
tree79ae8953421d065a13309ae5052a0faaee94b485 /nova/utils.py
parent993563b6cc9db9f24480678cf8b2d0750aee7a92 (diff)
parent2af3bad97be40c135fb73f2e595e7fda86f17900 (diff)
downloadnova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.gz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.xz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.zip
Merged with trunk
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/nova/utils.py b/nova/utils.py
index ee07d76b6..dc3c626ec 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -20,7 +20,7 @@
System-level utilities and helper functions.
"""
-from datetime import datetime, timedelta
+import datetime
import inspect
import logging
import os
@@ -32,9 +32,11 @@ import sys
from nova import exception
from nova import flags
+
FLAGS = flags.FLAGS
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
+
def import_class(import_str):
"""Returns a class from a string including module and class"""
mod_str, _sep, class_str = import_str.rpartition('.')
@@ -44,6 +46,7 @@ def import_class(import_str):
except (ImportError, ValueError, AttributeError):
raise exception.NotFound('Class %s cannot be found' % class_str)
+
def fetchfile(url, target):
logging.debug("Fetching %s" % url)
# c = pycurl.Curl()
@@ -126,16 +129,22 @@ def get_my_ip():
'''
if getattr(FLAGS, 'fake_tests', None):
return '127.0.0.1'
- csock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- csock.connect(('www.google.com', 80))
- (addr, port) = csock.getsockname()
- csock.close()
- return addr
+ try:
+ csock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ csock.connect(('www.google.com', 80))
+ (addr, port) = csock.getsockname()
+ csock.close()
+ return addr
+ except socket.gaierror as ex:
+ logging.warn("Couldn't get IP, using 127.0.0.1 %s", ex)
+ return "127.0.0.1"
+
def isotime(at=None):
if not at:
- at = datetime.utcnow()
+ at = datetime.datetime.utcnow()
return at.strftime(TIME_FORMAT)
+
def parse_isotime(timestr):
- return datetime.strptime(timestr, TIME_FORMAT)
+ return datetime.datetime.strptime(timestr, TIME_FORMAT)