From 3b22b5bfcf361d31d2110913128f60a85e0c923b Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Mon, 12 Mar 2012 10:27:24 +0000 Subject: [PATCH] Avoid nova-manage floating create /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 --- bin/nova-manage | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 00a824b0..cd438cbd 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -624,18 +624,17 @@ 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. + def address_to_hosts(addresses): """ + Iterate over hosts within a address range. - if network.size == 1: - yield network.ip - else: - for host in network.iter_hosts(): - yield host + If an explicit range specifier is missing, the parameter is + interpreted as a specific individual address. + """ + try: + return [netaddr.IPAddress(addresses)] + except ValueError: + return netaddr.IPNetwork(addresses).iter_hosts() @args('--ip_range', dest="ip_range", metavar='', help='IP range') @args('--pool', dest="pool", metavar='', help='Optional pool') @@ -643,13 +642,12 @@ class FloatingIpCommands(object): help='Optional interface') def create(self, ip_range, pool=None, interface=None): """Creates floating ips for zone by 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 self.network_to_host_list(addresses): + for address in self.address_to_hosts(ip_range): db.floating_ip_create(admin_context, {'address': str(address), 'pool': pool,