]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virsh: Move cmdConnect from virsh-host.c to virsh.c
authorPeter Krempa <pkrempa@redhat.com>
Wed, 27 Mar 2013 13:22:47 +0000 (14:22 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 5 Apr 2013 08:36:03 +0000 (10:36 +0200)
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.

Note that the "connect" command has moved from the host section of virsh to the
main section. It is now listed by 'virsh help virsh' instead of 'virsh help
host'.

tools/virsh-host.c
tools/virsh.c

index 2d492965025de079c200df61c7610f43f020c9e3..a7e31da613406851302fae24afec595d11329ca5 100644 (file)
@@ -67,67 +67,6 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     return true;
 }
 
-/*
- * "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
  */
@@ -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,
index d6c0e8cd2d4ba7d1900db7c8676052a35c8f0945..297591d13f6161dbf89af8ca9631c8e6bbca721a 100644 (file)
@@ -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, ...)
@@ -3006,6 +3069,12 @@ static const vshCmdDef virshCmds[] = {
      .info = info_cd,
      .flags = VSH_CMD_FLAG_NOCONNECT
     },
+    {.name = "connect",
+     .handler = cmdConnect,
+     .opts = opts_connect,
+     .info = info_connect,
+     .flags = VSH_CMD_FLAG_NOCONNECT
+    },
     {.name = "echo",
      .handler = cmdEcho,
      .opts = opts_echo,