mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
details: Reorg a bunch of the global helpers
Some were redundant, some should be in virtinst
This commit is contained in:
parent
4ad50d968a
commit
439e5ad0fe
@ -5368,14 +5368,12 @@ if you know what you are doing.</small></property>
|
||||
<property name="top_padding">3</property>
|
||||
<property name="left_padding">12</property>
|
||||
<child>
|
||||
<object class="GtkTable" id="table51">
|
||||
<object class="GtkGrid" id="table51">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">3</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="column_spacing">8</property>
|
||||
<property name="row_spacing">4</property>
|
||||
<property name="column_spacing">8</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label516">
|
||||
<property name="visible">True</property>
|
||||
@ -5385,8 +5383,8 @@ if you know what you are doing.</small></property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"/>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -5397,10 +5395,8 @@ if you know what you are doing.</small></property>
|
||||
<property name="label" translatable="yes">Address:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"/>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -5412,11 +5408,7 @@ if you know what you are doing.</small></property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"/>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -5428,9 +5420,7 @@ if you know what you are doing.</small></property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -159,56 +159,6 @@ remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
|
||||
DETAILS_PAGE_SNAPSHOTS) = range(3)
|
||||
|
||||
|
||||
def _prettyify_disk_bus(bus):
|
||||
if bus in ["ide", "sata", "scsi", "usb", "sd"]:
|
||||
return bus.upper()
|
||||
|
||||
if bus in ["xen"]:
|
||||
return bus.capitalize()
|
||||
|
||||
if bus == "virtio":
|
||||
return "VirtIO"
|
||||
|
||||
if bus == "spapr-vscsi":
|
||||
return "vSCSI"
|
||||
|
||||
return bus
|
||||
|
||||
|
||||
def safeint(val, fmt="%.3d"):
|
||||
try:
|
||||
int(val)
|
||||
except:
|
||||
return str(val)
|
||||
return fmt % int(val)
|
||||
|
||||
|
||||
def prettyify_bytes(val):
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GiB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MiB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
|
||||
def _build_redir_label(redirdev):
|
||||
# String shown in the devices details section
|
||||
addrlabel = ""
|
||||
# String shown in the VMs hardware list
|
||||
hwlabel = ""
|
||||
|
||||
if redirdev.type == 'spicevmc':
|
||||
addrlabel = None
|
||||
elif redirdev.type == 'tcp':
|
||||
addrlabel += _("%s:%s") % (redirdev.host, redirdev.service)
|
||||
else:
|
||||
raise RuntimeError("unhandled redirection kind: %s" % redirdev.type)
|
||||
|
||||
hwlabel = _("%s Redirector %s") % (redirdev.bus.upper(),
|
||||
redirdev.vmmindex + 1)
|
||||
|
||||
return addrlabel, hwlabel
|
||||
|
||||
|
||||
def _build_hostdev_label(hostdev):
|
||||
# String shown in the devices details section
|
||||
srclabel = ""
|
||||
@ -239,6 +189,13 @@ def _build_hostdev_label(hostdev):
|
||||
hwlabel += devstr
|
||||
|
||||
elif addrbus and addrdev:
|
||||
def safeint(val, fmt="%.3d"):
|
||||
try:
|
||||
int(val)
|
||||
except:
|
||||
return str(val)
|
||||
return fmt % int(val)
|
||||
|
||||
# USB by bus + dev
|
||||
srclabel += (" Bus %s Device %s" %
|
||||
(safeint(addrbus), safeint(addrdev)))
|
||||
@ -255,23 +212,6 @@ def _build_hostdev_label(hostdev):
|
||||
return srclabel, hwlabel
|
||||
|
||||
|
||||
def lookup_nodedev(vmmconn, hostdev):
|
||||
devtype = hostdev.type
|
||||
found_dev = None
|
||||
|
||||
# For USB we want a device, not a bus
|
||||
if devtype == 'usb':
|
||||
devtype = 'usb_device'
|
||||
|
||||
devs = vmmconn.get_nodedevs(devtype, None)
|
||||
for dev in devs:
|
||||
if dev.compare_to_hostdev(hostdev):
|
||||
found_dev = dev
|
||||
break
|
||||
|
||||
return found_dev
|
||||
|
||||
|
||||
def _label_for_device(dev):
|
||||
devtype = dev.virtual_device_type
|
||||
|
||||
@ -280,7 +220,7 @@ def _label_for_device(dev):
|
||||
if dev.address.type == "spapr-vio":
|
||||
bus = "spapr-vscsi"
|
||||
|
||||
busstr = _prettyify_disk_bus(bus) or ""
|
||||
busstr = virtinst.VirtualDisk.pretty_disk_bus(bus) or ""
|
||||
|
||||
if dev.device == "floppy":
|
||||
devstr = "Floppy"
|
||||
@ -325,7 +265,7 @@ def _label_for_device(dev):
|
||||
if devtype == "graphics":
|
||||
return _("Display %s") % dev.pretty_type_simple(dev.type)
|
||||
if devtype == "redirdev":
|
||||
return _build_redir_label(dev)[1]
|
||||
return _("%s Redirector %s") % (dev.bus.upper(), dev.vmmindex + 1)
|
||||
if devtype == "hostdev":
|
||||
return _build_hostdev_label(dev)[1]
|
||||
if devtype == "sound":
|
||||
@ -2712,7 +2652,10 @@ class vmmDetails(vmmGObjectUI):
|
||||
elif not self.conn.is_remote():
|
||||
ignore, val = virtinst.VirtualDisk.stat_local_path(path)
|
||||
if val != 0:
|
||||
size = prettyify_bytes(val)
|
||||
if val > (1024 * 1024 * 1024):
|
||||
size = "%2.2f GiB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
size = "%2.2f MiB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
is_cdrom = (devtype == virtinst.VirtualDisk.DEVICE_CDROM)
|
||||
is_floppy = (devtype == virtinst.VirtualDisk.DEVICE_FLOPPY)
|
||||
@ -2846,13 +2789,16 @@ class vmmDetails(vmmGObjectUI):
|
||||
if not rd:
|
||||
return
|
||||
|
||||
address = _build_redir_label(rd)[0] or "-"
|
||||
address = None
|
||||
if rd.type == 'tcp':
|
||||
address = _("%s:%s") % (rd.host, rd.service)
|
||||
|
||||
devlabel = "<b>%s Redirector</b>" % rd.bus.upper()
|
||||
self.widget("redir-title").set_markup(devlabel)
|
||||
self.widget("redir-address").set_text(address)
|
||||
self.widget("redir-title").set_markup(_label_for_device(rd))
|
||||
self.widget("redir-type").set_text(rd.pretty_type(rd.type))
|
||||
|
||||
self.widget("redir-type").set_text(rd.type)
|
||||
self.widget("redir-address").set_text(address or "")
|
||||
uiutil.set_grid_row_visible(
|
||||
self.widget("redir-address"), bool(address))
|
||||
|
||||
def refresh_tpm_page(self):
|
||||
tpmdev = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
@ -3027,8 +2973,16 @@ class vmmDetails(vmmGObjectUI):
|
||||
if rom_bar is None:
|
||||
rom_bar = True
|
||||
|
||||
devtype = hostdev.type
|
||||
if hostdev.type == 'usb':
|
||||
devtype = 'usb_device'
|
||||
|
||||
nodedev = None
|
||||
for trydev in self.vm.conn.get_nodedevs(devtype, None):
|
||||
if trydev.compare_to_hostdev(hostdev):
|
||||
nodedev = trydev
|
||||
|
||||
pretty_name = None
|
||||
nodedev = lookup_nodedev(self.vm.conn, hostdev)
|
||||
if nodedev:
|
||||
pretty_name = nodedev.pretty_name()
|
||||
if not pretty_name:
|
||||
|
@ -216,6 +216,18 @@ class VirtualDisk(VirtualDevice):
|
||||
return "dir"
|
||||
return "file"
|
||||
|
||||
@staticmethod
|
||||
def pretty_disk_bus(bus):
|
||||
if bus in ["ide", "sata", "scsi", "usb", "sd"]:
|
||||
return bus.upper()
|
||||
if bus in ["xen"]:
|
||||
return bus.capitalize()
|
||||
if bus == "virtio":
|
||||
return "VirtIO"
|
||||
if bus == "spapr-vscsi":
|
||||
return "vSCSI"
|
||||
return bus
|
||||
|
||||
@staticmethod
|
||||
def path_exists(conn, path):
|
||||
"""
|
||||
|
@ -33,6 +33,14 @@ class VirtualRedirDevice(VirtualDevice):
|
||||
TYPE_DEFAULT = "default"
|
||||
TYPES = ["tcp", "spicevmc", TYPE_DEFAULT]
|
||||
|
||||
@staticmethod
|
||||
def pretty_type(typ):
|
||||
if typ == "tcp":
|
||||
return "TCP"
|
||||
if typ == "spicevmc":
|
||||
return "SpiceVMC"
|
||||
return typ and typ.capitalize()
|
||||
|
||||
def parse_friendly_server(self, serverstr):
|
||||
if serverstr.count(":") != 1:
|
||||
raise ValueError(_("Could not determine or unsupported "
|
||||
|
Loading…
Reference in New Issue
Block a user