config/r815/Vagrant.setup

71 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2020-06-12 14:24:10 +00:00
install() {
# Install needed software once
sudo apt install -y vagrant virtualbox
}
setup() {
# Configure the virtual servers
mkdir -p ssh/
cp ~/.ssh/id_rsa.pub ssh/
cat ssh/*.pub > authorized_keys
cat >Vagrantfile <<'EOF'
Vagrant.configure("2") do |config|
config.vm.box = "debian/buster64"
config.vm.network "public_network"
(1..100).each do |i|
config.vm.define "vm%03d" % i do |node|
node.vm.hostname = "vm%03d" % i
# use the following line to map a range of ports on the host
# to the VNC port of each VM:
# node.vm.network "forwarded_port", host: 5900+i, guest: 5900
end
end
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("authorized_keys").first.strip
s.inline = <<-SHELL
mkdir /root/.ssh
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
apt-get update
apt-get install -y parallel
SHELL
end
end
EOF
}
start() {
testssh() {
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@"$1" echo "'$1'" '`uptime`'
}
export -f testssh
# Start the virtual servers
seq 100 | parallel vagrant up vm{}
# After this it is possible to do:
# ssh 10.0.0.99
# from another physical server
# How do we get the IP-addresses?
# parallel testssh
}
stop() {
# Stop the virtual servers
# After there is no running processes on the host server
# and after this it is no longer possible to do:
# ssh 10.0.0.99
# from another physical server
# The host server returns to the state before running `start`
vagrant suspend
}
destroy() {
# Remove the setup
# After this the host server returns to the state before running `setup`
?
}
full() {
install
setup
start
stop
destroy
}