[libvirt] [PATCH 2/3] virsh: Use VIR_ENUM* macros for vshCmdAttachInterface
Peter Krempa
pkrempa at redhat.com
Mon Feb 9 13:16:58 UTC 2015
On Mon, Feb 09, 2015 at 10:58:29 +0100, Michal Privoznik wrote:
> Instead of verbose string to enum conversion (if STREQ() else if
> STREQ() else if STREQ() ...) lets use awesome VIR_ENUM_* macros.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> tools/virsh-domain.c | 28 ++++++++++++++++++----------
> 1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index b465eb5..c7e4926 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -855,10 +855,16 @@ static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate)
> }
>
> typedef enum {
> - IFACE_TYPE_NETWORK,
> + IFACE_TYPE_NETWORK = 0,
> IFACE_TYPE_BRIDGE,
> + IFACE_TYPE_LAST,
Usually we don't put a comma after the _LAST item.
> } vshCmdAttachInterfaceType;
>
> +VIR_ENUM_DECL(vshCmdAttachInterface)
> +VIR_ENUM_IMPL(vshCmdAttachInterface, IFACE_TYPE_LAST,
> + "network",
> + "bridge")
> +
> static bool
> cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
> {
> @@ -906,11 +912,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
> goto cleanup;
>
> /* check interface type */
> - if (STREQ(type, "network")) {
> - typ = IFACE_TYPE_NETWORK;
> - } else if (STREQ(type, "bridge")) {
> - typ = IFACE_TYPE_BRIDGE;
> - } else {
> + if ((typ = vshCmdAttachInterfaceTypeFromString(type)) < 0) {
> vshError(ctl, _("No support for %s in command 'attach-interface'"),
> type);
> goto cleanup;
> @@ -943,10 +945,16 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
> virBufferAsprintf(&buf, "<interface type='%s'>\n", type);
> virBufferAdjustIndent(&buf, 2);
>
> - if (typ == IFACE_TYPE_NETWORK)
> - virBufferAsprintf(&buf, "<source network='%s'/>\n", source);
> - else if (typ == IFACE_TYPE_BRIDGE)
> - virBufferAsprintf(&buf, "<source bridge='%s'/>\n", source);
> + switch (typ) {
> + case IFACE_TYPE_NETWORK:
> + case IFACE_TYPE_BRIDGE:
> + virBufferAsprintf(&buf, "<source %s='%s'/>\n",
> + vshCmdAttachInterfaceTypeToString(typ), source);
> + break;
> + case IFACE_TYPE_LAST:
> + /* nada */
Usually we don't put the comment for the _LAST item as it's obvious it
does "nada".
> + break;
> + }
>
> if (target != NULL)
> virBufferAsprintf(&buf, "<target dev='%s'/>\n", target);
ACK with the cosmetic changes.
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150209/0b3c031d/attachment-0001.sig>
More information about the libvir-list
mailing list