mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
domain: Use virtinst for char device listing
This commit is contained in:
parent
f52d5c8b3a
commit
f0cb7c964e
@ -640,7 +640,7 @@ class vmmDetails(gobject.GObject):
|
||||
|
||||
devs = self.vm.get_serial_devs()
|
||||
if len(devs) == 0:
|
||||
item = gtk.MenuItem(_("No serial devices found"))
|
||||
item = gtk.MenuItem(_("No text console available"))
|
||||
item.set_sensitive(False)
|
||||
src.add(item)
|
||||
|
||||
@ -688,18 +688,20 @@ class vmmDetails(gobject.GObject):
|
||||
|
||||
devs = self.vm.get_graphics_devices()
|
||||
if len(devs) == 0:
|
||||
item = gtk.MenuItem(_("No graphics console found."))
|
||||
item = gtk.MenuItem(_("No graphical console available"))
|
||||
item.set_sensitive(False)
|
||||
src.add(item)
|
||||
else:
|
||||
dev = devs[0]
|
||||
item = gtk.RadioMenuItem(group, _("Graphical Console %s") % dev[2])
|
||||
item = gtk.RadioMenuItem(group, _("Graphical Console %s") %
|
||||
dev.type.upper())
|
||||
if group == None:
|
||||
group = item
|
||||
|
||||
if on_graphics:
|
||||
item.set_active(True)
|
||||
item.connect("toggled", self.control_serial_tab, dev[0], dev[2])
|
||||
item.connect("toggled", self.control_serial_tab,
|
||||
dev.virtual_device_type, dev.type)
|
||||
src.add(item)
|
||||
|
||||
src.show_all()
|
||||
@ -1940,19 +1942,19 @@ class vmmDetails(gobject.GObject):
|
||||
self.set_combo_label("sound-model", 0, sound.model)
|
||||
|
||||
def refresh_char_page(self):
|
||||
charinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not charinfo:
|
||||
chardev = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not chardev:
|
||||
return
|
||||
|
||||
char_type = charinfo[0].capitalize()
|
||||
target_port = charinfo[3]
|
||||
dev_type = charinfo[4] or "pty"
|
||||
src_path = charinfo[5]
|
||||
primary = charinfo[6]
|
||||
char_type = chardev.virtual_device_type.capitalize()
|
||||
target_port = chardev.index
|
||||
dev_type = chardev.char_type or "pty"
|
||||
src_path = chardev.source_path
|
||||
primary = hasattr(chardev, "console_dup")
|
||||
|
||||
typelabel = "%s Device" % char_type
|
||||
if target_port:
|
||||
typelabel += " %s" % target_port
|
||||
if target_port is not None:
|
||||
typelabel += " %s" % (int(target_port) + 1)
|
||||
if primary:
|
||||
typelabel += " (%s)" % _("Primary Console")
|
||||
typelabel = "<b>%s</b>" % typelabel
|
||||
@ -2215,18 +2217,19 @@ class vmmDetails(gobject.GObject):
|
||||
_("Sound: %s" % model), "audio-card", key)
|
||||
|
||||
# Populate list of char devices
|
||||
for charinfo in self.vm.get_char_devices():
|
||||
key = str(charinfo[1])
|
||||
devtype = charinfo[0]
|
||||
port = charinfo[3]
|
||||
for chardev in self.vm.get_char_devices():
|
||||
devtype = chardev.virtual_device_type
|
||||
port = chardev.index
|
||||
key = str(devtype + ":" + str(port))
|
||||
|
||||
currentChars[key] = 1
|
||||
|
||||
label = devtype.capitalize()
|
||||
if devtype != "console":
|
||||
# Don't show port for console
|
||||
label += " %s" % (int(port) + 1)
|
||||
|
||||
update_hwlist(HW_LIST_TYPE_CHAR, charinfo, label,
|
||||
update_hwlist(HW_LIST_TYPE_CHAR, chardev, label,
|
||||
"device_serial", key)
|
||||
|
||||
# Populate host devices
|
||||
|
@ -317,66 +317,35 @@ class vmmDomainBase(vmmLibvirtObject):
|
||||
# Device listing
|
||||
|
||||
def get_serial_devs(self):
|
||||
def _parse_serial_consoles(ctx):
|
||||
# [ Name, device type, source path
|
||||
serial_list = []
|
||||
sdevs = ctx.xpathEval("/domain/devices/serial")
|
||||
cdevs = ctx.xpathEval("/domain/devices/console")
|
||||
for node in sdevs:
|
||||
name = "Serial "
|
||||
dev_type = node.prop("type")
|
||||
source_path = None
|
||||
devs = self.get_char_devices()
|
||||
devlist = []
|
||||
|
||||
for child in node.children:
|
||||
if child.name == "target":
|
||||
target_port = child.prop("port")
|
||||
if target_port:
|
||||
name += str(target_port)
|
||||
if child.name == "source":
|
||||
source_path = child.prop("path")
|
||||
serials = filter(lambda x: x.virtual_device_type == "serial", devs)
|
||||
consoles = filter(lambda x: x.virtual_device_type == "console", devs)
|
||||
|
||||
serial_list.append([name, dev_type, source_path, target_port])
|
||||
for dev in serials:
|
||||
devlist.append(["Serial %s" % (dev.index + 1), dev.char_type,
|
||||
dev.source_path, dev.index])
|
||||
|
||||
for node in cdevs:
|
||||
name = "Serial Console"
|
||||
dev_type = "pty"
|
||||
source_path = None
|
||||
target_port = -1
|
||||
inuse = False
|
||||
for dev in consoles:
|
||||
devlist.append(["Text Console %s" % (dev.index + 1),
|
||||
dev.char_type, dev.source_path, dev.index])
|
||||
|
||||
for child in node.children:
|
||||
if child.name == "source":
|
||||
source_path = child.prop("path")
|
||||
|
||||
if child.name == "target":
|
||||
target_port = child.prop("port")
|
||||
|
||||
if target_port != -1:
|
||||
for dev in serial_list:
|
||||
if target_port == dev[3]:
|
||||
inuse = True
|
||||
break
|
||||
|
||||
if not inuse:
|
||||
serial_list.append([name, dev_type, source_path,
|
||||
target_port])
|
||||
|
||||
return serial_list
|
||||
return self._parse_device_xml(_parse_serial_consoles)
|
||||
return devlist
|
||||
|
||||
def get_graphics_console(self):
|
||||
gtype = vutil.get_xml_path(self.get_xml(),
|
||||
"/domain/devices/graphics/@type")
|
||||
vncport = vutil.get_xml_path(self.get_xml(),
|
||||
"/domain/devices/graphics[@type='vnc']/@port")
|
||||
|
||||
if gtype != "vnc":
|
||||
vncport = None
|
||||
else:
|
||||
vncport = int(vncport)
|
||||
|
||||
gdevs = self.get_graphics_devices()
|
||||
connhost = self.connection.get_uri_hostname()
|
||||
transport, username = self.connection.get_transport()
|
||||
vncport = None
|
||||
gport = None
|
||||
gtype = None
|
||||
if gdevs:
|
||||
gport = gdevs[0].port
|
||||
gtype = gdevs[0].type
|
||||
|
||||
if gtype == 'vnc':
|
||||
vncport = int(gport)
|
||||
|
||||
if connhost == None:
|
||||
# Force use of 127.0.0.1, because some (broken) systems don't
|
||||
@ -392,7 +361,7 @@ class vmmDomainBase(vmmLibvirtObject):
|
||||
|
||||
# Build VNC uri for debugging
|
||||
vncuri = None
|
||||
if gtype:
|
||||
if gtype == 'vnc':
|
||||
vncuri = str(gtype) + "://"
|
||||
if username:
|
||||
vncuri = vncuri + str(username) + '@'
|
||||
@ -402,12 +371,6 @@ class vmmDomainBase(vmmLibvirtObject):
|
||||
vncuri]
|
||||
|
||||
|
||||
# ----------------
|
||||
# get_X_devices functions: return a list of lists. Each sublist represents
|
||||
# a device, of the format:
|
||||
# [ device_type, unique_attribute(s), hw column label, attr1, attr2, ... ]
|
||||
# ----------------
|
||||
|
||||
def get_disk_devices(self, refresh_if_necc=True, inactive=False):
|
||||
device_type = "disk"
|
||||
guest = self._get_guest(refresh_if_necc=refresh_if_necc,
|
||||
@ -466,66 +429,32 @@ class vmmDomainBase(vmmLibvirtObject):
|
||||
return devs
|
||||
|
||||
def get_char_devices(self):
|
||||
def _parse_char_devs(ctx):
|
||||
chars = []
|
||||
devs = []
|
||||
devs.extend(ctx.xpathEval("/domain/devices/console"))
|
||||
devs.extend(ctx.xpathEval("/domain/devices/parallel"))
|
||||
devs.extend(ctx.xpathEval("/domain/devices/serial"))
|
||||
devs = []
|
||||
guest = self._get_guest()
|
||||
|
||||
# Since there is only one 'console' device ever in the xml
|
||||
# find its port (if present) and path
|
||||
cons_port = None
|
||||
cons_dev = None
|
||||
list_cons = True
|
||||
count_dict = {}
|
||||
serials = guest.get_devices("serial")
|
||||
parallels = guest.get_devices("parallel")
|
||||
consoles = guest.get_devices("console")
|
||||
|
||||
for node in devs:
|
||||
char_type = node.name
|
||||
dev_type = node.prop("type")
|
||||
target_port = None
|
||||
source_path = None
|
||||
for devicelist in [serials, parallels, consoles]:
|
||||
count = 0
|
||||
for dev in devicelist:
|
||||
dev.index = count
|
||||
count += 1
|
||||
|
||||
for child in node.children or []:
|
||||
if child.name == "source":
|
||||
source_path = child.prop("path")
|
||||
devs.extend(devicelist)
|
||||
|
||||
if not source_path:
|
||||
source_path = node.prop("tty")
|
||||
# Don't display <console> if it's just a duplicate of <serial>
|
||||
if (len(consoles) > 0 and len(serials) > 0):
|
||||
con = consoles[0]
|
||||
ser = serials[0]
|
||||
|
||||
# Rather than parse the target port, just calculate it
|
||||
# ourselves. This helps device removal when customizing
|
||||
# installs
|
||||
if count_dict.get(char_type) == None:
|
||||
count_dict[char_type] = -1
|
||||
count_dict[char_type] += 1
|
||||
target_port = str(count_dict[char_type])
|
||||
if (con.char_type == ser.char_type and
|
||||
con.target_type is None or con.target_type == "serial"):
|
||||
ser.console_dup = True
|
||||
devs.remove(con)
|
||||
|
||||
# [device type, unique, display string, target_port,
|
||||
# char device type, source_path, is_console_dup_of_serial?
|
||||
disp = "%s:%s" % (char_type, target_port)
|
||||
dev = [char_type, disp, disp, target_port,
|
||||
dev_type, source_path, False]
|
||||
|
||||
if node.name == "console":
|
||||
cons_port = target_port
|
||||
cons_dev = dev
|
||||
dev[6] = True
|
||||
continue
|
||||
elif node.name == "serial" and cons_port \
|
||||
and target_port == cons_port:
|
||||
# Console is just a dupe of this serial device
|
||||
dev[6] = True
|
||||
list_cons = False
|
||||
|
||||
chars.append(dev)
|
||||
|
||||
if cons_dev and list_cons:
|
||||
chars.append(cons_dev)
|
||||
|
||||
return chars
|
||||
|
||||
return self._parse_device_xml(_parse_char_devs)
|
||||
return devs
|
||||
|
||||
def get_video_devices(self):
|
||||
device_type = "video"
|
||||
|
Loading…
Reference in New Issue
Block a user