Skip to content

Instantly share code, notes, and snippets.

@riccardobl
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riccardobl/4ba8c71916dc147e1cc2 to your computer and use it in GitHub Desktop.
Save riccardobl/4ba8c71916dc147e1cc2 to your computer and use it in GitHub Desktop.
Read cidrs from provided urls and add them to a nova openstack's security group
SECURITY_GROUP='xxxxxx' #EDIT ME
REGION='xxxxxx' #EDIT ME
RC_FILE='xxxxxx' #EDIT ME
CIDR_LISTS=("https://gist.githubusercontent.com/riccardobl/28a616180d8d7ad44473/raw/telecom-italia-ips.txt")
DELETE_OLD_RULES=true
DELAY_BETWEEN_REQUESTS=2
source "$RC_FILE"
export OS_REGION_NAME="$REGION"
if [ "$DELETE_OLD_RULES" = true ]; then
# Remove all old rules
while read -r line
do
sleep $DELAY_BETWEEN_REQUESTS
parts=($(echo $line | sed -e 's/[|]/ /g'))
echo "Delete" $SECURITY_GROUP ${parts[0]} ${parts[1]} ${parts[2]} ${parts[3]} ${parts[4]} ${parts[5]}
nova secgroup-delete-rule $SECURITY_GROUP ${parts[0]} ${parts[1]} ${parts[2]} ${parts[3]} ${parts[4]} ${parts[5]} > /dev/null 2> /dev/null
done < <(nova secgroup-list-rules $SECURITY_GROUP)
fi
for a in "${CIDR_LISTS[@]}"
do
sleep $DELAY_BETWEEN_REQUESTS
content=$(curl "$a" )
while read -r line
do
parts=($(echo $line))
iprange=${parts[0]}
# ---- Generate new Rules ----
nova secgroup-add-rule $SECURITY_GROUP tcp 22 22 $iprange
# .... EDIT ME
# ......
# ........
# ----------------------------
done < <(echo "$content")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment