Skip to content

Commit

Permalink
Fixes nova-manage fixed list with deleted networks
Browse files Browse the repository at this point in the history
The fix addresses the bug reported in bug 1025827
currently command 'nova-manage fixed list' will return
'Command failed.' message when there is no network defined or
all networks have been deleted or even when a network gets
deleted, then a new network gets created. In all these cases,
the command produces the 'Command failed.' error message which
does not really tell what went wrong. This fix will produce
'No fixed IP found' in these conditions.
changes made for globalization.
changes made for based on the comments for patchset 7.

Change-Id: I3c2e9bf3fa3c748e680c1df27d243a648ed47cf5
  • Loading branch information
Tong Li committed Jul 20, 2012
1 parent 6de8c6a commit 7343f79
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions bin/nova-manage
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 7343f79

Please sign in to comment.