Adds support for floating ip pools

* Implements blueprint multiple-floating-ip-ranges
 * Adds pool and interface fields to floating ip tables
 * Adds extension to get a list of available pools
 * Optionally allows a pool to be specified when allocating
 * Changes nova-manage command to allow pool and interface
 * Ip binding uses the interface from table instead of flag
 * Adds default pool flag to use when pool is not specified
 * updates test to work with new fields
 * adds tests for extension

Change-Id: Ieb4cbbf07b211697d08178b1cf2252caf75049a2
This commit is contained in:
Vishvananda Ishaya
2012-01-04 12:47:40 -08:00
parent 85b070cb89
commit ce6e2050b9
2 changed files with 35 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
@@ -103,6 +104,8 @@ flags.DECLARE('multi_host', 'nova.network.manager')
flags.DECLARE('network_size', 'nova.network.manager')
flags.DECLARE('vlan_start', 'nova.network.manager')
flags.DECLARE('vpn_start', 'nova.network.manager')
flags.DECLARE('default_floating_pool', 'nova.network.manager')
flags.DECLARE('public_interface', 'nova.network.linux_net')
flags.DECLARE('libvirt_type', 'nova.virt.libvirt.connection')
flags.DEFINE_flag(flags.HelpFlag())
flags.DEFINE_flag(flags.HelpshortFlag())
@@ -684,14 +687,23 @@ class FixedIpCommands(object):
class FloatingIpCommands(object):
"""Class for managing floating ip."""
@args('--ip_range', dest="range", metavar='<range>', help='IP range')
def create(self, range):
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
@args('--pool', dest="pool", metavar='<pool>', help='Optional pool')
@args('--interface', dest="interface", metavar='<interface>',
help='Optional interface')
def create(self, ip_range, pool=None, interface=None):
"""Creates floating ips for zone by range"""
addresses = netaddr.IPNetwork(range)
addresses = netaddr.IPNetwork(ip_range)
admin_context = context.get_admin_context()
if not pool:
pool = FLAGS.default_floating_pool
if not interface:
interface = FLAGS.public_interface
for address in addresses.iter_hosts():
db.floating_ip_create(admin_context,
{'address': str(address)})
{'address': str(address),
'pool': pool,
'interface': interface})
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
def delete(self, ip_range):

View File

@@ -1,6 +1,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Rackspace
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -108,6 +109,8 @@ flavor = {'id': 0,
floating_ip_fields = {'id': 0,
'address': '192.168.10.100',
'pool': 'nova',
'interface': 'eth0',
'fixed_ip_id': 0,
'project_id': None,
'auto_assigned': False}
@@ -580,21 +583,29 @@ class VlanNetworkTestCase(test.TestCase):
# floating ip that's already associated
def fake2(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'fixed_ip_id': 1}
# floating ip that isn't associated
def fake3(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'fixed_ip_id': None}
# fixed ip with remote host
def fake4(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'network': {'multi_host': False, 'host': 'jibberjabber'}}
# fixed ip with local host
def fake5(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'network': {'multi_host': False, 'host': 'testhost'}}
def fake6(*args, **kwargs):
@@ -641,21 +652,29 @@ class VlanNetworkTestCase(test.TestCase):
# floating ip that isn't associated
def fake2(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'fixed_ip_id': None}
# floating ip that is associated
def fake3(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'fixed_ip_id': 1}
# fixed ip with remote host
def fake4(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'network': {'multi_host': False, 'host': 'jibberjabber'}}
# fixed ip with local host
def fake5(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
'network': {'multi_host': False, 'host': 'testhost'}}
def fake6(*args, **kwargs):