Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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