]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh-util: Move domain lookup helpers into virsh-util
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Apr 2017 08:18:06 +0000 (10:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 12 Apr 2017 11:23:10 +0000 (13:23 +0200)
Move virshLookupDomainBy, virshCommandOptDomainBy and
virshCommandOptDomainBy to the helper file. Additionally turn the
virshCommandOptDomainBy macro into a function.

po/POTFILES.in
tools/virsh-domain-monitor.c
tools/virsh-domain.c
tools/virsh-domain.h
tools/virsh-host.c
tools/virsh-snapshot.c
tools/virsh-util.c
tools/virsh-util.h

index 064abd5bbbc8be2f0440f662990a89a0ddad7161..ccef6f3cf155dfcbdff9d1bea91a176f76a90077 100644 (file)
@@ -310,6 +310,7 @@ tools/virsh-nwfilter.c
 tools/virsh-pool.c
 tools/virsh-secret.c
 tools/virsh-snapshot.c
+tools/virsh-util.c
 tools/virsh-volume.c
 tools/virsh.c
 tools/virt-admin.c
index 4ade5651c7000a5f824a2c72d0c68adc30bcc0f2..5215ac6f920b91039084ba55f01017a7964a0440 100644 (file)
@@ -37,7 +37,6 @@
 #include "intprops.h"
 #include "viralloc.h"
 #include "virmacaddr.h"
-#include "virsh-domain.h"
 #include "virxml.h"
 #include "virstring.h"
 
index d2f50177cc854de57f1ee8f499168311daf5a1bd..9684629d4539479395137c782df5b9b68d6ffcaf 100644 (file)
 #define VIRSH_COMMON_OPT_DOMAIN_CURRENT                   \
     VIRSH_COMMON_OPT_CURRENT(N_("affect current domain")) \
 
-static virDomainPtr
-virshLookupDomainInternal(vshControl *ctl,
-                          const char *cmdname,
-                          const char *name,
-                          unsigned int flags)
-{
-    virDomainPtr dom = NULL;
-    int id;
-    virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL);
-    virshControlPtr priv = ctl->privData;
-
-    /* try it by ID */
-    if (flags & VIRSH_BYID) {
-        if (virStrToLong_i(name, NULL, 10, &id) == 0 && id >= 0) {
-            vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> looks like ID\n",
-                     cmdname);
-            dom = virDomainLookupByID(priv->conn, id);
-        }
-    }
-
-    /* try it by UUID */
-    if (!dom && (flags & VIRSH_BYUUID) &&
-        strlen(name) == VIR_UUID_STRING_BUFLEN-1) {
-        vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain UUID\n",
-                 cmdname);
-        dom = virDomainLookupByUUIDString(priv->conn, name);
-    }
-
-    /* try it by NAME */
-    if (!dom && (flags & VIRSH_BYNAME)) {
-        vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain NAME\n",
-                 cmdname);
-        dom = virDomainLookupByName(priv->conn, name);
-    }
-
-    vshResetLibvirtError();
-
-    if (!dom)
-        vshError(ctl, _("failed to get domain '%s'"), name);
-
-    return dom;
-}
-
-
-virDomainPtr
-virshLookupDomainBy(vshControl *ctl,
-                    const char *name,
-                    unsigned int flags)
-{
-    return virshLookupDomainInternal(ctl, "unknown", name, flags);
-}
-
-
-virDomainPtr
-virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
-                        const char **name, unsigned int flags)
-{
-    const char *n = NULL;
-    const char *optname = "domain";
-
-    if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
-        return NULL;
-
-    vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n",
-             cmd->def->name, optname, n);
-
-    if (name)
-        *name = n;
-
-    return virshLookupDomainInternal(ctl, cmd->def->name, n, flags);
-}
 
 static virDomainPtr
 virshDomainDefine(virConnectPtr conn, const char *xml, unsigned int flags)
index 462f560f90dbbe9e6bc321c44dfcee797d6f4297..3f9d12a5ffdfe9bf3f7a9d5fbfc215d48ea9fe64 100644 (file)
 
 # include "virsh.h"
 
-virDomainPtr virshLookupDomainBy(vshControl *ctl,
-                                 const char *name,
-                                 unsigned int flags);
-
-virDomainPtr virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
-                                     const char **name, unsigned int flags);
-
-/* default is lookup by Id, Name and UUID */
-# define virshCommandOptDomain(_ctl, _cmd, _name)                      \
-    virshCommandOptDomainBy(_ctl, _cmd, _name,                         \
-                            VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME)
-
 extern const vshCmdDef domManagementCmds[];
 
 #endif /* VIRSH_DOMAIN_H */
