2017年4月23日 星期日

Ceph Calamari API access via curl


Initial account:
calamari-ctl add_user kido --password kido --email kido.idv.tw@gmail.com
calamari-ctl enable_user kido
calamari-ctl assign_role kido superuser

Prepare cookie:

curl -c cookies.txt -k -i -d username=kido -d password=kido https://10.5.15.50:8002/api/v2/auth/login

JSON
curl -b cookies.txt -s -k https://10.5.15.50:8002/api/v2/cluster/ad3f18fa-e58a-4625-ae1a-b6d6bab18de7/cli -X POST --referer "https://10.5.15.50:8002/api/v2/auth/login"  -H "Content-Type: application/json; charset=UTF-8" -H "X-XSRF-TOKEN: oQDbEVTSgNDnDxSFTH6PrFO9hi8ExCDd" -d '{"command":"ceph osd tree"}'

curl -b cookies.txt -s -k https://10.5.15.50:8002/api/v2/cluster/ad3f18fa-e58a-4625-ae1a-b6d6bab18de7/cli -X POST --referer "https://10. "Content-Type: application/json; charset=UTF-8" -H "X-XSRF-TOKEN: oQDbEVTSgNDnDxSFTH6PrFO9hi8ExCDd" -d '{"command":["ceph","osd","tree"]}'

X-WWW-FORM-URLENCODED
curl -b cookies.txt -s -k https://10.5.15.50:8002/api/v2/cluster/ad3f18fa-e58a-4625-ae1a-b6d6bab18de7/cli -X POST --referer "https://10.5.15.50:8002/api/v2/auth/login" -d "csrfmiddlewaretoken=ELR8K6Z83y2jWQJpl1t5K8yOotqwddp7" -d "command=ceph%20osd%20perf" -H "Content-Type: application/x-www-form-urlencoded"

Accessing Ceph via calamari-lite API need to go through https and port number has been changed to 8002

To ignore certificate check in curl command: -k
Accessing through default http header (x-www-form-urlencoded) csrfmiddlewaretoken is needed
Accessing through JSON header, X-XSRF-TOKEN need to be included in header. 
XSRF token can be discovered in cook file.

http://calamari.readthedocs.io/en/latest/calamari_rest/resources/resources.html#clusterviewset

沒有留言: