nova-manage vm list active

Bug #1494841 reported by Kevin Fox
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Wishlist
Matt Riedemann

Bug Description

Pre Kilo, nova-manage vm list only showed active vm's. This was useful for ops to track down what vms were on which hosts, etc.

After kilo, all the deleted ones are returned too. This is ok, but its much slower to query if you |grep active.

There needs to be an --active flag or something to filter on the db side for better performance.

Changed in nova:
assignee: nobody → Sriteja (sriteja-alapati)
tags: added: nova-manage
Revision history for this message
Markus Zoeller (markus_z) (mzoeller) wrote :

I assume this changed with [1]. The DB api returns the deleted instances by default, as long as the filter says otherwise [2]. "nova-manage" defines this filter in the context, but this context isn't used by the DB api.

[1] commit "Convert nova-manage list to use Instance objects";
    https://git.openstack.org/cgit/openstack/nova/commit/?id=ba5c71d8d38136e804409f93d7dc2cc7a79427fe
[2] method "instance_get_all_by_filters_sort";
    https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/api.py#L1883

Changed in nova:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Markus Zoeller (markus_z) (mzoeller) wrote :

@Sriteja: Thanks for taking over this bug. I'll put it to "in progress".

Changed in nova:
status: Confirmed → In Progress
tags: added: low-hanging-fruit
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.

Revision history for this message
Kevin Fox (kevpn) wrote :

Looks good. Does status match up with the field in the db/ what other cli tools call the state flag?

Thanks,
Kevin

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

Hi,

Thanks for your comments. " nova list " command also using the same parameter "status" to filter vms based on state.

stack@tcs:~/devstack$ nova list --status active
+--------------------------------------+---------+--------+------------+-------------+--------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+---------+--------+------------+-------------+--------------------------------+
| fd99107c-ecd0-4649-b8ab-3cb614fb9936 | sample3 | ACTIVE | - | Running | public=172.24.4.3, 2001:db8::4 |
+--------------------------------------+---------+--------+------------+-------------+--------------------------------+

Revision history for this message
Kevin Fox (kevpn) wrote :

Perfect. Thanks. :)

Kevin

Changed in nova:
assignee: Sriteja (sriteja-alapati) → nobody
Changed in nova:
assignee: nobody → Raga lahari (raga-lahari)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/231447

Matt Riedemann (mriedem)
Changed in nova:
importance: Low → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on nova (master)

Change abandoned by Michael Still (<email address hidden>) on branch: master
Review: https://review.openstack.org/231447
Reason: This patch has been idle for a long time, so I am abandoning it to keep the review clean sane. If you're interested in still working on this patch, then please unabandon it and upload a new patchset.

Revision history for this message
Markus Zoeller (markus_z) (mzoeller) wrote :

Cleanup
=======

There are no open reviews for this bug report since more than 2 weeks.
To signal that to other contributors which might provide patches for
this bug, I switch the status from "In Progress" to "Confirmed" and
remove the assignee.
Feel free to add yourself as assignee and to push a review for it.

Changed in nova:
status: In Progress → Confirmed
assignee: Raga lahari (raga-lahari) → nobody
Sujitha (sujitha-neti)
Changed in nova:
assignee: nobody → Sujitha (sujitha-neti)
Revision history for this message
Matt Riedemann (mriedem) wrote :

Why isn't the REST API sufficient for filtering the instances by status and host? nova-manage is mostly deprecated/feature frozen so I'd like to know the justification for adding this to the nova-manage CLI rather than just using the REST API.

Changed in nova:
status: Confirmed → Opinion
Revision history for this message
Kevin Fox (kevpn) wrote :

uhh. An operator should never have to run curl to do that. I don't really care if its nova-manage, nova, or openstack something-or-other. Just that there's a way to do it that isn't, "fetch a token by hand, craft a curl call manually, execute, parse json".

This was a regression in the tool that took it from commonly usable, to on the edge of unusable for us.

Revision history for this message
Matt Riedemann (mriedem) wrote :

So use python-novaclient? Then you don't have to fetch a token by hand, create the request and parse the results.

Revision history for this message
Matt Riedemann (mriedem) wrote :

I see an easy fix for this, I'll just push that up, as a regression fix, not as a new filtering feature.

Revision history for this message
Matt Riedemann (mriedem) wrote :

Or we just deprecate the nova-manage CLI and make people move to novaclient, and then we delete the CLI in Ocata.

Revision history for this message
Kevin Fox (kevpn) wrote :

The only thing I could find in novaclient is nova hypervisor-servers $hostname, so you could call nova hypervisor-list, parse it, and call hypervisor-servers on it. Its doable in bash, but a little ugly.

Could an --all-servers flag be added to nova hypervisor-servers? That would handle it too.

Thanks,
Kevin

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/339219

Changed in nova:
assignee: Sujitha (sujitha-neti) → Matt Riedemann (mriedem)
status: Opinion → In Progress
Revision history for this message
Matt Riedemann (mriedem) wrote :

Kevin, you can filter on host via nova list. I didn't even know that hypervisor-servers existed, it seems redundant.

Revision history for this message
Kevin Fox (kevpn) wrote :

nova list --all-tenants doesn't do what I want either. No host info.

I don't want to filter by host at all, but get basically a list of all non deleted vms, and which hosts they are on. so I can easily do stuff, for example, count the number of vms per host, or look at which vm's are running in a given rack.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/339219
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=5a5b06fb24fc6e392eb5381f1348e475f1302e1e
Submitter: Jenkins
Branch: master

commit 5a5b06fb24fc6e392eb5381f1348e475f1302e1e
Author: Matt Riedemann <email address hidden>
Date: Thu Jul 7 16:07:53 2016 -0400

    Deprecate nova-manage vm list command

    The nova-manage vm command is replaced with the nova list command
    in python-novaclient, and has been for a long time.

    As of microversion 2.3, the fields that are output from
    nova-manage vm list are all covered in the REST API for showing server
    details, which can also be used via the --fields option of the nova
    list command. The nova list command also allows filtering by host.

    This sets the timer for deprecation and then removal in Ocata.

    Change-Id: Ibce8c3deb24a16019b721d3b91640ca342ae541b
    Closes-Bug: #1494841

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/nova 14.0.0.0b2

This issue was fixed in the openstack/nova 14.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.