virt-manager: fix adding EGD RNG devices in UDP mode

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1001773

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2013-10-25 17:13:28 +02:00
parent a832d77559
commit a7519dc1e9
2 changed files with 297 additions and 157 deletions

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.0 on Sat Oct 5 13:36:37 2013 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkAdjustment" id="adjustment1">
@ -2277,143 +2276,11 @@
<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">5</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="xalign">1</property>
<property name="label" translatable="yes">Device:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</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="xalign">1</property>
<property name="label" translatable="yes">Backend Mode:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</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">4</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="xalign">1</property>
<property name="label" translatable="yes">Backend Type:</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-type">
<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>
<child>
<object class="GtkLabel" id="label19">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</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">2</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">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</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">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">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Type:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">tpm-type</property>
@ -2438,6 +2305,228 @@
<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="xalign">0</property>
<property name="label" translatable="yes">Backend Type:</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="GtkComboBox" id="rng-backend-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_rng_backend_type_changed" swapped="no"/>
</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="label12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</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>
<signal name="changed" handler="on_rng_backend_mode_changed" swapped="no"/>
</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>
<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">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="rng-connect-host-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkEntry" id="rng-connect-host">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="char-port-label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Port:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">char-port</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="rng-connect-service">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</property>
<property name="adjustment">adjustment3</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="rng-bind-host-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Bind Host:</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="rng-bind-host-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkEntry" id="rng-bind-host">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="char-port-label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Port:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">char-port</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="rng-bind-service">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</property>
<property name="adjustment">adjustment2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</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="xalign">0</property>
<property name="label" translatable="yes">Device:</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="GtkEntry" id="rng-device">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</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>
</object>
<packing>
<property name="position">14</property>

View File

@ -95,7 +95,9 @@ class vmmAddHardware(vmmGObjectUI):
"on_usbredir_type_changed": self.change_usbredir_type,
"on_rng_type_changed": self.change_rng_type,
"on_rng_type_changed": self.change_rng,
"on_rng_backend_mode_changed": self.change_rng,
"on_rng_backend_type_changed": self.change_rng,
})
self.bind_escape_key_close()
@ -496,8 +498,11 @@ class vmmAddHardware(vmmGObjectUI):
# RNG params
self.widget("rng-device").set_text("/dev/random")
self.widget("rng-host").set_text("localhost")
self.widget("rng-service").set_text("708")
for i in ["rng-bind-host", "rng-connect-host"]:
self.widget(i).set_text("localhost")
for i in ["rng-bind-service", "rng-connect-service"]:
self.widget(i).set_text("708")
self.set_hw_selection(0)
@ -895,26 +900,45 @@ class vmmAddHardware(vmmGObjectUI):
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()
def get_config_rng_host(self, is_connect=False):
connect_mode = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT in \
self.get_config_rng_backend_mode()
is_udp = self.get_config_rng_backend_type() == \
virtinst.VirtualRNGDevice.BACKEND_TYPE_UDP
if connect_mode == is_connect or is_udp:
widget_name = "rng-connect-host" if is_connect else "rng-bind-host"
return self.widget(widget_name).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()
def get_config_rng_service(self, is_connect=False):
connect_mode = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT in \
self.get_config_rng_backend_mode()
is_udp = self.get_config_rng_backend_type() == \
virtinst.VirtualRNGDevice.BACKEND_TYPE_UDP
if connect_mode == is_connect or is_udp:
if is_connect:
widget_name = "rng-connect-service"
else:
widget_name = "rng-bind-service"
return self.widget(widget_name).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()
if active < 0:
return None
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()
if active < 0:
return None
return model[active][0]
################
@ -1179,18 +1203,29 @@ class vmmAddHardware(vmmGObjectUI):
uihelpers.set_grid_row_visible(self.widget("usbredir-host-box"),
showhost)
def change_rng_type(self, ignore1):
def change_rng(self, ignore1):
model = self.get_config_rng_type()
if model is None:
return
is_egd = model == virtinst.VirtualRNGDevice.TYPE_EGD
uihelpers.set_grid_row_visible(self.widget("rng-device"), not is_egd)
uihelpers.set_grid_row_visible(self.widget("rng-host"), is_egd)
uihelpers.set_grid_row_visible(self.widget("rng-service"), is_egd)
uihelpers.set_grid_row_visible(self.widget("rng-backend-mode"), is_egd)
uihelpers.set_grid_row_visible(self.widget("rng-backend-type"), is_egd)
backend_type = self.get_config_rng_backend_type()
backend_mode = self.get_config_rng_backend_mode()
udp = backend_type == virtinst.VirtualRNGDevice.BACKEND_TYPE_UDP
bind = backend_mode == virtinst.VirtualRNGDevice.BACKEND_MODE_BIND
v = is_egd and (udp or bind)
uihelpers.set_grid_row_visible(self.widget("rng-bind-host-box"), v)
v = is_egd and (udp or not bind)
uihelpers.set_grid_row_visible(self.widget("rng-connect-host-box"), v)
v = is_egd and not udp
uihelpers.set_grid_row_visible(self.widget("rng-backend-mode"), v)
# FS listeners
def browse_fs_source(self, ignore1):
self._browse_file(self.widget("fs-source"), isdir=True)
@ -1730,31 +1765,47 @@ class vmmAddHardware(vmmGObjectUI):
return self.err.val_err(_("TPM device parameter error"), e)
def validate_page_rng(self):
conn = self.conn.get_backend()
conn = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT in \
self.get_config_rng_backend_mode()
model = self.get_config_rng_type()
is_udp = self.get_config_rng_backend_type() == \
virtinst.VirtualRNGDevice.BACKEND_TYPE_UDP
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."))
conn = self.get_config_rng_backend_mode() == \
virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT
if not self.get_config_rng_service():
return self.err.val_err(_("RNG selection error."),
_("The EGD service must be specified."))
if is_udp:
if not self.get_config_rng_host(is_connect=conn) or \
not self.get_config_rng_host(is_connect=not conn):
return self.err.val_err(_("RNG selection error."),
_("Please specify both bind and connect host"))
if not int(self.get_config_rng_service(is_connect=conn)) or \
not int(self.get_config_rng_service(is_connect=not conn)):
return self.err.val_err(_("RNG selection error."),
_("Please specify both bind and connect service"))
else:
if not self.get_config_rng_host(is_connect=conn):
return self.err.val_err(_("RNG selection error."),
_("The EGD host must be specified."))
if not int(self.get_config_rng_service(is_connect=conn)):
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(),
"connect_host" : self.get_config_rng_host(is_connect=True),
"connect_service" : self.get_config_rng_service(is_connect=True),
"bind_host" : self.get_config_rng_host(),
"bind_service" : self.get_config_rng_service(),
"device" : self.get_config_rng_device(),
}