nova-manage: allow use of /32 IP range
The current code does not allow to add an IP range which is /32, because netaddr considers that there's no host in such a network. While this is probably debatable, it disallow to add specific IP address in a pool, which is really handy and was possible before. This patch fix that by treating the /32 subnet as a special case. Change-Id: I38685e6f1a3541519d1f2a9ec8d3b00dd522b44a
This commit is contained in:
parent
d8324bb3d0
commit
e430c8424a
@ -627,6 +627,20 @@ class FixedIpCommands(object):
|
||||
class FloatingIpCommands(object):
|
||||
"""Class for managing floating ip."""
|
||||
|
||||
@staticmethod
|
||||
def network_to_host_list(network):
|
||||
"""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.
|
||||
"""
|
||||
|
||||
if network.size == 1:
|
||||
yield network.ip
|
||||
else:
|
||||
for host in network.iter_hosts():
|
||||
yield host
|
||||
|
||||
@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>',
|
||||
@ -639,7 +653,7 @@ class FloatingIpCommands(object):
|
||||
pool = FLAGS.default_floating_pool
|
||||
if not interface:
|
||||
interface = FLAGS.public_interface
|
||||
for address in addresses.iter_hosts():
|
||||
for address in self.network_to_host_list(addresses):
|
||||
db.floating_ip_create(admin_context,
|
||||
{'address': str(address),
|
||||
'pool': pool,
|
||||
@ -648,7 +662,7 @@ class FloatingIpCommands(object):
|
||||
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
|
||||
def delete(self, ip_range):
|
||||
"""Deletes floating ips by range"""
|
||||
for address in netaddr.IPNetwork(ip_range).iter_hosts():
|
||||
for address in self.network_to_host_list(netaddr.IPNetwork(ip_range)):
|
||||
db.floating_ip_destroy(context.get_admin_context(),
|
||||
str(address))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user