Advertisement
Guest User

python_script

a guest
Dec 27th, 2011
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import json
  4. import os
  5. import pycurl
  6. import sys
  7.  
  8. class GetHeaders:
  9. def __init__(self):
  10. self.contents = ''
  11. self.line = 0
  12.  
  13. def store(self, buf):
  14. self.line = self.line + 1
  15. self.contents = "%s%i: %s" % (self.contents, self.line, buf)
  16.  
  17.  
  18. def __str__(self):
  19. return self.contents
  20.  
  21.  
  22. if __name__ == "__main__":
  23.  
  24. curl_auth_token = pycurl.Curl()
  25.  
  26. headers = GetHeaders()
  27.  
  28. curl_auth_token.setopt(pycurl.URL, "http://192.168.100.241:8774/v1.1/")
  29. curl_auth_token.setopt(pycurl.POST, 1)
  30. curl_auth_token.setopt(pycurl.HTTPHEADER, ["X-Auth-User: cpca",
  31. "X-Auth-Key: 1e48f161-debd-4d34-a128-f2d5eb0e5c4d"])
  32. curl_auth_token.setopt(pycurl.HEADERFUNCTION, headers.store)
  33. curl_auth_token.perform()
  34.  
  35. auth_token = headers.contents[67: headers.contents.find("4:")-1]
  36.  
  37. print auth_token
  38.  
  39. curl_auth_token.close()
  40.  
  41.  
  42. curl_operations = pycurl.Curl()
  43.  
  44. curl_operations.setopt(pycurl.URL, "http://192.168.100.241:8774/v1.0/nuvemcpca/servers")
  45. curl_operations.setopt(pycurl.POST, 1)
  46. curl_operations.setopt(pycurl.HTTPHEADER, ["-H X-Auth-Token: "+auth_token])
  47.  
  48. curl_operations.perform();
  49.  
  50. curl_operations.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement