-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenstack-queries
executable file
·78 lines (69 loc) · 1.9 KB
/
openstack-queries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
#
# Usage:
#
set -e
function docstring {
sed -n "s/\$0/$(basename "$0")/; s/^# //p" "$0"
}
function bad_command {
echo -e "\033[0;31mNo such command '$*'\033[0m" >&2
docstring
exit 1
}
function security_group_ports {
# $0 security group ports
local id
for id in $(openstack security group list -f json | jq -r '.[] | .ID')
do
openstack security group show -f json "$id" \
| jq -r .project_id \
| xargs openstack project show -f json \
| jq '.description'
echo "Security Group ID: $id"
openstack security group rule list -f json \
| jq -r "$(cat <<EOF
.
| map(select(."Security Group" | contains("$id")))
| map(select(."IP Protocol" != null))
| .[]
| ."IP Protocol" + " " + ."IP Range" + " " + ."Port Range"
EOF
)"
done
}
function current_image_starting_with {
# $0 current image starting with [<startswith=provisioning>]
local startswith
startswith="$*"
startswith="${startswith:-provisioning}"
openstack image list --long --format json \
| jq -r "$(cat <<EOF
.
| map(select(.Name | startswith("$startswith")))
| map(select(.Tags | contains("current")))
| first
EOF
)"
}
function remote_vnc {
# $0 remote vnc <jump host> [<remote_controller=control-01.nyc.rf29.net> [<local_port=6080>]
local jump remote_controller local_port
jump="${1:-r29-mm}"
remote_controller="${2:-control-01.nyc.rf29.net}"
local_port="${3:-6080}"
# shellcheck disable=SC2029
ssh -L "$local_port:$remote_controller:6080" "$jump" &
}
function main {
declare -a query
query=( "$@" )
case "${query[*]}" in
(security\ group\ ports) security_group_ports;;
(current\ image\ starting\ with*) current_image_starting_with "${query[@]:4}";;
(remote_vnc*) remote_vnc "${query[@]:2}";;
('') docstring;;
(*) bad_command "${query[*]}";;
esac
}
main "$@"