[virt-tools-list] [PATCH 2/3] virt-manager: Add support for vsock device to hardware details UI
Pavel Hrdina
phrdina at redhat.com
Mon Dec 10 06:03:50 UTC 2018
On Fri, Dec 07, 2018 at 05:02:15PM +0200, Slavomir Kaslev wrote:
> Signed-off-by: Slavomir Kaslev <kaslevs at vmware.com>
> ---
> ui/details.ui | 119 +++++++++++++++++++++++++++++++++++++++++
> virtManager/details.py | 46 ++++++++++++++--
> virtManager/domain.py | 17 ++++++
> 3 files changed, 179 insertions(+), 3 deletions(-)
>
> diff --git a/ui/details.ui b/ui/details.ui
> index c18070c8..ba9970d8 100644
> --- a/ui/details.ui
> +++ b/ui/details.ui
> @@ -76,6 +76,12 @@
> <property name="step_increment">1</property>
> <property name="page_increment">2</property>
> </object>
> + <object class="GtkAdjustment" id="adjustment8">
> + <property name="lower">3</property>
> + <property name="upper">2147483647</property>
How did you get to this number? According to the vsock(7) man page the
CID address is 32-bit unsigned number which should be 4294967295.
> + <property name="step_increment">1</property>
> + <property name="page_increment">10</property>
> + </object>
> <object class="GtkImage" id="image70">
> <property name="visible">True</property>
> <property name="can_focus">False</property>
> @@ -5856,6 +5862,119 @@
> <property name="tab_fill">False</property>
> </packing>
> </child>
> + <child>
> + <object class="GtkFrame" id="frame25">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="label_xalign">0</property>
> + <property name="shadow_type">none</property>
> + <child>
> + <object class="GtkAlignment" id="alignment7">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="top_padding">3</property>
> + <property name="left_padding">12</property>
> + <child>
> + <object class="GtkGrid" id="table61">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="row_spacing">6</property>
> + <property name="column_spacing">6</property>
> + <child>
> + <object class="GtkLabel" id="label70">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="label" translatable="yes">Guest CID:</property>
Here we should use "underline" feature in order to have keyboard
shortcut:
<property name="label" translatable="yes">Guest C_ID:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">vsock-cid</property>
This way if you press ALT+i it will switch focus to the vsock-cid
SpinnButton and you can type in the value without moving your mouse.
We do that for almost all the UI elements.
> + </object>
> + <packing>
> + <property name="left_attach">0</property>
> + <property name="top_attach">0</property>
> + </packing>
> + </child>
> + <child>
> + <object class="GtkBox">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <child>
> + <object class="GtkCheckButton" id="vsock-auto">
> + <property name="label" translatable="yes">Auto</property>
Here same thing, than you can use ALT+u to switch the "Auto" checkbox.
<property name="label" translatable="yes">A_uto</property>
<property name="use_underline">True</property>
> + <property name="visible">True</property>
> + <property name="can_focus">True</property>
> + <property name="receives_default">False</property>
> + <property name="margin_top">3</property>
> + <property name="margin_bottom">3</property>
> + <property name="active">True</property>
> + <property name="draw_indicator">True</property>
> + <signal name="toggled" handler="on_vsock_auto_toggled" swapped="no"/>
> + </object>
> + <packing>
> + <property name="expand">False</property>
> + <property name="fill">True</property>
> + <property name="position">0</property>
> + </packing>
> + </child>
> + <child>
> + <object class="GtkSpinButton" id="vsock-cid">
> + <property name="visible">True</property>
> + <property name="can_focus">True</property>
> + <property name="text" translatable="yes">3</property>
> + <property name="input_purpose">number</property>
> + <property name="adjustment">adjustment8</property>
> + <property name="climb_rate">1</property>
> + <property name="numeric">True</property>
> + <property name="value">3</property>
> + <signal name="value-changed" handler="on_vsock_cid_changed" swapped="no"/>
> + </object>
> + <packing>
> + <property name="expand">False</property>
> + <property name="fill">True</property>
> + <property name="padding">12</property>
> + <property name="pack_type">end</property>
> + <property name="position">1</property>
> + </packing>
> + </child>
> + <child>
> + <placeholder/>
> + </child>
> + </object>
> + <packing>
> + <property name="left_attach">1</property>
> + <property name="top_attach">0</property>
> + </packing>
> + </child>
> + </object>
> + </child>
> + </object>
> + </child>
> + <child type="label">
> + <object class="GtkLabel" id="label67">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="label" translatable="yes"><b>VM Sockets</b></property>
> + <property name="use_markup">True</property>
> + </object>
> + </child>
> + <child internal-child="accessible">
> + <object class="AtkObject" id="frame25-atkobject">
> + <property name="AtkObject::accessible-name">controller-tab</property>
> + </object>
> + </child>
> + </object>
> + <packing>
> + <property name="position">22</property>
> + </packing>
> + </child>
> + <child type="tab">
> + <object class="GtkLabel" id="label95">
> + <property name="visible">True</property>
> + <property name="can_focus">False</property>
> + <property name="label" translatable="yes">vsock</property>
> + </object>
> + <packing>
> + <property name="position">22</property>
> + <property name="tab_fill">False</property>
> + </packing>
> + </child>
> </object>
> <packing>
> <property name="expand">True</property>
> diff --git a/virtManager/details.py b/virtManager/details.py
> index b7e7fc14..7608d70a 100644
> --- a/virtManager/details.py
> +++ b/virtManager/details.py
> @@ -99,9 +99,12 @@ from .storagebrowse import vmmStorageBrowser
> EDIT_TPM_TYPE,
> EDIT_TPM_MODEL,
>
> + EDIT_VSOCK_AUTO,
> + EDIT_VSOCK_CID,
> +
> EDIT_FS,
>
> - EDIT_HOSTDEV_ROMBAR) = range(1, 56)
> + EDIT_HOSTDEV_ROMBAR) = range(1, 58)
>
>
> # Columns in hw list model
> @@ -133,7 +136,8 @@ from .storagebrowse import vmmStorageBrowser
> HW_LIST_TYPE_REDIRDEV,
> HW_LIST_TYPE_TPM,
> HW_LIST_TYPE_RNG,
> - HW_LIST_TYPE_PANIC) = range(22)
> + HW_LIST_TYPE_PANIC,
> + HW_LIST_TYPE_VSOCK) = range(23)
>
> remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
> HW_LIST_TYPE_GRAPHICS, HW_LIST_TYPE_SOUND, HW_LIST_TYPE_CHAR,
> @@ -141,7 +145,7 @@ remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
> HW_LIST_TYPE_WATCHDOG, HW_LIST_TYPE_CONTROLLER,
> HW_LIST_TYPE_FILESYSTEM, HW_LIST_TYPE_SMARTCARD,
> HW_LIST_TYPE_REDIRDEV, HW_LIST_TYPE_TPM,
> - HW_LIST_TYPE_RNG, HW_LIST_TYPE_PANIC]
> + HW_LIST_TYPE_RNG, HW_LIST_TYPE_PANIC, HW_LIST_TYPE_VSOCK]
>
> # Boot device columns
> (BOOT_KEY,
> @@ -264,6 +268,7 @@ def _label_for_device(dev):
> devmap = {
> "panic": _("Panic Notifier"),
> "smartcard": _("Smartcard"),
> + "vsock": _("VM Sockets"),
> "watchdog": _("Watchdog"),
> }
> return devmap[devtype]
> @@ -312,6 +317,7 @@ def _icon_for_device(dev):
> "filesystem": "folder",
> "controller": "device_pci",
> "panic": "system-run",
> + "vsock": "network-idle",
> }
> return typemap[devtype]
>
> @@ -584,6 +590,10 @@ class vmmDetails(vmmGObjectUI):
> "on_smartcard_mode_combo_changed": lambda *x: self.enable_apply(x,
> EDIT_SMARTCARD_MODE),
>
> + "on_vsock_auto_toggled": self.vsock_auto_toggled,
> + "on_vsock_cid_changed": lambda *x: self.enable_apply(x,
> + EDIT_VSOCK_CID),
> +
> "on_hostdev_rombar_toggled": lambda *x: self.enable_apply(
> x, EDIT_HOSTDEV_ROMBAR),
> "on_controller_model_combo_changed": (lambda *x:
> @@ -1259,6 +1269,8 @@ class vmmDetails(vmmGObjectUI):
> self.refresh_rng_page(dev)
> elif pagetype == HW_LIST_TYPE_PANIC:
> self.refresh_panic_page(dev)
> + elif pagetype == HW_LIST_TYPE_VSOCK:
> + self.refresh_vsock_page(dev)
> else:
> pagetype = -1
> except Exception as e:
> @@ -1768,6 +1780,11 @@ class vmmDetails(vmmGObjectUI):
> self.widget("video-3d").set_inconsistent(False)
> self.enable_apply(EDIT_VIDEO_3D)
>
> + def vsock_auto_toggled(self, ignore):
> + is_auto = self.widget("vsock-auto").get_active()
> + self.widget("vsock-cid").set_visible(not is_auto)
> + self.enable_apply(EDIT_VSOCK_AUTO)
> +
> # Boot device / Autostart
> def config_bootdev_selected(self, ignore=None):
> boot_row = self.get_boot_selection()
> @@ -1916,6 +1933,8 @@ class vmmDetails(vmmGObjectUI):
> ret = self.config_hostdev_apply(key)
> elif pagetype is HW_LIST_TYPE_TPM:
> ret = self.config_tpm_apply(key)
> + elif pagetype is HW_LIST_TYPE_VSOCK:
> + ret = self.config_vsock_apply(key)
> else:
> ret = False
> except Exception as e:
> @@ -2324,6 +2343,18 @@ class vmmDetails(vmmGObjectUI):
> kwargs, self.vm, self.err,
> devobj=devobj)
>
> + def config_vsock_apply(self, devobj):
> + kwargs = {}
> +
> + if self.edited(EDIT_VSOCK_AUTO):
> + kwargs["auto_cid"] = self.widget("vsock-auto").get_active()
> + if self.edited(EDIT_VSOCK_CID):
> + kwargs["cid"] = self.widget("vsock-cid").get_value_as_int()
> +
> + return vmmAddHardware.change_config_helper(self.vm.define_vsock,
> + kwargs, self.vm, self.err,
> + devobj=devobj)
> +
>
> # Device removal
> def remove_device(self, devobj):
> @@ -2820,6 +2851,13 @@ class vmmDetails(vmmGObjectUI):
> self.widget("rng-type").set_text(dev.get_pretty_type(dev.type))
> self.widget("rng-device").set_text(dev.device or "")
>
> + def refresh_vsock_page(self, dev):
> + is_auto = bool(dev.auto_cid)
> + cid = dev.cid
> + self.widget("vsock-auto").set_active(is_auto)
> + self.widget("vsock-cid").set_value(int(cid) if cid is not None else 3)
We should avoid using "magic numbers", if we need to change the default
value it's better to have a const somewhere.
> + self.widget("vsock-cid").set_visible(not is_auto)
Here we could do similar thing what is done for Graphics Port and
TLSPort, if vsock-auto is set we can show the automatically generated
CID address in the UI:
Guest CID: [x] Auto (CID: 3)
You can check virtManager/gfxdetails.py set_dev() function for
inspiration.
Otherwise lookg good.
Pavel
> +
> def refresh_char_page(self, chardev):
> show_target_type = not (chardev.DEVICE_TYPE in
> ["serial", "parallel"])
> @@ -3201,6 +3239,8 @@ class vmmDetails(vmmGObjectUI):
> update_hwlist(HW_LIST_TYPE_RNG, dev)
> for dev in self.vm.xmlobj.devices.panic:
> update_hwlist(HW_LIST_TYPE_PANIC, dev)
> + for dev in self.vm.xmlobj.devices.vsock:
> + update_hwlist(HW_LIST_TYPE_VSOCK, dev)
>
> devs = list(range(len(hw_list_model)))
> devs.reverse()
> diff --git a/virtManager/domain.py b/virtManager/domain.py
> index 4fcc716e..a06dd0ad 100644
> --- a/virtManager/domain.py
> +++ b/virtManager/domain.py
> @@ -49,6 +49,7 @@ def compare_device(origdev, newdev, idx):
> "tpm": ["type", "xmlindex"],
> "rng": ["type", "xmlindex"],
> "panic": ["type", "xmlindex"],
> + "vsock": ["xmlindex"],
> }
>
> if id(origdev) == id(newdev):
> @@ -959,6 +960,22 @@ class vmmDomain(vmmLibvirtObject):
> else:
> self._redefine_xmlobj(xmlobj)
>
> + def define_vsock(self, devobj, do_hotplug,
> + auto_cid=_SENTINEL, cid=_SENTINEL):
> + xmlobj = self._make_xmlobj_to_define()
> + editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
> + if not editdev:
> + return
> +
> + if auto_cid != _SENTINEL:
> + editdev.auto_cid = auto_cid
> + if cid != _SENTINEL:
> + editdev.cid = cid
> +
> + if do_hotplug:
> + self.hotplug(device=editdev)
> + else:
> + self._redefine_xmlobj(xmlobj)
>
> ####################
> # Hotplug routines #
> --
> 2.19.1
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20181210/b6f2534c/attachment.sig>
More information about the virt-tools-list
mailing list