domain: Use virtinst for parsing input, gfx, sound, video, watchdog

This commit is contained in:
Cole Robinson 2010-09-03 15:59:33 -04:00
parent 58d0a67a54
commit f52d5c8b3a
2 changed files with 89 additions and 144 deletions

View File

@ -1873,22 +1873,23 @@ class vmmDetails(gobject.GObject):
self.set_combo_label("network-model", 0, model) self.set_combo_label("network-model", 0, model)
def refresh_input_page(self): def refresh_input_page(self):
inputinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) inp = self.get_hw_selection(HW_LIST_COL_DEVICE)
if not inputinfo: if not inp:
return return
if inputinfo[2] == "tablet:usb": ident = "%s:%s" % (inp.type, inp.bus)
if ident == "tablet:usb":
dev = _("EvTouch USB Graphics Tablet") dev = _("EvTouch USB Graphics Tablet")
elif inputinfo[2] == "mouse:usb": elif ident == "mouse:usb":
dev = _("Generic USB Mouse") dev = _("Generic USB Mouse")
elif inputinfo[2] == "mouse:xen": elif ident == "mouse:xen":
dev = _("Xen Mouse") dev = _("Xen Mouse")
elif inputinfo[2] == "mouse:ps2": elif ident == "mouse:ps2":
dev = _("PS/2 Mouse") dev = _("PS/2 Mouse")
else: else:
dev = inputinfo[4] + " " + inputinfo[3] dev = inp.bus + " " + inp.type
if inputinfo[4] == "tablet": if inp.type == "tablet":
mode = _("Absolute Movement") mode = _("Absolute Movement")
else: else:
mode = _("Relative Movement") mode = _("Relative Movement")
@ -1897,33 +1898,33 @@ class vmmDetails(gobject.GObject):
self.window.get_widget("input-dev-mode").set_text(mode) self.window.get_widget("input-dev-mode").set_text(mode)
# Can't remove primary Xen or PS/2 mice # Can't remove primary Xen or PS/2 mice
if inputinfo[4] == "mouse" and inputinfo[3] in ("xen", "ps2"): if inp.type == "mouse" and inp.bus in ("xen", "ps2"):
self.window.get_widget("config-remove").set_sensitive(False) self.window.get_widget("config-remove").set_sensitive(False)
else: else:
self.window.get_widget("config-remove").set_sensitive(True) self.window.get_widget("config-remove").set_sensitive(True)
def refresh_graphics_page(self): def refresh_graphics_page(self):
gfxinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) gfx = self.get_hw_selection(HW_LIST_COL_DEVICE)
if not gfxinfo: if not gfx:
return return
is_vnc = (gfxinfo[2] == "vnc") is_vnc = (gfx.type == "vnc")
is_sdl = (gfxinfo[2] == "sdl") is_sdl = (gfx.type == "sdl")
port = _("N/A") port = _("N/A")
if is_vnc: if is_vnc:
gtype = _("VNC server") gtype = _("VNC server")
port = (gfxinfo[4] == "-1" and port = (gfx.port == -1 and
_("Automatically allocated") or _("Automatically allocated") or
gfxinfo[4]) str(gfx.port))
elif is_sdl: elif is_sdl:
gtype = _("Local SDL window") gtype = _("Local SDL window")
else: else:
gtype = gfxinfo[2] gtype = gfx.type
address = (is_vnc and (gfxinfo[3] or "127.0.0.1") or _("N/A")) address = (is_vnc and (gfx.listen or "127.0.0.1") or _("N/A"))
passwd = (is_vnc and "-" or _("N/A")) passwd = (is_vnc and "-" or _("N/A"))
keymap = (is_vnc and (gfxinfo[5] or _("None")) or _("N/A")) keymap = (is_vnc and (gfx.keymap or _("None")) or _("N/A"))
self.window.get_widget("graphics-type").set_text(gtype) self.window.get_widget("graphics-type").set_text(gtype)
self.window.get_widget("graphics-address").set_text(address) self.window.get_widget("graphics-address").set_text(address)
@ -1932,13 +1933,11 @@ class vmmDetails(gobject.GObject):
self.window.get_widget("graphics-keymap").set_text(keymap) self.window.get_widget("graphics-keymap").set_text(keymap)
def refresh_sound_page(self): def refresh_sound_page(self):
soundinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) sound = self.get_hw_selection(HW_LIST_COL_DEVICE)
if not soundinfo: if not sound:
return return
model = soundinfo[2] self.set_combo_label("sound-model", 0, sound.model)
self.set_combo_label("sound-model", 0, model)
def refresh_char_page(self): def refresh_char_page(self):
charinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) charinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
@ -2036,11 +2035,13 @@ class vmmDetails(gobject.GObject):
"-") "-")
def refresh_video_page(self): def refresh_video_page(self):
vidinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) vid = self.get_hw_selection(HW_LIST_COL_DEVICE)
if not vidinfo: if not vid:
return return
ignore, ignore, model, ram, heads = vidinfo model = vid.model_type
ram = vid.vram
heads = vid.heads
try: try:
ramlabel = ram and "%d MB" % (int(ram) / 1024) or "-" ramlabel = ram and "%d MB" % (int(ram) / 1024) or "-"
except: except:
@ -2052,11 +2053,12 @@ class vmmDetails(gobject.GObject):
self.set_combo_label("video-model", 0, model) self.set_combo_label("video-model", 0, model)
def refresh_watchdog_page(self): def refresh_watchdog_page(self):
watchinfo = self.get_hw_selection(HW_LIST_COL_DEVICE) watch = self.get_hw_selection(HW_LIST_COL_DEVICE)
if not watchinfo: if not watch:
return return
ignore, ignore, model, action = watchinfo model = watch.model
action = watch.action
self.set_combo_label("watchdog-model", 0, model) self.set_combo_label("watchdog-model", 0, model)
self.set_combo_label("watchdog-action", 0, action) self.set_combo_label("watchdog-action", 0, action)
@ -2177,9 +2179,9 @@ class vmmDetails(gobject.GObject):
"NIC %s" % mac[-9:], "network-idle", key) "NIC %s" % mac[-9:], "network-idle", key)
# Populate list of input devices # Populate list of input devices
for inputinfo in self.vm.get_input_devices(): for inp in self.vm.get_input_devices():
key = str(inputinfo[1]) key = str("%s:%s" % (inp.type, inp.bus))
inptype = inputinfo[4] inptype = inp.type
currentInputs[key] = 1 currentInputs[key] = 1
icon = "input-mouse" icon = "input-mouse"
@ -2191,25 +2193,25 @@ class vmmDetails(gobject.GObject):
else: else:
label = _("Input") label = _("Input")
update_hwlist(HW_LIST_TYPE_INPUT, inputinfo, label, icon, key) update_hwlist(HW_LIST_TYPE_INPUT, inp, label, icon, key)
# Populate list of graphics devices # Populate list of graphics devices
for gfxinfo in self.vm.get_graphics_devices(): for gfx in self.vm.get_graphics_devices():
key = str(gfxinfo[1]) key = str(gfx.index)
gfxtype = gfxinfo[2] gfxtype = gfx.type
currentGraphics[key] = 1 currentGraphics[key] = 1
update_hwlist(HW_LIST_TYPE_GRAPHICS, gfxinfo, update_hwlist(HW_LIST_TYPE_GRAPHICS, gfx,
_("Display %s") % (gfxtype.upper()), _("Display %s") % (gfxtype.upper()),
"video-display", key) "video-display", key)
# Populate list of sound devices # Populate list of sound devices
for soundinfo in self.vm.get_sound_devices(): for sound in self.vm.get_sound_devices():
key = str(soundinfo[1]) key = str(sound.index)
model = soundinfo[2] model = sound.model
currentSounds[key] = 1 currentSounds[key] = 1
update_hwlist(HW_LIST_TYPE_SOUND, soundinfo, update_hwlist(HW_LIST_TYPE_SOUND, sound,
_("Sound: %s" % model), "audio-card", key) _("Sound: %s" % model), "audio-card", key)
# Populate list of char devices # Populate list of char devices
@ -2242,18 +2244,18 @@ class vmmDetails(gobject.GObject):
icon, key) icon, key)
# Populate video devices # Populate video devices
for vidinfo in self.vm.get_video_devices(): for vid in self.vm.get_video_devices():
key = str(vidinfo[1]) key = str(vid.index)
currentVids[key] = 1 currentVids[key] = 1
update_hwlist(HW_LIST_TYPE_VIDEO, vidinfo, _("Video"), update_hwlist(HW_LIST_TYPE_VIDEO, vid, _("Video"),
"video-display", key) "video-display", key)
for watchinfo in self.vm.get_watchdog_devices(): for watch in self.vm.get_watchdog_devices():
key = str(watchinfo[1]) key = str(watch.index)
currentWatchdogs[key] = 1 currentWatchdogs[key] = 1
update_hwlist(HW_LIST_TYPE_WATCHDOG, watchinfo, _("Watchdog"), update_hwlist(HW_LIST_TYPE_WATCHDOG, watch, _("Watchdog"),
"device_pci", key) "device_pci", key)
# Now remove any no longer current devs # Now remove any no longer current devs

