Inconsistent vm status

Elbandi

Renowned Member
Apr 4, 2011
29
5
68
Hi,

If i stop a vm, there is a small timeframe, that vm status is wrong in api.
When i watch the vm console, and it's closed because "Guest not running". I use two api call:
Code:
#pvesh get /nodes/vps2/qemu/200/status/current --output-format json-pretty
{
   "agent" : 1,
   "cpu" : 0,
   "cpus" : 2,
   "disk" : 0,
   "diskread" : 0,
   "diskwrite" : 0,
   "ha" : {
      "managed" : 0
   },
   "maxdisk" : 21474836480,
   "maxmem" : 2147483648,
   "mem" : 0,
   "name" : "ubuntu-root",
   "netin" : 0,
   "netout" : 0,
   "qmpstatus" : "stopped",
   "status" : "stopped",
   "uptime" : 0,
   "vmid" : 200
}
and
Code:
#pvesh get cluster/resources --type=vm --output-format json-pretty|grep qemu/200 -A14
      "id" : "qemu/200",
      "maxcpu" : 2,
      "maxdisk" : 21474836480,
      "maxmem" : 2147483648,
      "mem" : 426774528,
      "name" : "ubuntu-root",
      "netin" : 4761,
      "netout" : 1392,
      "node" : "vps2",
      "pool" : "test",
      "status" : "running",
      "template" : 0,
      "type" : "qemu",
      "uptime" : 32,
      "vmid" : 200

As you can see, the status is different. Is this a bug or feature?

I got this issue, when i use ansible to stop + reconfigure + start vm. when i wanted to start, ansible module made a status check, and detect the status wrong.
(get_vm() func use cluster/resources api call)
 
The "cluster/resources" status is a summary of all nodes. There can be a little lag, becaue data need to be sent to all nodes.

The "/nodes/vps2/qemu/200/status/current" status is more accurate, because that API call directly connets to the node the VM is running on.