From e430c8424a62d9d397980899ae0458a5e947704e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 14 Feb 2012 16:31:46 +0100 Subject: 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 --- bin/nova-manage | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 234f9d45e..dd4f6a389 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -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='', help='IP range') @args('--pool', dest="pool", metavar='', help='Optional pool') @args('--interface', dest="interface", metavar='', @@ -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='', 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)) -- cgit