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

[libvirt] [PATCH 3/4] Add a new 'virsh qemu-attach' command.



This command allows libvirt to attach to an existing QEMU
instance.

 $ qemu-kvm -cdrom ~/demo.iso \
     -monitor unix:/tmp/demo,server,nowait \
     -name foo \
     -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea  &
 $ QEMUPID=$$
 $ virsh qemu-attach $QEMUPID
---
 tools/virsh.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 5d8b025..e7122eb 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -10679,6 +10679,52 @@ cleanup:
     return ret;
 }
 
+/*
+ * "qemu-attach" command
+ */
+static const vshCmdInfo info_qemu_attach[] = {
+    {"help", N_("Qemu Attach")},
+    {"desc", N_("Qemu Attach")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_qemu_attach[] = {
+    {"pid", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pid")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdQemuAttach(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    bool ret = false;
+    unsigned int flags = 0;
+    int pid;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        goto cleanup;
+
+    if (vshCommandOptInt(cmd, "pid", &pid) < 0) {
+        vshError(ctl, "%s", _("missing pid value"));
+        goto cleanup;
+    }
+
+    if (!(dom = virDomainQemuAttach(ctl->conn, pid, flags)))
+        goto cleanup;
+
+    if (dom != NULL) {
+        vshPrint(ctl, _("Domain %s attached to pid %d\n"),
+                 virDomainGetName(dom), pid);
+        virDomainFree(dom);
+        ret = true;
+    } else {
+        vshError(ctl, _("Failed to attach to pid %d"), pid);
+    }
+
+cleanup:
+    return ret;
+}
+
 static const vshCmdDef domManagementCmds[] = {
     {"attach-device", cmdAttachDevice, opts_attach_device, info_attach_device},
     {"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk},
@@ -10875,6 +10921,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
     {"hostname", cmdHostname, NULL, info_hostname},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo},
     {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command},
+    {"qemu-attach", cmdQemuAttach, opts_qemu_attach, info_qemu_attach},
     {"sysinfo", cmdSysinfo, NULL, info_sysinfo},
     {"uri", cmdURI, NULL, info_uri},
     {NULL, NULL, NULL, NULL}
-- 
1.7.4.4


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