Avoid nova-manage floating create <IP addr>/32

Fixes bug 951161

Avoid the counter-intuitive use of the /32 range to indicate a specific
individial IP address.

Instead a floating IP for a specific individual address is created by
dropping the range specifier altogether, e.g.:

  nova-manage floating create 192.168.1.150

Change-Id: I54b124e961accefa47f6faa7f201809c545c3fa5
This commit is contained in:
Eoghan Glynn
2012-03-12 10:27:24 +00:00
parent 178fc320db
commit 3b22b5bfcf

View File

@@ -624,18 +624,17 @@ class FloatingIpCommands(object):
"""Class for managing floating ip.""" """Class for managing floating ip."""
@staticmethod @staticmethod
def network_to_host_list(network): def address_to_hosts(addresses):
"""Return the list of host of a network.
If the network is empty and only has one host, then we consider it
has the host in the network.
""" """
Iterate over hosts within a address range.
if network.size == 1: If an explicit range specifier is missing, the parameter is
yield network.ip interpreted as a specific individual address.
else: """
for host in network.iter_hosts(): try:
yield host return [netaddr.IPAddress(addresses)]
except ValueError:
return netaddr.IPNetwork(addresses).iter_hosts()
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range') @args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
@args('--pool', dest="pool", metavar='<pool>', help='Optional pool') @args('--pool', dest="pool", metavar='<pool>', help='Optional pool')
@@ -643,13 +642,12 @@ class FloatingIpCommands(object):
help='Optional interface') help='Optional interface')
def create(self, ip_range, pool=None, interface=None): def create(self, ip_range, pool=None, interface=None):
"""Creates floating ips for zone by range""" """Creates floating ips for zone by range"""
addresses = netaddr.IPNetwork(ip_range)
admin_context = context.get_admin_context() admin_context = context.get_admin_context()
if not pool: if not pool:
pool = FLAGS.default_floating_pool pool = FLAGS.default_floating_pool
if not interface: if not interface:
interface = FLAGS.public_interface interface = FLAGS.public_interface
for address in self.network_to_host_list(addresses): for address in self.address_to_hosts(ip_range):
db.floating_ip_create(admin_context, db.floating_ip_create(admin_context,
{'address': str(address), {'address': str(address),
'pool': pool, 'pool': pool,