kolla/vagrant/Vagrantfile
Martin André 4ceedb4ad3 Default vagrant deployment to AIO
The default for kolla-ansible is already AIO, let's be consistent.

Partially-Implements: blueprint vagrant-improvements
Change-Id: Ib2736806c373f18be7d758c06b88abe38a60bd55
2015-09-15 16:29:47 +09:00

158 lines
5.9 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
require "ipaddr"
# The base image to use
BASE_IMAGE="centos/7"
# Either libvirt or virtualbox
PROVIDER="libvirt"
# Whether to do Multi-node or All-in-One deployment
MULTINODE=false
# The following is only used when deploying in Multi-nodes
NUMBER_OF_CONTROL_NODES=3
NUMBER_OF_COMPUTE_NODES=1
NUMBER_OF_STORAGE_NODES=1
NUMBER_OF_NETWORK_NODES=1
# Private IP address network
# Sadly, DHCP assignment on private network is buggy with libvirt provider
# see https://github.com/pradels/vagrant-libvirt/issues/427
PRIVATE_NETWORK="10.10.10.0/24"
# Bridge interface
BRIDGE_INTERFACE="virbr0"
# Configure a new SSH key and config so the operator is able to connect with
# the other cluster nodes.
unless File.file?("./vagrantkey")
system("ssh-keygen -f ./vagrantkey -N '' -C this-is-vagrant")
end
# A poor's man DHCP server
# Note: this prevents safely running 'vagrant up' one VM at a time otherwise
# you're likely to have IP address conflicts. The shuffle is meant to reduce
# collisions. A safer way would be to make sure the host doesn't respond to
# pings.
# This should all go away once we find a way to make vagrant-libvirt work with
# private DHCP networks.
def pick_address
@available_addresses ||= IPAddr.new(PRIVATE_NETWORK).to_range.to_a.drop(2).shuffle
@available_addresses.shift.to_s
end
Vagrant.configure(2) do |config|
config.vm.box = BASE_IMAGE
# Next to the hostonly NAT-network there is a host-only network with all
# nodes attached. Plus, each node receives a 3rd adapter connected to the
# outside public network.
config.vm.network "private_network", ip: pick_address
config.vm.network "public_network", dev: BRIDGE_INTERFACE, mode: 'bridge', type: 'bridge'
my_privatekey = File.read(File.join(File.dirname(__FILE__), "vagrantkey"))
my_publickey = File.read(File.join(File.dirname(__FILE__), "vagrantkey.pub"))
config.vm.provision :shell, inline: <<-EOS
mkdir -p /root/.ssh
echo '#{my_privatekey}' > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
echo '#{my_publickey}' > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
mkdir -p /home/vagrant/.ssh
echo '#{my_privatekey}' >> /home/vagrant/.ssh/id_rsa
chmod 600 /home/vagrant/.ssh/*
echo 'Host *' > ~vagrant/.ssh/config
echo StrictHostKeyChecking no >> ~vagrant/.ssh/config
chown -R vagrant: /home/vagrant/.ssh
EOS
config.hostmanager.enabled = true
# The operator controls the deployment
config.vm.define "operator" do |admin|
admin.vm.hostname = "operator.local"
admin.vm.provision :shell, path: "bootstrap.sh", args: "operator #{MULTINODE ? 'multinode' : 'aio'}"
admin.vm.synced_folder "..", "/home/vagrant/kolla", create:"True", type: 'nfs'
admin.vm.synced_folder "storage/operator/", "/data/host", create:"True", type: 'nfs'
admin.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: 'nfs'
admin.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
admin.vm.provider PROVIDER do |vm|
vm.memory = MULTINODE ? 1024 : 4096
if PROVIDER == 'libvirt'
# This only works with libvirt provider.
# We should be able to do something similar for virtualbox
# http://askubuntu.com/questions/317338/how-can-i-increase-disk-size-on-a-vagrant-vm
vm.machine_virtual_size = 40
end
end
admin.hostmanager.aliases = "operator"
end
if MULTINODE
# Build compute nodes
(1..NUMBER_OF_COMPUTE_NODES).each do |i|
config.vm.define "compute0#{i}" do |compute|
compute.vm.hostname = "compute0#{i}.local"
compute.vm.provision :shell, path: "bootstrap.sh"
compute.vm.synced_folder "storage/compute/", "/data/host", create:"True", type: 'nfs'
compute.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: 'nfs'
compute.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
compute.vm.provider PROVIDER do |vm|
vm.memory = 1024
end
compute.hostmanager.aliases = "compute0#{i}"
end
end
# Build storage nodes
(1..NUMBER_OF_STORAGE_NODES).each do |i|
config.vm.define "storage0#{i}" do |storage|
storage.vm.hostname = "storage0#{i}.local"
storage.vm.provision :shell, path: "bootstrap.sh"
storage.vm.synced_folder "storage/storage/", "/data/host", create:"True"
storage.vm.synced_folder "storage/shared/", "/data/shared", create:"True"
storage.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
storage.vm.provider PROVIDER do |vm|
vm.memory = 1024
end
storage.hostmanager.aliases = "storage0#{i}"
end
end
# Build network nodes
(1..NUMBER_OF_NETWORK_NODES).each do |i|
config.vm.define "network0#{i}" do |network|
network.vm.hostname = "network0#{i}.local"
network.vm.provision :shell, path: "bootstrap.sh"
network.vm.synced_folder "storage/network/", "/data/host", create:"True"
network.vm.synced_folder "storage/shared/", "/data/shared", create:"True"
network.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
network.vm.provider PROVIDER do |vm|
vm.memory = 1024
end
network.hostmanager.aliases = "network0#{i}"
end
end
# Build control nodes
(1..NUMBER_OF_CONTROL_NODES).each do |i|
config.vm.define "control0#{i}" do |control|
control.vm.hostname = "control0#{i}.local"
control.vm.provision :shell, path: "bootstrap.sh"
control.vm.synced_folder "storage/control/", "/data/host", create:"True", type: 'nfs'
control.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: 'nfs'
control.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
control.vm.provider PROVIDER do |vm|
vm.memory = 2048
end
control.hostmanager.aliases = "control0#{i}"
end
end
end
end