Created
December 20, 2018 07:37
-
-
Save kaitoii11/4334c1ce473d0c91e345ee18020a4aa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python swift-proxy-check-with-request.py PROXY-IP | |
import requests | |
import json | |
import sys | |
import re | |
j = { "auth" : {\ | |
"passwordCredentials" : {\ | |
"username" : "<username>",\ | |
"password" : "<password>"\ | |
},\ | |
"tenantName" : "<tenant>"\ | |
}\ | |
} | |
header={"Content-Type": "application/json"} | |
tokenurl="http://<Keystone IP>:35357/v2.0/tokens" | |
r = requests.post(tokenurl, json.dumps(j),headers=header) | |
d = r.json() | |
token = d["access"]["token"]["id"] | |
url = d["access"]["serviceCatalog"][0]["endpoints"][0]["publicURL"] | |
# Change returned VIP to a given proxy server IP | |
url = re.sub("https://.*:8080", "http://"+sys.argv[1]+":8080", url) | |
header={"X-Auth-Token": token} | |
pheader = {"X-Auth-Token": token, "X-Delete-After":600} | |
# Assume you have ServiceCheck container | |
r = requests.put(url + "/ServiceCheck/test" ,headers=pheader) | |
print r.status_code | |
r = requests.get(url + "/ServiceCheck/test",headers=header) | |
print r.status_code | |
r = requests.delete(url + "/ServiceCheck/test",headers=header) | |
print r.status_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment