[virt-who] Update to version 0.7
by Radek Novacek
commit 363bbcad67e955e8da2b48e1fcc7d8fa60228dcd
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Jul 10 10:43:20 2012 +0200
Update to version 0.7
Makefile | 2 +-
virt-who.spec | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/Makefile b/Makefile
index e7d890c..a3e89ce 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
name = virt-who
-version = 0.6
+version = 0.7
.PHONY: pack check install srpm rpm rpmlint upload
diff --git a/virt-who.spec b/virt-who.spec
index aa206fa..d403d62 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -1,5 +1,5 @@
Name: virt-who
-Version: 0.6
+Version: 0.7
Release: 1%{?dist}
Summary: Agent for reporting virtual guest IDs to subscription-manager
@@ -69,6 +69,9 @@ fi
%changelog
+* Mon Jul 09 2012 Radek Novacek <rnovacek(a)redhat.com> 0.7-1
+- Version 0.7
+
* Mon Feb 13 2012 Radek Novacek <rnovacek(a)redhat.com> 0.6-1
- Version 0.6
11 years, 9 months
[virt-who] Start event loop every time except one-shot mode
by Radek Novacek
commit d9aaedcec11f1f05d71bd904a1c4af6994de7390
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Jul 16 16:02:30 2012 +0200
Start event loop every time except one-shot mode
virt-who.py | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index b1f7908..417c59f 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -405,12 +405,14 @@ def main():
if not daemonize(options.debug):
logger.error("Unable to fork, continuing in foreground")
- if options.background:
+ if not options.oneshot:
if options.virtType == "libvirt":
+ logger.debug("Starting event loop")
virEventLoopPureStart()
else:
logger.warning("Listening for events is not available in VDSM or ESX mode")
+ global RetryInterval
if options.interval < RetryInterval:
RetryInterval = options.interval
@@ -440,7 +442,7 @@ def main():
if virtWho.send():
# Check if connection is established each 'RetryInterval' seconds
slept = 0
- while slept < options.interval:
+ while slept <= options.interval:
# Sleep 'RetryInterval' or the rest of options.interval
t = min(RetryInterval, options.interval - slept)
time.sleep(t)
11 years, 9 months
[virt-who] Simplify exceptions
by Radek Novacek
commit 2ab883cee8b0187f6c12145f6f28a112e1b903e8
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Jul 16 15:59:37 2012 +0200
Simplify exceptions
Since virt-who can reload configuration now, most of the errors are not
fatal. Therefore exception can be simplified.
subscriptionmanager.py | 28 ++-------------
virt-who.py | 89 ++++++++++++++++++++++++++---------------------
virt.py | 5 ++-
3 files changed, 57 insertions(+), 65 deletions(-)
---
diff --git a/subscriptionmanager.py b/subscriptionmanager.py
index 4050655..2ffd8ce 100644
--- a/subscriptionmanager.py
+++ b/subscriptionmanager.py
@@ -26,17 +26,6 @@ import rhsm.certificate as rhsm_certificate
import rhsm.config as rhsm_config
class SubscriptionManagerError(Exception):
- def __init__(self):
- pass
-
-class SubscriptionManagerCertError(SubscriptionManagerError):
- def __init__(self, message):
- self.message = message
-
- def __str__(self):
- return self.message
-
-class SubscriptionManagerConnectionError(SubscriptionManagerError):
def __init__(self, message):
self.message = message
@@ -64,7 +53,7 @@ class SubscriptionManager:
self.cert_file = os.path.join(consumerCertDir, cert)
self.key_file = os.path.join(consumerCertDir, key)
if not os.access(self.cert_file, os.R_OK):
- raise SubscriptionManagerCertError("Unable to read certificate, system is not registered or you are not root")
+ raise SubscriptionManagerError("Unable to read certificate, system is not registered or you are not root")
def connect(self, Connection=rhsm_connection.UEPConnection):
""" Connect to the subscription-manager. """
@@ -92,11 +81,7 @@ class SubscriptionManager:
self.logger.debug("Sending list of uuids: %s" % uuids)
# Send list of guest uuids to the server
- try:
- self.connection.updateConsumer(self.uuid(), guest_uuids=uuids)
- except Exception, e:
- self.logger.exception("Updating consumer failed:")
- raise SubscriptionManagerError()
+ self.connection.updateConsumer(self.uuid(), guest_uuids=uuids)
def hypervisorCheckIn(self, owner, env, mapping):
""" Send hosts to guests mapping to subscription manager. """
@@ -104,11 +89,7 @@ class SubscriptionManager:
self.logger.debug("Sending update in hosts-to-guests mapping: %s" % mapping)
# Send the mapping
- try:
- return self.connection.hypervisorCheckIn(owner, env, mapping)
- except Exception, e:
- self.logger.exception("Hypervisor check-in failed:")
- raise SubscriptionManagerError()
+ return self.connection.hypervisorCheckIn(owner, env, mapping)
def uuid(self):
""" Read consumer certificate and get consumer UUID from it. """
@@ -116,8 +97,7 @@ class SubscriptionManager:
try:
f = open(self.cert_file, "r")
except Exception, e:
- self.logger.exception("Unable to open certificate (%s):" % self.cert_file)
- raise SubscriptionManagerError()
+ raise SubscriptionManagerError("Unable to open certificate %s (%s):" % self.cert_file, str(e))
certificate = rhsm_certificate.Certificate(f.read())
f.close()
self.cert_uuid = certificate.subject().get('CN')
diff --git a/virt-who.py b/virt-who.py
index 3ae6e37..b1f7908 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -28,7 +28,7 @@ from virt import Virt, VirtError
from vdsm import VDSM
from vsphere import VSphere
from event import virEventLoopPureStart
-from subscriptionmanager import SubscriptionManager, SubscriptionManagerError, SubscriptionManagerCertError
+from subscriptionmanager import SubscriptionManager, SubscriptionManagerError
import logging
import log
@@ -107,13 +107,11 @@ class VirtWho(object):
self.subscriptionManager = SubscriptionManager(self.logger)
self.subscriptionManager.connect()
except NoOptionError, e:
- self.logger.error("Error in reading configuration file (/etc/rhsm/rhsm.conf)")
- # Unability to parse configuration file is fatal error, so we'll quit
- sys.exit(4)
- except SubscriptionManagerCertError, e:
- self.logger.error(e.message)
- # virt-who can't work properly without certificate, exitting
- sys.exit(5)
+ self.logger.exception("Error in reading configuration file (/etc/rhsm/rhsm.conf):")
+ return
+ except SubscriptionManagerError, e:
+ self.logger.exception("Unable to obtain status from server, UEPConnection is likely not usable:")
+ return
if self.options.virtType == "libvirt":
self.tryRegisterEventCallback()
@@ -161,57 +159,58 @@ class VirtWho(object):
logger = self.logger
try:
self.checkConnections()
- if self.options.virtType == "esx":
- result = self.subscriptionManager.hypervisorCheckIn(self.options.esx_owner, self.options.esx_env, self.virt.getHostGuestMapping())
- # Show the result of hypervisorCheckIn
- for fail in result['failedUpdate']:
- logger.error("Error during update list of guests: %s", str(fail))
- for updated in result['updated']:
- guests = [x['guestId'] for x in updated['guestIds']]
- logger.info("Updated host: %s with guests: [%s]", updated['uuid'], ", ".join(guests))
- for created in result['created']:
- guests = [x['guestId'] for x in created['guestIds']]
- logger.info("Created host: %s with guests: [%s]", created['uuid'], ", ".join(guests))
- else:
- self.subscriptionManager.sendVirtGuests(self.virt.listDomains())
- return True
- except SystemExit,e:
- # In python2.4 SystemExit is inherited from Exception, so must be catched extra
- raise e
- except VirtError, e:
- # Communication with virtualization supervisor failed
- logger.exception(e)
- self.virt = None
- # Retry once
+ except Exception,e:
if retry:
- logger.error("Error in communication with virt backend, trying to recover")
+ logger.exception("Unable to create connection:")
return self._send(False)
else:
logger.error(self.unableToRecoverStr)
return False
- except SubscriptionManagerError, e:
- # Communication with subscription manager failed
- self.subscriptionManager = None
+
+ try:
+ if self.options.virtType != "esx":
+ virtualGuests = self.virt.listDomains()
+ else:
+ virtualGuests = self.virt.getHostGuestMapping()
+ except Exception, e:
+ # Communication with virtualization supervisor failed
+ self.virt = None
# Retry once
if retry:
- logger.error("Error in communication with candlepin, trying to recover")
+ logger.exception("Error in communication with virt backend, trying to recover:")
return self._send(False)
else:
logger.error(self.unableToRecoverStr)
return False
+
+ try:
+ if self.options.virtType != "esx":
+ self.subscriptionManager.sendVirtGuests(virtualGuests)
+ else:
+ result = self.subscriptionManager.hypervisorCheckIn(self.options.esx_owner, self.options.esx_env, virtualGuests)
+
+ # Show the result of hypervisorCheckIn
+ for fail in result['failedUpdate']:
+ logger.error("Error during update list of guests: %s", str(fail))
+ for updated in result['updated']:
+ guests = [x['guestId'] for x in updated['guestIds']]
+ logger.info("Updated host: %s with guests: [%s]", updated['uuid'], ", ".join(guests))
+ for created in result['created']:
+ guests = [x['guestId'] for x in created['guestIds']]
+ logger.info("Created host: %s with guests: [%s]", created['uuid'], ", ".join(guests))
except Exception, e:
- # Some other error happens
- logger.exception(e)
- self.virt = None
+ # Communication with subscription manager failed
self.subscriptionManager = None
# Retry once
if retry:
- logger.error("Unexcepted error occurs, trying to recover")
+ logger.exception("Error in communication with subscription manager, trying to recover:")
return self._send(False)
else:
logger.error(self.unableToRecoverStr)
return False
+ return True
+
def ping(self):
"""
Test if connection to virtualization manager is alive.
@@ -304,7 +303,7 @@ def cleanup(sig=None, stack=None):
if sig is not None and sig in [signal.SIGINT, signal.SIGTERM, signal.SIGKILL]:
sys.exit(0)
-if __name__ == '__main__':
+def main():
if os.access(PIDFILE, os.F_OK):
print >>sys.stderr, "virt-who seems to be already running. If not, remove %s" % PIDFILE
sys.exit(1)
@@ -459,3 +458,13 @@ if __name__ == '__main__':
else:
# If last send fails, new try will be sooner
time.sleep(RetryInterval)
+
+if __name__ == '__main__':
+ try:
+ main()
+ except SystemExit:
+ raise
+ except Exception, e:
+ logger = log.getLogger(False, False)
+ logger.exception("Fatal error:")
+ sys.exit(1)
diff --git a/virt.py b/virt.py
index 75d8019..4cb4b5e 100644
--- a/virt.py
+++ b/virt.py
@@ -86,7 +86,10 @@ class Virt:
break
if not hasDomain:
l.append(dom)
- self.changedCallback(l)
+ try:
+ self.changedCallback(l)
+ except Exception, e:
+ self.logger.exception("Updating consumer failed:")
def domainEventRegisterCallback(self, callback):
self.changedCallback = callback
11 years, 9 months
[virt-who] Add ability to restart itself on SIGHUP signal
by Radek Novacek
commit e649b5d8db85bcea23d04ba380c8f04cec5589d4
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Jul 16 15:50:26 2012 +0200
Add ability to restart itself on SIGHUP signal
It will reload configuration and reconnect to libvirt and rhsm.
Can be used by external programs to force virt-who to reload.
It's also send When virt-who is disconnected from libvirt (xen only).
event.py | 14 ++++++++++++--
subscriptionmanager.py | 20 ++++++++++++--------
virt-who.py | 26 ++++++++++++++++++++++++++
virt.py | 2 ++
4 files changed, 52 insertions(+), 10 deletions(-)
---
diff --git a/event.py b/event.py
index 0f035e6..9d3a557 100644
--- a/event.py
+++ b/event.py
@@ -14,7 +14,10 @@ import libvirt
import select
import time
import threading
+import signal
+# Type of virtualization
+virtType = None
# This general purpose event loop will support waiting for file handle
# I/O and errors events, as well as scheduling repeatable timers with
@@ -264,6 +267,12 @@ class virEventLoopPure:
self.handles = handles
self.interrupt()
+ # !!! This is NOT present in original example from libvirt
+ # Remove handle happens when libvirtd dies, so we'll restart ourself
+ # Only for XEN, works fine for other virt types
+ if virtType is not None and virtType == "Xen":
+ os.kill(os.getpid(), signal.SIGHUP)
+
# Stop firing the periodic timer
def remove_timer(self, timerID):
timers = []
@@ -308,13 +317,12 @@ class virEventLoopPure:
# This single global instance of the event loop wil be used for
# monitoring libvirt events
-eventLoop = virEventLoopPure()
+eventLoop = None
# This keeps track of what thread is running the event loop,
# (if it is run in a background thread)
eventLoopThread = None
-
# These next set of 6 methods are the glue between the official
# libvirt events API, and our particular impl of the event loop
#
@@ -365,6 +373,8 @@ def virEventLoopPureRun():
# Spawn a background thread to run the event loop
def virEventLoopPureStart():
global eventLoopThread
+ global eventLoop
+ eventLoop = virEventLoopPure()
virEventLoopPureRegister()
eventLoopThread = threading.Thread(target=virEventLoopPureRun, name="libvirtEventLoop")
eventLoopThread.setDaemon(True)
diff --git a/subscriptionmanager.py b/subscriptionmanager.py
index 1b82ec4..4050655 100644
--- a/subscriptionmanager.py
+++ b/subscriptionmanager.py
@@ -49,7 +49,7 @@ class SubscriptionManager:
self.logger = logger
self.cert_uuid = None
- self.config = rhsm_config.initConfig()
+ self.config = rhsm_config.initConfig(rhsm_config.DEFAULT_CONFIG_PATH)
self.readConfig()
# Consumer ID obtained from consumer certificate
@@ -68,13 +68,17 @@ class SubscriptionManager:
def connect(self, Connection=rhsm_connection.UEPConnection):
""" Connect to the subscription-manager. """
- self.connection = Connection(cert_file=self.cert_file, key_file=self.key_file)
- try:
- if not self.connection.ping()['result']:
- raise SubscriptionManagerConnectionError("Unable to obtain status from server, UEPConnection is likely not usable.")
- except Exception, e:
- self.logger.exception("Unable to obtain status from server, UEPConnection is likely not usable:")
- raise SubscriptionManagerError()
+ self.connection = Connection(
+ host=self.config.get('server', 'hostname'),
+ ssl_port=int(self.config.get('server', 'port')),
+ handler=self.config.get('server', 'prefix'),
+ proxy_hostname=self.config.get('server', 'proxy_hostname'),
+ proxy_port=self.config.get('server', 'proxy_port'),
+ proxy_user=self.config.get('server', 'proxy_user'),
+ proxy_password=self.config.get('server', 'proxy_password'),
+ cert_file=self.cert_file, key_file=self.key_file)
+ if not self.connection.ping()['result']:
+ 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. """
diff --git a/virt-who.py b/virt-who.py
index f154b14..3ae6e37 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -81,6 +81,9 @@ class VirtWho(object):
if not options.oneshot:
self.unableToRecoverStr += ", retry in %d seconds." % RetryInterval
+ # True if reload is queued
+ self.doReload = False
+
def initVirt(self):
"""
@@ -219,6 +222,22 @@ class VirtWho(object):
return False
return self.virt.ping()
+ def queueReload(self, *p):
+ """
+ Reload virt-who configuration. Called on SIGHUP signal arrival.
+ """
+ self.doReload = True
+
+ def reloadConfig(self):
+ if self.virt and self.virt.virt:
+ self.virt.virt.close()
+ self.virt = None
+ self.subscriptionManager = None
+ self.checkConnections()
+ self.logger.debug("virt-who configution reloaded")
+ self.doReload = False
+
+
def daemonize(debugMode):
""" Perform double-fork and redirect std* to /dev/null """
@@ -397,6 +416,7 @@ if __name__ == '__main__':
RetryInterval = options.interval
virtWho = VirtWho(logger, options)
+ signal.signal(signal.SIGHUP, virtWho.queueReload)
try:
virtWho.checkConnections()
except Exception:
@@ -426,6 +446,12 @@ if __name__ == '__main__':
t = min(RetryInterval, options.interval - slept)
time.sleep(t)
slept += t
+
+ # Reload configuration if queued
+ if virtWho.doReload:
+ virtWho.reloadConfig()
+ break
+
# Check the connection
if not virtWho.ping():
# End the cycle
diff --git a/virt.py b/virt.py
index d439c30..75d8019 100644
--- a/virt.py
+++ b/virt.py
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import libvirt
+import event
class VirtError(Exception):
pass
@@ -35,6 +36,7 @@ class Virt:
self.virt = libvirt.openReadOnly("")
# Register listener for domain changes
self.virt.domainEventRegister(self.changed, None)
+ event.virtType = self.virt.getType()
except libvirt.libvirtError, e:
raise VirtError(str(e))
11 years, 9 months
[virt-who] Fix event loop to receive migration events
by Radek Novacek
commit 261117c274a2864366bc6eab7ce601c4837fee7a
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Jul 11 08:51:44 2012 +0200
Fix event loop to receive migration events
event.py | 11 +----------
virt-who.py | 8 ++++----
virt.py | 4 +++-
3 files changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/event.py b/event.py
index 30940fd..0f035e6 100644
--- a/event.py
+++ b/event.py
@@ -86,8 +86,6 @@ class virEventLoopPure:
def __init__(self):
self.poll = select.poll()
self.pipetrick = os.pipe()
- self.pendingWakeup = False
- self.runningPoll = False
self.nextHandleID = 1
self.nextTimerID = 1
self.handles = []
@@ -161,7 +159,6 @@ class virEventLoopPure:
# these pointless repeated tiny sleeps.
def run_once(self):
sleep = -1
- self.runningPoll = True
next = self.next_timeout()
if next > 0:
now = int(time.time() * 1000)
@@ -178,7 +175,6 @@ class virEventLoopPure:
# telling us to wakup. if so, then discard
# the data just continue
if fd == self.pipetrick[0]:
- self.pendingWakeup = False
data = os.read(fd, 1)
continue
@@ -199,9 +195,6 @@ class virEventLoopPure:
t.set_last_fired(now)
t.dispatch()
- self.runningPoll = False
-
-
# Actually the event loop forever
def run_loop(self):
self.quit = False
@@ -209,9 +202,7 @@ class virEventLoopPure:
self.run_once()
def interrupt(self):
- if self.runningPoll and not self.pendingWakeup:
- self.pendingWakeup = True
- os.write(self.pipetrick[1], 'c')
+ os.write(self.pipetrick[1], 'c')
# Registers a new file handle 'fd', monitoring for 'events' (libvirt
diff --git a/virt-who.py b/virt-who.py
index ed04792..f154b14 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -103,7 +103,6 @@ class VirtWho(object):
try:
self.subscriptionManager = SubscriptionManager(self.logger)
self.subscriptionManager.connect()
- self.tryRegisterEventCallback()
except NoOptionError, e:
self.logger.error("Error in reading configuration file (/etc/rhsm/rhsm.conf)")
# Unability to parse configuration file is fatal error, so we'll quit
@@ -113,6 +112,9 @@ class VirtWho(object):
# virt-who can't work properly without certificate, exitting
sys.exit(5)
+ if self.options.virtType == "libvirt":
+ self.tryRegisterEventCallback()
+
def tryRegisterEventCallback(self):
"""
This method register the handler which listen to guest changes
@@ -124,9 +126,7 @@ class VirtWho(object):
if self.options.background and self.options.virtType == "libvirt":
if self.virt is not None and self.subscriptionManager is not None:
# Send list of virt guests when something changes in libvirt
- self.virt.domainListChangedCallback(self.subscriptionManager.sendVirtGuests)
- # Register listener for domain changes
- self.virt.virt.domainEventRegister(self.virt.changed, None)
+ self.virt.domainEventRegisterCallback(self.subscriptionManager.sendVirtGuests)
def checkConnections(self):
"""
diff --git a/virt.py b/virt.py
index bbedbf6..d439c30 100644
--- a/virt.py
+++ b/virt.py
@@ -33,6 +33,8 @@ class Virt:
libvirt.registerErrorHandler(lambda ctx, error: None, None) #self.logger.exception(error), None)
try:
self.virt = libvirt.openReadOnly("")
+ # Register listener for domain changes
+ self.virt.domainEventRegister(self.changed, None)
except libvirt.libvirtError, e:
raise VirtError(str(e))
@@ -84,7 +86,7 @@ class Virt:
l.append(dom)
self.changedCallback(l)
- def domainListChangedCallback(self, callback):
+ def domainEventRegisterCallback(self, callback):
self.changedCallback = callback
def ping(self):
11 years, 9 months
[virt-who] Fix logging, debug messages was not logged
by Radek Novacek
commit 9c0cd2e2d0c4ecccb739bbde9beb240318d93d63
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Jul 10 10:41:42 2012 +0200
Fix logging, debug messages was not logged
log.py | 6 +++++-
virt-who.py | 4 ++--
2 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/log.py b/log.py
index 87fc94a..e415001 100644
--- a/log.py
+++ b/log.py
@@ -26,6 +26,7 @@ import sys
def getLogger(debug, background):
logger = logging.getLogger("rhsm-app")
+ logger.setLevel(logging.DEBUG)
path = '/var/log/rhsm/rhsm.log'
try:
@@ -38,7 +39,10 @@ def getLogger(debug, background):
try:
fileHandler = logging.handlers.RotatingFileHandler(path, maxBytes=0x100000, backupCount=5)
fileHandler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] @%(filename)s:%(lineno)d - %(message)s'))
- fileHandler.setLevel(logging.DEBUG)
+ if debug:
+ fileHandler.setLevel(logging.DEBUG)
+ else:
+ fileHandler.setLevel(logging.WARNING)
logger.addHandler(fileHandler)
except Exception, e:
sys.stderr.write("Unable to log to %s: %s\n" % (path, e))
diff --git a/virt-who.py b/virt-who.py
index 8dc33bb..ed04792 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -317,12 +317,12 @@ if __name__ == '__main__':
if env in ["1", "true"]:
options.debug = True
- logger = log.getLogger(options.debug, options.background)
-
env = os.getenv("VIRTWHO_BACKGROUND", "0").strip().lower()
if env in ["1", "true"]:
options.background = True
+ logger = log.getLogger(options.debug, options.background)
+
env = os.getenv("VIRTWHO_ONE_SHOT", "0").strip().lower()
if env in ["1", "true"]:
options.oneshot = True
11 years, 9 months
[virt-who] Subclass OptionParser to add 'epilog' support
by Radek Novacek
commit 5ae2255e6875fc711ad12556aeff200bb8fac8c8
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Jul 10 09:22:51 2012 +0200
Subclass OptionParser to add 'epilog' support
'epilog' was add to OptionParser in Python 2.5,
but we need to support 2.4 too.
virt-who.py | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 5593288..8dc33bb 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -35,6 +35,24 @@ import log
from optparse import OptionParser, OptionGroup
+class OptionParserEpilog(OptionParser):
+ """ Epilog is new in Python 2.5, we need to support Python 2.4. """
+ def __init__(self, description, epilog=None):
+ self.myepilog = epilog
+ OptionParser.__init__(self, description)
+
+ def format_help(self, formatter=None):
+ if formatter is None:
+ formatter = self.formatter
+ help = OptionParser.format_help(self, formatter)
+ return help + "\n" + self.format_myepilog(formatter) + "\n"
+
+ def format_myepilog(self, formatter=None):
+ if self.myepilog is not None:
+ return formatter.format_description(self.myepilog)
+ else:
+ return ""
+
from ConfigParser import NoOptionError
# Default interval to retry after unsuccessful run
@@ -272,8 +290,8 @@ if __name__ == '__main__':
print >>sys.stderr, "virt-who seems to be already running. If not, remove %s" % PIDFILE
sys.exit(1)
- parser = OptionParser(description="Agent for reporting virtual guest IDs to subscription-manager",
- epilog="virt-who also reads enviromental variables. They have the same name as command line arguments but uppercased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled")
+ parser = OptionParserEpilog(description="Agent for reporting virtual guest IDs to subscription-manager",
+ epilog="virt-who also reads enviromental variables. They have the same name as command line arguments but uppercased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled")
parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable debugging output")
parser.add_option("-b", "--background", action="store_true", dest="background", default=False, help="Run in the background and monitor virtual guests")
parser.add_option("-o", "--one-shot", action="store_true", dest="oneshot", default=False, help="Send the list of guest IDs and exit immediately")
11 years, 9 months
[virt-who] Describe configuration (env vars) options in config file
by Radek Novacek
commit 74e139b78884275d3663ee82e4eecb283cca082f
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Jul 10 09:20:31 2012 +0200
Describe configuration (env vars) options in config file
virt-who.conf | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/virt-who.conf b/virt-who.conf
index b52983f..4d4f5a4 100644
--- a/virt-who.conf
+++ b/virt-who.conf
@@ -1,3 +1,34 @@
-# Enviromental variables for virt-who service can be specified here
+# Enviromental variables for virt-who service can be specified here.
+#
+# These enviromental variables are only used when starting virt-who as service,
+# otherwise you must specify them manually.
+
+# Start virt-who on background, perform doublefork and monitor for virtual guest
+# events (if possible). It is NOT recommended to turn off this option for
+# starting virt-who as service.
VIRTWHO_BACKGROUND=1
+
+# Enable debugging output.
VIRTWHO_DEBUG=0
+
+# Send the list of guest IDs and exit immediately.
+#VIRTWHO_ONE_SHOT=0
+
+# Acquire and send list of virtual guest each N seconds, 0 means default
+# configuration.
+#VIRTWHO_INTERVAL=0
+
+# virt-who mode, enable only one option from following 3:
+# Use libvirt to list virtual guests [default]
+#VIRTWHO_LIBVIRT=1
+# Use vdsm to list virtual guests
+#VIRTWHO_VDSM=0
+# Register ESX machines using vCenter
+#VIRTWHO_ESX=0
+
+# Option for ESX mode
+#VIRTWHO_ESX_OWNER=
+#VIRTWHO_ESX_ENV=
+#VIRTWHO_ESX_SERVER=
+#VIRTWHO_ESX_USERNAME=
+#VIRTWHO_ESX_PASSWORD=
11 years, 9 months