updates and fixes version 0.1.7.1
authorJens Kasten <jens@kasten-edv.de>
Wed, 23 Nov 2011 20:02:56 +0100
changeset 61 abba9906ca66
parent 60 70e7bfc80074
child 62 8525f85ce3ae
updates and fixes
bin/kvm-admin
kvmtools/config/parser.py
kvmtools/kvm/action.py
kvmtools/kvm/build_config.py
kvmtools/kvm/monitor.py
kvmtools/kvm/system.py
setup.py
--- a/bin/kvm-admin	Wed Nov 23 05:22:14 2011 +0100
+++ b/bin/kvm-admin	Wed Nov 23 20:02:56 2011 +0100
@@ -44,6 +44,7 @@
     def __init__(self):
         Action.__init__(self)
         self._args_value = None
+        self.debug = False
 
     def run(self):
         """Do an action for a domain.
@@ -108,6 +109,7 @@
         parser.error(_("Available domains: %s") % domains)
     kvm_admin.action = args.action
     kvm_admin.monitor = args.monitor
+    kvm_admin.debug = args.debug
     if not args.action == "modify" and kvm_admin.show_error() :
         sys.exit(1)
     if args.debug:
--- a/kvmtools/config/parser.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/kvmtools/config/parser.py	Wed Nov 23 20:02:56 2011 +0100
@@ -102,13 +102,15 @@
     def merge_configs(self, config_one, config_two):
         """Merge two configs into a single one without duplications."""
         config = {}
-        if not config_one or not config_two:
-            return
+        if not config_one and not config_two:
+            return {}
+        if config_one and not config_two:
+            return config_none
+        if not config_one and config_two:
+            return config_two
         for key, value in config_one.iteritems():
             config[key] = value
         for key in config_two.keys():
             if key not in config_one:
                 config[key] = config_two[key]
         return config
-
-
--- a/kvmtools/kvm/action.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/kvmtools/kvm/action.py	Wed Nov 23 20:02:56 2011 +0100
@@ -148,13 +148,14 @@
             print ("Guest is not running.")
             return False
         self.get_process_information()
-        print "Process name: %s" % self.kvm_process_name
-        print "%s" % self.kvm_process_status
-        print "Domain uuid: %s" % self.kvm_process_uuid
-        print "Process state: %s" % self.kvm_process_state
+        print ("Process name: %s" % self.kvm_process_name)
+        print ("Domain uuid:  %s" % self.kvm_process_uuid)
+        print ("%s :: Process state: %s" % (self.kvm_process_status,
+            self.kvm_process_state))
         print "UID: %s" % self.kvm_process_uid
         print "GID: %s" % self.kvm_process_gid
         print "Groups: %s" % self.kvm_process_groups
         print "PID: %s :: PPID: %s" % (self.kvm_process_pid, 
             self.kvm_process_ppid)
-        print "VNC: %s" % self.kvm_process_vnc
+        print ("VNC information")
+        print self.kvm_process_vnc
--- a/kvmtools/kvm/build_config.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/kvmtools/kvm/build_config.py	Wed Nov 23 20:02:56 2011 +0100
@@ -26,8 +26,6 @@
         kvm_conf_file = self.parse_config(self.kvm_conf_file)
         kvm_domain_file = self.parse_config(self.kvm_domain_file)
         self.config = self.merge_configs(kvm_conf_file, kvm_domain_file)
-        if not self.config:
-            return None
         self._add_name()
         self._add_uuid()
         self._add_pidfile()
@@ -45,7 +43,7 @@
     def _add_uuid(self):
         """Append an unique uuid to the config dictionary."""
         if "uuid" in self.config:
-            check_uid = re.match(r"([a-z,A-z,0-9]{8})-([a-z,A-Z,0-9]{4})-([a-z,A-Z,0-9]{4})-([a-z,A-Z,0-9]{4})-([a-z,A-Z,0-9]{12})", self.config["uuid"])
+            check_uid = re.match(r"([a-f,A-F,0-9]{8})-([a-f,A-F,0-9]{4})-([a-f,A-F,0-9]{4})-([a-f,A-F,0-9]{4})-([a-f,A-F,0-9]{12})", self.config["uuid"])
             if not check_uid:
                 msg = "Your uuid has wrong format, you can delete it, the script does generate a correct new one."
                 self.kvm_error(msg)
@@ -60,8 +58,9 @@
         twelve =  "".join(random.sample(charset, 12))
         uuid = "-".join([eight, four_first, four_second, four_third, twelve])
         # inster the uuid into domain config file if it not exists
-        with open(self.kvm_domain_file, "a+") as fd:
-            fd.write("uuid = %s\t# autogenerted and instert from script\n" % uuid)
+        if os.path.isfile(self.kvm_domain_file) and os.access(self.kvm_domain_file, os.W_OK):
+            with open(self.kvm_domain_file, "a+") as fd:
+                fd.write("uuid = %s\t# autogenerated and insert from script\n" % uuid)
         self.config["uuid"] = uuid
 
     def _add_name(self):
--- a/kvmtools/kvm/monitor.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/kvmtools/kvm/monitor.py	Wed Nov 23 20:02:56 2011 +0100
@@ -47,8 +47,9 @@
             try:
                 self.socket.connect(self.kvm_socketfile)
                 self.socket_status = True
-            except socket.error:
-                return False      
+            except socket.error, error_msg:
+                if self.debug:
+                    self.kvm_error(error_msg)
         else:
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             try:
--- a/kvmtools/kvm/system.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/kvmtools/kvm/system.py	Wed Nov 23 20:02:56 2011 +0100
@@ -46,8 +46,7 @@
         """Return vnc info."""
         self.monitor_send("info vnc")
         vnc = self.monitor_recieve()
-        vnc = "\n".join(vnc)
-        self.kvm_process_vnc = vnc
+        self.kvm_process_vnc = "\n".join(vnc)
 
     def _get_uuid(self):
         """Return the guest uuid."""
--- a/setup.py	Wed Nov 23 05:22:14 2011 +0100
+++ b/setup.py	Wed Nov 23 20:02:56 2011 +0100
@@ -41,7 +41,7 @@
 
 setup(
     name = "kvmtools",
-    version = "0.1.6.4",
+    version = "0.1.7",
     keywords = ["kvm-admin", "kvmtools"],
     author = "Jens Kasten",
     author_email = "jens@kasten-edv.de",