[virt-who] Update to version 0.8
by Radek Novacek
commit 0cf3a981f82e34d3d1aac0031ba0a4dea36c9a68
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Sep 26 09:10:40 2012 +0200
Update to version 0.8
virt-who.spec | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/virt-who.spec b/virt-who.spec
index c299a77..75ea8f7 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -1,5 +1,5 @@
Name: virt-who
-Version: 0.7
+Version: 0.8
Release: 1%{?dist}
Summary: Agent for reporting virtual guest IDs to subscription-manager
@@ -70,6 +70,9 @@ fi
%changelog
+* Fri Sep 14 2012 Radek Novacek <rnovacek(a)redhat.com> 0.8-1
+- Version 0.8
+
* Mon Jul 09 2012 Radek Novacek <rnovacek(a)redhat.com> 0.7-1
- Version 0.7
11 years, 6 months
[virt-who] Don't crash in vdsm mode
by Radek Novacek
commit 3837fc46333fe4d913a13116f756f83b5259dd64
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 24 09:52:30 2012 +0200
Don't crash in vdsm mode
virt-who.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 44f4088..0c8babf 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -231,8 +231,10 @@ class VirtWho(object):
self.doReload = True
def reloadConfig(self):
- if self.virt and self.virt.virt:
+ try:
self.virt.virt.close()
+ except AttributeError:
+ pass
self.virt = None
self.subscriptionManager = None
self.checkConnections()
11 years, 7 months
[virt-who] Add RHEV-M options to man page
by Radek Novacek
commit 4cfccf76a7c60af0327e974d674078de76f47508
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 17 14:41:01 2012 +0200
Add RHEV-M options to man page
virt-who.8 | 36 +++++++++++++++++++++++++++++++++---
1 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/virt-who.8 b/virt-who.8
index 5b21062..f26175e 100644
--- a/virt-who.8
+++ b/virt-who.8
@@ -2,7 +2,7 @@
.SH NAME
virt-who - Agent for reporting virtual guest IDs to Subscription Asset Manager.
.SH SYNOPSIS
-virt-who [-d] [-i INTERVAL] [-b] [-o] [--libvirt|--vdsm|--esx]
+virt-who [-d] [-i INTERVAL] [-b] [-o] [--libvirt|--vdsm|--esx|--rhevm]
.SH OPTIONS
.TP
\fB\-h\fR, \fB\-\-help\fR
@@ -28,8 +28,12 @@ Use vdsm to list virtual guests
.TP
\fB\-\-esx\fR
Register ESX machines using vCenter
-.SS vCenter/ESX options
.TP
+\fB\-\-rhevm\fR
+Register guests using RHEV\-M
+.IP
+.SS vCenter/ESX options
+.IP
Use this options with \fB\-\-esx\fR
.TP
\fB\-\-esx\-owner\fR=\fIOWNER\fR
@@ -46,7 +50,26 @@ Username for connecting to vCenter
.TP
\fB\-\-esx\-password\fR=\fIPASSWORD\fR
Password for connecting to vCenter
-
+.IP
+.SS RHEV\-M options
+.IP
+Use this options with \fB\-\-rhevm\fR
+.TP
+\fB\-\-rhevm\-owner\fR=\fIOWNER\fR
+Organization who has purchased subscriptions of the products
+.TP
+\fB\-\-rhevm\-env\fR=\fIENV\fR
+Environment where the RHEV\-M belongs to
+.TP
+\fB\-\-rhevm\-server\fR=\fISERVER\fR
+URL of the RHEV\-M server to connect to
+.TP
+\fB\-\-rhevm\-username\fR=\fIUSERNAME\fR
+Username for connecting to RHEV\-M
+.TP
+\fB\-\-rhevm\-password\fR=\fIPASSWORD\fR
+Password for connecting to RHEV\-M
+.PP
.SH ENVIRONMENT
virt-who also reads environmental variables. They have the same name as command line arguments but upper-cased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled
.SH USAGE
@@ -97,6 +120,13 @@ Use vdsm as virtualization backend.
Use ESX (vCenter) as virtualization backend and specify option required to connect to ESX server.
+.TP
+4. RHEV-M
+
+# virt-who --rhevm --rhevm-owner=RHEVM_OWNER --rhevm-env=RHEVM_ENV --rhevm-server=RHEVM_SERVER --rhevm-username=RHEVM_USERNAME --rhevm-password=RHEVM_PASSWORD
+
+Use RHEV-M as virtualization backend and specify option required to connect to RHEV-M server.
+
.SH LOGGING
virt-who always writes error output to file /var/log/rhsm/rhsm.log. In all modes, excluding background ("-b"), it writes same output also to the standard error output.
11 years, 7 months
[virt-who] Add virt-who man page
by Radek Novacek
commit 7fb269d2cdefd7718fa491474767e2d8eb0f4b86
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 17 14:16:48 2012 +0200
Add virt-who man page
Makefile | 4 ++-
virt-who.8 | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
virt-who.spec | 1 +
3 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/Makefile b/Makefile
index a3e89ce..0d0d861 100644
--- a/Makefile
+++ b/Makefile
@@ -13,11 +13,13 @@ check:
pyflakes *.py
install:
- install -d $(DESTDIR)/usr/share/$(name)/ $(DESTDIR)/usr/bin $(DESTDIR)/etc/rc.d/init.d $(DESTDIR)/etc/sysconfig
+ install -d $(DESTDIR)/usr/share/$(name)/ $(DESTDIR)/usr/bin $(DESTDIR)/etc/rc.d/init.d $(DESTDIR)/etc/sysconfig $(DESTDIR)/usr/share/man/man8/
install -pm 0644 *.py $(DESTDIR)/usr/share/$(name)/
install virt-who $(DESTDIR)/usr/bin/
install virt-who-initscript $(DESTDIR)/etc/rc.d/init.d/virt-who
install -pm 0644 virt-who.conf $(DESTDIR)/etc/sysconfig/virt-who
+ gzip -c virt-who.8 > virt-who.8.gz
+ install virt-who.8.gz $(DESTDIR)/usr/share/man/man8/
srpm: pack
rpmbuild --define "_sourcedir $(PWD)" --define "_specdir $(PWD)" --define "_srcrpmdir $(PWD)" -bs $(name).spec
diff --git a/virt-who.8 b/virt-who.8
new file mode 100644
index 0000000..5b21062
--- /dev/null
+++ b/virt-who.8
@@ -0,0 +1,106 @@
+.TH VIRT-WHO "8" "September 2012" "virt-who"
+.SH NAME
+virt-who - Agent for reporting virtual guest IDs to Subscription Asset Manager.
+.SH SYNOPSIS
+virt-who [-d] [-i INTERVAL] [-b] [-o] [--libvirt|--vdsm|--esx]
+.SH OPTIONS
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+show this help message and exit
+.TP
+\fB\-d\fR, \fB\-\-debug\fR
+Enable debugging output
+.TP
+\fB\-b\fR, \fB\-\-background\fR
+Run in the background and monitor virtual guests
+.TP
+\fB\-o\fR, \fB\-\-one\-shot\fR
+Send the list of guest IDs and exit immediately
+.TP
+\fB\-i\fR INTERVAL, \fB\-\-interval\fR=\fIINTERVAL\fR
+Acquire and send list of virtual guest each N seconds
+.TP
+\fB\-\-libvirt\fR
+Use libvirt to list virtual guests [default]
+.TP
+\fB\-\-vdsm\fR
+Use vdsm to list virtual guests
+.TP
+\fB\-\-esx\fR
+Register ESX machines using vCenter
+.SS vCenter/ESX options
+.TP
+Use this options with \fB\-\-esx\fR
+.TP
+\fB\-\-esx\-owner\fR=\fIOWNER\fR
+Organization who has purchased subscriptions of the products
+.TP
+\fB\-\-esx\-env\fR=\fIENV\fR
+Environment where the vCenter server belongs to
+.TP
+\fB\-\-esx\-server\fR=\fISERVER\fR
+URL of the vCenter server to connect to
+.TP
+\fB\-\-esx\-username\fR=\fIUSERNAME\fR
+Username for connecting to vCenter
+.TP
+\fB\-\-esx\-password\fR=\fIPASSWORD\fR
+Password for connecting to vCenter
+
+.SH ENVIRONMENT
+virt-who also reads environmental variables. They have the same name as command line arguments but upper-cased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled
+.SH USAGE
+.SS MODE
+virt-who has three modes how it can run:
+.TP
+1. one-shot mode
+# virt-who -o
+
+In this mode virt-who just sends list of guest UUIDs to the server and exits.
+.TP
+2. interval mode
+# virt-who
+
+This is default mode. virt-who will check and send list of guest UUIDs once per hour. This interval can be changed using "-i INTERVAL" option where INTERVAL is number of seconds how often it should check and send the list.
+.TP
+3. background mode
+# virt-who -b
+
+This mode is similar to interval mode but it monitors events from libvirt and update list of guest UUIDs as soon as possible. It also does the interval check (interval can be altered by "-i INTERVAL" option).
+.IP
+NOTE: virt-who don't print anything to terminal in this mode
+.IP
+NOTE: monitoring for events requires libvirt backend, but this mode can be used with all backends.
+
+.SS BACKEND
+
+virt-who can use couple of virtualization backends.
+.TP
+1. libvirt
+# virt-who
+
+# virt-who --libvirt
+
+Use libvirt as virtualization backend. This is default.
+.IP
+
+NOTE: virt-who can monitor for events only in this mode.
+.TP
+2. vdsm
+# virt-who --vdsm
+
+Use vdsm as virtualization backend.
+.TP
+3. ESX
+
+# virt-who --esx --esx-owner=ESX_OWNER --esx-env=ESX_ENV --esx-server=ESX_SERVER --esx-username=ESX_USERNAME --esx-password=ESX_PASSWORD
+
+Use ESX (vCenter) as virtualization backend and specify option required to connect to ESX server.
+
+.SH LOGGING
+virt-who always writes error output to file /var/log/rhsm/rhsm.log. In all modes, excluding background ("-b"), it writes same output also to the standard error output.
+
+virt-who can be started with option "-d" in all modes and with all backends. This option will enable verbose output with more information.
+
+.SH AUTHOR
+Radek Novacek <rnovacek at redhat dot com>
diff --git a/virt-who.spec b/virt-who.spec
index d403d62..c299a77 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -66,6 +66,7 @@ fi
%{_datadir}/virt-who/
%{_sysconfdir}/rc.d/init.d/virt-who
%config(noreplace) %{_sysconfdir}/sysconfig/virt-who
+%{_mandir}/man8/virt-who.8.gz
%changelog
11 years, 7 months
[virt-who] Add support for RHEV-M server (same as ESX)
by Radek Novacek
commit 856e010326ca6ce7c674b628a34196cf4f1f2601
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Fri Sep 14 13:17:37 2012 +0200
Add support for RHEV-M server (same as ESX)
Also add missing license headers to vsphere.py
rhevm.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
virt-who.conf | 11 +++++-
virt-who.py | 61 ++++++++++++++++++++++-----------
vsphere.py | 23 ++++++++++++
4 files changed, 178 insertions(+), 22 deletions(-)
---
diff --git a/rhevm.py b/rhevm.py
new file mode 100644
index 0000000..188c4fa
--- /dev/null
+++ b/rhevm.py
@@ -0,0 +1,105 @@
+"""
+Module for communcating with RHEV-M, part of virt-who
+
+Copyright (C) 2012 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+import sys
+import urlparse
+import urllib2
+import base64
+
+# Import XML parser
+try:
+ from elementtree import ElementTree
+except ImportError:
+ from xml.etree import ElementTree
+
+class RHEVM:
+ def __init__(self, logger, url, username, password):
+ self.logger = logger
+ self.url = url
+ if "//" not in self.url:
+ self.url = "//" + url
+ parsed = urlparse.urlsplit(self.url, "https")
+ if ":" not in parsed[1]:
+ netloc = parsed[1] + ":8443"
+ else:
+ netloc = parsed[1]
+ self.url = urlparse.urlunsplit((parsed[0], netloc, parsed[2], "", ""))
+
+ self.username = username
+ self.password = password
+
+ self.hosts_url = urlparse.urljoin(self.url, "/api/hosts")
+ self.vms_url = urlparse.urljoin(self.url, "/api/vms")
+
+ self.auth = base64.encodestring('%s:%s' % (username, password))[:-1]
+
+ def get(self, url):
+ """
+ Call RHEV-M server and retrieve what's on given url.
+ """
+ request = urllib2.Request(url)
+ request.add_header("Authorization", "Basic %s" % self.auth)
+ return urllib2.urlopen(request)
+
+ def getHostGuestMapping(self):
+ """
+ Returns dictionary with host to guest mapping, e.g.:
+
+ { 'host_id_1': ['guest1', 'guest2'],
+ 'host_id_2': ['guest3', 'guest4'],
+ }
+ """
+ mapping = {}
+
+ hosts_xml = ElementTree.parse(self.get(self.hosts_url))
+ vms_xml = ElementTree.parse(self.get(self.vms_url))
+
+ for host in hosts_xml.findall('host'):
+ id = host.get('id')
+ mapping[id] = []
+
+ for vm in vms_xml.findall('vm'):
+ guest_id = vm.get('id')
+ host = vm.find('host')
+ if host is None:
+ # Guest don't have any host
+ continue
+
+ host_id = host.get('id')
+ if host_id not in mapping.keys():
+ self.logger.warning("Guest %s claims that it belongs to host %s which doen't exist" % (guest_id, host_id))
+ else:
+ mapping[host_id].append(guest_id)
+
+ return mapping
+
+ def ping(self):
+ return True
+
+if __name__ == '__main__':
+ # TODO: read from config
+ if len(sys.argv) < 4:
+ print "Usage: %s url username password"
+ sys.exit(0)
+
+ import logging
+ logger = logging.Logger("")
+ rhevm = RHEVM(logger, sys.argv[1], sys.argv[2], sys.argv[3])
+ rhevm.getHostGuestMapping()
diff --git a/virt-who.conf b/virt-who.conf
index 4d4f5a4..043b695 100644
--- a/virt-who.conf
+++ b/virt-who.conf
@@ -18,13 +18,15 @@ VIRTWHO_DEBUG=0
# configuration.
#VIRTWHO_INTERVAL=0
-# virt-who mode, enable only one option from following 3:
+# virt-who mode, enable only one option from following 4:
# 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
+# Register guests using RHEV-M
+#VIRTWHO_RHEVM=0
# Option for ESX mode
#VIRTWHO_ESX_OWNER=
@@ -32,3 +34,10 @@ VIRTWHO_DEBUG=0
#VIRTWHO_ESX_SERVER=
#VIRTWHO_ESX_USERNAME=
#VIRTWHO_ESX_PASSWORD=
+
+# Options for RHEV-M mode
+#VIRTWHO_RHEVM_OWNER=
+#VIRTWHO_RHEVM_ENV=
+#VIRTWHO_RHEVM_SERVER=
+#VIRTWHO_RHEVM_USERNAME=
+#VIRTWHO_RHEVM_PASSWORD=
diff --git a/virt-who.py b/virt-who.py
index b4b481b..44f4088 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -27,6 +27,7 @@ import signal
from virt import Virt, VirtError
from vdsm import VDSM
from vsphere import VSphere
+from rhevm import RHEVM
from event import virEventLoopPureStart
from subscriptionmanager import SubscriptionManager, SubscriptionManagerError
@@ -95,9 +96,11 @@ class VirtWho(object):
self.virt = Virt(self.logger, registerEvents=self.options.background)
# We can listen for libvirt events
self.tryRegisterEventCallback()
+ elif self.options.virtType == "rhevm":
+ self.virt = RHEVM(self.logger, self.options.server, self.options.username, self.options.password)
else:
# ESX
- self.virt = VSphere(self.logger, self.options.esx_server, self.options.esx_username, self.options.esx_password)
+ self.virt = VSphere(self.logger, self.options.server, self.options.username, self.options.password)
def initSM(self):
"""
@@ -168,7 +171,7 @@ class VirtWho(object):
return False
try:
- if self.options.virtType != "esx":
+ if self.options.virtType not in ["esx", "rhevm"]:
virtualGuests = self.virt.listDomains()
else:
virtualGuests = self.virt.getHostGuestMapping()
@@ -184,10 +187,10 @@ class VirtWho(object):
return False
try:
- if self.options.virtType != "esx":
+ if self.options.virtType not in ["esx", "rhevm"]:
self.subscriptionManager.sendVirtGuests(virtualGuests)
else:
- result = self.subscriptionManager.hypervisorCheckIn(self.options.esx_owner, self.options.esx_env, virtualGuests)
+ result = self.subscriptionManager.hypervisorCheckIn(self.options.owner, self.options.env, virtualGuests)
# Show the result of hypervisorCheckIn
for fail in result['failedUpdate']:
@@ -317,15 +320,23 @@ def main():
parser.add_option("--libvirt", action="store_const", dest="virtType", const="libvirt", default="libvirt", help="Use libvirt to list virtual guests [default]")
parser.add_option("--vdsm", action="store_const", dest="virtType", const="vdsm", help="Use vdsm to list virtual guests")
parser.add_option("--esx", action="store_const", dest="virtType", const="esx", help="Register ESX machines using vCenter")
+ parser.add_option("--rhevm", action="store_const", dest="virtType", const="rhevm", help="Register guests using RHEV-M")
esxGroup = OptionGroup(parser, "vCenter/ESX options", "Use this options with --esx")
- esxGroup.add_option("--esx-owner", action="store", dest="esx_owner", default="", help="Organization who has purchased subscriptions of the products")
- esxGroup.add_option("--esx-env", action="store", dest="esx_env", default="", help="Environment where the vCenter server belongs to")
- esxGroup.add_option("--esx-server", action="store", dest="esx_server", default="", help="URL of the vCenter server to connect to")
- esxGroup.add_option("--esx-username", action="store", dest="esx_username", default="", help="Username for connecting to vCenter")
- esxGroup.add_option("--esx-password", action="store", dest="esx_password", default="", help="Password for connecting to vCenter")
+ esxGroup.add_option("--esx-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products")
+ esxGroup.add_option("--esx-env", action="store", dest="env", default="", help="Environment where the vCenter server belongs to")
+ esxGroup.add_option("--esx-server", action="store", dest="server", default="", help="URL of the vCenter server to connect to")
+ esxGroup.add_option("--esx-username", action="store", dest="username", default="", help="Username for connecting to vCenter")
+ esxGroup.add_option("--esx-password", action="store", dest="password", default="", help="Password for connecting to vCenter")
parser.add_option_group(esxGroup)
+ rhevmGroup = OptionGroup(parser, "RHEV-M options", "Use this options with --rhevm")
+ rhevmGroup.add_option("--rhevm-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products")
+ rhevmGroup.add_option("--rhevm-env", action="store", dest="env", default="", help="Environment where the RHEV-M belongs to")
+ rhevmGroup.add_option("--rhevm-server", action="store", dest="server", default="", help="URL of the RHEV-M server to connect to")
+ rhevmGroup.add_option("--rhevm-username", action="store", dest="username", default="", help="Username for connecting to RHEV-M")
+ rhevmGroup.add_option("--rhevm-password", action="store", dest="password", default="", help="Password for connecting to RHEV-M")
+ parser.add_option_group(rhevmGroup)
(options, args) = parser.parse_args()
@@ -360,6 +371,10 @@ def main():
if env in ["1", "true"]:
options.virtType = "esx"
+ env = os.getenv("VIRTWHO_RHEVM", "0").strip().lower()
+ if env in ["1", "true"]:
+ options.virtType = "rhevm"
+
def checkEnv(variable, option, name):
"""
If `option` is empty, check enviromental `variable` and return its value.
@@ -368,21 +383,25 @@ def main():
if len(option) == 0:
option = os.getenv(variable, "").strip()
if len(option) == 0:
- logger.error("Required parameter '%s' for vCenter is not set, exitting" % name)
+ logger.error("Required parameter '%s' is not set, exitting" % name)
sys.exit(1)
return option
if options.virtType == "esx":
- options.esx_owner = checkEnv("VIRTWHO_ESX_OWNER", options.esx_owner, "owner")
- options.esx_env = checkEnv("VIRTWHO_ESX_ENV", options.esx_env, "env")
- options.esx_server = checkEnv("VIRTWHO_ESX_SERVER", options.esx_server, "server")
- options.esx_username = checkEnv("VIRTWHO_ESX_USERNAME", options.esx_username, "username")
- if len(options.esx_password) == 0:
- options.esx_password = os.getenv("VIRTWHO_ESX_PASSWORD", "")
-
- # Url must contain protocol (usualy https://)
- if not "://" in options.esx_server:
- options.esx_server = "https://%s" % options.esx_server
+ options.owner = checkEnv("VIRTWHO_ESX_OWNER", options.owner, "owner")
+ options.env = checkEnv("VIRTWHO_ESX_ENV", options.env, "env")
+ options.server = checkEnv("VIRTWHO_ESX_SERVER", options.server, "server")
+ options.username = checkEnv("VIRTWHO_ESX_USERNAME", options.username, "username")
+ if len(options.password) == 0:
+ options.password = os.getenv("VIRTWHO_ESX_PASSWORD", "")
+
+ if options.virtType == "rhevm":
+ options.owner = checkEnv("VIRTWHO_RHEVM_OWNER", options.owner, "owner")
+ options.env = checkEnv("VIRTWHO_RHEVM_ENV", options.env, "env")
+ options.server = checkEnv("VIRTWHO_RHEVM_SERVER", options.server, "server")
+ options.username = checkEnv("VIRTWHO_RHEVM_USERNAME", options.username, "username")
+ if len(options.password) == 0:
+ options.password = os.getenv("VIRTWHO_RHEVM_PASSWORD", "")
if options.interval < 0:
logger.warning("Interval is not positive number, ignoring")
@@ -410,7 +429,7 @@ def main():
logger.debug("Starting event loop")
virEventLoopPureStart()
else:
- logger.warning("Listening for events is not available in VDSM or ESX mode")
+ logger.warning("Listening for events is not available in VDSM, ESX or RHEV-M mode")
global RetryInterval
if options.interval < RetryInterval:
diff --git a/vsphere.py b/vsphere.py
index 5441216..3dffca9 100644
--- a/vsphere.py
+++ b/vsphere.py
@@ -1,3 +1,22 @@
+"""
+Module for communcating with vCenter/ESX, part of virt-who
+
+Copyright (C) 2012 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
import sys
import suds
@@ -90,6 +109,10 @@ class VSphere:
self.logger = logger
self.url = url
+ # Url must contain protocol (usualy https://)
+ if not "://" in self.url:
+ self.url = "https://%s" % self.url
+
# Connect to the vCenter server
self.client = suds.client.Client("%s/sdk/vimService.wsdl" % url)
11 years, 7 months
[virt-who] Use RetrievePropertiesEx instead of RetrieveProperties by default
by Radek Novacek
commit ea9a929d8e8c2aae0b421161ec59fd35830e8eb9
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Thu Sep 13 14:12:45 2012 +0200
Use RetrievePropertiesEx instead of RetrieveProperties by default
vsphere.py | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/vsphere.py b/vsphere.py
index 4f3552c..5441216 100644
--- a/vsphere.py
+++ b/vsphere.py
@@ -125,8 +125,16 @@ class VSphere:
ts.type = 'ComputeResource'
ts.pathSet = 'name'
ts.all = True
- object_content = self.client.service.RetrieveProperties(_this=self.sc.propertyCollector,
- specSet=[get_search_filter_spec(self.client, self.sc.rootFolder, [ts])])
+ try:
+ retrieve_result = self.client.service.RetrievePropertiesEx(_this=self.sc.propertyCollector,
+ specSet=[get_search_filter_spec(self.client, self.sc.rootFolder, [ts])])
+ if retrieve_result is None:
+ object_content = []
+ else:
+ object_content = retrieve_result[0]
+ except suds.MethodNotFound:
+ object_content = self.client.service.RetrieveProperties(_this=self.sc.propertyCollector,
+ specSet=[get_search_filter_spec(self.client, self.sc.rootFolder, [ts])])
# Get properties of each cluster
clusterObjs = [] # List of objs for 'ComputeResource' query
@@ -217,7 +225,14 @@ class VSphere:
pfs.objectSet = objectSets
# Query the VSphere server
- return self.client.service.RetrieveProperties(_this=self.sc.propertyCollector, specSet=[pfs])
+ try:
+ retrieve_result = self.client.service.RetrievePropertiesEx(_this=self.sc.propertyCollector, specSet=[pfs])
+ if retrieve_result is None:
+ return []
+ else:
+ return retrieve_result[0]
+ except suds.MethodNotFound:
+ return self.client.service.RetrieveProperties(_this=self.sc.propertyCollector, specSet=[pfs])
def getHostGuestMapping(self):
"""
11 years, 7 months
[virt-who] Fix crash when running virt-who in interval mode
by Radek Novacek
commit a1646f81185cabc287e23026b7ab5c0865453219
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 3 10:25:41 2012 +0200
Fix crash when running virt-who in interval mode
virt-who.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 7faaa17..b4b481b 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -92,7 +92,7 @@ class VirtWho(object):
if self.options.virtType == "vdsm":
self.virt = VDSM(self.logger)
elif self.options.virtType == "libvirt":
- self.virt = Virt(self.logger, registerEvents=not self.options.oneshot)
+ self.virt = Virt(self.logger, registerEvents=self.options.background)
# We can listen for libvirt events
self.tryRegisterEventCallback()
else:
11 years, 7 months
[virt-who] Fix formatting of string
by Radek Novacek
commit 425f7e159a989c1d070eeb084e654a310e9ea3c0
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 3 09:12:10 2012 +0200
Fix formatting of string
subscriptionmanager.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/subscriptionmanager.py b/subscriptionmanager.py
index 4ca98dc..6dc2482 100644
--- a/subscriptionmanager.py
+++ b/subscriptionmanager.py
@@ -98,7 +98,7 @@ class SubscriptionManager:
certificate = rhsm_certificate.create_from_file(self.cert_file)
self.cert_uuid = certificate.subject["CN"]
except Exception, e:
- raise SubscriptionManagerError("Unable to open certificate %s (%s):" % self.cert_file, str(e))
+ raise SubscriptionManagerError("Unable to open certificate %s (%s):" % (self.cert_file, str(e)))
return self.cert_uuid
def getFacts(self):
11 years, 7 months