Created
April 21, 2018 10:02
-
-
Save gnuoy/c3775ebdf1b00f38fd36fa8b9014349c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests_oauthlib | |
url = 'http://10.0.0.205/MAAS' | |
mac_url = '{}/api/2.0/machines/?format=json'.format(url) | |
api_key = 'YOUR MAAS API KEY' | |
_keys = api_key.split(':') | |
consumer_key = _keys[0] | |
access_token = _keys[1] | |
token_secret = _keys[2] | |
maas_session = requests_oauthlib.OAuth1Session( | |
consumer_key, | |
signature_method='PLAINTEXT', | |
resource_owner_key=access_token, | |
resource_owner_secret=token_secret) | |
print(maas_session.get(mac_url).text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works out of the box and is IMHO much better (smaller & easier to understand) than the original MAAS API documentation.
Thanks!
BTW: the
?format=json
does not work nowadays. Instead you need to pass in the HTTP Accept header (likeapplication/x-yaml
or evenapplication/python-pickle
)