[root@mycompany2test.cambridge.mycompany1.co.uk vmx-test]# cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
def get_mac(oui="28:b7:ad")
"Generate a MAC address"
nic = (1..3).map{"%0.2x"%rand(256)}.join(":")
return "#{oui}:#{nic}"
end
cwd = Dir.pwd.split("/").last
username = ENV['USER']
domain_prefix = "#{username}_#{cwd}"
Vagrant.configure("2") do |config|
config.vm.define "vmx-vcp-01" do |node|
guest_name = "vmx-vcp-01"
node.vm.box = "juniper/vmx-vcp"
node.vm.box_version = "17.1R1.8"
node.vm.guest = :tinycore
node.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
node.ssh.insert_key = false
node.vm.provider :libvirt do |domain|
domain.default_prefix = "#{domain_prefix}"
domain.cpus = 1
domain.memory = 1024
domain.disk_bus = "ide"
domain.nic_adapter_count = 11
domain.storage :file, :path => "#{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2", :size => "196870144", :type => "qcow2", :bus => "ide", :device => "hdb", :allow_existing => true
domain.storage :file, :path => "#{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img", :size => "16777216", :type => "raw", :bus => "ide", :device => "hdc", :allow_existing => true
end
add_volumes = [
"virsh vol-create-as default #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 196870144",
"sleep 1",
"virsh vol-upload --pool default #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 /opt/vagrant/storage/vmx-vcp-hdb-17.1R1.8-base.qcow2",
"sleep 1",
"virsh vol-create-as default #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img 16777216",
"sleep 1",
"virsh vol-upload --pool default #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img /opt/vagrant/storage/vmx-vcp-hdc-17.1R1.8-base.img",
"sleep 1"
]
add_volumes.each do |i|
node.trigger.before :up do |trigger|
trigger.name = "add-volumes"
trigger.info = "Adding Volumes"
trigger.run = {inline: i}
end
end
delete_volumes = [
"virsh vol-delete #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 default",
"virsh vol-delete #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img default"
]
delete_volumes.each do |i|
node.trigger.after :destroy do |trigger|
trigger.name = "remove-volumes"
trigger.info = "Removing Volumes"
trigger.run = {inline: i}
end
end
node.vm.network :private_network,
# vmx-vcp-01-int1 <--> vmx-vfp-01-int1
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.255.1",
:libvirt__tunnel_local_port => 10001,
:libvirt__tunnel_ip => "127.255.255.2",
:libvirt__tunnel_port => 10001,
:libvirt__iface_name => "internal",
auto_config: false
end
config.vm.define "vmx-vfp-01" do |node|
guest_name = "vmx-vfp-01"
node.vm.box = "juniper/vmx-vfp"
node.vm.box_version = "17.1R1.8"
node.vm.guest = :tinycore
node.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
node.ssh.insert_key = false
node.ssh.username = "root"
node.vm.provider :libvirt do |domain|
domain.default_prefix = "#{domain_prefix}"
domain.cpus = 3
domain.memory = 4096
domain.disk_bus = "ide"
domain.nic_adapter_count = 11
end
node.vm.network :private_network,
# vmx-vfp-01-int1 <--> vmx-vcp-01-int1
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.255.2",
:libvirt__tunnel_local_port => 10001,
:libvirt__tunnel_ip => "127.255.255.1",
:libvirt__tunnel_port => 10001,
:libvirt__iface_name => "internal",
auto_config: false
node.vm.network :private_network,
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.255.2",
:libvirt__tunnel_local_port => 10002,
:libvirt__tunnel_ip => "127.255.254.2",
:libvirt__tunnel_port => 10002,
:libvirt__iface_name => "external",
auto_config: false
end
config.vm.define "vmx-vcp-02" do |node|
guest_name = "vmx-vcp-02"
node.vm.box = "juniper/vmx-vcp"
node.vm.box_version = "17.1R1.8"
node.vm.guest = :tinycore
node.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
node.ssh.insert_key = false
node.vm.provider :libvirt do |domain|
domain.default_prefix = "#{domain_prefix}"
domain.cpus = 1
domain.memory = 1024
domain.disk_bus = "ide"
domain.nic_adapter_count = 11
domain.storage :file, :path => "#{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2", :size => "196870144", :type => "qcow2", :bus => "ide", :device => "hdb", :allow_existing => true
domain.storage :file, :path => "#{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img", :size => "16777216", :type => "raw", :bus => "ide", :device => "hdc", :allow_existing => true
end
add_volumes = [
"virsh vol-create-as default #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 196870144",
"sleep 1",
"virsh vol-upload --pool default #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 /opt/vagrant/storage/vmx-vcp-hdb-17.1R1.8-base.qcow2",
"sleep 1",
"virsh vol-create-as default #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img 16777216",
"sleep 1",
"virsh vol-upload --pool default #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img /opt/vagrant/storage/vmx-vcp-hdc-17.1R1.8-base.img",
"sleep 1"
]
add_volumes.each do |i|
node.trigger.before :up do |trigger|
trigger.name = "add-volumes"
trigger.info = "Adding Volumes"
trigger.run = {inline: i}
end
end
delete_volumes = [
"virsh vol-delete #{username}-#{guest_name}-vmx-vcp-hdb-17.1R1.8-base.qcow2 default",
"virsh vol-delete #{username}-#{guest_name}-vmx-vcp-hdc-17.1R1.8-base.img default"
]
delete_volumes.each do |i|
node.trigger.after :destroy do |trigger|
trigger.name = "remove-volumes"
trigger.info = "Removing Volumes"
trigger.run = {inline: i}
end
end
node.vm.network :private_network,
# vmx-vcp-02-int1 <--> vmx-vfp-012-int1
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.254.1",
:libvirt__tunnel_local_port => 10001,
:libvirt__tunnel_ip => "127.255.254.2",
:libvirt__tunnel_port => 10001,
:libvirt__iface_name => "internal",
auto_config: false
end
config.vm.define "vmx-vfp-02" do |node|
guest_name = "vmx-vfp-02"
node.vm.box = "juniper/vmx-vfp"
node.vm.box_version = "17.1R1.8"
node.vm.guest = :tinycore
node.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
node.ssh.insert_key = false
node.ssh.username = "root"
node.vm.provider :libvirt do |domain|
domain.default_prefix = "#{domain_prefix}"
domain.cpus = 3
domain.memory = 4096
domain.disk_bus = "ide"
domain.nic_adapter_count = 11
end
node.vm.network :private_network,
# vmx-vfp-02-int1 <--> vmx-vcp-02-int1
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.254.2",
:libvirt__tunnel_local_port => 10001,
:libvirt__tunnel_ip => "127.255.254.1",
:libvirt__tunnel_port => 10001,
:libvirt__iface_name => "internal",
auto_config: false
node.vm.network :private_network,
:mac => "#{get_mac()}",
:libvirt__tunnel_type => "udp",
:libvirt__tunnel_local_ip => "127.255.254.2",
:libvirt__tunnel_local_port => 10002,
:libvirt__tunnel_ip => "127.255.255.2",
:libvirt__tunnel_port => 10002,
:libvirt__iface_name => "external",
auto_config: false
end
end