Extract a list of virtual guests and corresponding "Virtual Host" (Hypervisor)

Latest response

I have a list of virtual content hosts and I need to produce a list of their corresponding hypervisors. I have been trying to leverage hammer to no effect. I would imagine this could be produced by using,

hammer fact list --search

or

hammer host list --search

but I have yet to find the proper "fact" or field to search for. One can see the desired information on the Satellite UI, under the details for each host, listed as "Virtual Host", when the content host in question is a VM and is identified as a guest on a hypervisor.
Any insights? I am running Satellite 6.2.14.
Thanks.

Responses

Take a look at Subscription-manager for the former Red Hat Network User: Part 12 - Subscription Reporting Tools

An example command would be

hammer csv content-hosts \
 --export \
 --file content-hosts-export.csv \
 --itemized-subscriptions \
 --verbose \
 --organization Example

Following up on your suggestion, and after doing some reading, I thought the following would produce the desired output:

hammer csv content-hosts  --export  --file content-hosts-export.csv --columns "Name,Guest of Host" --organization Organization

However, I keep on getting "500 internal Server Error", with no output. Researching this, I found this article and also this other article. I tried the steps on the second article to no avail. The first article states, in a nutshell, that hammer is ignoring its own timeout and that this issue has been resolved in Satellite 6.3. It also points to an article that shows how to increase hammer's timeout, which is kind of pointless, because this parameter is being ignored. It is kind of hard for me to upgrade to 6.3 at the moment, just to solve this issue. It would be good to figure out another way this report can be produced in 6.2. 14

A workaround is using the api instead. Involves looping all host records so it´s quite heavy ...then again that´s what hammer csv content-hosts does anyway ...

  • Get all host records using /api/hosts
  • Get details for each host using /api/hosts/%numeric-id-of-host% and you will get:
{
  "subscription_facet_attributes" => {
        "compliance_reasons" => [],
              "virtual_host" => {
            "name" => "name-of-virtual-host",
              "id" => 1234
        }
  }
}

Ok, this sounds intriguing. What language would be this code in? Do you have an actual working implementation that you would be willing to share?

Well, I have developed a workaround in the form of a shell script. This is a quick and dirty script that would need more work, as it does not collate information or group VMs on a per hypervisor basis. It is also very expensive, as it makes calls to the API interface via URL and has to authenticate every time:

#!/bin/sh
rm -f hvs.log hvs_sorted.log
echo -n "Type Satellite's admin password:"
read -es password
echo ""
for i in $(hammer --csv fact list --search "fact=virt::host_type and value=vmware" | awk -F, '$1 != "Host" {print $1}');do
  curl -k -s -u admin:$password https://$(hostname -f)/api/hosts/$i | json_reformat | awk -F: 'f{print $2;f=0} $1 ~/virtual_host/{f=1}' | sed -e 's/[", ]//g' | tee -a hvs.log
done
sort --output=hvs_sorted.log -u hvs.log

The script here shows how to use hammer to produce a list of virtual hosts, unfortunately, the facts do not seem to produce the name of the "Virtual Host" or "Guest of Host". Standard disclaimers apply, YMMV.

Check this script out: https://github.com/gorantornqvist/redhat-satellite/blob/master/satellite-report-html.py , function hosts_by_hypervisor

That is a pretty handy script, although a bit rough. I modified my local copy to ask for the password, as I am not too keen on hardcoding passwords in scripts. That might defeat a potential purpose of running this in a cron job though. Thanks!

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.