From b927d0f6a82bcd1739f5a210fcf2129bb076e0ae Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 11 May 2012 17:00:13 +0000 Subject: [PATCH] Handle hpcloud assigning ips by default. HPCloud now includes a public ip on every server, but still _also_ has the floating ip extension. Try to identify the public ip (by guessing!) and stop using floating ips if possible. Change-Id: I7c089b94b64cf6ebc168d44b55f43bd07ca12563 --- devstack-vm-launch.py | 6 ++++-- devstack-vm-update-image.py | 5 +++-- utils.py | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/devstack-vm-launch.py b/devstack-vm-launch.py index c034a327..a2b56dcf 100755 --- a/devstack-vm-launch.py +++ b/devstack-vm-launch.py @@ -86,11 +86,13 @@ def check_machine(client, machine, error_counts): return if server.status == 'ACTIVE': - if 'os-floating-ips' in utils.get_extensions(client): - utils.add_public_ip(server) ip = utils.get_public_ip(server) + if not ip and 'os-floating-ips' in utils.get_extensions(client): + utils.add_public_ip(server) + ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") + machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, 'jenkins'): diff --git a/devstack-vm-update-image.py b/devstack-vm-update-image.py index 0180ff33..a00fbf86 100755 --- a/devstack-vm-update-image.py +++ b/devstack-vm-update-image.py @@ -121,9 +121,10 @@ def local_prep(distribution): def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api - if 'os-floating-ips' in utils.get_extensions(client): - utils.add_public_ip(server) ip = utils.get_public_ip(server) + if not ip and 'os-floating-ips' in utils.get_extensions(client): + utils.add_public_ip(server) + ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") diff --git a/utils.py b/utils.py index 5d1216c7..42456054 100644 --- a/utils.py +++ b/utils.py @@ -87,14 +87,16 @@ def get_public_ip(server, version=4): if addr.instance_id == server.id: print 'found addr', addr return addr.ip - else: - print 'no floating ips, addresses:' - print server.addresses - for addr in server.addresses.get('public', []): - if type(addr) == type(u''): # Rackspace/openstack 1.0 - return addr - if addr['version'] == version: #Rackspace/openstack 1.1 - return addr['addr'] + print 'no floating ip, addresses:' + print server.addresses + for addr in server.addresses.get('public', []): + if type(addr) == type(u''): # Rackspace/openstack 1.0 + return addr + if addr['version'] == version: #Rackspace/openstack 1.1 + return addr['addr'] + for addr in server.addresses.get('private', []): + if addr['version'] == version and not addr['addr'].startswith('10.'): #HPcloud + return addr['addr'] return None def add_public_ip(server):