Skip to content

Instantly share code, notes, and snippets.

@gnuoy
Created April 21, 2018 10:02
Show Gist options
  • Save gnuoy/c3775ebdf1b00f38fd36fa8b9014349c to your computer and use it in GitHub Desktop.
Save gnuoy/c3775ebdf1b00f38fd36fa8b9014349c to your computer and use it in GitHub Desktop.
#!/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)
@florath
Copy link

florath commented Nov 14, 2020

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 (like application/x-yaml or even application/python-pickle)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment