2016-06-14 16:21:56 +00:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
2016-06-20 14:12:18 +00:00
|
|
|
pool = ENV["VAGRANT_POOL"] || "10.250.0.0/16"
|
|
|
|
|
2016-06-14 16:21:56 +00:00
|
|
|
ENV["VAGRANT_DEFAULT_PROVIDER"] = "libvirt"
|
2016-06-16 09:48:51 +00:00
|
|
|
prefix = pool.gsub(/\.\d+\.\d+\/16$/, "")
|
2016-06-14 16:21:56 +00:00
|
|
|
|
|
|
|
$num_instances = 7
|
|
|
|
$vm_memory = 2048
|
|
|
|
$vm_cpus = 2
|
|
|
|
|
2016-06-16 09:48:51 +00:00
|
|
|
$user = ENV["USER"]
|
|
|
|
$public_subnet = prefix.to_s + ".0"
|
|
|
|
$private_subnet = prefix.to_s + ".1"
|
|
|
|
$mgmt_cidr = prefix.to_s + ".2.0/24"
|
2016-06-14 16:21:56 +00:00
|
|
|
|
|
|
|
$instance_name_prefix = "#{$user}-k8s"
|
2016-06-16 10:29:08 +00:00
|
|
|
|
2016-06-14 16:21:56 +00:00
|
|
|
# Boxes with libvirt provider support:
|
|
|
|
#$box = "yk0/ubuntu-xenial" #900M
|
|
|
|
#$box = "centos/7"
|
|
|
|
$box = "nrclark/xenial64-minimal-libvirt"
|
|
|
|
|
2016-06-16 10:29:08 +00:00
|
|
|
# Create SSH keys for future lab
|
2016-06-27 15:57:29 +00:00
|
|
|
system 'bash vagrant-scripts/ssh-keygen.sh'
|
2016-06-16 10:29:08 +00:00
|
|
|
|
|
|
|
# Create nodes list for future kargo deployment
|
2016-06-16 09:48:51 +00:00
|
|
|
nodes=""
|
2016-06-16 11:00:51 +00:00
|
|
|
(2..$num_instances).each do |i|
|
2016-06-16 09:48:51 +00:00
|
|
|
ip = "#{$private_subnet}.#{i+10}"
|
|
|
|
nodes = "#{nodes}#{ip}\n"
|
|
|
|
end
|
|
|
|
File.open("nodes", 'w') { |file| file.write(nodes) }
|
|
|
|
|
2016-06-16 10:29:08 +00:00
|
|
|
# Create the lab
|
2016-06-14 16:21:56 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
(1..$num_instances).each do |i|
|
2016-06-16 09:48:51 +00:00
|
|
|
# First node would be master node
|
2016-06-14 16:21:56 +00:00
|
|
|
if i == 1
|
2016-06-16 09:48:51 +00:00
|
|
|
master = true
|
2016-06-14 16:21:56 +00:00
|
|
|
else
|
2016-06-16 09:48:51 +00:00
|
|
|
master = false
|
2016-06-14 16:21:56 +00:00
|
|
|
end
|
2016-06-16 10:29:08 +00:00
|
|
|
|
2016-06-14 16:21:56 +00:00
|
|
|
config.ssh.insert_key = false
|
|
|
|
vm_name = "%s-%02d" % [$instance_name_prefix, i]
|
2016-06-16 10:29:08 +00:00
|
|
|
|
2016-06-14 16:21:56 +00:00
|
|
|
config.vm.define vm_name do |test_vm|
|
|
|
|
test_vm.vm.box = $box
|
|
|
|
test_vm.vm.hostname = vm_name
|
2016-06-16 10:29:08 +00:00
|
|
|
|
|
|
|
# Libvirt provider settings
|
2016-06-14 16:21:56 +00:00
|
|
|
test_vm.vm.provider :libvirt do |domain|
|
|
|
|
domain.uri = "qemu+unix:///system"
|
|
|
|
domain.memory = $vm_memory
|
|
|
|
domain.cpus = $vm_cpus
|
|
|
|
domain.driver = "kvm"
|
|
|
|
domain.host = "localhost"
|
|
|
|
domain.connect_via_ssh = false
|
|
|
|
domain.username = $user
|
|
|
|
domain.storage_pool_name = "default"
|
|
|
|
domain.nic_model_type = "e1000"
|
|
|
|
domain.management_network_name = "#{$instance_name_prefix}-mgmt-net"
|
|
|
|
domain.management_network_address = $mgmt_cidr
|
2016-06-16 09:48:51 +00:00
|
|
|
domain.nested = true
|
|
|
|
domain.cpu_mode = "host-passthrough"
|
|
|
|
domain.volume_cache = "unsafe"
|
|
|
|
domain.disk_bus = "virtio"
|
2016-06-14 16:21:56 +00:00
|
|
|
end
|
|
|
|
|
2016-06-20 12:42:46 +00:00
|
|
|
# Networks and interfaces
|
2016-06-16 09:48:51 +00:00
|
|
|
ip = "#{$private_subnet}.#{i+10}"
|
2016-06-20 12:42:46 +00:00
|
|
|
pub_ip = "#{$public_subnet}.#{i+10}"
|
|
|
|
# "public" network with nat forwarding
|
|
|
|
test_vm.vm.network :private_network,
|
|
|
|
:ip => pub_ip,
|
|
|
|
:model_type => "e1000",
|
2016-06-20 13:03:24 +00:00
|
|
|
:libvirt__network_name => "#{$instance_name_prefix}-public",
|
2016-06-20 12:42:46 +00:00
|
|
|
:libvirt__dhcp_enabled => false,
|
|
|
|
:libvirt__forward_mode => "nat"
|
|
|
|
# "private" isolated network
|
|
|
|
test_vm.vm.network :private_network,
|
|
|
|
:ip => ip,
|
|
|
|
:model_type => "e1000",
|
2016-06-20 13:03:24 +00:00
|
|
|
:libvirt__network_name => "#{$instance_name_prefix}-private",
|
2016-06-20 12:42:46 +00:00
|
|
|
:libvirt__dhcp_enabled => false,
|
|
|
|
:libvirt__forward_mode => "none"
|
2016-06-14 16:21:56 +00:00
|
|
|
|
|
|
|
# Provisioning
|
2016-06-20 10:02:25 +00:00
|
|
|
config.vm.provision "file", source: "ssh", destination: "~/ssh"
|
2016-06-16 09:48:51 +00:00
|
|
|
if master
|
2016-06-20 10:02:25 +00:00
|
|
|
config.vm.provision "deploy-k8s", type: "file", source: "deploy-k8s.kargo.sh", destination: "~/deploy-k8s.kargo.sh"
|
2016-06-28 08:55:23 +00:00
|
|
|
config.vm.provision "deploy-ccp", type: "file", source: "deploy-ccp.sh", destination: "~/deploy-ccp.sh"
|
2016-06-20 10:02:25 +00:00
|
|
|
config.vm.provision "custom.yaml", type: "file", source: "custom.yaml", destination: "~/custom.yaml"
|
2016-06-22 16:43:39 +00:00
|
|
|
config.vm.provision "playbooks", type: "file", source: "playbooks", destination: "~/playbooks"
|
2016-06-20 10:02:25 +00:00
|
|
|
config.vm.provision "nodes", type: "file", source: "nodes", destination: "~/nodes"
|
2016-06-27 15:57:29 +00:00
|
|
|
config.vm.provision "ccp", type: "file", source: "ccp", destination: "~/ccp"
|
|
|
|
config.vm.provision "bootstrap", type: "shell", path: "vagrant-scripts/bootstrap-master.sh"
|
2016-06-20 10:02:25 +00:00
|
|
|
else
|
2016-06-27 15:57:29 +00:00
|
|
|
config.vm.provision "bootstrap", type: "shell", path: "vagrant-scripts/bootstrap-node.sh"
|
2016-06-16 09:48:51 +00:00
|
|
|
end
|
2016-06-16 11:00:51 +00:00
|
|
|
|
2016-06-14 16:21:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|