From 8d70245cc78075356ec1ebabc4810df8b07428f6 Mon Sep 17 00:00:00 2001 From: "Joel Moore joelbm24@gmail.com" <> Date: Tue, 3 Aug 2010 11:02:58 -0700 Subject: Get IP doesn't fail of you not connected to the intetnet ------------- This line and the following will be ignored -------------- modified: nova/utils.py unknown: CA/cacert.pem CA/index.txt CA/openssl.cnf CA/serial CA/private/cakey.pem bin/nova@ --- nova/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nova/utils.py b/nova/utils.py index 0016b656e..da6efd39a 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -119,11 +119,15 @@ 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: -- cgit