[virt-tools-list] [RFC PATCH 2/3] virt-install: add support for virtio-rng devices

Giuseppe Scrivano gscrivan at redhat.com
Wed Sep 18 13:29:29 UTC 2013


Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 man/virt-install.pod | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/clitest.py     |  6 ++++++
 virt-install         |  1 +
 virtinst/cli.py      | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+)

diff --git a/man/virt-install.pod b/man/virt-install.pod
index 456f21c..40d153e 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1215,6 +1215,55 @@ Make the host's TPM accessible to a single guest.
 See C<http://libvirt.org/formatdomain.html#elementsTpm> for complete
 details.
 
+=item --rng=TYPE[,OPTS]
+
+Configure a virtual RNG device.
+
+Type can be B<random> or B<egd>.
+
+If the specified type is B<random> then these values must
+be specified:
+
+=over 4
+
+=item B<backend_device>
+
+The device to use as a source of entropy.
+
+=back
+
+Whereas, when the type is B<egd>, these values must be provided:
+
+=over 4
+
+=item B<backend_host>
+
+Specify the host of the Entropy Gathering Daemon to connect to.
+
+=item B<backend_service>
+
+Specify the port of the Entropy Gathering Daemon to connect to.
+
+=item B<backend_type>
+
+Specify the type of the connection: B<tcp> or B<udp>.
+
+=back
+
+An example invocation:
+
+=over 4
+
+=item B<--rng egd,backend_host=localhost,backend_service=8000,backend_type=tcp>
+
+Connect to localhost to the TCP port 8000 to get entropy data.
+
+
+See C<http://libvirt.org/formatdomain.html#elementsRng> for complete
+details.
+
+=back
+
 =back
 
 =head2 Miscellaneous Options
diff --git a/tests/clitest.py b/tests/clitest.py
index b6e0d19..2c5d4b5 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -436,6 +436,12 @@ c.add_valid("--tpm passthrough,model=tpm-tis")  # --tpm backend type with model
 c.add_valid("--tpm passthrough,model=tpm-tis,path=/dev/tpm0")  # --tpm backend type with model and device path
 c.add_invalid("--tpm passthrough,model=foo")  # Invalid model
 
+c = vinst.add_category("tpm", "--noautoconsole --nodisks --pxe")
+c.add_valid("--rng random,device=/dev/random")  # random device backend
+c.add_valid("--rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=tcp")  # egd backend
+c.add_valid("--rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=tcp,backend_mode=bind")  # egd backend, bind mode
+c.add_invalid("--rng foo,backend_host=127.0.0.1,backend_service=8000,backend_mode=connect")  # invalid type
+
 
 c = vinst.add_category("xen", "--connect %(XENURI)s --noautoconsole")
 c.add_compare("--disk %(EXISTIMG1)s --import", "xen-default")  # Xen default
diff --git a/virt-install b/virt-install
index 4fe4ce1..22a4fc7 100755
--- a/virt-install
+++ b/virt-install
@@ -527,6 +527,7 @@ def build_guest_instance(conn, options):
     cli.get_hostdevs(options.hostdevs, guest)
     cli.get_smartcard(guest, options.smartcard)
     cli.get_tpm(guest, options.tpm)
+    cli.get_rng(guest, options.rng)
 
     if not guest.get_devices("input"):
         guest.add_default_input_device()
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 8553434..18707ea 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -894,6 +894,17 @@ def get_tpm(guest, tpm_opts):
             guest.add_device(dev)
 
 
+def get_rng(guest, rng_opts):
+    for rng in listify(rng_opts):
+        try:
+            dev = parse_rng(guest, rng)
+        except Exception, e:
+            fail(_("Error in RNG device parameters: %s") % str(e))
+
+        if dev:
+            guest.add_device(dev)
+
+
 def get_controller(guest, sc_opts):
     for sc in listify(sc_opts):
         try:
@@ -1034,6 +1045,9 @@ def add_device_options(devg):
     devg.add_option("", "--tpm", dest="tpm", action="append",
                     help=_("Configure a guest TPM device. Ex:\n"
                            "--tpm type=passthrough"))
+    devg.add_option("", "--rng", dest="rng", action="append",
+                    help=_("Configure a guest RNG device. Ex:\n"
+                           "--rng type=egd,host=localhost,service=708"))
 
 
 def add_gfx_option(devg):
@@ -1773,6 +1787,32 @@ def parse_tpm(guest, optstring, dev=None):
     return dev
 
 
+def parse_rng(guest, optstring, dev=None):
+    if optstring is None:
+        return None
+
+    opts = parse_optstr(optstring, remove_first="type")
+    if opts.get("type") == "none":
+        return None
+
+    if not dev:
+        dev = virtinst.VirtualRNGDevice(guest.conn)
+
+    set_param = _build_set_param(dev, opts)
+
+    set_param("type", "type")
+    set_param("backend_source_host", "backend_host")
+    set_param("backend_source_service", "backend_service")
+    set_param("backend_source_mode", "backend_mode")
+    set_param("backend_type", "backend_type")
+    set_param("device", "device")
+    set_param("model", "model")
+    set_param("rate_bytes", "rate_bytes")
+    set_param("rate_period", "rate_period")
+
+    return dev
+
+
 ######################
 # --watchdog parsing #
 ######################
-- 
1.8.3.1




More information about the virt-tools-list mailing list