[libvirt] [PATCH 1/3] virsh: Use VIR_ENUM_* instead of open coding string -> enum conversion

Michal Privoznik posted 3 patches 4 years, 10 months ago
[libvirt] [PATCH 1/3] virsh: Use VIR_ENUM_* instead of open coding string -> enum conversion
Posted by Michal Privoznik 4 years, 10 months ago
There are more occurrences, but I'm converting --source argument
of domifaddr command only, because I will need it in next commit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/virsh-domain-monitor.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 9e6bc99bf2..de4abbaee7 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2358,6 +2358,13 @@ static const vshCmdOptDef opts_domifaddr[] = {
     {.name = NULL}
 };
 
+VIR_ENUM_DECL(virshDomainInterfaceAddressesSource);
+VIR_ENUM_IMPL(virshDomainInterfaceAddressesSource,
+              VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST,
+              "lease",
+              "agent",
+              "arp");
+
 static bool
 cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
 {
@@ -2379,17 +2386,10 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0)
         goto cleanup;
 
-    if (sourcestr) {
-        if (STREQ(sourcestr, "lease")) {
-            source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE;
-        } else if (STREQ(sourcestr, "agent")) {
-            source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT;
-        } else if (STREQ(sourcestr, "arp")) {
-            source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP;
-        } else {
-            vshError(ctl, _("Unknown data source '%s'"), sourcestr);
-            goto cleanup;
-        }
+    if (sourcestr &&
+        (source = virshDomainInterfaceAddressesSourceTypeFromString(sourcestr)) < 0) {
+        vshError(ctl, _("Unknown data source '%s'"), sourcestr);
+        goto cleanup;
     }
 
     if ((ifaces_count = virDomainInterfaceAddresses(dom, &ifaces, source, 0)) < 0) {
-- 
2.24.1

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

Re: [libvirt] [PATCH 1/3] virsh: Use VIR_ENUM_* instead of open coding string -> enum conversion
Posted by Daniel P. Berrangé 4 years, 10 months ago
On Tue, Jan 07, 2020 at 09:41:52AM +0100, Michal Privoznik wrote:
> There are more occurrences, but I'm converting --source argument
> of domifaddr command only, because I will need it in next commit.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tools/virsh-domain-monitor.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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