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

[libvirt] [PATCHv3 4/6] virsh: Move cmdConnect from virsh-host.c to virsh.c



The function is used to establish connection so it should be in the main
virsh file. This movement also enables further improvements done in next
patches.
---
 tools/virsh-host.c | 67 ----------------------------------------------------
 tools/virsh.c      | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 67 deletions(-)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 2d49296..a7e31da 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -68,67 +68,6 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }

 /*
- * "connect" command
- */
-static const vshCmdInfo info_connect[] = {
-    {.name = "help",
-     .data = N_("(re)connect to hypervisor")
-    },
-    {.name = "desc",
-     .data = N_("Connect to local hypervisor. This is built-in "
-                "command after shell start up.")
-    },
-    {.name = NULL}
-};
-
-static const vshCmdOptDef opts_connect[] = {
-    {.name = "name",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_EMPTY_OK,
-     .help = N_("hypervisor connection URI")
-    },
-    {.name = "readonly",
-     .type = VSH_OT_BOOL,
-     .help = N_("read-only connection")
-    },
-    {.name = NULL}
-};
-
-static bool
-cmdConnect(vshControl *ctl, const vshCmd *cmd)
-{
-    bool ro = vshCommandOptBool(cmd, "readonly");
-    const char *name = NULL;
-
-    if (ctl->conn) {
-        int ret;
-        if ((ret = virConnectClose(ctl->conn)) != 0) {
-            vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
-            return false;
-        }
-        ctl->conn = NULL;
-    }
-
-    VIR_FREE(ctl->name);
-    if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
-        return false;
-
-    ctl->name = vshStrdup(ctl, name);
-
-    ctl->useGetInfo = false;
-    ctl->useSnapshotOld = false;
-    ctl->readonly = ro;
-
-    ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
-                                   ctl->readonly ? VIR_CONNECT_RO : 0);
-
-    if (!ctl->conn)
-        vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
-
-    return !!ctl->conn;
-}
-
-/*
  * "freecell" command
  */
 static const vshCmdInfo info_freecell[] = {
@@ -912,12 +851,6 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_capabilities,
      .flags = 0
     },
-    {.name = "connect",
-     .handler = cmdConnect,
-     .opts = opts_connect,
-     .info = info_connect,
-     .flags = VSH_CMD_FLAG_NOCONNECT
-    },
     {.name = "freecell",
      .handler = cmdFreecell,
      .opts = opts_freecell,
diff --git a/tools/virsh.c b/tools/virsh.c
index d6c0e8c..a43c236 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -355,6 +355,69 @@ vshReconnect(vshControl *ctl)
     ctl->useSnapshotOld = false;
 }

+
+/*
+ * "connect" command
+ */
+static const vshCmdInfo info_connect[] = {
+    {.name = "help",
+     .data = N_("(re)connect to hypervisor")
+    },
+    {.name = "desc",
+     .data = N_("Connect to local hypervisor. This is built-in "
+                "command after shell start up.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_connect[] = {
+    {.name = "name",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_EMPTY_OK,
+     .help = N_("hypervisor connection URI")
+    },
+    {.name = "readonly",
+     .type = VSH_OT_BOOL,
+     .help = N_("read-only connection")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdConnect(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ro = vshCommandOptBool(cmd, "readonly");
+    const char *name = NULL;
+
+    if (ctl->conn) {
+        int ret;
+        if ((ret = virConnectClose(ctl->conn)) != 0) {
+            vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
+            return false;
+        }
+        ctl->conn = NULL;
+    }
+
+    VIR_FREE(ctl->name);
+    if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
+        return false;
+
+    ctl->name = vshStrdup(ctl, name);
+
+    ctl->useGetInfo = false;
+    ctl->useSnapshotOld = false;
+    ctl->readonly = ro;
+
+    ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
+                                   ctl->readonly ? VIR_CONNECT_RO : 0);
+
+    if (!ctl->conn)
+        vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
+
+    return !!ctl->conn;
+}
+
+
 #ifndef WIN32
 static void
 vshPrintRaw(vshControl *ctl, ...)
@@ -3000,6 +3063,12 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
 }

 static const vshCmdDef virshCmds[] = {
+    {.name = "connect",
+     .handler = cmdConnect,
+     .opts = opts_connect,
+     .info = info_connect,
+     .flags = VSH_CMD_FLAG_NOCONNECT
+    },
     {.name = "cd",
      .handler = cmdCd,
      .opts = opts_cd,
-- 
1.8.1.5


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