forked from futuretea/harvester-auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
112 lines (101 loc) · 4.01 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# vi: set ft=ruby ts=2 :
require 'yaml'
VAGRANTFILE_API_VERSION = "2"
# check for required plugins
_required_plugins_list = %w{vagrant-libvirt}
exit(1) unless _required_plugins_list.all? do |plugin|
Vagrant.has_plugin?(plugin) || (
STDERR.puts "Required plugin '#{plugin}' is missing; please install using:"
STDERR.puts " % vagrant plugin install #{plugin}"
false
)
end
# ensure libvirt is the default provider in case the vagrant box config
# doesn't specify it
ENV['VAGRANT_DEFAULT_PROVIDER'] = "libvirt"
@root_dir = File.dirname(File.expand_path(__FILE__))
@settings = YAML.load_file(File.join(@root_dir, "settings.yml"))
dhcp_server_ip = @settings['harvester_network_config']['dhcp_server']['ip']
cpu_count = @settings['harvester_node_config']['cpu']
memory_size = @settings['harvester_node_config']['memory']
disk_size = @settings['harvester_node_config']['disk_size']
cluster_create_node_number = @settings['harvester_cluster_create_nodes']
namespace_id = @settings['harvester_cluster']['namespace_id']
cluster_id = @settings['harvester_cluster']['cluster_id']
name_suffix = @settings['harvester_cluster']['name_suffix']
network_name = "harvester-#{name_suffix}"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# continerd is taking more than 60 seconds to shutdown in SUSE platforms
# so increase the timeout to 120 seconds
config.vm.graceful_halt_timeout = 120
vm_name = "pxe-server-#{name_suffix}"
config.vm.define vm_name do |pxe_server|
pxe_server.vm.box = 'generic/debian10'
pxe_server.vm.hostname = 'pxe-server'
pxe_server.vm.network 'private_network',
ip: "#{dhcp_server_ip}",
libvirt__network_name: "#{network_name}",
libvirt__always_destroy: false,
# don't enable DHCP as this node will have it's now DHCP server for iPXE
# boot
libvirt__dhcp_enabled: false
pxe_server.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
libvirt.memory = '4096'
libvirt.cpus = '4'
libvirt.graphics_type = 'vnc'
libvirt.graphics_ip = "0.0.0.0"
end
# Use ansible to install server
pxe_server.vm.provision :ansible do |ansible|
ansible.playbook = 'ansible/setup_pxe_server.yml'
ansible.extra_vars = {
settings: @settings
}
end
end
(1..cluster_create_node_number).each do |node_number|
vm_name = "harvester-#{name_suffix}-#{node_number}"
storage_pool_id = "#{namespace_id}#{node_number}#{cluster_id}".to_i % 4 + 1
storage_pool_name = "pool#{storage_pool_id}"
config.vm.define vm_name, autostart: true do |harvester_node|
harvester_node.vm.hostname = "#{vm_name}"
harvester_node.vm.network 'private_network',
libvirt__network_name: "#{network_name}",
libvirt__always_destroy: false,
mac: @settings['harvester_network_config']['cluster'][node_number-1]['mac']
harvester_node.vm.network 'private_network',
libvirt__network_name: "#{network_name}",
libvirt__always_destroy: false,
mac: @settings['harvester_network_config']['cluster'][node_number-1]['mac_second']
harvester_node.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
libvirt.memory = memory_size
libvirt.cpus = cpu_count
libvirt.storage_pool_name = "#{storage_pool_name}"
libvirt.storage :file,
size: disk_size,
type: 'qcow2',
bus: 'virtio',
device: 'vda',
cache: 'none',
io: 'native'
libvirt.storage :file,
size: '50G',
type: 'qcow2',
bus: 'virtio',
device: 'vdb',
cache: 'none',
io: 'native'
boot_network = {'network' => "#{network_name}"}
libvirt.boot 'hd'
libvirt.boot boot_network
# NOTE: default to UEFI boot. Comment this out for legacy BIOS.
libvirt.loader = '/usr/share/qemu/OVMF.fd'
libvirt.nic_model_type = 'virtio'
libvirt.graphics_type = 'vnc'
libvirt.graphics_ip = "0.0.0.0"
end
end
end
end