virsh: Add auth options for pool-{create|define}-as

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>
This commit is contained in:
John Ferlan 2014-12-03 18:45:50 -05:00
parent c9ffd3ea9e
commit 893258063d
2 changed files with 33 additions and 2 deletions

View File

@ -223,6 +223,18 @@ static const vshCmdOptDef opts_pool_X_as[] = {
.type = VSH_OT_STRING, .type = VSH_OT_STRING,
.help = N_("format for underlying storage") .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} {.name = NULL}
}; };
@ -234,7 +246,8 @@ vshBuildPoolXML(vshControl *ctl,
{ {
const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL, const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
*srcDev = NULL, *srcName = NULL, *srcFormat = NULL, *srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
*target = NULL; *target = NULL, *authType = NULL, *authUsername = NULL,
*secretUsage = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) 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-dev", &srcDev) < 0 ||
vshCommandOptStringReq(ctl, cmd, "source-name", &srcName) < 0 || vshCommandOptStringReq(ctl, cmd, "source-name", &srcName) < 0 ||
vshCommandOptStringReq(ctl, cmd, "source-format", &srcFormat) < 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; goto cleanup;
virBufferAsprintf(&buf, "<pool type='%s'>\n", type); virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
@ -263,6 +279,14 @@ vshBuildPoolXML(vshControl *ctl,
virBufferAsprintf(&buf, "<dir path='%s'/>\n", srcPath); virBufferAsprintf(&buf, "<dir path='%s'/>\n", srcPath);
if (srcDev) if (srcDev)
virBufferAsprintf(&buf, "<device path='%s'/>\n", 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) if (srcFormat)
virBufferAsprintf(&buf, "<format type='%s'/>\n", srcFormat); virBufferAsprintf(&buf, "<format type='%s'/>\n", srcFormat);
if (srcName) if (srcName)

View File

@ -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>] =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-host hostname>] [I<--source-path path>] [I<--source-dev path>]
[I<--source-name name>] [I<--target path>] [I<--source-format format>] [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 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 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 [I<--source-format format>] provides information about the format of the
pool (pool types fs, netfs, disk, logical). 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> =item B<pool-define> I<file>
Create, but do not start, a pool object from the XML 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>] =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-host hostname>] [I<--source-path path>] [I<--source-dev path>]
[I<--source-name name>] [I<--target path>] [I<--source-format format>] [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 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 I<--print-xml> is specified, then print the XML of the pool object