Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save weshayutin/8504cdb66a5db3bb7c6b1b4c30561d13 to your computer and use it in GitHub Desktop.
Save weshayutin/8504cdb66a5db3bb7c6b1b4c30561d13 to your computer and use it in GitHub Desktop.
Script to delete and re-create openstack users and networks
#!/bin/bash
#Script to delete and re-create openstack users and networks
. ~/keystonerc_admin
echo "================"
echo "running $0"
echo "About to really clean up, type "yes" to continue"
read CONTINUE
if [[ $CONTINUE != "yes" ]]
then
echo "Chicken !!"
exit
fi
# Delete old ports, instances, images, networks, groups, users, networks and subnets
#TENANTS=$(keystone tenant-list | tail -n +4 | head -n -1 | grep -v "admin\|services" |awk '{print $2}')
#for TENANT in $TENANTS
#do
. ~/keystonerc_user1
for PORT in $(neutron port-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting PORT: $PORT
neutron port-delete $PORT
done
# Then the routers are going
for ROUTER in $(neutron router-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting ROUTER: $ROUTER
neutron router-delete $ROUTER
done
# Then lets get rid of the subnets
for SUBNET in $(neutron subnet-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting SUBNET: $SUBNET
neutron subnet-delete $SUBNET
done
# Now lets delete the nets
for NET in $(neutron net-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting NET: $NET
neutron net-delete $NET
done
#done
. ~/keystonerc_admin
# The users have to be deleted
for USER in $(keystone user-list | tail -n +4 | head -n -1 | grep user | awk '{print $2}')
do
echo Deleting USER: $USER
keystone user-delete $USER
done
# Delete the projects/tenants
for TENANT in $(keystone tenant-list | tail -n +4 | head -n -1 | grep project | awk '{print $2}')
do
echo Deleting TENANT: $TENANT
keystone tenant-delete $TENANT
done
# and finally the images
for IMAGE in $(glance image-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting IMAGE: $IMAGE
glance image-delete $IMAGE
done
#exit
keystone tenant-create --name=project1
TENANT_ID=$(keystone tenant-list | grep project1 | awk '{print $2}')
keystone user-create --name user1 --tenant_id $TENANT_ID --pass redhat
keystone user-password-update --pass redhat user1
. ~/keystonerc_user1
glance image-create --name centos64-image --disk-format qcow2 --container-format bare --is-public True --file ~/centos64.qcow2
neutron net-create net1
neutron net-create net2
neutron subnet-create net1 --allocation-pool start=192.168.104.26,end=192.168.104.99 --gateway=192.168.104.25 --enable_dhcp=True 192.168.104.0/24
neutron subnet-create net2 --allocation-pool start=192.168.4.80,end=192.168.4.99 --gateway=192.168.4.1 --enable_dhcp=False 192.168.4.0/24
neutron router-create router1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment