Created
May 26, 2015 15:02
-
-
Save ilyash-p/f36bc313b94cd3cde586 to your computer and use it in GitHub Desktop.
Celestial CLI helpers
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
# No warranties of any kind. Works for me. | |
# Make sure to edit all XXX marked places in this file before using it. | |
export CELESTIAL_LAST_JOB_FILE=~/.celestial.last-job | |
function C() { | |
# Expects "user:pass" in ~/.celestial-creds | |
u="$1" | |
shift | |
curl -s -k "https://`cat ~/.celestial-creds`@XXX:8443/$u" "$@" | |
} | |
function CJ() { | |
C jobs/running | jq '.jobs[] | "\(.id) \(.env) \(.type) \(.status) \(.tid)"' -r | column -t | |
} | |
function _celestial_job() { | |
C jobs/$1/$2 -X POST | |
echo $2 >$CELESTIAL_LAST_JOB_FILE | |
echo $2 >>$CELESTIAL_LAST_JOB_FILE.history | |
echo | |
} | |
function _celestial_log_id_by_system_id() { | |
id="$1" | |
( | |
CJ | awk -v id="$id" '$1 == id {print $5}' | |
CJD | awk -v id="$id" '$1 == id {print $7}' | |
) | head -1 | |
} | |
function CJprovision() { | |
_celestial_job provision $1 | |
} | |
function CJstage() { | |
_celestial_job stage $1 | |
} | |
function CJdestroy() { | |
_celestial_job destroy $1 | |
} | |
function CJclear() { | |
_celestial_job clear $1 | |
} | |
function CJdeploy-config() { | |
_celestial_job deploy-config $1 | |
} | |
function CJdeploy-latest() { | |
_celestial_job deploy-latest $1 | |
} | |
function CJD() { | |
C 'jobs/done?page=1&offset=20' | jq '.jobs[] | "\(.identity) \(.env) \(.args[0].type) \(.hostname) \(.status) \(.["end"]) \(.tid)"' -r | while read line;do | |
t=$(echo "$line" | awk '{print int($6 / 1000)}') | |
t=$(date -u -d "@$t" '+%Y-%m-%d_%H:%M:%S') | |
line=$(echo "$line" | awk -v t="$t" '{$6 = t; print}') | |
echo "$line" | |
done | column -t | |
} | |
function CE() { | |
C environments | jq .environments | |
} | |
function CT() { | |
C types | jq '.types[] | "\(.type) \(.classes|keys)"' -r | column -t | |
} | |
function CS() { | |
o=$(C 'systems?page=1&offset=1000' | jq '.systems[] | "\(.[0]) \(.[1].env) \(.[1].type) \(.[1].machine.hostname) \(.[1].machine.ip) \(.[1].openstack["flavor"]) owner=\(.[1].owner) key=\(.[1].openstack["key-name"]) sg=\(.[1].openstack["security-groups"]) \(.[1].openstack["instance-id"])"' -r | column -t) | |
if [ -z "$1" ];then | |
echo "$o" | |
else | |
echo "$o" | grep "$1" | |
fi | |
} | |
function CL() { | |
if [ -z "$1" ];then | |
log_id=$(_celestial_log_id_by_system_id "$(cat $CELESTIAL_LAST_JOB_FILE)") | |
set -- $log_id | |
fi | |
curl -s "http://XXX:9200/_search?size=${2-1000}&sort=@timestamp:desc&q=tid:$1" | jq '.hits.hits[] | "\(._source["@timestamp"]) \(._source.message)"' -r | tac | |
} | |
function CLW() { | |
if [ -z "$1" ];then | |
log_id=$(_celestial_log_id_by_system_id "$(cat $CELESTIAL_LAST_JOB_FILE)") | |
set -- $log_id | |
fi | |
while true;do | |
lines=$((LINES-2)) | |
o=`CL $1 $lines` | |
clear | |
echo "$o" | |
if echo "$o" | grep -q 'Flushing index celestial-systems';then | |
break | |
fi | |
sleep 2 | |
done | |
} | |
# ----- CREATE SYSTEM EXAMPLE ----- | |
# C systems -X POST -d '{ "openstack": { "networks": ["XXX"],"flavor": "XXX","key-name": "celestial","security-groups": ["default","XXX"],"tenant": "XXX" },"user": "XXX","type": "XXX","env":"XXX","machine": { "domain": "XXX","os": "ubuntu-14.10","hostname": "XXX","user": "ubuntu" }, "owner": "XXX" }' -H 'Content-Type: application/json' | jq . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment