[virt-who] Fix traceback when no guest exists.
by Radek Novacek
commit f12f4b173b233e038335e492175e7609ee8e1547
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Fri Jan 20 09:32:38 2012 +0100
Fix traceback when no guest exists.
Also add some checks to prevent failure when there is no host on cluster
or no guest on host.
vsphere.py | 37 +++++++++++++++++++++++++++----------
1 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/vsphere.py b/vsphere.py
index 569f818..4f3552c 100644
--- a/vsphere.py
+++ b/vsphere.py
@@ -136,17 +136,27 @@ class VSphere:
self.clusters[cluster.obj.value] = Cluster(propSet.val)
clusterObjs.append(cluster.obj)
+ if len(clusterObjs) == 0:
+ return
+
# Get list of hosts from cluster
object_contents = self.RetrieveProperties('ComputeResource', ['host'], clusterObjs)
hostObjs = [] # List of objs for 'HostSystem' query
for cluster in object_contents:
for propSet in cluster.propSet:
if propSet.name == 'host':
- for host in propSet.val.ManagedObjectReference:
- h = Host()
- self.hosts[host.value] = h
- self.clusters[cluster.obj.value].hosts.append(h)
- hostObjs.append(host)
+ try:
+ for host in propSet.val.ManagedObjectReference:
+ h = Host()
+ self.hosts[host.value] = h
+ self.clusters[cluster.obj.value].hosts.append(h)
+ hostObjs.append(host)
+ except AttributeError:
+ # This means that there is no host on given cluster
+ pass
+
+ if len(hostObjs) == 0:
+ return
# Get list of host uuids, names and virtual machines
object_contents = self.RetrieveProperties('HostSystem', ['vm', 'hardware'], hostObjs)
@@ -156,11 +166,18 @@ class VSphere:
if propSet.name == "hardware":
self.hosts[host.obj.value].uuid = propSet.val.systemInfo.uuid
elif propSet.name == "vm":
- for vm in propSet.val.ManagedObjectReference:
- vmObjs.append(vm)
- v = VM()
- self.vms[vm.value] = v
- self.hosts[host.obj.value].vms.append(v)
+ try:
+ for vm in propSet.val.ManagedObjectReference:
+ vmObjs.append(vm)
+ v = VM()
+ self.vms[vm.value] = v
+ self.hosts[host.obj.value].vms.append(v)
+ except AttributeError:
+ # This means that there is no guest on given host
+ pass
+
+ if len(vmObjs) == 0:
+ return
# Get list of virtual machine uuids
object_contents = self.RetrieveProperties('VirtualMachine', ['config'], vmObjs)
12 years, 3 months
[virt-who] Assume using https protocol when not given
by Radek Novacek
commit ec3a17834c2c45f9d053590085177fda1fe977ac
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Jan 11 17:47:29 2012 +0100
Assume using https protocol when not given
virt-who.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index f2aaf0b..ce5ce2e 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -265,6 +265,10 @@ if __name__ == '__main__':
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
+
if options.interval < 0:
logger.warning("Interval is not positive number, ignoring")
options.interval = 0
12 years, 3 months
[virt-who] Make the password for ESX not mandatory
by Radek Novacek
commit a3fd0061fffcc7501c2b48bb89f4f8293e343f93
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Jan 11 17:42:40 2012 +0100
Make the password for ESX not mandatory
virt-who.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 21ad083..f2aaf0b 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -262,7 +262,8 @@ if __name__ == '__main__':
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")
- options.esx_password = checkEnv("VIRTWHO_ESX_PASSWORD", options.esx_password, "password")
+ if len(options.esx_password) == 0:
+ options.esx_password = os.getenv("VIRTWHO_ESX_PASSWORD", "")
if options.interval < 0:
logger.warning("Interval is not positive number, ignoring")
12 years, 3 months