Add --alias to support custom alias in virsh attach-interface. Report error if custom alias doesn't start with 'ua-'. Signed-off-by: Han Han <hhan@xxxxxxxxxx> --- tools/virsh-domain.c | 15 ++++++++++++++- tools/virsh.pod | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 467417852e..66b7cea353 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -842,6 +842,10 @@ static const vshCmdOptDef opts_attach_interface[] = { .type = VSH_OT_STRING, .help = N_("model type") }, + {.name = "alias", + .type = VSH_OT_STRING, + .help = N_("custom alias name of interface device") + }, {.name = "inbound", .type = VSH_OT_STRING, .help = N_("control domain's incoming traffics") @@ -915,7 +919,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom = NULL; const char *mac = NULL, *target = NULL, *script = NULL, *type = NULL, *source = NULL, *model = NULL, - *inboundStr = NULL, *outboundStr = NULL; + *inboundStr = NULL, *outboundStr = NULL, alias= NULL; virNetDevBandwidthRate inbound, outbound; virDomainNetType typ; int ret; @@ -945,6 +949,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0 || vshCommandOptStringReq(ctl, cmd, "script", &script) < 0 || vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 || + vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 || vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0) goto cleanup; @@ -1042,6 +1047,14 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (model != NULL) virBufferAsprintf(&buf, "<model type='%s'/>\n", model); + if (alias != NULL) { + if (!STRPREFIX(alias, "ua-")) { + vshError(ctl, _("Custom alias name should start with ua-")); + goto cleanup; + } + virBufferAsprintf(&buf, "<alias name='%s'/>\n", alias); + } + if (inboundStr || outboundStr) { virBufferAddLit(&buf, "<bandwidth>\n"); virBufferAdjustIndent(&buf, 2); diff --git a/tools/virsh.pod b/tools/virsh.pod index 4f0d12225a..4af21462e9 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3085,7 +3085,7 @@ Likewise, I<--shareable> is an alias for I<--mode shareable>. [[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>] [I<--inbound average,peak,burst,floor>] [I<--outbound average,peak,burst>] -[I<--managed>] [I<--print-xml>] +[I<--alias alias>] [I<--managed>] [I<--print-xml>] Attach a new network interface to the domain. @@ -3139,6 +3139,8 @@ I<bridge> type and only for Xen domains. B<--model> specifies the network device model to be presented to the domain. +B<alias> can set user supplied alias. It should start with 'ua-'. + B<--inbound> and B<--outbound> control the bandwidth of the interface. At least one from the I<average>, I<floor> pair must be specified. The other two I<peak> and I<burst> are optional, so -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list