[virt-tools-list] [PATCH] virt-install: accept a single argument form for RNG devices

Giuseppe Scrivano gscrivan at redhat.com
Wed Sep 25 21:04:12 UTC 2013


Detect the "--rng /dev/random" case and assume it is the "random" type.

Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---

this is a follow on patch to the previous RNG devices support series.

Now it is possible to pass directly an arg to "--rng" and it will be
assumed a "random" type RNG device.

 man/virt-install.pod |  5 +++++
 tests/clitest.py     |  2 ++
 virtinst/cli.py      | 28 ++++++++++++++++++----------
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/man/virt-install.pod b/man/virt-install.pod
index 40d153e..378cebb 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1258,6 +1258,11 @@ An example invocation:
 
 Connect to localhost to the TCP port 8000 to get entropy data.
 
+=item B<--rng /dev/random>
+
+Use the /dev/random device to get entropy data, this form implicitly uses the
+"random" model.
+
 
 See C<http://libvirt.org/formatdomain.html#elementsRng> for complete
 details.
diff --git a/tests/clitest.py b/tests/clitest.py
index ca4b019..f8e2b04 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -438,6 +438,8 @@ 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 /dev/random")  # random device backend, short form
+c.add_invalid("--rng /FOO/BAR")  # random device backend, short form, invalid device
 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
diff --git a/virtinst/cli.py b/virtinst/cli.py
index bff7374..3f0d86a 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1005,6 +1005,7 @@ def add_device_options(devg):
                            "--tpm type=passthrough"))
     devg.add_option("", "--rng", dest="rng", action="append",
                     help=_("Configure a guest RNG device. Ex:\n"
+                           "--rng /dev/random\n"
                            "--rng type=egd,host=localhost,service=708"))
 
 
@@ -1750,7 +1751,8 @@ def parse_rng(guest, optstring, dev=None):
         return None
 
     opts = parse_optstr(optstring, remove_first="type")
-    if opts.get("type") == "none":
+    dev_type = opts.get("type")
+    if dev_type == "none":
         return None
 
     if not dev:
@@ -1758,15 +1760,21 @@ def parse_rng(guest, optstring, dev=None):
 
     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")
+    if dev_type.startswith("/"):
+        # if the provided type begins with '/' then assume it is the name of
+        # the RNG device and that its type is "random".
+        dev.device = dev_type
+        dev.type = "random"
+    else:
+        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
 
-- 
1.8.3.1




More information about the virt-tools-list mailing list