virt-who deepdive

Radek Nováček

what is virt-who

  • system service running on RHEL
  • gathers host/guest association from hypervisor
  • sends the data somewhere
  • written in Python
  • tied to RHEL lifecycle
  • github.com/virt-who/virt-who

Hypervisors

Local

  • KVM (libvirt)
  • VDSM (RHEV-H)

Remote

  • KVM (libvirt)
  • VMWare ESX(i)
  • Microsoft Hyper-V
  • RHEV-M
  • Citrix XenServer

Fake

Data consumers

  • Satellite 5

  • Customer Portal
  • Subscription Asset Manager
  • Satellite 6

Documentation

Modes of operation

interval

  • get data every ~60 seconds (configurable)
  • listen for events if available (ESX, XenServer, libvirt)

one-shot

  • get data from hypervisors once, send it and exit

print

  • get data and print it to stdout as JSON

Configuration

/etc/sysconfig/virt-who
# General options
VIRTWHO_DEBUG=1
VIRTWHO_INTERVAL=60

# Following is deprecated
VIRTWHO_SATELLITE6=1
VIRTWHO_SATELLITE5=0
VIRTWHO_ESX=1
VIRTWHO_ESX_SERVER=esx.example.com
VIRTWHO_ESX_USERNAME=admin
VIRTWHO_ESX_PASSWORD=password
VIRTWHO_ESX_OWNER=owner
VIRTWHO_ESX_ENV=env
/etc/virt-who.conf

Configuration

/etc/virt-who.d/*
[esx-name]
type=esx
server=esx.example.com
username=admin
password=password
#encrypted_password=a4393c84f76b4c80bf4246f2129dec29
hypervisor_id=uuid # or hostname or hwuuid
filter_hosts=   # what hypervisors should be reported
exclude_hosts=  # what hypervisors should NOT be reported

# For SAM and Satellite 6
owner=owner
env=env
rhsm_XXX # override XXX option in /etc/rhsm/rhsm.conf
         # can be used on unregistered system

# For Satellite 5
sat_server
sat_username
sat_password
#sat_encrypted_password

Data gathered

{
    "hypervisors": [
        {
            "uuid": "9705df9f-76d4-4343-bf10-229e8692ecee",
            "guests": [
                {
                    "guestId": "564dae86-b20b-0214-0203-dc50d3be0ec2",
                    "state": 5,
                    "attributes": {
                        "active": 0,
                        "virtWhoType": "esx"
                    }
                },
                ...
            ],
            "facts": {
                "hypervisor.type": "VMware ESXi",
                "cpu.cpu_socket(s)": "2",
                "hypervisor.version": "5.5.0"
            },
            "name": "localhost"
        }
    ]
}

how to debug

debug mode

  • -d on command-line
  • VIRTWHO_DEBUG=1 in /etc/sysconfig/virt-who

logs

  • /var/log/rhsm/rhsm.log

Code overview

  • main.py - entry point, daemonize, execute
  • parser.py - parse cli options
  • executor.py - main loop
  • virt/virt.py - hypervisor and vm abstrations, base for virt backends
  • virt/[backend]/[backend].py - backend implementation, derives from Virt class
  • manager/manager.py - base for managers
  • manager/subscriptionmanager/subscriptionmanager.py - communication with candlepin (SAM, Sat6)
  • manager/satellite/satellite.py - communication with Satellite 5
  • ...

Communication with Satellite 6

using python-rhsm package

API calls used

  • ping() for connection checking
  • updateConsumer() for local hypervisors
  • hypervisorCheckIn() for remote hypervisors
  • getJob() get job status if jobs are supported (needs Candlepin 2.0)

Communication with Satellite 5

  • for remote hypervisors only
  • creates and uses special hypervisor channel for hypervisor registration
  • used to consume RHEL-6 server subscription per hypervisor (until RHEL-7.3, RHEL-6.9)
  • saves hypervisor registration to
    /var/lib/virt-who/hypervisor-systemid-*

Communication with Satellite 5

using XMLRPC, two API endpoints

/rpc/api

  • auth.login
  • channel.software.getDetails
  • channel.software.create
  • distchannel.setMapForOrg

/XMLRPC

  • registration.new_system_user_pass
  • registration.refresh_hw_profile
  • registration.virt_notify

Thanks for listening



Questions?