index 3b86c75fa446d683b8ebddf2bc8b9417c0c8e994..5509065fd606aeb8fb93bf35751b2e8f5a1503de 100644 (file)
@@ -35,7 +35,6 @@
 #include "virbitmap.h"
 #include "virbuffer.h"
 #include "viralloc.h"
-#include "virsh-domain.h"
 #include "virxml.h"
 #include "virtypedparam.h"
 #include "virstring.h"
index 5c844a5ea8446d75dd2df9ff227c1e4650a2e342..46e2cbb2441f7b358b7d5fbb33918f1cbc91a89a 100644 (file)
@@ -37,7 +37,7 @@
 #include "virbuffer.h"
 #include "viralloc.h"
 #include "virfile.h"
-#include "virsh-domain.h"
+#include "virsh-util.h"
 #include "virstring.h"
 #include "virxml.h"
 #include "conf/snapshot_conf.h"
index 98f16ff1a8700e3b6c8cb63bf18a0d8495a84f25..5c99655fbcde0990d8108280735a3bcd8cb890cb 100644 (file)
 #include "virsh-util.h"
 
 #include "virfile.h"
+#include "virstring.h"
+
+static virDomainPtr
+virshLookupDomainInternal(vshControl *ctl,
+                          const char *cmdname,
+                          const char *name,
+                          unsigned int flags)
+{
+    virDomainPtr dom = NULL;
+    int id;
+    virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL);
+    virshControlPtr priv = ctl->privData;
+
+    /* try it by ID */
+    if (flags & VIRSH_BYID) {
+        if (virStrToLong_i(name, NULL, 10, &id) == 0 && id >= 0) {
+            vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> looks like ID\n",
+                     cmdname);
+            dom = virDomainLookupByID(priv->conn, id);
+        }
+    }
+
+    /* try it by UUID */
+    if (!dom && (flags & VIRSH_BYUUID) &&
+        strlen(name) == VIR_UUID_STRING_BUFLEN-1) {
+        vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain UUID\n",
+                 cmdname);
+        dom = virDomainLookupByUUIDString(priv->conn, name);
+    }
+
+    /* try it by NAME */
+    if (!dom && (flags & VIRSH_BYNAME)) {
+        vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain NAME\n",
+                 cmdname);
+        dom = virDomainLookupByName(priv->conn, name);
+    }
+
+    vshResetLibvirtError();
+
+    if (!dom)
+        vshError(ctl, _("failed to get domain '%s'"), name);
+
+    return dom;
+}
+
+
+virDomainPtr
+virshLookupDomainBy(vshControl *ctl,
+                    const char *name,
+                    unsigned int flags)
+{
+    return virshLookupDomainInternal(ctl, "unknown", name, flags);
+}
+
+
+virDomainPtr
+virshCommandOptDomainBy(vshControl *ctl,
+                        const vshCmd *cmd,
+                        const char **name,
+                        unsigned int flags)
+{
+    const char *n = NULL;
+    const char *optname = "domain";
+
+    if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
+        return NULL;
+
+    vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n",
+             cmd->def->name, optname, n);
+
+    if (name)
+        *name = n;
+
+    return virshLookupDomainInternal(ctl, cmd->def->name, n, flags);
+}
+
+
+virDomainPtr
+virshCommandOptDomain(vshControl *ctl,
+                      const vshCmd *cmd,
+                      const char **name)
+{
+    return virshCommandOptDomainBy(ctl, cmd, name,
+                                   VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME);
+}
+
 
 int
 virshDomainState(vshControl *ctl,
index 207d5785979abeef4de904af789ecf3e661abc65..132bf0b4b0063af2b69969edac2571db618cfd2d 100644 (file)
 
 # include "virsh.h"
 
+
+virDomainPtr
+virshLookupDomainBy(vshControl *ctl,
+                    const char *name,
+                    unsigned int flags);
+
+virDomainPtr
+virshCommandOptDomainBy(vshControl *ctl,
+                        const vshCmd *cmd,
+                        const char **name,
+                        unsigned int flags);
+
+virDomainPtr
+virshCommandOptDomain(vshControl *ctl,
+                      const vshCmd *cmd,
+                      const char **name);
+
 int
 virshDomainState(vshControl *ctl,
                  virDomainPtr dom,