Skip to content

Commit 23db3df

Browse files
author
David Borman
committed
Support for additional disks, big nodes, update channel and Parallels
Create big nodes - In addition to the normal nodes, you can also add additional nodes with a larger memory/cpu configuration. $num_big_instances = 1 $vm_big_memory = 8192 $vm_big_cpus = 2 Additional disks - Each node can be configured with additional disks. $num_data_disks = 3 $data_disk_size = 10 # GBytes Specify the coreos update channel: $update_channel = "alpha" Also add .virtualbox/ to .gitignore Add Parallels support - Set the memory size and number of cpus for Parallels, as well as setting the download path. - Change Vagrant file config.vm.provider order so that VirtualBox is first, which makes it the default provider (assuming it works), and the util.rb reflects that assumption. In general, setting VAGRANT_DEFAULT_PROVIDER is the best way to be deterministic about what provider is used.
1 parent 68ba227 commit 23db3df

3 files changed

Lines changed: 154 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vagrant/
2+
.virtualbox/
23
log/
34
user-data
45
config.rb

Vagrantfile

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# # vi: set ft=ruby :
33

44
require 'fileutils'
5+
require_relative 'util.rb'
56

67
Vagrant.require_version ">= 1.6.0"
78

@@ -30,9 +31,16 @@ $share_home = false
3031
$vm_gui = false
3132
$vm_memory = 1024
3233
$vm_cpus = 1
34+
$num_big_instances = 0
35+
$vm_big_memory = 8192
36+
$vm_big_cpus = 2
3337
$vb_cpuexecutioncap = 100
3438
$shared_folders = {}
3539
$forwarded_ports = {}
40+
$update_channel = "alpha"
41+
# Additional disks to configure on each node
42+
$num_data_disks = 0
43+
$data_disk_size = 10 # GBytes
3644

3745
# Attempt to apply the deprecated environment variable NUM_INSTANCES to
3846
# $num_instances while allowing config.rb to override it
@@ -49,11 +57,17 @@ def vm_gui
4957
$vb_gui.nil? ? $vm_gui : $vb_gui
5058
end
5159

52-
def vm_memory
60+
def vm_memory(instance)
61+
if instance > $num_instances then
62+
return $vm_big_memory
63+
end
5364
$vb_memory.nil? ? $vm_memory : $vb_memory
5465
end
5566

56-
def vm_cpus
67+
def vm_cpus(instance)
68+
if instance > $num_instances then
69+
return $vm_big_cpus
70+
end
5771
$vb_cpus.nil? ? $vm_cpus : $vb_cpus
5872
end
5973

@@ -63,14 +77,12 @@ Vagrant.configure("2") do |config|
6377
# forward ssh agent to easily ssh into the different machines
6478
config.ssh.forward_agent = true
6579

66-
config.vm.box = "coreos-alpha"
67-
config.vm.box_url = "https://alpha.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json"
80+
config.vm.box = "coreos-%s" % $update_channel
81+
config.vm.box_url = "https://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json" % $update_channel
6882

69-
["vmware_fusion", "vmware_workstation"].each do |vmware|
70-
config.vm.provider vmware do |v, override|
71-
override.vm.box_url = "https://alpha.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json"
72-
end
73-
end
83+
# Note: Having VirtualBox be the first config.vm.provider means
84+
# it will be the default provider. For details on this see:
85+
# https://www.vagrantup.com/docs/providers/basic_usage.html
7486

7587
config.vm.provider :virtualbox do |v|
7688
# On VirtualBox, we don't have guest additions or a functional vboxsf
@@ -81,12 +93,23 @@ Vagrant.configure("2") do |config|
8193
config.ignition.enabled = true
8294
end
8395

96+
["vmware_fusion", "vmware_workstation"].each do |vmware|
97+
config.vm.provider vmware do |v, override|
98+
override.vm.box_url = "https://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel
99+
end
100+
end
101+
102+
config.vm.provider :parallels do |v, override|
103+
override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_parallels.json" % $update_channel
104+
end
105+
84106
# plugin conflict
85107
if Vagrant.has_plugin?("vagrant-vbguest") then
86108
config.vbguest.auto_update = false
87109
end
88110

89-
(1..$num_instances).each do |i|
111+
total_instances=$num_instances+$num_big_instances
112+
(1..total_instances).each do |i|
90113
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
91114
config.vm.hostname = vm_name
92115

@@ -120,20 +143,26 @@ Vagrant.configure("2") do |config|
120143
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
121144
end
122145

146+
config.vm.provider :virtualbox do |vb|
147+
vb.gui = vm_gui
148+
vb.memory = vm_memory i
149+
vb.cpus = vm_cpus i
150+
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{$vb_cpuexecutioncap}"]
151+
config.ignition.config_obj = vb
152+
end
153+
123154
["vmware_fusion", "vmware_workstation"].each do |vmware|
124155
config.vm.provider vmware do |v|
125156
v.gui = vm_gui
126-
v.vmx['memsize'] = vm_memory
127-
v.vmx['numvcpus'] = vm_cpus
157+
v.vmx['memsize'] = vm_memory i
158+
v.vmx['numvcpus'] = vm_cpus i
128159
end
129160
end
130161

