[libvirt] [PATCH 3/4] virsh: Add auth options for pool-{create|define}-as

John Ferlan jferlan at redhat.com
Thu Dec 4 14:45:58 UTC 2014


Add 3 new optional options for the pool-create-as and pool-define-as
command in order to define the 3 elements required in order to add
an auth element, such as:

<auth type='chap' username='myuser'>
  <secret usage='libvirtiscsi'/>
</auth>

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 tools/virsh-pool.c | 28 ++++++++++++++++++++++++++--
 tools/virsh.pod    |  7 +++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index cf7776c..bba7d68 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -223,6 +223,18 @@ static const vshCmdOptDef opts_pool_X_as[] = {
      .type = VSH_OT_STRING,
      .help = N_("format for underlying storage")
     },
+    {.name = "auth-type",
+     .type = VSH_OT_STRING,
+     .help = N_("auth type to be used for underlying storage")
+    },
+    {.name = "auth-username",
+     .type = VSH_OT_STRING,
+     .help = N_("auth username to be used for underlying storage")
+    },
+    {.name = "secret-usage",
+     .type = VSH_OT_STRING,
+     .help = N_("auth secret usage to be used for underlying storage")
+    },
     {.name = NULL}
 };
 
@@ -234,7 +246,8 @@ vshBuildPoolXML(vshControl *ctl,
 {
     const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
                *srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
-               *target = NULL;
+               *target = NULL, *authType = NULL, *authUsername = NULL,
+               *secretUsage = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
     if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
@@ -247,7 +260,10 @@ vshBuildPoolXML(vshControl *ctl,
         vshCommandOptStringReq(ctl, cmd, "source-dev", &srcDev) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "source-name", &srcName) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "source-format", &srcFormat) < 0 ||
-        vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
+        vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "auth-type", &authType) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "auth-username", &authUsername) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "secret-usage", &secretUsage) < 0)
         goto cleanup;
 
     virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
@@ -263,6 +279,14 @@ vshBuildPoolXML(vshControl *ctl,
             virBufferAsprintf(&buf, "<dir path='%s'/>\n", srcPath);
         if (srcDev)
             virBufferAsprintf(&buf, "<device path='%s'/>\n", srcDev);
+        if (authType && authUsername && secretUsage) {
+            virBufferAsprintf(&buf, "<auth type='%s' username='%s'>\n",
+                              authType, authUsername);
+            virBufferAdjustIndent(&buf, 2);
+            virBufferAsprintf(&buf, "<secret usage='%s'/>\n", secretUsage);
+            virBufferAdjustIndent(&buf, -2);
+            virBufferAddLit(&buf, "</auth>\n");
+        }
         if (srcFormat)
             virBufferAsprintf(&buf, "<format type='%s'/>\n", srcFormat);
         if (srcName)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1b31597..45dd924 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2959,6 +2959,7 @@ Create and start a pool object from the XML I<file>.
 =item B<pool-create-as> I<name> I<type> [I<--print-xml>]
 [I<--source-host hostname>] [I<--source-path path>] [I<--source-dev path>]
 [I<--source-name name>] [I<--target path>] [I<--source-format format>]
+[I<--auth-type authtype> I<--auth-username username> I<--secret-usage usage>]
 
 Create and start a pool object I<name> from the raw parameters.  If
 I<--print-xml> is specified, then print the XML of the pool object
@@ -2984,6 +2985,11 @@ the host file system.
 [I<--source-format format>] provides information about the format of the
 pool (pool types fs, netfs, disk, logical).
 
+[I<--auth-type authtype> I<--auth-username username> I<--secret-usage usage>]
+provides the elements required to generate authentication credentials for
+the storage pool. The I<authtype> is either chap for iscsi I<type> pools or
+ceph for rbd I<type> pools.
+
 =item B<pool-define> I<file>
 
 Create, but do not start, a pool object from the XML I<file>.
@@ -2991,6 +2997,7 @@ Create, but do not start, a pool object from the XML I<file>.
 =item B<pool-define-as> I<name> I<type> [I<--print-xml>]
 [I<--source-host hostname>] [I<--source-path path>] [I<--source-dev path>]
 [I<--source-name name>] [I<--target path>] [I<--source-format format>]
+[I<--auth-type authtype> I<--auth-username username> I<--secret-usage usage>]
 
 Create, but do not start, a pool object I<name> from the raw parameters.  If
 I<--print-xml> is specified, then print the XML of the pool object
-- 
1.9.3




More information about the libvir-list mailing list