fix(host): parse qga command and args (#20506)

This commit is contained in:
wanyaoqi
2024-06-07 15:03:40 +08:00
committed by GitHub
parent 2a7bfec231
commit a307cc9196
2 changed files with 8 additions and 9 deletions
@@ -901,11 +901,13 @@ func qgaCommand(ctx context.Context, userCred mcclient.TokenCredential, sid stri
return nil, httperrors.NewInputParameterError("failed parse qga command")
}
qgaCmd := &monitor.Command{}
err = cmdJson.Unmarshal(qgaCmd)
qgaCmd.Execute, err = cmdJson.GetString("execute")
if err != nil {
return nil, httperrors.NewInputParameterError("failed unmarshal qga command")
return nil, httperrors.NewInputParameterError("failed get qga command")
}
if cmdJson.Contains("arguments") {
qgaCmd.Args, _ = cmdJson.Get("arguments")
}
return gm.QgaCommand(qgaCmd, sid, input.Timeout)
}
+3 -6
View File
@@ -27,6 +27,7 @@ import (
"time"
"unsafe"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
@@ -171,12 +172,8 @@ func (qga *QemuGuestAgent) execCmd(cmd *monitor.Command, expectResp bool, readTi
}
}
rawCmd, err := json.Marshal(cmd)
if err != nil {
return nil, errors.Wrap(err, "marshal qga cmd")
}
err = qga.write(rawCmd)
rawCmd := jsonutils.Marshal(cmd).String()
err := qga.write([]byte(rawCmd))
if err != nil {
return nil, errors.Wrap(err, "write cmd")
}