[et-mgmt-tools] [PATCH][RFC] Add --keymap option to virt-install

Takahashi Tomohiro takatom at jp.fujitsu.com
Thu Mar 8 12:14:19 UTC 2007


Hi,

Previously I tested keymap patch on virt-inst which was already posted.
Today I test the patch on virt-manager.Then I found a bug.
This patch fixes this problem.

I would like to post an update patch. Because I caught a bug in keymap patch
that I had posted on March 6. Errors did happen, when I used virt-manager.
Because It doesn't have a function for keymap.

virtmanager does not have keymap setting function.
So I add a check "keymap" exists or not.


Please refer to following error message.

Traceback (most recent call last):
  File "/usr/local/share/virt-manager/virtManager/create.py", line 508, in 
finish
    guest.graphics = "vnc"
  File "/usr/lib/python2.5/site-packages/virtinst/Guest.py", line 414, in 
set_graphics
    gt = VNCVirtualGraphics(opts, self._graphics["keymap"])
KeyError: 'keymap'

The difference is following in virtinst/Guest.py.
modification:
===FIXED====
@@ -386,7 +411,10 @@ class Guest(object):

         if self._graphics["enabled"] == True:
             if t == "vnc":
-                gt = VNCVirtualGraphics(opts)
+                if self.graphics.has_key("keymap"):
+                    gt = VNCVirtualGraphics(opts, self._graphics["keymap"])
+                else:
+                    gt = VNCVirtualGraphics(opts)
             elif t == "sdl":
                 gt = SDLVirtualGraphics(opts)
             else:

===BEFORE===
@@ -386,7 +411,7 @@ class Guest(object):

         if self._graphics["enabled"] == True:
             if t == "vnc":
-                gt = VNCVirtualGraphics(opts)
+                gt = VNCVirtualGraphics(opts, self._graphics["keymap"])
             elif t == "sdl":
                 gt = SDLVirtualGraphics(opts)
             else:
==========

Signed-off-by: Tomohiro Takahashi <takatom at jp.fujitsu.com>

Thanks,
Tomohiro Takahashi.

===================================================================
diff -uNrp virtinst-0.101.0.orig/virt-install virtinst-0.101.0/virt-install
--- virtinst-0.101.0.orig/virt-install 2007-03-05 21:29:44.000000000 +0900
+++ virtinst-0.101.0/virt-install 2007-03-06 15:51:22.000000000 +0900
@@ -96,6 +96,13 @@ def get_vcpus(vcpus, guest):
         except ValueError, e:
             print "ERROR: ", e

+def get_keymap(keymap, guest):
+    if keymap:
+        try:
+            guest.keymap = keymap
+        except ValueError, e:
+            print "ERROR: ", e
+
 def get_disk(disk, size, sparse, guest, hvm):
     # FIXME: need to handle a list of disks at some point
     while 1:
@@ -160,14 +167,14 @@ def get_networks(macs, bridges, guest):
     else:
         get_network(macs, bridges, guest)

-def get_graphics(vnc, vncport, nographics, sdl, guest):
+def get_graphics(vnc, vncport, nographics, sdl, keymap, guest):
     if vnc and nographics:
         raise ValueError, "Can't do both VNC graphics and nographics"
     if nographics:
         guest.graphics = False
         return
     if vnc is not None:
-        guest.graphics = (True, "vnc", vncport)
+        guest.graphics = (True, "vnc", vncport, keymap)
         return
     if sdl is not None:
         guest.graphics = (True, "sdl")
