Command to display hosted Virtual Machines
To combat scope-creep of having VMs unmanaged on a number of KVM Hypervisors, I am attempting to figure out how to leverage Satellite's ability to see which VMs are currently being hosted.
At this point I have a good idea of where my hypervisors are in my environment, but.. I'd like it to be a bit more dynamic.
Why: If someone gets paged to look at vmhost100.company.com - currently I have no way of knowing if it's RHEV, VMware, or KVM at this point. A quick glance at Satellite will at least tell me if it is VMware vs RHEV vs KVM (which is cool).. but.. if the VM is a KVM host, I have no way of knowing which hypervisor it belongs to.
I have added the necessary packages so that my KVM hosts will report back to Satellite
yum -y install rhn-virtualization-host
Now I am looking for the API (or better yet, spacecmd) that will replicate the functionality found in the WebUI when you click on "Virtualization".
As always, thanks in advance for responses ;-)
Responses
Hello James,
Currently Red Hat Satellite 5.6 provides the ability to list system's virtual_host via spacewalk-report:
[root@sat-56-server ~]# spacewalk-report inventory
server_id,profile_name,hostname,ip_address,ipv6_address,registered_by,registration_time,last_checkin_time,kernel_version,packages_out_of_date,errata_out_of_date,software_channel,configuration_channel,entitlements,system_group,organization,virtual_host,architecture,is_virtualized,osad_status,hardware
In addition, we're tracking an existing feature request for the upcoming Satellite 5.7 release - private BZ #1012261 "[RFE] spacewalk-report should report the virtualization of a system (e.g. KVM/QEMU, VMware, ...)" - from upstream Spacewalk commit 7a59ed592f7b85b33d6f031e6136a8573d7b368b. Please feel free to submit a support case to track agains this RFE.
Hope this helps
James, I am interested in trying what Xixi mentions above... and am going to check it out for use with our satellite servers.
Hope this bit below helps... I am certain there are more elegant ways to do this
The next example will give a raw output of a systems' kvm guests using spacecmd and the 'virsh list --all' command
- Perhaps set up a system group called "kvmhosts"
- Assign all the kvm hosts to that group
- You can run this on your satellite server or a system (perhaps your admin workstation), just have a place for your scripts (if you want them shared,
perhaps an nfs share that's trusted only between your specific system and your satellite server).
simple script for use with spacecmd
#!/bin/bash
/usr/bin/virsh list --all
## cmd='/usr/bin/virsh list --all | egrep -v "things|to|filter|out"'
# reference
# $cmd | perl -ne 'chomp;system("echo `hostname -s` $_")'
I do not have time now, but I typically attempt to filter the output to something relevant and then preface the queries I run by the hostname I'll t
ry to come back later with something more refined...
Then after establishing the system group (perhaps called "kvmhosts") in your satellite server
- If you run from your local system:
spacecmd -u someadmin -s yoursatserver
spacecmd {SSM:0}> system_runscript -f /path/to/that/script.sh group:kvmhosts
User: root
Group: root
Timeout: 600 seconds
Start Time: <time stamp here>
Script Contents
----------------
#!/bin/bash
/usr/bin/virsh list --all
Systems
-----------
box1
box2
server55
webserv404
<output truncated
Is this ok [y/N]: y
INFO: Action ID: 9533
INFO: Scheduled: 79 system(s)
Spacecmd {SSM:0}> quit
The output will be 'raw', and can be refined further, I typically alter the output so I get something like.
box1 <line of output I want>
so that the hostname is at the left, and the output I want follows so i can sort/make my own reference as needed.
You can watch this drain out with (using ID# 9533 above)
# get recent list of scripts ran:
spacecmd -u userid -s satservername schedule_listcompleted | grep arbitrary | head -15
<log in>
9991 <time stamp> 6 0 1 Run an arbitrary script #drives me mad we can not label these!!!
9989 <time stamp> 452 0 22 Run an arbitrary script
<more output>
Pick the relevant id you want, make note of it when you pass the script such as above
spacecmd -u userid -s satservername schedule_list_completed | egrep 'ID|9533'
ID date C F P Action
9533 <time stamp> 325 2 0 Run an arbitrary script
The three relevant columns above are "C"-completed "F"-failed "P"-pending
Once the systems drain out of "P" (Pending), then run:
spacecmd -u userid -s yoursatserver schedule_getoutput 9533
Make note of the output and start dropping off what you don't need with grep/egrep, 'egrep -A # -B #' etc...
I can post more examples at a later time...
Gladly...
I tried the
spacewalk-report inventory
edited
and it gave me the block of text for each and every system, then I would have to sift (adjust the output via cmdline, etc) to acquire what is relevant...
The initial system report of:
spacewalk-report inventory | grep 'Yes'
seems to return only just the virtual systems.
For each system, the output gives a hearty (but relevant) block of text of useful info in a raw format....
Some of my satellite servers are on 5.6 and I can use there and see what options I can use to garner the relevant bits from the output... It would be a useful report for my customers as well.
I put in a feature request a while ago via a ticket to be able to put a name/label for whatever script I pass to the satellite server. It drives me nuts to have everything shunted to "Run Arbitrary Script".
I was told it may appear in a future release... I put it in I think at the advent of version 5.5
As Xixi mentioned in the opening reply, spacewalk-report inventory provides the reporting
spacewalk-report --list-fields-info inventory
server_id: System identifier
profile_name: Profile name, as stored on server
hostname: Hostname, as reported by the system
ip_address: IPv4 address, as reported by the system
ipv6_address: IPv6 address, as reported by the system
registered_by: User under which the system is registered
registration_time: Registration time
last_checkin_time: Last checkin time
kernel_version: Kernel version, as reported by the system
packages_out_of_date: Number of packages that can be upgraded
errata_out_of_date: Number of erratas that can be applied
software_channel: List of channels to which the system is registered
configuration_channel: List of configuration channels
entitlements: List of entitlements
system_group: List of system group to which the system belongs
organization: Organization name
virtual_host: System identifier of host, if system is a guest
architecture: Architecture of the system
is_virtualized: Information whether system is virtualized or not
virt_type: System virtualization type
osad_status: OSAD status
hardware: Hardware information
Assuming the information is in Satellite 5 about which host has which guest, you'll see it in this report. And more specifically you'll see this in the host-guests report.
# spacewalk-report --list-fields-info host-guests
server_id: System identifier
guests: Guests
Example output:
# spacewalk-report host-guests
server_id,guests
1000010522,1000011498;1000011499;1000010321;1000011005;1000010361;1000011559;1000010659
1000010523,1000011074;1000011009;1000011563;1000010652;1000010561;1000010562;1000011561;1000011562;1000010490;1000011109;1000011011;1000010398;1000010917
1000010527,1000011058;1000011554;1000011054
1000010528,1000011472;1000010926;1000011573;1000011035;1000011505;1000011459;1000011055;1000011004;1000011555;1000011504
The question now is how do I get the hosts to report which guests are they hosting.
For Red Hat hypervisors, install the rhn-virtualization-host package. For non-Red Hat hypervisors such a VMWare a differing method is needed. You can leverage virt-who to report ESX hypervisors to Satellite 5. Once properly configured, your ESX hypervisors will now show up in Satellite's UI, (and in the reports listed above).
Lastly, you can use the spacewalk-report scripts as shown above to get your data. Alternatively you can leverage the API, namely the system.listVirtualHosts and system.listVirtualGuests methods.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
