OpenStack: List State of All VMs

Hi All! Today’s post is a quick script to show how you can get all your OpenStack VMs and their state in a single command. Check it out!

For the impatient: Use this link os-vm-state-sh and rename to .sh

What’s Going On?

The nova list command returns just a subset of information we want; you have to use it in conjunction with the nova show command to get all the output you want. In my case I wanted a single command to show me the VM information by host, tenant, and state (such as RUNNING). The script gives you a good starting point for your own needs and is very simple.

Here’s the output:


vm_id|vm_host|vm_tenant|vm_name|vm_state
b0b4ae74-5058-42a8-9f63-e657ad086674|lposhostx010.foo.local|Tenant1|Ge-bariCluster-umrdj6wznztq-5fulmnfxptfq-d4zhxsxnvd64|active
b0f68a3d-1787-4170-bd16-723eb470070d|lposhostx010.foo.local|Tenant1|Ge-bariCluster-umrdj6wznztq-qk4zwfvu5k56-ftoqe4nat4l2|active
18ec9dfc-bc95-474c-a323-efd13947a990|lposhostx010.foo.local|Tenant1|Ge-bariCluster-umrdj6wznztq-vojwuj7b4s5s-ldjgmes5wvoy|active
55ba1b1d-d6e3-4dc9-903d-03ac4208c0bf|lposhostx010.foo.local|Tenant1|Ge-verTemplate-ypd5oy66ampj-Tenant2Server-vqfkioljd37t|active
5abb367f-1c21-4d38-aac0-5da99fe9969c|lposhostx010.foo.local|Tenant2|amagent090201|active
12379e16-c37f-4227-8699-1cfb92a962e8|lposhostx010.foo.local|Tenant2|amagent090202|active
86778a10-50c5-47b3-b347-28a0093bd345|lposhostx010.foo.local|Tenant2|amsrv0902|active
39612446-a2b9-4b6b-ab25-08af0d3a0f85|lposhostx010.foo.local|Tenant3|ch-bariCluster-ojhusmryqnmo-a75e6k3qu5r2-2wnpsshcxgei|active
73e4268e-c92d-437c-823c-8c2108330f99|lposhostx010.foo.local|Tenant3|ch-bariCluster-ojhusmryqnmo-vmioliasl636-2uhz4jbkwbez|active
81c65419-2c73-4629-b8be-22bd64158126|lposhostx010.foo.local|Tenant3|ch-verTemplate-glcb53r63hg5-Tenant2Server-ajnhy3lmzrzg|active
4d62bbd0-6a90-40ab-a4e4-6860683a8663|lposhostx010.foo.local|Tenant4|dbcoord|active
622625c6-d829-47ab-a3bd-0c75d53fceca|lposhostx010.foo.local|Tenant4|dbmgr|active
d865e31a-6de2-4f78-b398-c1395b8a390c|lposhostx200.foo.local|demo|demo-ptest-01|stopped
1473271e-bc0d-4eb0-898e-65d27daa06e6|lposhostx010.foo.local|Tenant3|ehrtestsuite|active
8d909e5d-e380-4368-b2b8-4e4e5bda4c39|lposhostx200.foo.local|infrastructure|fill-hyper|active
b42918df-6a58-452f-b7e1-fb59301c7fcf|lposhostx010.foo.local|lab-dev|lmgitlab|active
b1452ff6-4f38-4a91-8f0b-6a044d4f226f|lposhostx010.foo.local|lab-dev|lmjenkins|active
b91d9dae-8e34-4428-b186-b8375f263aea|lposhostx200.foo.local|infrastructure|lvinaddcx100|active
dfb39f28-066e-4522-b27f-b12054a5611e|lposhostx200.foo.local|infrastructure|lvinnagio100|active
d50854fa-5c50-4dba-a51e-7dffc49cbbe4|lposhostx200.foo.local|infrastructure|lvinpuppd100|active
994c319d-028c-4e91-9c64-4e0020bf934b|lposhostx200.foo.local|infrastructure|lvinpuppd110|active
ea69b8e2-9791-4eec-b761-37b77ebd7d33|lposhostx200.foo.local|infrastructure|lvinstmpx100|active
a288bdce-a0c4-4ba8-b6d7-28274ca47fa1|lposhostx010.foo.local|Tenant3|mongodb|active
34e81f13-5d7e-4999-9652-0fc44d1cbe1e|lposhostx010.foo.local|Tenant5|mstrat-03|active
6c16bd8d-6d5e-476e-8279-061713c2c63b|lposhostx010.foo.local|Tenant5|mstrat-04|active
dd2bbc8c-c2fa-4894-8c98-3c858e604d46|lposhostx010.foo.local|Tenant4|pentahoce|active
1146b768-88e0-435c-83c5-602f4a103b84|lposhostx010.foo.local|common|redmine|active
8768a494-6e8c-4cc0-96d7-ef219065a751|lposhostx010.foo.local|Tenant1|test-cloud|active
02d9069c-9972-402b-8022-c690293a2773|lposhostx010.foo.local|Tenant3|testing|active

Run the output through sort, load it into a spreadsheet, or use the output as input for another script.

Happy Computing! 🙂

Team-oriented systems mentor with deep knowledge of numerous software methodologies, technologies, languages, and operating systems. Excited about turning emerging technology into working production-ready systems. Focused on moving software teams to a higher level of world-class application development. Specialties:Software analysis and development...Product management through the entire lifecycle...Discrete product integration specialist!

Tagged with: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.