Blob Blame History Raw
From 0f0ada4131eafe4712513cd0859f076bb8c44ac9 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 30 Sep 2013 17:15:43 +0200
Subject: [RHEL-7.0 virt-manager PATCH] virt-install: accept a single argument
 form for RNG devices

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
(cherry picked from commit 601eb5f15e70288009088c425c910d32ee15976d)

Conflicts:
	tests/clitest.py
---
 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 80d4d88..e6d6e4b 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1221,6 +1221,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 3082a1f..42911b0 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -682,6 +682,8 @@ vinst.add_valid("rng", "--rng random,device=/dev/random")  # random device backe
 vinst.add_valid("rng", "--rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=tcp")  # egd backend
 vinst.add_valid("rng", "--rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=tcp,backend_mode=bind")  # egd backend, bind mode
 vinst.add_invalid("rng", "--rng foo,backend_host=127.0.0.1,backend_service=8000,backend_mode=connect")  # invalid type
+vinst.add_valid("rng", "--rng /dev/random")  # random device backend, short form
+vinst.add_invalid("rng", "--rng /FOO/BAR")  # random device backend, short form, invalid device


 vimag = App("virt-image")
diff --git a/virtinst/cli.py b/virtinst/cli.py
index e31401c..99fcef0 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1198,6 +1198,7 @@ def add_device_options(devg):
                            "--memballoon model=virtio"))
     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"))


@@ -1928,7 +1929,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:
@@ -1936,15 +1938,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.2