[virt-who] libvirt domain instance might not have state method
by Radek Novacek
commit 433ccc155c12f4f6c4ace049ad591f065098d6d5
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Thu May 22 10:55:00 2014 +0200
libvirt domain instance might not have state method
virt.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/virt.py b/virt.py
index f7bb3a8..0fc1920 100644
--- a/virt.py
+++ b/virt.py
@@ -34,7 +34,11 @@ class Domain(dict):
}
if domain.isActive():
self['attributes']['active'] = 1
- self['state'] = domain.state(0)[0]
+ try:
+ self['state'] = domain.state(0)[0]
+ except AttributeError:
+ # Some versions of libvirt doesn't have domain.state() method
+ pass
class Virt:
""" Class for interacting with libvirt. """
10 years
[virt-who] Fix incompatibility with python 2.4
by Radek Novacek
commit 67a947545a781677128037e57d041af9408e3543
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Thu May 22 09:42:50 2014 +0200
Fix incompatibility with python 2.4
virt.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/virt.py b/virt.py
index cb20d71..f7bb3a8 100644
--- a/virt.py
+++ b/virt.py
@@ -30,8 +30,10 @@ class Domain(dict):
self['attributes'] = {
'hypervisorType': virt.getType(),
'virtWhoType': "libvirt",
- 'active': 1 if domain.isActive() else 0
+ 'active': 0
}
+ if domain.isActive():
+ self['attributes']['active'] = 1
self['state'] = domain.state(0)[0]
class Virt:
10 years