Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1001773 Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx> --- ui/vmm-add-hardware.ui | 235 +++++++++++++++++++++++++++++++++++++++ ui/vmm-details.ui | 271 +++++++++++++++++++++++++++++++++++++++++++++ virtManager/addhardware.py | 107 ++++++++++++++++++ virtManager/details.py | 41 ++++++- virtManager/domain.py | 3 + virtManager/uihelpers.py | 58 ++++++++++ 6 files changed, 713 insertions(+), 2 deletions(-) diff --git a/ui/vmm-add-hardware.ui b/ui/vmm-add-hardware.ui index 4b8f341..31d3f13 100644 --- a/ui/vmm-add-hardware.ui +++ b/ui/vmm-add-hardware.ui @@ -2198,6 +2198,241 @@ <property name="tab_fill">False</property> </packing> </child> + <child> + <object class="GtkGrid" id="rng-table"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="valign">start</property> + <property name="row_spacing">6</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="label4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="label" translatable="yes">_Type:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">tpm-type</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="rng-type"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <signal name="changed" handler="on_rng_type_changed" swapped="no"/> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkNotebook" id="rng-host-notebook"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="halign">start</property> + <property name="valign">start</property> + <property name="show_tabs">False</property> + <property name="show_border">False</property> + <child> + <object class="GtkGrid" id="grid2"> + <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="GtkEntry" id="rng-device"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Device:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <object class="GtkGrid" id="grid1"> + <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="label17"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Host:</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label19"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Service:</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="rng-host"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="rng-service"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label8"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Backend Type:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="rng-backend-type"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">2</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label12"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Backend Mode:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="rng-backend-mode"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">3</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child type="tab"> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child type="tab"> + <placeholder/> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">14</property> + </packing> + </child> + <child type="tab"> + <object class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">rng</property> + </object> + <packing> + <property name="position">14</property> + <property name="tab_fill">False</property> + </packing> + </child> </object> </child> </object> diff --git a/ui/vmm-details.ui b/ui/vmm-details.ui index 1b89c72..efebb9b 100644 --- a/ui/vmm-details.ui +++ b/ui/vmm-details.ui @@ -6998,6 +6998,277 @@ I/O:</property> <property name="tab_fill">False</property> </packing> </child> + <child> + <object class="GtkTable" id="table16"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="border_width">3</property> + <property name="n_rows">8</property> + <property name="n_columns">2</property> + <property name="column_spacing">8</property> + <property name="row_spacing">4</property> + <child> + <object class="GtkLabel" id="rng-type"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="ypad">2</property> + <property name="label">rng-type</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"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="label89"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Type:</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Device:</property> + </object> + <packing> + <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> + <object class="GtkLabel" id="rng-device"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-device</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> + <object class="GtkLabel" id="rng-label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Host:</property> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Service:</property> + </object> + <packing> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-host"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-host</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-service"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-service</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Backend type:</property> + </object> + <packing> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-backend-type"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-backend-type</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Rate (bytes):</property> + </object> + <packing> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Rate (period):</property> + </object> + <packing> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-rate-bytes"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-rate-bytes</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-rate-period"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-rate-period</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-label7"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="ypad">2</property> + <property name="label" translatable="yes">Mode:</property> + </object> + <packing> + <property name="top_attach">7</property> + <property name="bottom_attach">8</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + <child> + <object class="GtkLabel" id="rng-mode"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">rng-mode</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">7</property> + <property name="bottom_attach">8</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"/> + </packing> + </child> + </object> + <packing> + <property name="position">19</property> + </packing> + </child> + <child type="tab"> + <object class="GtkLabel" id="label81"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">rng</property> + </object> + <packing> + <property name="position">19</property> + <property name="tab_fill">False</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index e13482c..0fe6d06 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -54,6 +54,7 @@ PAGE_FILESYSTEM = 10 PAGE_SMARTCARD = 11 PAGE_USBREDIR = 12 PAGE_TPM = 13 +PAGE_RNG = 14 char_widget_mappings = { "source_path" : "char-path", @@ -105,6 +106,8 @@ class vmmAddHardware(vmmGObjectUI): "on_fs_source_browse_clicked": self.browse_fs_source, "on_usbredir_type_changed": self.change_usbredir_type, + + "on_rng_type_changed": self.change_rng_type, }) self.bind_escape_key_close() @@ -310,6 +313,14 @@ class vmmAddHardware(vmmGObjectUI): combo = self.widget("tpm-type") uihelpers.build_tpm_type_combo(self.vm, combo) + # RNG widgets + combo = self.widget("rng-type") + uihelpers.build_rng_type_combo(self.vm, combo) + combo = self.widget("rng-backend-type") + uihelpers.build_rng_backend_type_combo(self.vm, combo) + combo = self.widget("rng-backend-mode") + uihelpers.build_rng_backend_mode_combo(self.vm, combo) + # Available HW options is_local = not self.conn.is_remote() is_storage_capable = self.conn.is_storage_capable() @@ -376,6 +387,7 @@ class vmmAddHardware(vmmGObjectUI): True, None) add_hw_option("TPM", "device_cpu", PAGE_TPM, True, None) + add_hw_option("RNG", "system-run", PAGE_RNG, True, None) def reset_state(self): # Storage init @@ -474,6 +486,11 @@ class vmmAddHardware(vmmGObjectUI): widget = notebook.get_nth_page(page) widget.hide() + # RNG params + self.widget("rng-device").set_text("/dev/random") + self.widget("rng-host").set_text("localhost") + self.widget("rng-service").set_text("708") + self.set_hw_selection(0) ######################### @@ -771,6 +788,44 @@ class vmmAddHardware(vmmGObjectUI): typestr = typ.get_model().get_value(typ.get_active_iter(), 0) return typestr + # RNG getters + def get_config_rng_type(self): + src = self.widget("rng-type") + idx = src.get_active() + if idx < 0: + return None + + selected_type = src.get_model()[idx][0] + return selected_type + + def get_config_rng_device(self): + if self.get_config_rng_type() == virtinst.VirtualRNGDevice.TYPE_RANDOM: + return self.widget("rng-device").get_text() + + return None + + def get_config_rng_host(self): + if self.get_config_rng_type() == virtinst.VirtualRNGDevice.TYPE_EGD: + return self.widget("rng-host").get_text() + + return None + + def get_config_rng_service(self): + if self.get_config_rng_type() == virtinst.VirtualRNGDevice.TYPE_EGD: + return self.widget("rng-service").get_text() + + return None + + def get_config_rng_backend_type(self): + active = self.widget("rng-backend-type").get_active() + model = self.widget("rng-backend-type").get_model() + return model[active][0] + + def get_config_rng_backend_mode(self): + active = self.widget("rng-backend-mode").get_active() + model = self.widget("rng-backend-mode").get_model() + return model[active][0] + ################ # UI listeners # ################ @@ -929,6 +984,8 @@ class vmmAddHardware(vmmGObjectUI): return _("USB Redirection") if page == PAGE_TPM: return _("TPM") + if page == PAGE_RNG: + return _("Random Number Generator") if page == PAGE_CHAR: char_class = self.get_char_type() @@ -990,6 +1047,14 @@ class vmmAddHardware(vmmGObjectUI): uihelpers.set_grid_row_visible(self.widget("usbredir-host-box"), showhost) + def change_rng_type(self, ignore1): + model = self.get_config_rng_type() + if model is None: + return + + page_idx = virtinst.VirtualRNGDevice.TYPES.index(model) + self.widget("rng-host-notebook").set_current_page(page_idx) + # FS listeners def browse_fs_source(self, ignore1): self._browse_file(self.widget("fs-source"), isdir=True) @@ -1166,6 +1231,8 @@ class vmmAddHardware(vmmGObjectUI): return self.validate_page_usbredir() elif page_num == PAGE_TPM: return self.validate_page_tpm() + elif page_num == PAGE_RNG: + return self.validate_page_rng() def validate_page_storage(self): bus, device = self.get_config_disk_target() @@ -1539,6 +1606,46 @@ class vmmAddHardware(vmmGObjectUI): except Exception, e: return self.err.val_err(_("TPM device parameter error"), e) + def validate_page_rng(self): + conn = self.conn.get_backend() + model = self.get_config_rng_type() + + if model == virtinst.VirtualRNGDevice.TYPE_RANDOM: + if not self.get_config_rng_device(): + return self.err.val_err(_("RNG selection error."), + _("A device must be specified.")) + elif model == virtinst.VirtualRNGDevice.TYPE_EGD: + if not self.get_config_rng_host(): + return self.err.val_err(_("RNG selection error."), + _("The EGD host must be specified.")) + + if not self.get_config_rng_service(): + return self.err.val_err(_("RNG selection error."), + _("The EGD service must be specified.")) + else: + return self.err.val_err(_("RNG selection error."), + _("Invalid RNG type.")) + + value_mappings = { + "backend_mode" : "connect", + "backend_type" : self.get_config_rng_backend_type(), + "backend_source_mode" : self.get_config_rng_backend_mode(), + "backend_source_host" : self.get_config_rng_host(), + "backend_source_service" : self.get_config_rng_service(), + "device" : self.get_config_rng_device(), + "model" : "virtio" + } + + try: + self._dev = virtinst.VirtualRNGDevice(conn) + self._dev.type = self.get_config_rng_type() + for param_name, val in value_mappings.items(): + if self._dev.supports_property(param_name): + setattr(self._dev, param_name, val) + except Exception, e: + return self.err.val_err(_("TPM device parameter error"), e) + + #################### # Unsorted helpers # #################### diff --git a/virtManager/details.py b/virtManager/details.py index a02778c..d08ef71 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -122,14 +122,16 @@ EDIT_TPM_TYPE, HW_LIST_TYPE_FILESYSTEM, HW_LIST_TYPE_SMARTCARD, HW_LIST_TYPE_REDIRDEV, - HW_LIST_TYPE_TPM) = range(19) + HW_LIST_TYPE_TPM, + HW_LIST_TYPE_RNG) = range(20) remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT, HW_LIST_TYPE_GRAPHICS, HW_LIST_TYPE_SOUND, HW_LIST_TYPE_CHAR, HW_LIST_TYPE_HOSTDEV, HW_LIST_TYPE_DISK, HW_LIST_TYPE_VIDEO, 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_REDIRDEV, HW_LIST_TYPE_TPM, + HW_LIST_TYPE_RNG] # Boot device columns (BOOT_DEV_TYPE, @@ -1256,6 +1258,8 @@ class vmmDetails(vmmGObjectUI): self.refresh_redir_page() elif pagetype == HW_LIST_TYPE_TPM: self.refresh_tpm_page() + elif pagetype == HW_LIST_TYPE_RNG: + self.refresh_rng_page() else: pagetype = -1 except Exception, e: @@ -3143,6 +3147,34 @@ class vmmDetails(vmmGObjectUI): # Device type specific properties, only show if apply to the cur dev show_ui("device_path") + def refresh_rng_page(self): + dev = self.get_hw_selection(HW_LIST_COL_DEVICE) + values = {"rng-type" : "type", + "rng-device" : "device", + "rng-host" : "backend_source_host", + "rng-service" : "backend_source_service", + "rng-mode" : "backend_source_mode", + "rng-backend-type" : "backend_type", + "rng-rate-bytes" : "rate_bytes", + "rng-rate-period" : "rate_period"} + rewriter = {"rng-type" : lambda x: + virtinst.VirtualRNGDevice.get_pretty_type(x), + "rng-backend-type" : lambda x: + virtinst.VirtualRNGDevice.get_pretty_backend_type(x), + "rng-mode" : lambda x: + virtinst.VirtualRNGDevice.get_pretty_mode(x) + } + + for k in values: + prop = values[k] + val = "-" + if dev.supports_property(prop): + val = getattr(dev, prop) or "-" + r = rewriter.get(k) + if r: + val = r(val) + self.widget(k).set_text(val) + def refresh_char_page(self): chardev = self.get_hw_selection(HW_LIST_COL_DEVICE) if not chardev: @@ -3607,6 +3639,11 @@ class vmmDetails(vmmGObjectUI): update_hwlist(HW_LIST_TYPE_TPM, tpm, _("TPM"), "device_cpu") + # Populate list of RNG devices + for rng in self.vm.get_rng_devices(): + update_hwlist(HW_LIST_TYPE_RNG, rng, + _("RNG"), "system-run") + devs = range(len(hw_list_model)) devs.reverse() for i in devs: diff --git a/virtManager/domain.py b/virtManager/domain.py index cf2825d..7ce65ef 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -55,6 +55,7 @@ def compare_device(origdev, newdev, idx): "smartcard" : ["mode" , "vmmindex"], "redirdev" : ["bus" , "type", "vmmindex"], "tpm" : ["type" , "vmmindex"], + "rng" : ["type" , "vmmindex"], } if id(origdev) == id(newdev): @@ -1144,6 +1145,8 @@ class vmmDomain(vmmLibvirtObject): return self._build_device_list("redirdev") def get_tpm_devices(self): return self._build_device_list("tpm") + def get_rng_devices(self): + return self._build_device_list("rng") def get_disk_devices(self, refresh_if_nec=True, inactive=False): devs = self._build_device_list("disk", refresh_if_nec, inactive) diff --git a/virtManager/uihelpers.py b/virtManager/uihelpers.py index 68fd32e..c86d951 100644 --- a/virtManager/uihelpers.py +++ b/virtManager/uihelpers.py @@ -330,6 +330,64 @@ def populate_tpm_type_combo(vm, combo): types.append([t, virtinst.VirtualTPMDevice.get_pretty_type(t)]) +def build_combo_with_values(combo, values, default=None): + dev_model = Gtk.ListStore(str, str) + combo.set_model(dev_model) + text = Gtk.CellRendererText() + combo.pack_start(text, True) + combo.add_attribute(text, 'text', 1) + dev_model.set_sort_column_id(0, Gtk.SortType.ASCENDING) + + types = combo.get_model() + types.clear() + + # [xml value, label] + for t in values: + types.append(t[0:2]) + + if default: + idx = -1 + for rowid in range(len(combo.get_model())): + idx = 0 + row = combo.get_model()[rowid] + if row[0] == default: + idx = rowid + break + combo.set_active(idx) + + +def build_rng_type_combo(vm, combo): + ignore = vm + + types = [] + for t in virtinst.VirtualRNGDevice.TYPES: + types.append([t, virtinst.VirtualRNGDevice.get_pretty_type(t)]) + + build_combo_with_values(combo, types, virtinst.VirtualRNGDevice.TYPE_RANDOM) + + +def build_rng_backend_type_combo(vm, combo): + ignore = vm + default = virtinst.VirtualRNGDevice.BACKEND_TYPE_TCP + + types = [] + for t in virtinst.VirtualRNGDevice.BACKEND_TYPES: + types.append([t, virtinst.VirtualRNGDevice.get_pretty_backend_type(t)]) + + build_combo_with_values(combo, types, default) + + +def build_rng_backend_mode_combo(vm, combo): + ignore = vm + default = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT + + types = [] + for t in virtinst.VirtualRNGDevice.BACKEND_MODES: + types.append([t, virtinst.VirtualRNGDevice.get_pretty_backend_type(t)]) + + build_combo_with_values(combo, types, default) + + def build_netmodel_combo(vm, combo): dev_model = Gtk.ListStore(str, str) combo.set_model(dev_model) -- 1.8.3.1 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list