Update AAI instructions
[integration.git] / bootstrap / vagrant-onap / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 configuration = {
5   # Generic parameters used across all ONAP components
6   'key_name'            => 'ecomp_key',
7   'pub_key'             => '',
8   'nexus_repo'          => 'https://nexus.onap.org/content/sites/raw',
9   'nexus_repo_root'     => 'https://nexus.onap.org',
10   'nexus_url_snapshot'  => 'https://nexus.onap.org/content/repositories/snapshots',
11   'nexus_docker_repo'   => 'nexus3.onap.org:10001',
12   'nexus_username'      => 'docker',
13   'nexus_password'      => 'docker',
14   'dmaap_topic'         => 'AUTO',
15   'artifacts_version'   => '1.0.0',
16   'docker_version'      => 'latest',
17   # Parameters for DCAE instantiation
18   'dcae_zone'           => 'iad4',
19   'dcae_state'          => 'vi',
20   'openstack_tenant_id' => '',
21   'openstack_username'  => '',
22   'openstack_api_key'   => '',
23   'openstack_password'  => '',
24   'odl_version'         => '0.5.3-Boron-SR3',
25   # Parameters for enabling features
26   'debug'               => 'True',
27   'build_image'         => 'True',
28   'clone_repo'          => 'True',
29   'compile_repo'        => 'False',
30   'enable_oparent'      => 'True',
31   'skip_get_images'     => 'False',
32   'skip_install'        => 'True'
33 }
34
35 box = {
36   :virtualbox => 'ubuntu/trusty64',
37   :libvirt => 'elastic/ubuntu-14.04-x86_64',
38   :openstack => nil
39 }
40
41 nodes = [
42     {
43     :name   => "aai",
44     :ips    => ['10.252.0.6', "192.168.50.6"],
45     :macs   => [],
46     :cpus   => 2,
47     :cpu    => "50",
48     :ram    => 6 * 1024,
49     :groups => ["individual"],
50     :args   => ["aai"],
51     :fwds   => [
52       { :guest => 8446, :host => 8446, :guest_ip => '192.168.50.6' },
53       { :guest => 9446, :host => 9446, :guest_ip => '192.168.50.6' },
54     ]
55   },
56   {
57     :name   => "all-in-one",
58     :ips    => ['10.252.1.3', "192.168.51.3"],
59     :macs   => [],
60     :cpus   => 2,
61     :cpu    => "50",
62     :ram    => 12 * 1024,
63     :groups => ["all-in-one"],
64     :flavor => 'm1.xlarge',
65     :args   => ['mr', 'sdc', 'aai', 'mso', 'robot', 'vid', 'sdnc', 'portal', 'dcae', 'policy', 'appc', 'vfc', 'ccsdk', 'multicloud', 'vnfsdk', 'vpp', 'msb'],
66   },
67   {
68     :name   => "appc",
69     :ips    => ['10.252.0.14', "192.168.50.14"],
70     :macs   => [],
71     :cpus   => 2,
72     :cpu    => "50",
73     :ram    => 4 * 1024,
74     :groups => ["individual"],
75     :args   => ["appc"],
76   },
77   {
78     :name   => "ccsdk",
79     :ips    => ['10.252.0.19', "192.168.50.19"],
80     :macs   => [],
81     :cpus   => 2,
82     :cpu    => "50",
83     :ram    => 4 * 1024,
84     :groups => ["individual"],
85     :args   => ["ccsdk"],
86   },
87   {
88     :name   => "dcae",
89     :ips    => ['10.252.0.12', "192.168.50.12"],
90     :macs   => [],
91     :cpus   => 2,
92     :cpu    => "50",
93     :ram    => 4 * 1024,
94     :groups => ["individual"],
95     :args   => ["dcae"],
96   },
97   {
98     :name   => "dns",
99     :ips    => ['10.252.0.3', "192.168.50.3"],
100     :macs   => [],
101     :cpus   => 2,
102     :cpu    => "50",
103     :ram    => 1 * 1024,
104     :groups => ["individual"],
105     :flavor => 'm1.small',
106     :args   => [" "]
107   },
108   {
109     :name   => "message-router",
110     :ips    => ['10.252.0.4', "192.168.50.4"],
111     :macs   => [],
112     :cpus   => 2,
113     :cpu    => "50",
114     :ram    => 4 * 1024,
115     :groups => ["individual"],
116     :args   => ["mr"],
117   },
118   {
119     :name   => "mso",
120     :ips    => ['10.252.0.20', "192.168.50.20"],
121     :macs   => [],
122     :cpus   => 2,
123     :cpu    => "50",
124     :ram    => 4 * 1024,
125     :groups => ["individual"],
126     :args   => ["mso"],
127   },
128   {
129     :name   => "msb",
130     :ips    => ['10.252.0.7', "192.168.50.7"],
131     :macs   => [],
132     :cpus   => 2,
133     :cpu    => "50",
134     :ram    => 4 * 1024,
135     :groups => ["individual"],
136     :args   => ["msb"],
137   },
138   {
139     :name   => "multicloud",
140     :ips    => ['10.252.0.16', "192.168.50.16"],
141     :macs   => [],
142     :cpus   => 2,
143     :cpu    => "50",
144     :ram    => 4 * 1024,
145     :groups => ["individual"],
146     :args   => ["multicloud"],
147     :fwds   => [
148       { :guest => 9003, :host => 9003, :guest_ip => '192.168.50.16' },
149     ]
150   },
151   {
152     :name   => "oom",
153     :ips    => ['10.252.0.21', "192.168.50.21"],
154     :macs   => [],
155     :cpus   => 16,
156     :cpu    => "50",
157     :ram    => 64 * 1024,
158     :groups => ["individual"],
159     :args   => ["oom"],
160     :hd     => "60G",
161     :fwds   => [
162       { :guest => 8880, :host => 8880, :guest_ip => '192.168.50.21' },
163       { :guest => 8989, :host => 8989, :guest_ip => '192.168.50.21' },
164     ]
165   },
166   {
167     :name   => "policy",
168     :ips    => ['10.252.0.13', "192.168.50.13"],
169     :macs   => [],
170     :cpus   => 2,
171     :cpu    => "50",
172     :ram    => 4 * 1024,
173     :groups => ["individual"],
174     :args   => ["policy"],
175   },
176   {
177     :name   => "portal",
178     :ips    => ['10.252.0.11', "192.168.50.11"],
179     :macs   => [],
180     :cpus   => 2,
181     :cpu    => "50",
182     :ram    => 4 * 1024,
183     :groups => ["individual"],
184     :args   => ["portal"],
185   },
186   {
187     :name   => "robot",
188     :ips    => ['10.252.0.8', "192.168.50.8"],
189     :macs   => [],
190     :cpus   => 2,
191     :cpu    => "50",
192     :ram    => 4 * 1024,
193     :groups => ["individual"],
194     :args   => ["robot"],
195   },
196   {
197     :name   => "sdc",
198     :ips    => ['10.252.0.5', "192.168.50.5"],
199     :macs   => [],
200     :cpus   => 2,
201     :cpu    => "50",
202     :ram    => 8 * 1024,
203     :groups => ["individual"],
204     :args   => ["sdc"],
205     :hd     => "20G",
206   },
207   {
208     :name   => "sdnc",
209     :ips    => ['10.252.0.10', "192.168.50.10"],
210     :macs   => [],
211     :cpus   => 2,
212     :cpu    => "50",
213     :ram    => 4 * 1024,
214     :groups => ["individual"],
215     :args   => ["sdnc"],
216   },
217   {
218     :name   => "testing",
219     :ips    => ['10.252.2.3', "192.168.52.3"],
220     :macs   => [],
221     :cpus   => 2,
222     :cpu    => "50",
223     :ram    => 4 * 1024,
224     :groups => ["testing"],
225     :flavor => 'm1.small',
226     :args   => [""],
227   },
228   {
229     :name   => "vfc",
230     :ips    => ['10.252.0.15', "192.168.50.15"],
231     :macs   => [],
232     :cpus   => 2,
233     :cpu    => "50",
234     :ram    => 4 * 1024,
235     :groups => ["individual"],
236     :args   => ['vfc'],
237   },
238   {
239     :name   => "vid",
240     :ips    => ['10.252.0.9', "192.168.50.9"],
241     :macs   => [],
242     :cpus   => 2,
243     :cpu    => "50",
244     :ram    => 4 * 1024,
245     :groups => ["individual"],
246     :args   => ['vid'],
247   },
248   {
249     :name   => "vnfsdk",
250     :ips    => ['10.252.0.18', "192.168.50.18"],
251     :macs   => [],
252     :cpus   => 2,
253     :cpu    => "50",
254     :ram    => 4 * 1024,
255     :groups => ["individual"],
256     :args   => ['vnfsdk'],
257   },
258   {
259     :name   => "vvp",
260     :ips    => ['10.252.0.17', "192.168.50.17"],
261     :macs   => [],
262     :cpus   => 2,
263     :cpu    => "50",
264     :ram    => 4 * 1024,
265     :groups => ["individual"],
266     :args   => ['vvp'],
267   },
268   {
269     :name   => "openstack",
270     :ips    => ['10.252.3.3', "192.168.53.3"],
271     :macs   => [],
272     :cpus   => 2,
273     :cpu    => "50",
274     :ram    => 8 * 1024,
275     :groups => ["individual"],
276     :args   => ['openstack'],
277     :fwds   => [
278       { :guest => 80, :host => 8888, :guest_ip => '192.168.53.4' },
279       { :guest => 6080, :host => 6080, :guest_ip => '192.168.53.4' },
280     ]
281   }
282 ]
283
284 run_path   = 'vagrant_utils/postinstall.sh'
285 sdc_volume = 'vol1-sdc-data.vdi'
286
287 Vagrant.require_version ">= 1.8.6"
288
289 # Determine the provider used
290 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
291 puts "[INFO] Provider: #{provider} "
292
293 vd_conf = ENV.fetch('VD_CONF', 'etc/settings.yaml')
294 if File.exist?(vd_conf)
295   require 'yaml'
296   user_conf = YAML.load_file(vd_conf)
297   configuration.update(user_conf)
298 end
299
300 # Set network interface
301 net_interface = 'vboxnet0'
302 is_windows = Gem.win_platform?
303 if is_windows
304     net_interface = 'VirtualBox Host-Only Ethernet Adapter #2'
305 end
306 puts "[INFO] Net interface: #{net_interface}"
307
308
309 # If argument is given use it. Otherwise use Env: DEPLOY_MODE else use default
310 requested_machine = ARGV[1]
311
312 deploy_mode = ENV.fetch('DEPLOY_MODE', 'individual')
313 if requested_machine != nil
314     if requested_machine.include?("all-in-one") || requested_machine.include?("testing")
315         deploy_mode = requested_machine
316     end
317 end
318
319 # Catch the status of all machines
320 if ARGV[0] == 'status' || ARGV[0] == 'destroy'
321     deploy_mode = 'NA'
322 end
323
324 puts "[INFO] Deploy Mode:  #{deploy_mode}"
325
326 # In case of all-in-one or testing clean the nodes list
327 case deploy_mode
328     when 'all-in-one'
329         nodes.select! do |node|
330             if node[:name].include?("all-in-one")
331               true if node[:name]
332             end
333         end
334
335     when 'individual'
336         nodes.select! do |node|
337             if node[:groups][0].include?("individual")
338               true if node[:name]
339             end
340         end
341
342     when 'testing'
343         nodes.select! do |node|
344             if node[:name].include?("testing")
345               true if node[:name]
346             end
347         end
348 end
349
350 Vagrant.configure("2") do |config|
351
352     # PROXY definitions
353     if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil
354       if not Vagrant.has_plugin?('vagrant-proxyconf')
355         system 'vagrant plugin install vagrant-proxyconf'
356         raise 'vagrant-proxyconf was installed but it requires to execute again'
357       end
358       config.proxy.http     = ENV['http_proxy']
359       config.proxy.https    = ENV['https_proxy']
360       configuration['socks_proxy'] = ENV['socks_proxy']
361     end
362
363     if Vagrant.has_plugin?('vagrant-vbguest')
364       puts 'vagrant-vbguest auto_update feature will be disable to avoid sharing conflicts'
365       config.vbguest.auto_update = false
366     end
367
368     sync_type = "virtualbox"
369     if provider == :libvirt
370       if not Vagrant.has_plugin?('vagrant-libvirt')
371         system 'vagrant plugin install vagrant-libvirt'
372         raise 'vagrant-libvirt was installed but it requires to execute again'
373       end
374       sync_type = "nfs"
375     end
376
377     if provider == :openstack
378       config.ssh.username = 'ubuntu'
379       if not Vagrant.has_plugin?('vagrant-openstack-provider')
380         system 'vagrant plugin install vagrant-openstack-provider'
381         raise 'vagrant-openstack-provider was installed but it requires to execute again'
382       end
383     end
384
385     nodes.each do |node|
386       config.vm.define node[:name] do |nodeconfig|
387
388       # NO_PROXY definitions
389       if ENV['no_proxy'] != nil
390         if not Vagrant.has_plugin?('vagrant-proxyconf')
391           system 'vagrant plugin install vagrant-proxyconf'
392           raise 'vagrant-proxyconf was installed but it requires to execute again'
393         end
394         config.proxy.no_proxy = node[:ips].join(",") + "," + ENV['no_proxy']
395       end
396
397         # Common Settings:
398
399         nodeconfig.vm.provider "virtualbox" do |vbox|
400           vbox.customize ['modifyvm', :id, '--nictype1', 'virtio']
401           vbox.customize ['modifyvm', :id, '--audio', 'none']
402           vbox.customize ['modifyvm', :id, '--vram', '1']
403           vbox.customize ['modifyvm', :id, "--cpuhotplug", "off"]
404           vbox.customize ['modifyvm', :id, "--cpuexecutioncap", node[:cpu]]
405           vbox.customize ['modifyvm', :id, "--cpus", node[:cpus]]
406           vbox.customize ["modifyvm", :id, "--memory", node[:ram]]
407
408           # Set Network
409           nodeconfig.vm.network :private_network,
410             :adapter => 2,
411             :name => net_interface,
412             :ip  => node[:ips][0]
413
414           nodeconfig.vm.network :private_network,
415             :adapter => 3,
416             :ip  => node[:ips][1],
417             :type => :static
418
419           # Set Storage
420           if node.has_key? :hd
421             volume_file = node[:name] + '-vol1-data.vdi'
422             unless File.exist?(volume_file)
423               vbox.customize ['createhd', '--filename', volume_file, '--size', node[:hd]]
424             end
425             vbox.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', volume_file]
426           end
427         end
428
429         nodeconfig.vm.provider "libvirt" do |lbox|
430           lbox.memory = node[:ram]
431           lbox.nested = true
432           lbox.cpu_mode = 'host-passthrough'
433           lbox.cpus = node[:cpus]
434
435           # Set Network
436           nodeconfig.vm.network :private_network,
437             :ip  => node[:ips][0]
438
439           nodeconfig.vm.network :private_network,
440             :ip  => node[:ips][1],
441             :type => :static
442
443           # Set Storage
444           if node.has_key? :hd
445             lbox.storage :file, bus: 'sata', device: 'sda', size: node[:hd]
446           end
447         end
448         if node.has_key? :fwds
449           node[:fwds].each do |fwd|
450             nodeconfig.vm.network :forwarded_port,
451               :guest => fwd[:guest],
452               :guest_ip => fwd[:guest_ip],
453               :host => fwd[:host],
454               :host_ip => "0.0.0.0"
455           end
456         end
457
458         nodeconfig.vm.provider :openstack do |obox|
459           obox.openstack_auth_url               = ENV.fetch('OS_AUTH_URL', '')
460           obox.tenant_name                      = ENV.fetch('OS_TENANT_NAME', '')
461           obox.username                         = ENV.fetch('OS_USERNAME', '')
462           obox.password                         = ENV.fetch('OS_PASSWORD', '')
463           obox.region                           = ENV.fetch('OS_REGION_NAME', '')
464           obox.identity_api_version             = ENV.fetch('OS_IDENTITY_API_VERSION', '')
465           obox.domain_name                      = ENV.fetch('OS_PROJECT_DOMAIN_ID', '')
466           obox.project_name                     = ENV.fetch('OS_PROJECT_NAME', '')
467           obox.floating_ip_pool                 = ENV.fetch('OS_FLOATING_IP_POOL', '')
468           obox.floating_ip_pool_always_allocate = (ENV['OS_FLOATING_IP_ALWAYS_ALLOCATE'] == 'true')
469           obox.image                            = ENV.fetch('OS_IMAGE', '')
470           obox.security_groups                  = [ENV.fetch('OS_SEC_GROUP', '')]
471           obox.networks                         = ENV.fetch('OS_NETWORK', '')
472           obox.flavor                           = node[:flavor]
473           obox.server_name                      = node[:name]
474         end
475
476         # Set Box type
477         if "openstack" == node[:name]
478           box = {
479             :virtualbox => 'ubuntu/xenial64',
480             :libvirt => 'elastic/ubuntu-16.04-x86_64'
481           }
482         end
483         nodeconfig.vm.box = box[provider]
484
485         # Set Node name
486         nodeconfig.vm.hostname = node[:name]
487
488         # Set Sync Folder
489         nodeconfig.vm.synced_folder ".", "/vagrant", disabled: true
490         nodeconfig.vm.synced_folder './opt', '/opt/', create: true, type: sync_type
491         nodeconfig.vm.synced_folder './lib', '/var/onap/', create: true, type: sync_type
492         if !is_windows
493           nodeconfig.vm.synced_folder '~/.m2', '/root/.m2/', create: true
494         end
495
496         # Specific settings:
497
498         if node[:name].include? "testing"
499             nodeconfig.vm.synced_folder './tests', '/var/onap_tests/', create: true
500             test_suite = ENV.fetch('TEST_SUITE', '*')
501             test_case = ENV.fetch('TEST_CASE', '*')
502             # Override variables
503             run_path = 'vagrant_utils/unit_testing.sh'
504             node[:args] = [test_suite, test_case]
505         else
506             configuration['skip_get_images'] = ENV.fetch('SKIP_GET_IMAGES', configuration['skip_get_images'])
507             configuration['skip_install'] = ENV.fetch('SKIP_INSTALL', configuration['skip_install'])
508         end
509
510         if node[:name].include? "vfc"
511           nodeconfig.vm.provision 'docker'
512         end
513
514         nodeconfig.vm.provision 'shell' do |s|
515           s.path = run_path
516           s.args = node[:args]
517           s.env  = configuration
518         end
519
520       end #nodeconfig
521     end #node
522 end #config