kolla-ansible/dev/vagrant/Vagrantfile
Diogo Monteiro d2b388d55c Get kolla path from settings when provisioning box
The path for the kolla source dir was being
hardcoded on the ubuntu-bootstrap provision script
instead of utilizing the path defined in the
PROVIDER_DEFAULTS settings in the Vagrantfile

Change-Id: I0eb752ecf4db580838687c290ccf36810e8a4ff3
2015-11-12 08:55:57 -05:00

219 lines
7.6 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
require "ipaddr"
# Either libvirt or virtualbox
PROVIDER = "libvirt"
# Either centos or ubuntu
DISTRO = "centos"
PROVIDER_DEFAULTS = {
libvirt: {
centos: {
base_image: "centos/7",
bridge_interface: "virbr0",
vagrant_shared_folder: "/home/vagrant/sync",
sync_method: "nfs",
provision_script: "bootstrap.sh",
kolla_path: "/home/vagrant/kolla"
}
},
virtualbox: {
centos: {
base_image: "puppetlabs/centos-7.0-64-puppet",
bridge_interface: "wlp3s0b1",
vagrant_shared_folder: "/vagrant",
sync_method: "virtualbox",
provision_script: "bootstrap.sh",
kolla_path: "/home/vagrant/kolla"
},
ubuntu: {
base_image: "ubuntu/vivid64",
bridge_interface: "wlp3s0b1",
vagrant_shared_folder: "/home/vagrant/sync",
sync_method: "nfs",
provision_script: "ubuntu-bootstrap.sh",
kolla_path: "/usr/local/kolla"
}
}
}
# 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
NODE_SETTINGS = {
aio: {
cpus: 4,
memory: 4096
},
operator: {
cpus: 1,
memory: 1024
},
controller: {
cpus: 1,
memory: 2048
},
compute: {
cpus: 1,
memory: 1024
},
storage: {
cpus: 1,
memory: 1024
},
network: {
cpus: 1,
memory: 1024
}
}
# 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
def get_default(setting)
PROVIDER_DEFAULTS[PROVIDER.to_sym][DISTRO.to_sym][setting]
end
def get_setting(node, setting)
NODE_SETTINGS[node][setting]
end
Vagrant.configure(2) do |config|
config.vm.box = get_default(: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", type: "dhcp"
config.vm.network "public_network", dev: get_default(: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
echo '#{my_publickey}' > /root/.ssh/id_rsa.pub
chmod 644 /root/.ssh/id_rsa.pub
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
# Make sure hostmanager picks IP address of eth1
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
case PROVIDER
when "libvirt"
if vm.name
`virsh -c qemu:///system net-dhcp-leases vagrant-private-dhcp | awk -F'[ /]+' '/#{vm.name} / {print $6}'`.chop
end
when "virtualbox_ubuntu"
when "virtualbox_centos"
if vm.id
`VBoxManage guestproperty get #{vm.id} "/VirtualBox/GuestInfo/Net/1/V4/IP"`.split()[1]
end
end
end
# The operator controls the deployment
config.vm.define "operator" do |admin|
admin.vm.hostname = "operator.local"
admin.vm.provision :shell, path: get_default(:provision_script), args: "operator #{MULTINODE ? 'multinode' : 'aio'} #{get_default(:kolla_path)}"
admin.vm.synced_folder "../../etc/kolla", "/etc/kolla", type: "nfs"
admin.vm.synced_folder "../..", get_default(:kolla_path), create:"True", type: get_default(:sync_method)
admin.vm.synced_folder "storage/operator/", "/data/host", create:"True", type: get_default(:sync_method)
admin.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: get_default(:sync_method)
admin.vm.synced_folder ".", get_default(:vagrant_shared_folder), disabled: true
admin.vm.provider PROVIDER do |vm|
vm.memory = MULTINODE ? get_setting(:operator, :memory) : get_setting(:aio, :memory)
vm.cpus = MULTINODE ? get_setting(:operator, :cpus) : get_setting(:aio, :cpus)
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: get_default(:sync_method)
compute.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: get_default(:sync_method)
compute.vm.synced_folder ".", get_default(:vagrant_shared_folder), disabled: true
compute.vm.provider PROVIDER do |vm|
vm.memory = get_setting(:compute, :memory)
vm.cpus = get_setting(:compute, :cpus)
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", type: get_default(:sync_method)
storage.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: get_default(:sync_method)
storage.vm.synced_folder ".", get_default(:vagrant_shared_folder), disabled: true
storage.vm.provider PROVIDER do |vm|
vm.memory = get_setting(:storage, :memory)
vm.cpus = get_setting(:storage, :cpus)
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", type: get_default(:sync_method)
network.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: get_default(:sync_method)
network.vm.synced_folder ".", get_default(:vagrant_shared_folder), disabled: true
network.vm.provider PROVIDER do |vm|
vm.memory = get_setting(:network, :memory)
vm.cpus = get_setting(:network, :cpus)
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: get_default(:sync_method)
control.vm.synced_folder "storage/shared/", "/data/shared", create:"True", type: get_default(:sync_method)
control.vm.synced_folder ".", get_default(:vagrant_shared_folder), disabled: true
control.vm.provider PROVIDER do |vm|
vm.memory = get_setting(:controller, :memory)
vm.cpus = get_setting(:controller, :cpus)
end
control.hostmanager.aliases = "control0#{i}"
end
end
end
end