0

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)

1 Answers1

1

First, I notice you have a typo in data = client.get("nodes", op=list").read() (notice the " after list)

That, however, may be a typo just in here.

If you remove the ,op=list portion, it should work.

I have the following in a script I run and it works just fine: nodes=client.get(u"nodes/?hostname="+hostname).read().decode("utf-8")

strocknar
  • 126