[virt-who/systemd] Support for sending additional information together with guest uuids
by Radek Novacek
commit 2ac716f84d87dc75898bd5b24bf56ee159a688a4
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 6dc2482..4cf3191 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):
""" Send hosts to guests mapping to subscription manager. """
diff --git a/vdsm.py b/vdsm.py
index e4a6b9e..afad285 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 75ea8f7..800be47 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -13,8 +13,8 @@ BuildArch: noarch
BuildRequires: python2-devel
Requires: libvirt-python
Requires: libvirt
-# python-rhsm 0.98.6 has required call for vSphere support
-Requires: python-rhsm >= 0.98.6
+# 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
Requires(post): chkconfig
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:
10 years, 3 months
[virt-who/systemd] vsphere: create connection to vsphere each time
by Radek Novacek
commit 08c5db906c333a2a47e060af42c85df95c13d513
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Fri Jan 3 09:05:47 2014 +0100
vsphere: create connection to vsphere each time
The connection to the vsphere tends to timeout when not used for some
time. The login will fail after that. This commit forces virt-who to reconnect
to vsphere each time.
vsphere.py | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/vsphere.py b/vsphere.py
index 415df65..5afbcb3 100644
--- a/vsphere.py
+++ b/vsphere.py
@@ -115,6 +115,16 @@ class VSphere:
if not "://" in self.url:
self.url = "https://%s" % self.url
+ self.clusters = {}
+ self.hosts = {}
+ self.vms = {}
+
+ def scan(self):
+ """
+ Scan method does full inventory traversal on the vCenter machine. It finds
+ all ComputeResources, Hosts and VirtualMachines.
+ """
+
# Connect to the vCenter server
self.client = suds.client.Client("%s/sdk/vimService.wsdl" % self.url)
@@ -127,16 +137,6 @@ class VSphere:
# Service Content object defines properties of the ServiceInstance object
self.sc = self.client.service.RetrieveServiceContent(_this=self.moRef)
- self.clusters = {}
- self.hosts = {}
- self.vms = {}
-
- def scan(self):
- """
- Scan method does full inventory traversal on the vCenter machine. It finds
- all ComputeResources, Hosts and VirtualMachines.
- """
-
# Login to server using given credentials
self.client.service.Login(_this=self.sc.sessionManager, userName=self.username, password=self.password)
10 years, 3 months