View File

@ -434,67 +434,36 @@ class vmmDomainBase(vmmLibvirtObject):
device_type = "interface" device_type = "interface"
guest = self._get_guest(refresh_if_necc=refresh_if_necc) guest = self._get_guest(refresh_if_necc=refresh_if_necc)
devs = guest.get_devices(device_type) devs = guest.get_devices(device_type)
return devs return devs
def get_input_devices(self): def get_input_devices(self):
def _parse_input_devs(ctx): device_type = "input"
inputs = [] guest = self._get_guest()
ret = ctx.xpathEval("/domain/devices/input") devs = guest.get_devices(device_type)
for node in ret: return devs
typ = node.prop("type")
bus = node.prop("bus")
# [device type, unique, display string, bus type, input type]
inputs.append(["input", (typ, bus), typ + ":" + bus, bus, typ])
return inputs
return self._parse_device_xml(_parse_input_devs)
def get_graphics_devices(self): def get_graphics_devices(self):
def _parse_graphics_devs(ctx): device_type = "graphics"
graphics = [] guest = self._get_guest()
devs = guest.get_devices(device_type)
count = 0 count = 0
ret = ctx.xpathEval("/domain/devices/graphics") for dev in devs:
dev.index = count
for node in ret:
typ = node.prop("type")
listen = None
port = None
keymap = None
if typ == "vnc":
listen = node.prop("listen")
port = node.prop("port")
keymap = node.prop("keymap")
unique = count
count += 1 count += 1
# [device type, unique, graphics type, listen addr, port, return devs
# keymap ]
graphics.append(["graphics", unique, typ, listen, port, keymap])
return graphics
return self._parse_device_xml(_parse_graphics_devs)
def get_sound_devices(self): def get_sound_devices(self):
def _parse_sound_devs(ctx): device_type = "sound"
sound = [] guest = self._get_guest()
devs = guest.get_devices(device_type)
count = 0 count = 0
ret = ctx.xpathEval("/domain/devices/sound") for dev in devs:
dev.index = count
for node in ret:
model = node.prop("model")
unique = count
count += 1 count += 1
# [device type, unique, sound model] return devs
sound.append(["sound", unique, model])
return sound
return self._parse_device_xml(_parse_sound_devs)
def get_char_devices(self): def get_char_devices(self):
def _parse_char_devs(ctx): def _parse_char_devs(ctx):
@ -559,33 +528,15 @@ class vmmDomainBase(vmmLibvirtObject):
return self._parse_device_xml(_parse_char_devs) return self._parse_device_xml(_parse_char_devs)
def get_video_devices(self): def get_video_devices(self):
def _parse_video_devs(ctx): device_type = "video"
vids = [] guest = self._get_guest()
devs = ctx.xpathEval("/domain/devices/video") devs = guest.get_devices(device_type)
count = 0 count = 0
for dev in devs: for dev in devs:
model = None dev.index = count
ram = None
heads = None
for node in dev.children or []:
if node.name == "model":
model = node.prop("type")
ram = node.prop("vram")
heads = node.prop("heads")
if ram:
ram = safeint(ram, "%d")
unique = count
count += 1 count += 1
row = ["video", unique, model, ram, heads] return devs
vids.append(row)
return vids
return self._parse_device_xml(_parse_video_devs)
def get_hostdev_devices(self): def get_hostdev_devices(self):
def _parse_hostdev_devs(ctx): def _parse_hostdev_devs(ctx):
@ -679,23 +630,15 @@ class vmmDomainBase(vmmLibvirtObject):
return self._parse_device_xml(_parse_hostdev_devs) return self._parse_device_xml(_parse_hostdev_devs)
def get_watchdog_devices(self): def get_watchdog_devices(self):
def _parse_devs(ctx): device_type = "watchdog"
vids = [] guest = self._get_guest()
devs = ctx.xpathEval("/domain/devices/watchdog") devs = guest.get_devices(device_type)
count = 0 count = 0
for dev in devs: for dev in devs:
model = dev.prop("model") dev.index = count
action = dev.prop("action")
unique = count
count += 1 count += 1
row = ["watchdog", unique, model, action] return devs
vids.append(row)
return vids
return self._parse_device_xml(_parse_devs)
def _parse_device_xml(self, parse_function): def _parse_device_xml(self, parse_function):
def parse_wrap_func(doc, ctx): def parse_wrap_func(doc, ctx):
@ -728,7 +671,7 @@ class vmmDomainBase(vmmLibvirtObject):
xpath = "/domain/devices/disk[target/@dev='%s'][1]" % dev_id_info xpath = "/domain/devices/disk[target/@dev='%s'][1]" % dev_id_info
elif dev_type=="input": elif dev_type=="input":
typ, bus = dev_id_info typ, bus = dev_id_info.split(":")
xpath = ("/domain/devices/input[@type='%s' and @bus='%s'][1]" % xpath = ("/domain/devices/input[@type='%s' and @bus='%s'][1]" %
(typ, bus)) (typ, bus))