diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-03-12 21:57:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-03-12 21:57:47 +0000 |
| commit | d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0 (patch) | |
| tree | 8e09dc36ac0ac3bff4e025b6622636fdc2428f33 | |
| parent | e18996253ccde16aaf65866d85d05372b75b3a1f (diff) | |
| parent | c5e51415282330030385304c5af8216e47b84991 (diff) | |
| download | nova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.tar.gz nova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.tar.xz nova-d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0.zip | |
Merge "Avoid nova-manage floating create <IP addr>/32"
| -rwxr-xr-x | bin/nova-manage | 22 |
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, |
