Skip to content

Instantly share code, notes, and snippets.

@kaitoii11
Created December 20, 2018 07:37
Show Gist options
  • Save kaitoii11/4334c1ce473d0c91e345ee18020a4aa7 to your computer and use it in GitHub Desktop.
Save kaitoii11/4334c1ce473d0c91e345ee18020a4aa7 to your computer and use it in GitHub Desktop.
# 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