131-
config.vm.provider :virtualbox do |vb|
132-
vb.gui = vm_gui
133-
vb.memory = vm_memory
134-
vb.cpus = vm_cpus
135-
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{$vb_cpuexecutioncap}"]
136-
config.ignition.config_obj = vb
162+
config.vm.provider :parallels do |vb|
163+
vb.memory = vm_memory i
164+
vb.cpus = vm_cpus i
165+
vb.name = vm_name
137166
end
138167

139168
ip = "172.17.8.#{i+100}"
@@ -167,6 +196,10 @@ Vagrant.configure("2") do |config|
167196
config.ignition.path = 'config.ign'
168197
end
169198
end
199+
200+
if $num_data_disks > 0
201+
attach_volumes(config, $num_data_disks, $data_disk_size)
202+
end
170203
end
171204
end
172205
end

util.rb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
def get_provider
3+
# Look for "--provider foo"
4+
provider_index = ARGV.index('--provider')
5+
if (provider_index && ARGV[provider_index + 1])
6+
return ARGV[provider_index + 1]
7+
end
8+
9+
# Look for "--provider=foo"
10+
for i in 1 ... ARGV.length
11+
if ARGV[i].include?('--provider=')
12+
return ARGV[i].sub('--provider=', '')
13+
end
14+
end
15+
16+
# Note: The assumption of the default provider
17+
# being VirtualBox is predecated on the order
18+
# of the config.vm.provider calls in Vagrantfile
19+
return ENV['VAGRANT_DEFAULT_PROVIDER'] || 'virtualbox'
20+
end
21+
22+
$provider = get_provider().to_sym
23+
24+
class VagrantPlugins::ProviderVirtualBox::Action::SetName
25+
alias_method :original_call, :call
26+
def call(env)
27+
machine = env[:machine]
28+
driver = machine.provider.driver
29+
uuid = driver.instance_eval { @uuid }
30+
ui = env[:ui]
31+
32+
controller_name="SATA Controller"
33+
34+
vm_info = driver.execute("showvminfo", uuid)
35+
controller_already_exists = vm_info.match("Storage Controller Name.*#{controller_name}")
36+
37+
if controller_already_exists
38+
ui.info "already has the #{controller_name} hdd controller, skipping creation/add"
39+
else
40+
ui.info "creating #{controller_name} hdd controller"
41+
driver.execute(
42+
'storagectl',
43+
uuid,
44+
'--name', "#{controller_name}",
45+
'--add', 'sata',
46+
'--controller', 'IntelAHCI')
47+
end
48+
49+
original_call(env)
50+
end
51+
end
52+
53+
# Add persistent storage volumes
54+
def attach_volumes(node, num_volumes, volume_size)
55+
56+
if $provider == :virtualbox
57+
node.vm.provider :virtualbox do |v, override|
58+
(1..num_volumes).each do |disk|
59+
diskname = File.join(File.dirname(File.expand_path(__FILE__)), ".virtualbox", "#{node.vm.hostname}-#{disk}.vdi")
60+
unless File.exist?(diskname)
61+
v.customize ['createhd', '--filename', diskname, '--size', volume_size * 1024]
62+
end
63+
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', disk, '--device', 0, '--type', 'hdd', '--medium', diskname]
64+
end
65+
end
66+
end
67+
68+
if $provider == :vmware_fusion || $provider == "vmware_workstation"
69+
["vmware_fusion", "vmware_workstation"].each do |vmware|
70+
node.vm.provider vmware do |v, override|
71+
72+
vdiskmanager = '/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager'
73+
if File.exist?(vdiskmanager)
74+
dir = File.join(File.dirname(File.expand_path(__FILE__)), ".vmware")
75+
unless File.directory?( dir )
76+
Dir.mkdir dir
77+
end
78+
79+
(1..num_volumes).each do |disk|
80+
diskname = File.join(dir, "#{node.vm.hostname}-#{disk}.vmdk")
81+
unless File.exist?(diskname)
82+
`#{vdiskmanager} -c -s #{volume_size}GB -a lsilogic -t 1 #{diskname}`
83+
end
84+
85+
v.vmx["scsi0:#{disk}.filename"] = diskname
86+
v.vmx["scsi0:#{disk}.present"] = 'TRUE'
87+
v.vmx["scsi0:#{disk}.redo"] = ''
88+
end
89+
end
90+
end
91+
end
92+
end
93+
94+
if $provider == :parallels
95+
node.vm.provider :parallels do |v, override|
96+
(1..num_volumes).each do |disk|
97+
v.customize ['set', :id, '--device-add', 'hdd', '--size', volume_size * 1024]
98+
end
99+
end
100+
end
101+
102+
end

0 commit comments

Comments
 (0)