1234567891011121314151617181920212223242526272829303132 |
- #! /bin/bash
- usage() {
- cat << EOF
- Usage: ${0##*/} [-h] <cidr>
- List security groups matching cidr
- -h Print this help
- EOF
- }
- while getopts h opt; do
- case $opt in
- h) usage; exit 0 ;;
- esac
- done
- shift $(( OPTIND - 1 ))
- . ~/.os_helpers
- endpoint="$(get_service_endpoint network)"
- get_rules() {
- curl -s \
- -H "X-Auth-Token: $CURL_OS_TOKEN" \
- "${endpoint}/security-group-rules?remote_ip_prefix=${1}&direction=ingress&sort_key=project_id&sort_dir=asc&sort_key=security_group_id&sort_dir=asc&sort_key=port_range_min&sort_dir=asc"
- }
- get_rules "$1" \
- | jq -r '.security_group_rules[] | [.id, .security_group_id, .project_id, .protocol, .port_range_min, .port_range_max, .created_at, .updated_at] | @tsv' \
- | column -s$'\t' -t --table-columns id,security_group_id,project_id,protocol,p_min,p_max,created_at,updated_at
|