Once again I'm trying to figure out how to query MAAS with python ...
I have the following in the config file ...
# /etc/maasinv/maasinv.ini
[maas]
apikey = FbT9S6S9B3U7y38HKZ:NotRealNunyaNunya:randomkeyblahwhatever
url = http://<valid IP>:5240/MAAS/api/2.0/
I have the following in the script ..
#!/usr/bin/env python3
from apiclient import maas_client
import configparser
config = configparser.ConfigParser()
config.read('/etc/maasinv/maasinv.ini')
APIKEY = config['maas']['apikey']
MAAS_URL = config['maas']['url']
auth = maas_client.MAASOAuth(*APIKEY.split(":"))
client = maas_client.MAASClient(auth, maas_client.MAASDispatcher(), MAAS_URL)
data = client.get("nodes", op=list").read()
print (data)
The response I get is ...
urllib.error.HTTPError: HTTP Error 400: BAD REQUEST
Running a the below curl request gives me forbidden which seems to tell me that I'm close:
curl http://<valid IP>:5240/MAAS/api/2.0/nodes/op=list/
Has anyone gotten this to work or should I go back to using subprocess to run the client ?
MAAS Version 2.1.3+bzr5573-0ubuntu1 (16.04.1)