# E.G. to boot 20 instances
openstack server create --user-data isen-postinstall.sh --min 20 --max 20 --flavor d2-4 --image 'Debian 11' --net Ext-Net --key-name arnaud-choupinette isen

# Then copy/paste openrc files into the servers so that students can do
# source /root/openrc

# Clean the project, from k8s-1
for o in $(ls -1 openrc_is*) ; do 
    source $o
    openstack keypair list -f value -c Name | xargs openstack keypair delete
    openstack security group rule list -c ID -f value | xargs openstack security group rule delete
    openstack security group rule create --egress default
    openstack floating ip list -c ID -f value | xargs openstack floating ip delete
    for router in $(openstack router list -c ID -f value); do
        for subnet in $(openstack router show -c interfaces_info $router -f json | jq -r ".interfaces_info[].subnet_id" | uniq) ; do
            openstack router remove subnet $router $subnet
        done
        openstack router delete $router
    done
    openstack network list --internal -f value -c ID | xargs openstack network delete
done
