Re: [PATCH v4 7/7] virt-admin: Introduce cmdSrvList

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12.02.2016 11:08, Erik Skultety wrote:
> Since we introduced listing API earlier in these series, it's time
> to wire up the API to the virt-admin client.
> 
> Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
> ---
>  tools/virt-admin.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/tools/virt-admin.c b/tools/virt-admin.c
> index 1372963..23af274 100644
> --- a/tools/virt-admin.c
> +++ b/tools/virt-admin.c
> @@ -300,6 +300,56 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
>      return !!priv->conn;
>  }
>  
> +
> +/* ---------------
> + * Command Srv-list
> + * ---------------
> + */
> +
> +static const vshCmdInfo info_srv_list[] = {
> +    {.name = "help",
> +     .data = N_("list available servers on a daemon")
> +    },
> +    {.name = "desc",
> +     .data = N_("List all manageable servers on a daemon.")
> +    },
> +    {.name = NULL}
> +};
> +
> +static bool
> +cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> +{
> +    int nsrvs = 0;
> +    size_t i;
> +    bool ret = false;
> +    const char *uri = NULL;
> +    virAdmServerPtr *srvs = NULL;
> +    vshAdmControlPtr priv = ctl->privData;
> +
> +    /* Obtain a list of available servers on the daemon */
> +    if ((nsrvs = virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) {
> +        uri = virAdmConnectGetURI(priv->conn);
> +        vshError(ctl, _("failed to obtain list of available servers from %s"),
> +                 NULLSTR(uri));
> +        goto cleanup;
> +    }
> +
> +    printf(" %-5s %-15s\n", "Id", "Name");
> +    printf("---------------\n");
> +    for (i = 0; i < nsrvs; i++)
> +        vshPrint(ctl, " %-5zu %-15s\n", i, virAdmServerGetName(srvs[i]));
> +
> +    ret = true;
> + cleanup:
> +    if (srvs) {
> +        for (i = 0; i < nsrvs; i++)
> +            virAdmServerFree(srvs[i]);
> +        VIR_FREE(srvs);
> +    }

Or: for (i = 0; i < nsrvs && srvs; i++); I've noticed this could be
changed in previous patch too. The similar pattern appears there. But
it's your call what you prefer more.

ACK

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]