@@ -180,7 +187,7 @@ def get_graphics(vnc, vncport, nographic
             print "ERROR", e
             continue
         if vnc:
-            guest.graphics = "vnc"
+            guest.graphics = (True, "vnc", vncport, keymap)
         else:
             guest.graphics = False
         break
@@ -256,6 +263,9 @@ def parse_args():
                       action="store_false", dest="autoconsole",
                       help="Don't automatically try to connect to the guest 
console")

+    parser.add_option("-k", "--keymap", type="string", dest="keymap",
+                      help="set up keymap for a graphical console")
+
     parser.add_option("", "--accelerate", action="store_true", 
dest="accelerate",
                       help="Use kernel acceleration capabilities")
     parser.add_option("", "--connect", type="string", dest="connect",
@@ -417,6 +427,7 @@ def main():
     get_memory(options.memory, guest)
     get_uuid(options.uuid, guest)
     get_vcpus(options.vcpus, guest)
+    get_keymap(options.keymap, guest)

     # set up disks
     get_disks(options.diskfile, options.disksize, options.sparse,
@@ -426,7 +437,7 @@ def main():
     get_networks(options.mac, options.bridge, guest)

     # set up graphics information
-    get_graphics(options.vnc, options.vncport, options.nographics, 
options.sdl, guest)
+    get_graphics(options.vnc, options.vncport, options.nographics, 
options.sdl, options.keymap, guest)

     # and now for the full-virt vs paravirt specific questions
     if not hvm: # paravirt
diff -uNrp virtinst-0.101.0.orig/virtinst/Guest.py 
virtinst-0.101.0/virtinst/Guest.py
--- virtinst-0.101.0.orig/virtinst/Guest.py   2007-03-05 21:29:44.000000000 
+0900
+++ virtinst-0.101.0/virtinst/Guest.py  2007-03-08 20:01:04.000000000 +0900
@@ -185,9 +185,17 @@ class VNCVirtualGraphics(XenGraphics):
             self.port = args[0]
         else:
             self.port = -1
+        if len(args) >= 2 and args[1]:
+            self.keymap = args[1]
+        else:
+            self.keymap = None

     def get_xml_config(self):
-        return "    <graphics type='vnc' port='%d'/>" % (self.port)
+        if self.keymap == None:
+            keymapstr = ""
+        else:
+            keymapstr = "keymap='"+self.keymap+"' "
+        return "    <graphics type='vnc' port='%(port)d' %(keymapstr)s/>" % 
{"port":self.port, "keymapstr":keymapstr}

 # Back compat class to avoid ABI break
 class XenVNCGraphics(VNCVirtualGraphics):
@@ -218,6 +226,7 @@ class Guest(object):
         self._maxmemory = None
         self._vcpus = None
         self._graphics = { "enabled": False }
+        self._keymap = None

         self.domain = None
         self.conn = connection
@@ -301,6 +310,21 @@ class Guest(object):
         self._vcpus = val
     vcpus = property(get_vcpus, set_vcpus)

+
+    # keymap for the guest
+    def get_keymap(self):
+        return self._keymap
+    def set_keymap(self, val):
+        if val and (re.match("^[a-zA-Z0-9_]*$", val) == None):
+            raise ValueError, "Keymap be alphanumeric or _"
+        if val and (len(val) > 16):
+            raise ValueError, "Keymap must be less than 16 characters"
+        if val and (type(val) != type("string")):
+            raise ValueError, "Keymap must be a string"
+        self._keymap = val
+    keymap = property(get_keymap, set_keymap)
+
+
     # kernel + initrd pair to use for installing as opposed to using a 
location
     def get_boot(self):
         return self._boot
@@ -374,6 +398,7 @@ class Guest(object):
             if len(val) >= 1: self._graphics["enabled"] = val[0]
             if len(val) >= 2: t = val[1]
             if len(val) >= 3: opts = val[2]
+            if len(val) >= 4: self._graphics["keymap"] = val[3]
         else:
             if val in ("vnc", "sdl"):
                 t = val
@@ -386,7 +411,10 @@ class Guest(object):

         if self._graphics["enabled"] == True:
             if t == "vnc":
-                gt = VNCVirtualGraphics(opts)
+                if self.graphics.has_key("keymap"):
+                    gt = VNCVirtualGraphics(opts, self._graphics["keymap"])
+                else:
+                    gt = VNCVirtualGraphics(opts)
             elif t == "sdl":
                 gt = SDLVirtualGraphics(opts)
             else:



> Hi, Dan
>
> Thank you for your comments.
> Please commit this keymap patch, if it hasn't problem.
>
> Thanks,
> Tomohiro Takahashi.
>
>> On Tue, Mar 06, 2007 at 09:59:16PM +0900, Takahashi Tomohiro wrote:
>>> Hi,
>>>
>>> I would like to add --keymap option to virt-install in order to set up
>>> jp106 keymap. Because I can't use jp106 keyboard. So, I made a patch
>>> (notes:It relates libvirt)
>>>
>>>  Usage: virt-install --keymap=ja
>>>
>>> I confirmed that I can use jp106 keyboard on HVM domain.
>>> But didn't confirm PV domain.
>>>
>>> Please give me an advice, if you have it.
>>
>> ACK. The patch looks fine to me.
>>
>> Regards,
>> Dan.
>> -- 
>> |=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 
>> 2496 -=|
>> |=-           Perl modules: .cpan.org/~danberr/              -=|
>> |=-               Projects: at.net/~danielpb/               -=|
>> |=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 
>> 05  -=|
>>
> 





More information about the et-mgmt-tools mailing list