adding sfc demo with icn sdewan cnf
[ovn4nfv-k8s-plugin.git] / demo / sfc-setup / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3 # SPDX-license-identifier: Apache-2.0
4 ##############################################################################
5 # Copyright (c) 2018
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 box = {
13   :virtualbox => { :name => 'elastic/ubuntu-18.04-x86_64', :version => '20191013.0.0'},
14   :libvirt => { :name => 'intergratedcloudnative/ubuntu1804', :version => '1.0.0'}
15 }
16
17 require 'yaml'
18 pdf = File.dirname(__FILE__) + '/config/default.yml'
19 nodes = YAML.load_file(pdf)
20
21 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :libvirt).to_sym
22 puts "[INFO] Provider: #{provider} "
23
24 if ENV['no_proxy'] != nil or ENV['NO_PROXY']
25   $no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
26   nodes.each do |node|
27     $no_proxy += "," + node['ip']
28   end
29   $subnet = "192.168.121"
30   if provider == :virtualbox
31     $subnet = "10.0.2"
32   end
33   # NOTE: This range is based on vagrant-libvirt network definition CIDR 192.168.121.0/27
34   (1..31).each do |i|
35     $no_proxy += ",#{$subnet}.#{i}"
36   end
37 end
38
39 Vagrant.configure("2") do |config|
40   config.vm.box =  box[provider][:name]
41   config.vm.box_version = box[provider][:version]
42   config.ssh.insert_key = false
43
44   if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil
45     if Vagrant.has_plugin?('vagrant-proxyconf')
46       config.proxy.http     = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ""
47       config.proxy.https    = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ""
48       config.proxy.no_proxy = $no_proxy
49       config.proxy.enabled = { docker: false }
50     end
51   end
52   config.vm.provider 'libvirt' do |v|
53     v.nested = true
54     v.cpu_mode = 'host-passthrough'
55     v.management_network_address = "192.168.121.0/27"
56     v.random_hostname = true
57   end
58
59   sync_type = "virtualbox"
60   if provider == :libvirt
61     sync_type = "nfs"
62   end
63
64   nodes.each do |node|
65     config.vm.define node['name'] do |nodeconfig|
66       nodeconfig.vm.hostname = node['name']
67       nodeconfig.vm.network :private_network, :ip => node['ip'], :type => :static
68       nodeconfig.vm.provider 'virtualbox' do |v|
69         v.customize ["modifyvm", :id, "--memory", node['memory']]
70         v.customize ["modifyvm", :id, "--cpus", node['cpus']]
71         if node.has_key? "volumes"
72           node['volumes'].each do |volume|
73             $volume_file = "#{node['name']}-#{volume['name']}.vdi"
74             unless File.exist?($volume_file)
75               v.customize ['createmedium', 'disk', '--filename', $volume_file, '--size', volume['size']]
76             end
77             v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', $volume_file]
78           end
79         end
80       end
81       nodeconfig.vm.provider 'libvirt' do |v|
82         v.memory = node['memory']
83         v.cpus = node['cpus']
84         nodeconfig.vm.provision 'shell' do |sh|
85           sh.path =  "node.sh"
86           if node.has_key? "volumes"
87             $volume_mounts_dict = ''
88             node['volumes'].each do |volume|
89               $volume_mounts_dict += "#{volume['name']}=#{volume['mount']},"
90               $volume_file = "./#{node['name']}-#{volume['name']}.qcow2"
91               v.storage :file, :bus => 'sata', :device => volume['name'], :size => volume['size']
92             end
93             sh.args = ['-v', $volume_mounts_dict[0...-1]]
94           end
95         end
96       end
97     end
98   end
99 end