python-libmaas icon indicating copy to clipboard operation
python-libmaas copied to clipboard

Get json result ?

Open rudy-l opened this issue 5 years ago • 1 comments

Hello, I'm new with maas and python and I want to get json result after an allocate or a deploy :

import json
from maas.client import connect

client = connect(
    "my_maas_server",
    apikey="my_api_key"
)

my_machine = client.machines.allocate(
    architectures="amd64/generic",
    cpus=16,
    memory=128000,
    comment="python library test"
)

my_json = json.dumps(my_machine)

Unfortunately : TypeError: Object of type 'Machine' is not JSON serializable

Do you know if it's possible and how please ? MAAS version: 2.4.2

rudy-l avatar Feb 25 '20 07:02 rudy-l

I don't know if this is new since you raised the issue but I found I could do it using the _data attribute as follows:

import json
from maas.client import connect

client = connect(
    "my_maas_server",
    apikey="my_api_key"
)

my_machine = client.machines.allocate(
    architectures="amd64/generic",
    cpus=16,
    memory=128000,
    comment="python library test"
)

my_json = json.dumps(my_machine._data)

tomkivlin avatar Feb 17 '21 10:02 tomkivlin