@@ -302,57 +302,30 @@ def get_xml_string(dom, path):
302302 doc .freeDoc ()
303303 return None
304304
305- def vnc_console (dom ):
306- import time ;
307- num = 0
308- while num < ( 40 / 0.25 ): # 40 seconds, .25 second sleeps
309- vncport = get_xml_string (dom ,
310- "/domain/devices/graphics[@type='vnc']/@port" )
311- if vncport == '-1' :
312- num += 1
313- time .sleep (0.25 )
314- else :
315- break
316- if vncport == '-1' or vncport is None :
317- print >> sys .stderr , _ ("Unable to connect to graphical console; vnc port number not found." )
318- return None
319- vncport = int (vncport )
320- vnchost = "localhost"
321- if not os .path .exists ("/usr/bin/vncviewer" ):
322- print >> sys .stderr , _ ("Unable to connect to graphical console; vncviewer not installed. Please connect to %(serv)s:%(port)d" ) % \
323- {'serv' : vnchost , 'port' : vncport }
324- return None
325- if not os .environ .has_key ("DISPLAY" ):
326- print >> sys .stderr , _ ("Unable to connect to graphical console; vncviewer not installed. Please connect to %(serv)s:%(port)d" ) % \
327- {'serv' : vnchost , 'port' : vncport }
328- logging .debug ("VNC Port: %d; VNC host: %s" % (vncport , vnchost ))
329-
305+ def vnc_console (dom , uri ):
306+ args = ["/usr/bin/virt-viewer" ]
307+ if uri is not None and uri != "" :
308+ args = args + [ "--connect" , uri ]
309+ args = args + [ "--wait" , "%s" % dom .ID ()]
330310 child = os .fork ()
331311 if not child :
332- os .execvp ("/usr/bin/vncviewer" , ["/usr/bin/vncviewer" ,
333- "%s:%d" % (vnchost , vncport ) ])
312+ os .execvp (args [0 ], args )
334313 os ._exit (1 )
335314
336315 return child
337316
338- def txt_console (dom ):
339- tty = get_xml_string (dom , "/domain/devices/console/@tty" )
340- if tty is None or not os .access (tty , os .R_OK | os .W_OK ):
341- return None
317+ def txt_console (dom , uri ):
318+ args = ["/usr/bin/virsh" ]
319+ if uri is not None and uri != "" :
320+ args = args + [ "--connect" , uri ]
321+ args = args + [ "console" , "%s" % dom .ID ()]
342322 child = os .fork ()
343323 if not child :
344- os .execvp ("/usr/sbin/xm" ,
345- ["/usr/sbin/xm" , "console" , "%s" % (dom .ID (),)])
324+ os .execvp (args [0 ], args )
346325 os ._exit (1 )
347326
348327 return child
349328
350- def show_console (dom ):
351- gfxtype = get_xml_string (dom , "/domain/devices/graphics/@type" )
352- if gfxtype == "vnc" :
353- return vnc_console (dom )
354- return txt_console (dom )
355-
356329### Let's do it!
357330def main ():
358331 options = parse_args ()
@@ -437,7 +410,16 @@ def main():
437410 if options .os_variant is not None :
438411 guest .set_os_variant (options .os_variant )
439412 continue_inst = guest .get_continue_inst ()
440-
413+
414+ def show_console (dom ):
415+ if guest .graphics ["enabled" ]:
416+ if guest .graphics ["type" ].name == "vnc" :
417+ return vnc_console (dom , options .connect )
418+ else :
419+ return None # SDL needs no viewer app
420+ else :
421+ return txt_console (dom , options .connect )
422+
441423 if options .autoconsole is False :
442424 conscb = None
443425 else :
0 commit comments