QGA命令行使用

## 需要确保服务器的qga在线,并且端口是通的

命令行操作:

0. 查看guest的具体信息

virsh qemu-agent-command ${KVMID} --cmd '{"execute":"guest-info"}'

1. 修改密码

# virsh set-user-password vm4 --user root --password 123456789

2. 查看这台虚拟机支持哪些api

# virsh qemu-agent-command vm4 '{"execute":"guest-info"}'   //enabled=true的表示支持

{"return":{"version":"2.8.0","supported_commands":[{"enabled":true,"name":"guest-sync-delimited","success-response":true},{"enabled":true,"name":"guest-sync","success-response":true},{"enabled":true,"name":"guest-suspend-ram","success-response":false},{"enabled":true,"name":"guest-suspend-hybrid","success-response":false},{"enabled":true,"name":"guest-suspend-disk","success-response":false},{"enabled":true,"name":"guest-shutdown","success-response":false},{"enabled":true,"name":"guest-set-vcpus","success-response":true},{"enabled":true,"name":"guest-set-user-password","success-response":true},{"enabled":true,"name":"guest-set-time","success-response":true},{"enabled":true,"name":"guest-set-memory-blocks","success-response":true},{"enabled":true,"name":"guest-ping","success-response":true},{"enabled":true,"name":"guest-network-get-interfaces","success-response":true},{"enabled":true,"name":"guest-info","success-response":true},{"enabled":true,"name":"guest-get-vcpus","success-response":true},{"enabled":true,"name":"guest-get-time","success-response":true},{"enabled":true,"name":"guest-get-memory-blocks","success-response":true},{"enabled":true,"name":"guest-get-memory-block-info","success-response":true},{"enabled":true,"name":"guest-get-fsinfo","success-response":true},{"enabled":true,"name":"guest-fstrim","success-response":true},{"enabled":true,"name":"guest-fsfreeze-thaw","success-response":true},{"enabled":true,"name":"guest-fsfreeze-status","success-response":true},{"enabled":true,"name":"guest-fsfreeze-freeze-list","success-response":true},{"enabled":true,"name":"guest-fsfreeze-freeze","success-response":true},{"enabled":false,"name":"guest-file-write","success-response":true},{"enabled":false,"name":"guest-file-seek","success-response":true},{"enabled":false,"name":"guest-file-read","success-response":true},{"enabled":false,"name":"guest-file-open","success-response":true},{"enabled":false,"name":"guest-file-flush","success-response":true},{"enabled":false,"name":"guest-file-close","success-response":true},{"enabled":false,"name":"guest-exec-status","success-response":true},{"enabled":false,"name":"guest-exec","success-response":true}]}}

3. 试探能否正常通信

  # virsh qemu-agent-command vm4 '{"execute":"guest-ping"}'

4. 创建文件

[root@hypersys184 ~]# virsh qemu-agent-command vm4 '{"execute":"guest-file-create","arguments":{"path":"c:\\test.txt"}}'

Please enter your authentication name: root

Please enter your password:

error: 内部错误:无法执行 QEMU 代理命令 'guest-file-create':The command guest-file-create has not been found

5. 打开文件

[root@hypersys184 ~]# virsh qemu-agent-command win7 '{"execute":"guest-file-open","arguments":{"path":"C:\\Users\\win7\\Desktop\\test.txt"}}'

Please enter your authentication name: root

Please enter your password:

{"return":1000}

  以写模式打开(w+),以读模式打开(r)

[root@hypersys184 ~]# virsh qemu-agent-command win7 '{"execute":"guest-file-open","arguments":{"path":"C:\\Users\\win7\\Desktop\\test.txt", "mode":"w+"}}'

Please enter your authentication name: root

Please enter your password:

{"return":1002}

6. 关闭打开的文件

[root@hypersys184 ~]# virsh qemu-agent-command win7 '{"execute":"guest-file-close","arguments":{"handle": 1002}}'

Please enter your authentication name: root

Please enter your password:

{"return":{}}

7. 往文件内写入数据

[root@hypersys184 ~]# virsh qemu-agent-command win7 '{"execute":"guest-file-write","arguments":{"handle": 1002, "buf-b64": "MTExMWFhYWFh"}}'

Please enter your authentication name: root

Please enter your password:

{"return":{"count":0,"eof":false}}

posted @ 2023-04-25 10:03  XU-NING  阅读(189)  评论(0编辑  收藏  举报