Determining Virtual Machine vs Physical Machine in API / JSON

Hello everyone!

I’m working on a project where we are taking certain datapoints from the MAAS (v2.9.2) and applying it to Netbox, but the Netbox needs to know if a device is a Physical or Virtual Machine before it can create the device in its own database.

I can see in the MAAS GUI that Machines are listed in the Status area as Physical or Virtual, but as we are using code to pull the JSON data via the API, I have been unable to determine the factor that tells us this information when querying the API.

Can someone point me in the right direction in the API to determine if a machine is Virtual or Physical?

Thank you!

I would look either at the tags of the machine or the power type. A virtual machine should, unless changed, be tagged virtual, or the power type should be virsh or something like that.

Hi there!
As james-o-benson said above, querying the virtual tag or power state would certainly be easiest.
To provide some documentation references that may help:

If haven’t manually modified the vitual tag, you should be able to query all virtual machines with GET /MAAS/api/2.0/tags/virtual/?op=machines.

If you have, you should still be able to query each machine individually with GET /MAAS/api/2.0/machines/{system_id} to determine it’s power type:

{
    ...
    "memory_test_status_name": "Passed",
    "power_type": "virsh",
    "interface_set": [
        {
            "system_id": "g8xyqs",
            ...
}

(I’ve trimmed the example JSON output to show only the relevant section)

Depending on your use-case it may be a viable alternative to query all machines with GET /MAAS/api/2.0/machines/ and sift through the JSON output, rather than querying each machine individually.

@tama23, have you tried querying the tags yet? any luck?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.