summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-03-12 21:57:47 +0000
committerGerrit Code Review <review@openstack.org>2012-03-12 21:57:47 +0000
commitd15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0 (patch)
tree8e09dc36ac0ac3bff4e025b6622636fdc2428f33 /bin
parente18996253ccde16aaf65866d85d05372b75b3a1f (diff)
parentc5e51415282330030385304c5af8216e47b84991 (diff)
downloadnova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.tar.gz
nova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.tar.xz
nova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.zip
Merge "Avoid nova-manage floating create <IP addr>/32"
Diffstat (limited to 'bin')
-rwxr-xr-xbin/nova-manage22
1 files changed, 10 insertions, 12 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index 51ed6f2f1..cf296b537 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='<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,