From 4c7c93252db70e8b186f2ff9f3227f418eb78a4d Mon Sep 17 00:00:00 2001 From: Dmitry Teselkin Date: Thu, 16 Oct 2014 22:03:38 +0400 Subject: [PATCH] Improve network support in launch-node.py Currently launch-node.py doesn't allow to specify network label and floating IP pool name, using the defaults from nova-network. This patch allows to specify network label to attach instance to, and floating IP pool from which floating IPs could be assigned. Change-Id: I46024bc1c217f99f19717aeb04d424a01440203a --- launch/launch-node.py | 21 ++++++++++++++++----- launch/utils.py | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/launch/launch-node.py b/launch/launch-node.py index a750be323b..69efdd5f13 100755 --- a/launch/launch-node.py +++ b/launch/launch-node.py @@ -53,8 +53,8 @@ def get_client(): def bootstrap_server(server, admin_pass, key, cert, environment, name, - puppetmaster, volume): - ip = utils.get_public_ip(server) + puppetmaster, volume, floating_ip_pool): + ip = utils.get_public_ip(server, floating_ip_pool=floating_ip_pool) if not ip: raise Exception("Unable to find public ip of server") @@ -130,12 +130,19 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name, def build_server( client, name, image, flavor, cert, environment, puppetmaster, volume, - keep): + keep, net_label, floating_ip_pool): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) + if net_label: + nics = [] + for net in client.networks.list(): + if net.label == net_label: + nics.append({'net-id': net.id}) + create_kwargs['nics'] = nics + key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" @@ -161,7 +168,7 @@ def build_server( raise Exception("Couldn't attach volume") bootstrap_server(server, admin_pass, key, cert, environment, name, - puppetmaster, volume) + puppetmaster, volume, floating_ip_pool) print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id, server.accessIPv4, server.accessIPv6)) @@ -203,6 +210,10 @@ def main(): help="Don't clean up or delete the server on error.", action='store_true', default=False) + parser.add_argument("--net-label", dest="net_label", default='', + help="network label to attach instance to") + parser.add_argument("--fip-pool", dest="floating_ip_pool", default=None, + help="pool to assign floating IP from") options = parser.parse_args() client = get_client() @@ -243,7 +254,7 @@ def main(): build_server(client, options.name, image, flavor, cert, options.environment, options.server, options.volume, - options.keep) + options.keep, options.net_label, options.floating_ip_pool) dns.print_dns(client, options.name) if __name__ == '__main__': diff --git a/launch/utils.py b/launch/utils.py index a9f8d01bab..fb0437654d 100644 --- a/launch/utils.py +++ b/launch/utils.py @@ -88,13 +88,13 @@ def get_flavor(client, min_ram): return flavors[0] -def get_public_ip(server, version=4): +def get_public_ip(server, version=4, floating_ip_pool=None): if 'os-floating-ips' in get_extensions(server.manager.api): for addr in server.manager.api.floating_ips.list(): if addr.instance_id == server.id: return addr.ip # We don't have one - so add one please - new_ip = server.manager.api.floating_ips.create() + new_ip = server.manager.api.floating_ips.create(pool=floating_ip_pool) server.add_floating_ip(new_ip) for addr in server.manager.api.floating_ips.list(): if addr.instance_id == server.id: