Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit a1db529

Browse files
committed
Use virt-viewer & virsh console instead of vncviewer & xm console
1 parent edd4a48 commit a1db529

2 files changed

Lines changed: 23 additions & 40 deletions

File tree

python-virtinst.spec.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
2020
BuildArch: noarch
2121
Url: http://virt-manager.et.redhat.com
2222
Requires: libvirt-python >= 0.2.0
23+
Requires: virt-viewer
2324
Requires: urlgrabber
2425
BuildRequires: python-devel
2526

virt-install

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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!
357330
def 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

Comments
 (0)