#!/usr/bin/env python #-*- coding:utf-8 -*- import base64 import urllib, urllib2 from urllib2 import URLError import requests import httplib import os import socket from urlparse import urlparse try: import json except Exception: import simplejson as json class AuthToken(): ''' Get the openstack access token ''' def __init__(self): #self.url = "172.16.200.105:5000" self.url = "http://172.16.200.105:5000/v3/auth/tokens" self.header = {"Content-Type": "application/json"} def auth(self): body = """ {"auth": { "scope": { "project": { "id": "462dc687079d46bb9fb1f14e61b84002"} }, "identity": { "methods": ["password"], "password": { "user": { "id": "e4e68753e726470384c7b6ad0420f097", "domain": { "id": "default" }, "password": "kadei3Phoh" } } } } } """ req = requests.post(self.url, data=body, headers=self.header) #print req.status_code, req.content header = req.headers token = header['X-Subject-Token'] return token """ conn = httplib.HTTPConnection(self.url) conn.request("POST", "/v3/auth/tokens", body, self.header) response = conn.getresponse() print response data = response.read() res = json.loads(data) conn.close() return res['token']['audit_ids'] """ #Token = AuthToken() #print Token.auth() #print json.dumps(Token.auth())
http://developer.openstack.org/api-ref/identity/v2-admin/