[virt-tools-list] [PATCH] Virt-manager host device information bits
Cole Robinson
crobinso at redhat.com
Wed Nov 4 15:40:04 UTC 2009
On 11/04/2009 05:39 AM, Michal Novotny wrote:
>>
> Right, this is new version of my patch... It has also "Source Device"
> value aligned to the left (there was a bad alignment to right) and also
> helper functions attrVal() which checks whether we have attr and if so
> it returns it contents, otherwise it returns None and also intify()
> function with arguments of val and hex... It converts val from decimal
> string to int (if hex is False) or hex string to int (if hex is True).
> The function is used for both the cases in this refresh_hostdev_info()
> method so please review...
>
> In the glade file, the bad deletion of delete_event has been neutralized
> by adding it back manually not to cause problems...
>
> Thanks,
> Michal
Applied, with some minor changes mentioned in line.
> diff -r a5b9807ead04 src/virtManager/details.py
> --- a/src/virtManager/details.py Sun Nov 01 21:56:21 2009 -0500
> +++ b/src/virtManager/details.py Wed Nov 04 11:34:35 2009 +0100
> @@ -634,6 +634,12 @@
>
> def refresh_resources(self, ignore):
> details = self.window.get_widget("details-pages")
> +
> + # If details are NoneType return not to cause errors like
> + # you can see in the log file
> + if not details:
> + return
> +
Dropped this, this was added to work around the glade brokeness I imagine?
> page = details.get_current_page()
>
> # If the dialog is visible, we want to make sure the XML is always
> @@ -908,17 +914,78 @@
> self.window.get_widget("char-target-port").set_text(charinfo[3] or "")
> self.window.get_widget("char-source-path").set_text(charinfo[5] or "-")
>
> + # Function to intify val. If hex is set to True, the val is considered
> + # to be a hex string so it tries to convert from hex or returns 0
> + def intify(self, val, hex=False):
> + try:
> + if hex:
hex is a builtin, renamed to do_hex.
> + return int(val or '0x00', 16)
> + else:
> + return int(val)
> + except:
> + return -1
> +
> + # Function to get attribute value (if exists) from node, otherwise
> + # returns None
> + def attrVal(self, node, attr):
> + if not hasattr(node, attr):
> + return None
> + return getattr(node, attr)
> +
Moved these functions as internal functions of refresh_hostdev_page
> def refresh_hostdev_page(self):
> hostdevinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
> if not hostdevinfo:
> return
>
> + devinfo = hostdevinfo[1]
> + if devinfo.get("vendor") and devinfo.get("product"):
> + vendor_id = devinfo["vendor"].get("id") or -1
> + product_id = devinfo["product"].get("id") or -1
> + device = 0
> + bus = 0
> + domain = 0
> + func = 0
> + slot = 0
> + elif devinfo.get("address"):
> + vendor_id = -1
> + product_id = -1
> + device = self.intify(devinfo["address"].get("device"), True)
> + bus = self.intify(devinfo["address"].get("bus"), True)
> + domain = self.intify(devinfo["address"].get("domain"), True)
> + func = self.intify(devinfo["address"].get("function"), True)
> + slot = self.intify(devinfo["address"].get("slot"), True)
> +
> + typ = devinfo.get("type")
> + # For USB we want a device, not a bus
> + if typ == 'usb':
> + typ = 'usb_device'
> + dev_pretty_name = None
> + devs = self.vm.get_connection().get_devices( typ, None )
> +
> + # Get device pretty name
> + for dev in devs:
> + # Try to get info from {product|vendor}_id
> + if (self.attrVal(dev, "product_id") == product_id
> + and self.attrVal(dev, "vendor_id") == vendor_id):
> + dev_pretty_name = dev.pretty_name()
> + break
> + else:
> + # Try to get info from bus/addr
> + dev_id = self.intify(self.attrVal(dev, "device"))
> + bus_id = self.intify(self.attrVal(dev, "bus"))
> + dom_id = self.intify(self.attrVal(dev, "domain"))
> + func_id = self.intify(self.attrVal(dev, "function"))
> + slot_id = self.intify(self.attrVal(dev, "slot"))
> +
> + if ((dev_id == device and bus_id == bus)
> + or (dom_id == domain and func_id == func and slot_id == slot)):
PCI devices also use 'bus', so we need to compare that in the second
line as well.
> + dev_pretty_name = dev.pretty_name()
> + break
> +
> devlabel = "<b>Physical %s Device</b>" % hostdevinfo[4].upper()
>
> self.window.get_widget("hostdev-title").set_markup(devlabel)
> - self.window.get_widget("hostdev-type").set_text(hostdevinfo[4])
> - self.window.get_widget("hostdev-mode").set_text(hostdevinfo[3])
> - self.window.get_widget("hostdev-source").set_text(hostdevinfo[5])
> + self.window.get_widget("hostdev-source").set_text(dev_pretty_name or "-")
>
> def refresh_video_page(self):
> vidinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
Thanks,
Cole
More information about the virt-tools-list
mailing list