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
This commit is contained in:
parent
7fff4e7e93
commit
4c7c93252d
@ -53,8 +53,8 @@ def get_client():
|
|||||||
|
|
||||||
|
|
||||||
def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
||||||
puppetmaster, volume):
|
puppetmaster, volume, floating_ip_pool):
|
||||||
ip = utils.get_public_ip(server)
|
ip = utils.get_public_ip(server, floating_ip_pool=floating_ip_pool)
|
||||||
if not ip:
|
if not ip:
|
||||||
raise Exception("Unable to find public ip of server")
|
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(
|
def build_server(
|
||||||
client, name, image, flavor, cert, environment, puppetmaster, volume,
|
client, name, image, flavor, cert, environment, puppetmaster, volume,
|
||||||
keep):
|
keep, net_label, floating_ip_pool):
|
||||||
key = None
|
key = None
|
||||||
server = None
|
server = None
|
||||||
|
|
||||||
create_kwargs = dict(image=image, flavor=flavor, name=name)
|
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())
|
key_name = 'launch-%i' % (time.time())
|
||||||
if 'os-keypairs' in utils.get_extensions(client):
|
if 'os-keypairs' in utils.get_extensions(client):
|
||||||
print "Adding keypair"
|
print "Adding keypair"
|
||||||
@ -161,7 +168,7 @@ def build_server(
|
|||||||
raise Exception("Couldn't attach volume")
|
raise Exception("Couldn't attach volume")
|
||||||
|
|
||||||
bootstrap_server(server, admin_pass, key, cert, environment, name,
|
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,
|
print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
|
||||||
server.accessIPv4,
|
server.accessIPv4,
|
||||||
server.accessIPv6))
|
server.accessIPv6))
|
||||||
@ -203,6 +210,10 @@ def main():
|
|||||||
help="Don't clean up or delete the server on error.",
|
help="Don't clean up or delete the server on error.",
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False)
|
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()
|
options = parser.parse_args()
|
||||||
|
|
||||||
client = get_client()
|
client = get_client()
|
||||||
@ -243,7 +254,7 @@ def main():
|
|||||||
|
|
||||||
build_server(client, options.name, image, flavor, cert,
|
build_server(client, options.name, image, flavor, cert,
|
||||||
options.environment, options.server, options.volume,
|
options.environment, options.server, options.volume,
|
||||||
options.keep)
|
options.keep, options.net_label, options.floating_ip_pool)
|
||||||
dns.print_dns(client, options.name)
|
dns.print_dns(client, options.name)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -88,13 +88,13 @@ def get_flavor(client, min_ram):
|
|||||||
return flavors[0]
|
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):
|
if 'os-floating-ips' in get_extensions(server.manager.api):
|
||||||
for addr in server.manager.api.floating_ips.list():
|
for addr in server.manager.api.floating_ips.list():
|
||||||
if addr.instance_id == server.id:
|
if addr.instance_id == server.id:
|
||||||
return addr.ip
|
return addr.ip
|
||||||
# We don't have one - so add one please
|
# 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)
|
server.add_floating_ip(new_ip)
|
||||||
for addr in server.manager.api.floating_ips.list():
|
for addr in server.manager.api.floating_ips.list():
|
||||||
if addr.instance_id == server.id:
|
if addr.instance_id == server.id:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user