diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-07-20 20:44:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-07-20 20:44:47 +0000 |
| commit | 7587738bdf52588672af014acf5f5b48e02205ba (patch) | |
| tree | 6203b347e10e88a533a95e02764b79f9df20ebdc | |
| parent | 935748e05026388dd578ec24579e5c26de365be5 (diff) | |
| parent | 7343f79cbe9ecc62f81a0170a182cb5363b6df24 (diff) | |
Merge "Fixes nova-manage fixed list with deleted networks"
| -rwxr-xr-x | bin/nova-manage | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index 857b7070f..24e095b92 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -282,24 +282,43 @@ class FixedIpCommands(object): _('IP address'), _('hostname'), _('host')) + + all_networks = {} + try: + # use network_get_all to retrieve all existing networks + # this is to ensure that IPs associated with deleted networks + # will not throw exceptions. + for network in db.network_get_all(context.get_admin_context()): + all_networks[network.id] = network + except exception.NoNetworksFound: + # do not have any networks, so even if there are IPs, these + # IPs should have been deleted ones, so return. + print _('No fixed IP found.') + return + + has_ip = False for fixed_ip in fixed_ips: hostname = None host = None mac_address = None - network = db.network_get(context.get_admin_context(), - fixed_ip['network_id']) - if fixed_ip['instance_id']: - instance = instances_by_id.get(fixed_ip['instance_id']) - if instance: - hostname = instance['hostname'] - host = instance['host'] - else: - print ('WARNING: fixed ip %s allocated to missing' - ' instance' % str(fixed_ip['address'])) - print "%-18s\t%-15s\t%-15s\t%s" % ( - network['cidr'], - fixed_ip['address'], - hostname, host) + network = all_networks.get(fixed_ip['network_id']) + if network: + has_ip = True + if fixed_ip['instance_id']: + instance = instances_by_id.get(fixed_ip['instance_id']) + if instance: + hostname = instance['hostname'] + host = instance['host'] + else: + print _('WARNING: fixed ip %s allocated to missing' + ' instance') % str(fixed_ip['address']) + print "%-18s\t%-15s\t%-15s\t%s" % ( + network['cidr'], + fixed_ip['address'], + hostname, host) + + if not has_ip: + print _('No fixed IP found.') @args('--address', dest="address", metavar='<ip address>', help='IP address') |
