Skip to content

Instantly share code, notes, and snippets.

@nicolasenno
Last active September 27, 2017 15:26
Show Gist options
  • Save nicolasenno/d39255d130cbde11c8b5868f1be7b310 to your computer and use it in GitHub Desktop.
Save nicolasenno/d39255d130cbde11c8b5868f1be7b310 to your computer and use it in GitHub Desktop.
MAAS API example: POST
import json
from requests import Request, Session
from requests_oauthlib import OAuth1
# <consumer_key>:<token_key>:<token_secret>
# xxxxxxxxxxxxxx:yyyyyyyyyyy:zzzzzzzzzzzzzz
auth1 = OAuth1(u'xxxxxxxxxxxxxx', u'',
u'yyyyyyyyyyy', u'zzzzzzzzzzzzzz')
headers = {'Accept': 'application/json'}
url = u'http://10.10.2.222:5240/MAAS/api/2.0/dnsresources/'
body = json.dumps({'domain': 'my-domain.com',
'name': 'demo',
'ip_addresses': '10.11.1.1',
'address_ttl': '86400',
'fqdn': 'my-domain.com'})
headers = {'Content-Type': 'application/json',
'Content-Length': str(len(body))}
s = Session()
req = Request('POST', url, data=body, headers=headers, auth=auth1)
prepped = req.prepare()
resp = s.send(prepped)
print(resp.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment