make it backward compatible
authorJens Kasten <jens@kasten-edv.de>
Mon, 19 Mar 2012 04:17:51 +0100
changeset 86 6de509143aea
parent 85 558997826ae7
child 87 228ce8fbd4ff
make it backward compatible
kvmtools/kvm/system.py
--- a/kvmtools/kvm/system.py	Mon Mar 19 04:17:17 2012 +0100
+++ b/kvmtools/kvm/system.py	Mon Mar 19 04:17:51 2012 +0100
@@ -49,8 +49,14 @@
     def get_pid(self):
         """Set pif if pidfile is available"""
         if os.path.isfile(self.kvm_pidfile):
-            with open(self.kvm_pidfile) as fd:
+            try:
+                fd = open(self.kvm_pidfile)
                 self.kvm_pid = int(fd.readline().strip())
+            except IOError, e:
+                print "Operation failed: %s" % e
+            finally:
+                if fd:
+                    fd.close()
 
     def _get_vnc(self):
         """Return vnc info."""
@@ -72,8 +78,14 @@
 
     def _get_process_info(self):
         """Collect information from proc."""
-        with open(os.path.join("/proc", "%d/status" % self.kvm_pid)) as fd:
+        try:
+            fd = open(os.path.join("/proc", "%d/status" % self.kvm_pid))
             lines = [line.strip().split(':') for line in fd.readlines()]
+        except IOError, e:
+            print "Operation failed: %s" % e
+        finally:    
+            if fd:
+                fd.close()
         for i in lines:
             name = "kvm_process_" + i[0].strip().lower()
             value = i[1].strip("\t").strip()