commit ee127e3a7c4281776f84c2a09229b73be54cd054
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Fri Jan 10 16:51:32 2014 +0100
Support for sending additional information together with guest uuids
So for state and virt type are send when using libvirt.
subscriptionmanager.py | 40 ++++++++++++++++++++++++++++++----------
vdsm.py | 13 +------------
virt-who.spec | 4 ++--
virt.py | 16 +++++++++++++---
4 files changed, 46 insertions(+), 27 deletions(-)
---
diff --git a/subscriptionmanager.py b/subscriptionmanager.py
index 51345d9..0045d38 100644
--- a/subscriptionmanager.py
+++ b/subscriptionmanager.py
@@ -70,18 +70,38 @@ class SubscriptionManager:
raise SubscriptionManagerError("Unable to obtain status from server,
UEPConnection is likely not usable.")
def sendVirtGuests(self, domains):
- """ Update consumer facts with UUIDs of virtual guests.
"""
-
- # Get comma separated list of UUIDs
- uuids = []
- for domain in domains:
- uuids.append(domain.UUIDString())
- uuids.sort()
-
- self.logger.debug("Sending list of uuids: %s" % uuids)
+ """
+ Update consumer facts with info about virtual guests.
+
+ :param domain: List of guest UUIDs for current machine or list of
+ dictionaries in the format: [
+ {
+ 'guestId': <uuid of guest>,
+ 'attributes': { # supplemental list a attributes, supported
are following:
+ 'hypervisorType': <type of hypervisor, e.g. QEMU>,
+ 'virtWhoType': <virtwho type of operation, e.g.
libvirt>,
+ 'active': <1 if guest is active, 0 otherwise, -1 on
error>
+ },
+ },
+ ...
+ ]
+ :type domain: list of str or list of dict domains
+ """
+
+ # Sort the list
+ key = None
+ if len(domains) > 0:
+ if isinstance(domains[0], basestring):
+ key = "guestId"
+ domains.sort(key=key)
+
+ if key is not None:
+ self.logger.debug("Sending list of uuids: %s" % [domain[key] for
domain in domains])
+ else:
+ self.logger.debug("Sending list of uuids: %s" % domains)
# Send list of guest uuids to the server
- self.connection.updateConsumer(self.uuid(), guest_uuids=uuids)
+ self.connection.updateConsumer(self.uuid(), guest_uuids=domains)
def hypervisorCheckIn(self, owner, env, mapping, type=None):
""" Send hosts to guests mapping to subscription manager.
"""
diff --git a/vdsm.py b/vdsm.py
index 957ea55..2802f75 100644
--- a/vdsm.py
+++ b/vdsm.py
@@ -28,17 +28,6 @@ import subprocess
class VdsmError(Exception):
pass
-class Domain:
- """ Class for compatibility with libvirt Domain class. Only UUID
supported. """
- def __init__(self, uuid):
- self.uuid = uuid
-
- def UUIDString(self):
- return self.uuid
-
- def __str__(self):
- return self.uuid
-
class VDSM:
def __init__(self, logger):
self.logger = logger
@@ -101,7 +90,7 @@ class VDSM:
self.logger.error("Unable to list virtual machines: %s" %
response['status']['message'])
else:
for vm in response['vmList']:
- domains.append(Domain(vm['vmId']))
+ domains.append(vm['vmId'])
return domains
def ping(self):
diff --git a/virt-who.spec b/virt-who.spec
index 0c7e069..a5ef0b6 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -12,8 +12,8 @@ BuildRoot: %(mktemp -ud
%{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: noarch
BuildRequires: python2-devel
Requires: libvirt-python
-# python-rhsm 1.0.4 contains new module for reading certificates
-Requires: python-rhsm >= 1.0.4
+# python-rhsm 1.10.10 has required call for guestId support
+Requires: python-rhsm >= 1.10.10
# python-suds is required for vSphere support
Requires: python-suds
# m2crypto is required for Hyper-V support
diff --git a/virt.py b/virt.py
index 9a09a04..cb20d71 100644
--- a/virt.py
+++ b/virt.py
@@ -24,6 +24,16 @@ import event
class VirtError(Exception):
pass
+class Domain(dict):
+ def __init__(self, virt, domain):
+ self['guestId'] = domain.UUIDString()
+ self['attributes'] = {
+ 'hypervisorType': virt.getType(),
+ 'virtWhoType': "libvirt",
+ 'active': 1 if domain.isActive() else 0
+ }
+ self['state'] = domain.state(0)[0]
+
class Virt:
""" Class for interacting with libvirt. """
def __init__(self, logger, registerEvents=True):
@@ -52,13 +62,13 @@ class Virt:
if domain.UUIDString() ==
"00000000-0000-0000-0000-000000000000":
# Don't send Domain-0 on xen (zeroed uuid)
continue
- domains.append(domain)
+ domains.append(Domain(self.virt, domain))
self.logger.debug("Virtual machine found: %s: %s" %
(domain.name(), domain.UUIDString()))
# Non active domains
for domainName in self.virt.listDefinedDomains():
domain = self.virt.lookupByName(domainName)
- domains.append(domain)
+ domains.append(Domain(self.virt, domain))
self.logger.debug("Virtual machine found: %s: %s" %
(domainName, domain.UUIDString()))
except libvirt.libvirtError, e:
raise VirtError(str(e))
@@ -86,7 +96,7 @@ class Virt:
hasDomain = True
break
if not hasDomain:
- l.append(dom)
+ l.append(Domain(self.virt, dom))
try:
self.changedCallback(l)
except Exception, e: