From 458a5d61eac5eb5cef34ab301b67fa37271ba407 Mon Sep 17 00:00:00 2001 From: Tong Li Date: Wed, 18 Jul 2012 11:26:12 -0400 Subject: fixes for nova-manage network list if network has been deleted this fix addresses the bug #1021810 Currently command 'nova-manage network list' or 'nova-manage fixed list' will return 'Command failed.' message when there is no network defined or networks get deleted. This fix combined with fixes to bug 1025827 will fix both command problem. also change the print out message so that it can be translated. code structure changes according to the suggestion from comments. Change-Id: Id9a1a10217aac971cbbba9db5829c8478892db1a --- bin/nova-manage | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index b477ed284..857b7070f 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -542,16 +542,24 @@ class NetworkCommands(object): _('VlanID'), _('project'), _("uuid")) - for network in db.network_get_all(context.get_admin_context()): - print _fmt % (network.id, - network.cidr, - network.cidr_v6, - network.dhcp_start, - network.dns1, - network.dns2, - network.vlan, - network.project_id, - network.uuid) + try: + # Since network_get_all can throw exception.NoNetworksFound + # for this command to show a nice result, this exception + # should be caught and handled as such. + networks = db.network_get_all(context.get_admin_context()) + except exception.NoNetworksFound: + print _('No networks found') + else: + for network in networks: + print _fmt % (network.id, + network.cidr, + network.cidr_v6, + network.dhcp_start, + network.dns1, + network.dns2, + network.vlan, + network.project_id, + network.uuid) def quantum_list(self): """List all created networks with Quantum-relevant fields""" -- cgit