Merge "Fixes nova-manage fixed list with deleted networks"
This commit is contained in:
@@ -282,24 +282,43 @@ class FixedIpCommands(object):
|
|||||||
_('IP address'),
|
_('IP address'),
|
||||||
_('hostname'),
|
_('hostname'),
|
||||||
_('host'))
|
_('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:
|
for fixed_ip in fixed_ips:
|
||||||
hostname = None
|
hostname = None
|
||||||
host = None
|
host = None
|
||||||
mac_address = None
|
mac_address = None
|
||||||
network = db.network_get(context.get_admin_context(),
|
network = all_networks.get(fixed_ip['network_id'])
|
||||||
fixed_ip['network_id'])
|
if network:
|
||||||
if fixed_ip['instance_id']:
|
has_ip = True
|
||||||
instance = instances_by_id.get(fixed_ip['instance_id'])
|
if fixed_ip['instance_id']:
|
||||||
if instance:
|
instance = instances_by_id.get(fixed_ip['instance_id'])
|
||||||
hostname = instance['hostname']
|
if instance:
|
||||||
host = instance['host']
|
hostname = instance['hostname']
|
||||||
else:
|
host = instance['host']
|
||||||
print ('WARNING: fixed ip %s allocated to missing'
|
else:
|
||||||
' instance' % str(fixed_ip['address']))
|
print _('WARNING: fixed ip %s allocated to missing'
|
||||||
print "%-18s\t%-15s\t%-15s\t%s" % (
|
' instance') % str(fixed_ip['address'])
|
||||||
network['cidr'],
|
print "%-18s\t%-15s\t%-15s\t%s" % (
|
||||||
fixed_ip['address'],
|
network['cidr'],
|
||||||
hostname, host)
|
fixed_ip['address'],
|
||||||
|
hostname, host)
|
||||||
|
|
||||||
|
if not has_ip:
|
||||||
|
print _('No fixed IP found.')
|
||||||
|
|
||||||
@args('--address', dest="address", metavar='<ip address>',
|
@args('--address', dest="address", metavar='<ip address>',
|
||||||
help='IP address')
|
help='IP address')
|
||||||
|
|||||||
Reference in New Issue
Block a user