python-libmaas
python-libmaas copied to clipboard
Get json result ?
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
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)