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:
@@ -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='<range>', help='IP range')
|
||||
@args('--pool', dest="pool", metavar='<pool>', 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,
|
||||
|
||||
Reference in New Issue
Block a user