Skip to content

Commit

Permalink
Get IP doesn't fail of you not connected to the intetnet
Browse files Browse the repository at this point in the history
------------- 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@
  • Loading branch information
Joel Moore joelbm24@gmail.com committed Aug 3, 2010
1 parent 75c8cca commit 8d70245
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nova/utils.py
Expand Up @@ -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:
Expand Down

0 comments on commit 8d70245

Please sign in to comment.