管理虚拟机资源
概述
本节将介绍如何使用QMP命令管理磁盘和网卡。
StratoVirt使用QMP管理虚拟机,使用QMP管理虚拟机资源前,请参见”管理虚拟机生命周期”使用QMP连接到虚拟机。
热插拔磁盘
StratoVirt支持在虚拟机运行过程中调整磁盘数量,即在不中断业务前提下,增加或删除虚拟机磁盘。
热插磁盘
用法:
{"execute": "blockdev-add", "arguments": {"node-name": "drive-0", "file": {"driver": "file", "filename": "/path/to/block"}, "cache": {"direct": true}, "read-only": false}}
{"execute": "device_add", "arguments": {"id": "drive-0", "driver": "virtio-blk-mmio", "addr": "0x1"}}
参数
blockdev-add中的node-name要和device_add中的id一致,如上都是drive-0。
/path/to/block是被热插磁盘的镜像路径,不能是启动rootfs的磁盘镜像。
- 对于addr来说,它从0x0开始与虚拟机的vda映射,0x1与vdb映射,以此类推。为了兼容QMP协议,”addr”也可以用”lun”代替,但是lun=0与客户机的vdb映射。只支持热插6张virtio-blk磁盘。
示例
<- {"execute": "blockdev-add", "arguments": {"node-name": "drive-0", "file": {"driver": "file", "filename": "/path/to/block"}, "cache": {"direct": true}, "read-only": false}}
-> {"return": {}}
<- {"execute": "device_add", "arguments": {"id": "drive-0", "driver": "virtio-blk-mmio", "addr": "0x1"}}
-> {"return": {}}
热拔磁盘
用法:
{“execute”: “device_del”, “arguments”: {“id”:”drive-0”}}
参数:
id 为热拔磁盘的ID号。
示例
<- {"execute": "device_del", "arguments": {"id": "drive-0"}}
-> {"event":"DEVICE_DELETED","data":{"device":"drive-0","path":"drive-0"},"timestamp":{"seconds":1598513162,"microseconds":367129}}
-> {"return": {}}
热插拔网卡
StratoVirt支持在虚拟机运行过程中调整网卡数量,即在不中断业务前提下,给虚拟机增加或删除网卡。
热插网卡
用法
{"execute":"netdev_add", "arguments":{"id":"net-0", "ifname":"tap0"}}
{"execute":"device_add", "arguments":{"id":"net-0", "driver":"virtio-net-mmio", "addr":"0x0"}}
参数
netdev_add中的id应该和device_add中的id一致,ifname是后端的tap设备名称。
对于addr来说,它从0x0开始与虚拟机的eth0映射,0x1和虚拟机的eth1映射,只支持热插2张virtio-net网卡。
示例
<- {"execute":"netdev_add", "arguments":{"id":"net-0", "ifname":"tap0"}}
<- {"execute":"device_add", "arguments":{"id":"net-0", "driver":"virtio-net-mmio", "addr":"0x0"}}
其中,addr:0x0,对应虚拟机内部的eth0。
热拔网卡
用法
{“execute”: “device_del”, “arguments”: {“id”: “net-0”}}
参数
id:网卡的ID号,例如net-0。
示例
<- {"execute": "device_del", "arguments": {"id": "net-0"}}
-> {"event":"DEVICE_DELETED","data":{"device":"net-0","path":"net-0"},"timestamp":{"seconds":1598513339,"microseconds":97310}}
-> {"return": {}}