Fuel CCP - Installer sub-project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Vagrantfile 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # -*- mode: ruby -*-
  2. # # vi: set ft=ruby :
  3. require 'yaml'
  4. Vagrant.require_version ">= 1.8.0"
  5. defaults_cfg = YAML.load_file('vagrant-settings.yaml_defaults')
  6. if File.exist?('vagrant-settings.yaml')
  7. custom_cfg = YAML.load_file('vagrant-settings.yaml')
  8. cfg = defaults_cfg.merge(custom_cfg)
  9. else
  10. cfg = defaults_cfg
  11. end
  12. # Defaults for config options
  13. $num_instances = (cfg['num_instances'] || 3).to_i
  14. $kargo_node_index = (cfg['kargo_node_index'] || 1).to_i
  15. $instance_name_prefix = cfg['instance_name_prefix'] || "node"
  16. $vm_gui = cfg['vm_gui'] || false
  17. $vm_memory = (cfg['vm_memory'] || 2048).to_i
  18. $vm_cpus = (cfg['vm_cpus'] || 1).to_i
  19. $vm_cpu_limit = (cfg['vm_cpu_limit'] || 1).to_i
  20. $vm_linked_clone = cfg['vm_linked_clone'] || true
  21. $forwarded_ports = cfg['forwarded_ports'] || {}
  22. $subnet_prefix = cfg['subnet_prefix'] || "172.17"
  23. $public_subnet = cfg['public_subnet'] || "#{$subnet_prefix}.0"
  24. $private_subnet = cfg['private_subnet'] || "#{$subnet_prefix}.1"
  25. $neutron_subnet = cfg['neutron_subnet'] || "#{$subnet_prefix}.3"
  26. $mgmt_cidr = cfg['mgmt_cidr'] || "#{$subnet_prefix}.2.0/24"
  27. $box = cfg['box']
  28. $sync_type = cfg['sync_type'] || "rsync"
  29. $kargo_repo = ENV['KARGO_REPO'] || cfg['kargo_repo']
  30. $kargo_commit = ENV['KARGO_COMMIT'] || cfg['kargo_commit']
  31. def with_env(filename, env=[])
  32. "#{env.join ' '} /bin/bash -x -c #{filename}"
  33. end
  34. Vagrant.configure("2") do |config|
  35. config.ssh.username = 'vagrant'
  36. config.ssh.password = 'vagrant'
  37. config.vm.box = $box
  38. # plugin conflict
  39. if Vagrant.has_plugin?("vagrant-vbguest") then
  40. config.vbguest.auto_update = false
  41. end
  42. node_ips = []
  43. (1 .. $num_instances).each { |i| node_ips << "#{$private_subnet}.#{i+10}" }
  44. # Serialize nodes startup order for the virtualbox provider
  45. $num_instances.downto(1).each do |i|
  46. config.vm.define vm_name = "%s%d" % [$instance_name_prefix, i] do |config|
  47. if i != $kargo_node_index
  48. config.vm.provision "shell", inline: "/bin/true"
  49. else
  50. # Only execute once the Ansible provisioner on a kargo node,
  51. # when all the machines are up and ready.
  52. ip = "#{$private_subnet}.#{$kargo_node_index+10}"
  53. vars = {
  54. "KARGO_REPO" => $kargo_repo,
  55. "KARGO_COMMIT" => $kargo_commit,
  56. "SLAVE_IPS" => "\"#{node_ips.join(' ')}\"",
  57. "ADMIN_IP" => "local",
  58. "IMAGE_PATH" => $box.sub('/','_'),
  59. }
  60. env = []
  61. vars.each { |k, v| env << "#{k}=#{v}" }
  62. deploy = with_env("/vagrant/utils/jenkins/kargo_deploy.sh", env)
  63. config.vm.provision "shell", inline: "#{deploy}", privileged: false
  64. end
  65. end
  66. end
  67. # Define nodes configuration
  68. (1 .. $num_instances).each do |i|
  69. config.vm.define vm_name = "%s%d" % [$instance_name_prefix, i] do |config|
  70. config.vm.box = $box
  71. config.vm.hostname = vm_name
  72. # Networks and interfaces and ports
  73. ip = "#{$private_subnet}.#{i+10}"
  74. nets = [{:ip => ip, :name => "private",
  75. :mode => "none", :dhcp => false, :intnet => true},
  76. {:ip => "#{$public_subnet}.#{i+10}", :name => "public",
  77. :mode => "nat", :dhcp => false, :intnet => false},
  78. {:ip => "#{$neutron_subnet}.#{i+10}", :name => "neutron",
  79. :mode => "none", :dhcp => false, :intnet => true}]
  80. if $expose_docker_tcp
  81. config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
  82. end
  83. $forwarded_ports.each do |guest, host|
  84. config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
  85. end
  86. config.vm.provider :virtualbox do |vb|
  87. vb.gui = $vm_gui
  88. vb.memory = $vm_memory
  89. vb.cpus = $vm_cpus
  90. vb.linked_clone = $vm_linked_clone
  91. vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{$vm_cpu_limit}"]
  92. vb.check_guest_additions = false
  93. vb.functional_vboxsf = false
  94. end
  95. config.vm.provider :libvirt do |domain|
  96. domain.uri = "qemu+unix:///system"
  97. domain.memory = $vm_memory
  98. domain.cpus = $vm_cpus
  99. domain.driver = "kvm"
  100. domain.host = "localhost"
  101. domain.connect_via_ssh = false
  102. domain.username = $user
  103. domain.storage_pool_name = "default"
  104. domain.nic_model_type = "e1000"
  105. domain.management_network_name = "#{$instance_name_prefix}-mgmt-net"
  106. domain.management_network_address = $mgmt_cidr
  107. domain.nested = true
  108. domain.cpu_mode = "host-passthrough"
  109. domain.volume_cache = "unsafe"
  110. domain.disk_bus = "virtio"
  111. domain.graphics_ip = "0.0.0.0"
  112. end
  113. if $sync_type == 'nfs'
  114. config.vm.synced_folder ".", "/vagrant", type: "nfs"
  115. end
  116. if $sync_type == 'rsync'
  117. config.vm.synced_folder ".", "/vagrant", type: "rsync",
  118. rsync__args: ["--verbose", "--archive", "--delete", "-z"],
  119. rsync__verbose: true, rsync__exclude: [".git/", ".tox/", "output*/",
  120. "packer_cache/"]
  121. end
  122. # This works for all providers
  123. nets.each do |net|
  124. config.vm.network :private_network,
  125. :ip => net[:ip],
  126. :model_type => "e1000",
  127. :libvirt__network_name => "#{$instance_name_prefix}-#{net[:name]}",
  128. :libvirt__dhcp_enabled => net[:dhcp],
  129. :libvirt__forward_mode => net[:mode],
  130. :virtualbox__intnet => net[:intnet]
  131. end
  132. end
  133. end
  134. # Force-plug nat devices to ensure an IP is assigned via DHCP
  135. config.vm.provider :virtualbox do |vb|
  136. vb.customize "post-boot",["controlvm", :id, "setlinkstate1", "on"]
  137. end
  138. end