The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6427

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From e50caecd0d2a48a351446778ea68020789f18ff7 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Mon, 28 Oct 2019 12:29:49 +0100
Subject: [PATCH] lxd/vm: Implement Exec for VMs

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 lxd/vm_qemu.go | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index eca1bbe0e8..53cabf528f 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -1969,8 +1969,42 @@ func (vm *vmQemu) Console() (*os.File, error) {
 }
 
 func (vm *vmQemu) Exec(command []string, env map[string]string, stdin 
*os.File, stdout *os.File, stderr *os.File, wait bool, cwd string, uid uint32, 
gid uint32) (*exec.Cmd, int, int, error) {
-       return nil, 0, 0, fmt.Errorf("Exec Not implemented")
+       agent, err := lxdClient.ConnectLXDHTTP(nil, vm.agentClient)
+       if err != nil {
+               return nil, 0, 0, err
+       }
+
+       post := api.InstanceExecPost{
+               Command:     command,
+               WaitForWS:   wait,
+               Interactive: stdin == stdout,
+               Environment: env,
+               User:        uid,
+               Group:       gid,
+               Cwd:         cwd,
+       }
+
+       args := lxdClient.InstanceExecArgs{
+               Stdin:    stdin,
+               Stdout:   stdout,
+               Stderr:   stderr,
+               DataDone: make(chan bool),
+       }
+
+       op, err := agent.ExecInstance("", post, &args)
+       if err != nil {
+               return nil, -1, -1, err
+       }
+
+       err = op.Wait()
+       if err != nil {
+               return nil, -1, -1, err
+       }
+       opAPI := op.Get()
+
+       <-args.DataDone
 
+       return nil, int(opAPI.Metadata["return"].(float64)), -1, nil
 }
 
 func (vm *vmQemu) Render() (interface{}, interface{}, error) {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to