Comment 3 for bug 1494841

Revision history for this message
Sriteja (sriteja-alapati) wrote :

Hi,

As described in bug, We are proposing a new parameter --status for "nova-manage vm list" command.

Updated filter accordingly to get the vms from db by status(active,error..).

Proposing below mentioned code changes in /opt/stack/nova/nova/cmd/manage.py.

class VmCommands(object):
      ....
+ @args('--status', metavar='<status>', help='Vm state')
- def list(self, host=None):
+ def list(self, host=None,status=None):
         """Show a list of all instances."""

         print(("%-10s %-15s %-10s %-10s %-26s %-9s %-9s %-9s"
@@ -674,9 +676,19 @@ class VmCommands(object):
                                              _('zone'),
                                              _('index'))))

+ if status is not None:
+ filters={'vm_state': status}
+ else:
+ filters={}
+
         if host is None:
             instances = objects.InstanceList.get_by_filters(
- context.get_admin_context(), {}, expected_attrs=['flavor'])
+ context.get_admin_context(), filters, expected_attrs=['flavor'])

with these changes "nova-manage vm list" help text dispalys as follows ,

stack@tcs:~/devstack$ nova-manage vm list -h
No handlers could be found for logger "oslo_config.cfg"
usage: nova-manage vm list [-h] [--host <host>] [--status <status>]

optional arguments:
  -h, --help show this help message and exit
  --host <host> Host
  --status <status> Vm state

Please share your comments.