I am trying to figure out how to query the MAAS server using curl.

I am starting to experiment with CLI query so that I may build a python script for remote command and query without having to use the MAAS CLI app.

The end goal is to control/query MAAS with ansible.

I tried:

curl -u "username:password"  "http://machine/MAAS/api/1.0/nodes/?op=list" 

The response was:

Unrecognised signature: GET
share|improve this question
up vote 1 down vote accepted

The issue you are running into is that MAAS requires authentication before it will return the node listing. MAAS normally authenticates API requests through OAuth, not HTTP Basic Authentication which is what curl -u uses by default for web URLs.

Luckily, MAAS also provides a Python client library called apiclient which is included in the python-maas-client package. Using that library would allow you to trivially issue the query with an apikey, which you can get from http://$MAAS_URL/MAAS/account/prefs/. Assuming you have APIKEY and MAAS_URL, the below snippet demonstrates how you'd fetch the listing:

APIKEY = "foo:bar:baz"
MAAS_URL = "http://my.maas.host/MAAS/api/1.0"

from apiclient import maas_client
auth = maas_client.MAASOAuth(*APIKEY.split(":"))
client = maas_client.MAASClient(auth, maas_client.MAASDispatcher(), MAAS_URL)
print client.get(u"nodes/", "list").read()

Incidentally, AIUI curl -X GET is the query type curl issues by default.

[*] I believe marking the path as unicode should not be necessary, but there's an assertion in the code that may be a bug. Reported https://bugs.launchpad.net/maas/+bug/1418158.

share|improve this answer
    
See blog.allenap.me/2013/06/… for a more complete example of using the maas_client module. – kiko Feb 4 '15 at 19:23
    
I got this to work beautifully, thanks. dpaste.com/0ETVXZ1 – Simply Seth Feb 5 '15 at 2:37
1  
Cool, but you don't need the first import statement, as you're using everything inside maas_client! – kiko Feb 5 '15 at 12:01
    
Note to self: check to see whether using github.com/mojodna/oauth-proxy would be useful – kiko Jul 13 '15 at 20:06

I looked at http://marsweather.ingenology.com/ and found this example

curl -X GET http://marsweather.ingenology.com/v1/latest/

plus other shell code using "curl". I think that will get you started. You still need to have tools to deal with JSON, but that seems out of scope for this question.

share|improve this answer
    
Failed with: curl -X GET -A "Mozilla/4.0" "10.34.20.34/MAAS/api/1.0/nodes/?op=list"; – Simply Seth Feb 4 '15 at 17:13
    
Okay, but note that the Mars Atmospheric Aggregation System API is not the MAAS the OP was referring to! – kiko May 19 '15 at 19:31

Example of post in the maas-api

desiredSettings = {
    "ip_range_high": "10.30.0.252",
    "ip_range_low": "10.30.0.152",
    "broadcast_ip": "10.30.0.255",
    "name": "eth3",
    "ip": "10.30.0.0",
    "subnet_mask": "255.255.255.0",
    "management": "2",
    "interface": "eth3"
}

#resp = client.post(u"nodegroups/%s/interfaces/" % (cluster_uuid), "new", **desiredSettings)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.