-
Notifications
You must be signed in to change notification settings - Fork 15
/
Vagrantfile
104 lines (91 loc) · 3.54 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Defaults and constants
vmNameFromEnv = 'VAGRANT_SAPNW_VM_NAME'
argVagrantName = 'sapnw'
argMachineName = 'sap-nw752sp4'
unless ENV[vmNameFromEnv].to_s.strip.empty?
argVagrantName = ENV[vmNameFromEnv]
argMachineName = ENV[vmNameFromEnv]
puts "[!] VAGRANT_SAPNW_VM_NAME env detected"
puts "[!] VM name is redefined to: #{argVagrantName}"
end
# Create additional disk in VM directory
class VagrantPlugins::ProviderVirtualBox::Action::SetName
alias_method :original_call, :call
def call(env)
machine = env[:machine]
driver = machine.provider.driver
uuid = driver.instance_eval { @uuid }
ui = env[:ui]
# Find out folder of VM
vm_folder = ""
vm_info = driver.execute("showvminfo", uuid, "--machinereadable")
lines = vm_info.split("\n")
lines.each do |line|
if line.start_with?("CfgFile")
vm_folder = line.split("=")[1].gsub('"','')
vm_folder = File.dirname(File.expand_path(vm_folder))
ui.info "VM Folder is: #{vm_folder}"
break
end
end
disk_size = 60 * 1024 # 1GB
disk_file = File.join(vm_folder, "sybase.vdi")
ui.info "VM additional disk is: #{disk_file}"
ui.info "Adding disk to VM ..."
if File.exist?(disk_file)
ui.info " disk already exists"
else
ui.info " creating new disk"
driver.execute(
'createhd',
'--filename', disk_file,
'--format', 'VDI',
'--size', "#{disk_size}",
'--variant', 'Standard' # dynamic disk
)
ui.info " attaching disk to VM"
driver.execute(
'storageattach', uuid,
'--storagectl', 'SCSI',
'--port', '2',
'--device', '0',
'--type', 'hdd',
'--medium', disk_file
)
end
original_call(env)
end
end
# Vagrant config
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.hostname = "vhcalnplci"
config.vm.define argVagrantName
# Check for updates only on `vagrant box outdated`
config.vm.box_check_update = false
# stopsap may take time
config.vm.graceful_halt_timeout = 600
# Network
config.vm.network "forwarded_port", guest: 22, guest_ip: "10.0.2.15", host_ip: "127.0.0.1", host: 2222, id: "ssh", auto_correct: true
config.vm.network "forwarded_port", guest: 8000, guest_ip: "10.0.2.15", host_ip: "127.0.0.1", host: 8000, id: "http"
config.vm.network "forwarded_port", guest: 44300, guest_ip: "10.0.2.15", host_ip: "127.0.0.1", host: 44300, id: "https"
config.vm.network "forwarded_port", guest: 3300, guest_ip: "10.0.2.15", host_ip: "127.0.0.1", host: 3300, id: "rfc"
config.vm.network "forwarded_port", guest: 3200, guest_ip: "10.0.2.15", host_ip: "127.0.0.1", host: 3200, id: "sapgui"
# Virtualbox settings
config.vm.provider "virtualbox" do |vb|
vb.name = argMachineName
vb.memory = "6144" # 6 GB
# vb.memory = "4096" # 4 GB + enable add_swap.sh below !!!
end
# Provision scripts
config.vm.provision "shell", path: "scripts/provision/add_disk.sh"
# config.vm.provision "shell", path: "scripts/provision/add_swap.sh"
# config.vm.provision "shell", path: "scripts/provision/patch_install_script.sh"
config.vm.provision "shell", path: "scripts/provision/pre_install.sh"
config.vm.provision "shell", path: "scripts/provision/install_nw.sh"
config.vm.provision "shell", path: "scripts/provision/startup.sh"
config.vm.provision "shell", path: "scripts/provision/post_install.sh"
config.vm.provision "shell", path: "scripts/provision/finalize.sh"
end