[libvirt] [PATCH v2 2/2] virsh: Support alias in attach-interface

Michal Prívozník mprivozn at redhat.com
Mon Jul 23 10:21:53 UTC 2018


On 07/15/2018 12:08 PM, Han Han wrote:
> 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 at redhat.com>
> ---
>  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..7fb419f6b5 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);

Same here. This check is not desired here. To extend my reasoning in 1/2
- we are not checking if provided MAC address really is MAC address. For
instance:

# attach-interface --print-xml fedora network default --mac blah

Michal




More information about the libvir-list mailing list