Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import json
- import os
- import pycurl
- import sys
- class GetHeaders:
- def __init__(self):
- self.contents = ''
- self.line = 0
- def store(self, buf):
- self.line = self.line + 1
- self.contents = "%s%i: %s" % (self.contents, self.line, buf)
- def __str__(self):
- return self.contents
- if __name__ == "__main__":
- curl_auth_token = pycurl.Curl()
- headers = GetHeaders()
- curl_auth_token.setopt(pycurl.URL, "http://192.168.100.241:8774/v1.1/")
- curl_auth_token.setopt(pycurl.POST, 1)
- curl_auth_token.setopt(pycurl.HTTPHEADER, ["X-Auth-User: cpca",
- "X-Auth-Key: 1e48f161-debd-4d34-a128-f2d5eb0e5c4d"])
- curl_auth_token.setopt(pycurl.HEADERFUNCTION, headers.store)
- curl_auth_token.perform()
- auth_token = headers.contents[67: headers.contents.find("4:")-1]
- print auth_token
- curl_auth_token.close()
- curl_operations = pycurl.Curl()
- curl_operations.setopt(pycurl.URL, "http://192.168.100.241:8774/v1.0/nuvemcpca/servers")
- curl_operations.setopt(pycurl.POST, 1)
- curl_operations.setopt(pycurl.HTTPHEADER, ["-H X-Auth-Token: "+auth_token])
- curl_operations.perform();
- curl_operations.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement