Skip to content

Commit

Permalink
fix(host): parse qga command and args (#20505)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi authored Jun 7, 2024
1 parent c9c2b27 commit cdd5977
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 5 additions & 3 deletions pkg/hostman/guestman/guesthandlers/guesthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,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)
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/hostman/monitor/qga/qga.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"
"unsafe"

"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"

Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit cdd5977

Please sign in to comment.