Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional parameters to support synced folder and ip-adress #42

Merged
merged 3 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 84 additions & 11 deletions project/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VAGRANTFILE_API_VERSION = "2"

def load_properties(properties_filename, prefix = "")
properties = {}

if File.exists? properties_filename
File.open(properties_filename, 'r') do |properties_file|
properties_file.read.each_line do |line|
Expand Down Expand Up @@ -34,14 +34,24 @@ end
puts "ml-version=#{@ml_version}"
puts "nr-hosts=#{@nr_hosts}"

@priv_net_ip = ENV['PRIV_NET_IP'] || @properties['PRIV_NET_IP'] || "192.168.33.10"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer no default ip, and use dhcp as default for private network as well.

puts "priv-net-ip=#{@priv_net_ip}"


@shared_folder_host = ENV['SHARED_FOLDER_HOST'] || @properties['SHARED_FOLDER_HOST'] || "./"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./ = Vagrantfile folder, that is already mounted as /vagrant. I'd suggest no default for this..

@shared_folder_guest = ENV['SHARED_FOLDER_GUEST'] || @properties['SHARED_FOLDER_GUEST'] || "/home/vagrant"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default for this..

puts "shared-folder-host=#{@shared_folder_host}"
puts "shared-folder-guest=#{@shared_folder_guest}"


def get_vm_name(i)
File.basename(Dir.getwd) + "-ml" + i.to_s
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

mastername = get_vm_name(1)

config.hostmanager.enabled = false
config.hostmanager.manage_host = true
config.hostmanager.include_offline = true
Expand All @@ -53,30 +63,31 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end
(ip = /^\s*inet .*?(\d+\.\d+\.\d+\.\d+)\s+/.match(result)) && ip[1]
end

# Customize the virtual machine environments
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
#vb.gui = true # for debugging
end

config.vm.define mastername do |master|
master.vm.box = "chef/centos-6.5"
master.vm.provider "virtualbox" do |v|
v.name = mastername
v.memory = 2048
v.memory = 6144
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6gb is too much if you want to create multiple vm's. 2gb per vm is better in that case. Someone already did a pull to make mem and cpu configurable. Time I look into merging that..

v.cpus = 2
end
master.vm.hostname = mastername
master.vm.network "public_network", bridge: 'en0: Wi-Fi (AirPort)'
master.vm.network "private_network", ip: @priv_net_ip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm eager to switch to private network, but with dhcp as default. We should do something like priv_net_ip || dhcp..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as long the choice is there.

master.vm.synced_folder "/opt/vagrant", "/opt/vagrant"
master.vm.synced_folder "/space/software", "/space/software"

master.vm.synced_folder @shared_folder_host, @shared_folder_guest, :create => true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a condition around this, if shared_folder then yes, else skip..


master.vm.provision :hostmanager
master.vm.provision :shell, :path => "/opt/vagrant/bootstrap-centos-master.sh", :args => ["-v", "#{@ml_version}", mastername, File.basename(Dir.getwd)]
end

if @nr_hosts > 1
(2..@nr_hosts).each do |i|
hostname = get_vm_name(i)
Expand All @@ -91,11 +102,73 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
data.vm.network "public_network", bridge: 'en0: Wi-Fi (AirPort)'
data.vm.synced_folder "/opt/vagrant", "/opt/vagrant"
data.vm.synced_folder "/space/software", "/space/software"

data.vm.provision :hostmanager
data.vm.provision :shell, :path => "/opt/vagrant/bootstrap-centos-extra.sh", :args => ["-v", "#{@ml_version}", mastername, hostname, File.basename(Dir.getwd)]
end
end
end


end
module UpdateCentOSKernel
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting stuff, but is this necessary? Maybe there is a newer base vm that we could leverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. To my understanding this is an issue with CentOS 6.5, could be that another vm or using a newer version of CentOS could solve this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What issue? I have been running CentOS 6.5 vm's for a while, haven't had any trouble..

class UpdateCentOSKernelPlugin < Vagrant.plugin('2')
name 'update_centos_kernel_plugin'

# update yum after first boot when provisioning
action_hook(:update_yum, :machine_action_up) do |hook|
hook.after(VagrantPlugins::ProviderVirtualBox::Action::CheckGuestAdditions, UpdateCentOSKernel::Middleware::KernelUpdater)
end
end

module Middleware
class KernelUpdater
@@rebooted = {};

def initialize(app, env)
@app = app
end

def call(env)
@env = env
@vm = env[:machine]
@ui = env[:ui]
self.update_kernel()
end

def update_kernel()
if !@@rebooted[@vm.id]
@@rebooted[@vm.id] = true

@ui.info 'Updating kernel'
@vm.communicate.sudo('yum install -y kernel kernel-devel') do |type, data|
if type == :stderr
@ui.error(data);
else
@ui.info(data);
end
end

self.reboot()
end
end

def reboot()
@ui.info('Rebooting after updating kernel')
simle_reboot = Vagrant::Action::Builder.new.tap do |b|
b.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :poweroff, :running do |env2, b2|
if !env2[:result]
b2.use VagrantPlugins::ProviderVirtualBox::Action::ForcedHalt
end
end

b.use VagrantPlugins::ProviderVirtualBox::Action::Boot
if defined?(Vagrant::Action::Builtin::WaitForCommunicator)
b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running]
end
b.use VagrantVbguest::Middleware
end
@env[:action_runner].run(simle_reboot, @env)
end
end
end
end
5 changes: 4 additions & 1 deletion project/project.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ml_version=8
nr_hosts=3
nr_hosts=1
priv_net_ip=192.168.33.10
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put these in as commented entries..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just forgot to reset to the default settings before committing...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, you can easily append to this PR by committing additional updates to your master branch..

shared_folder_host=./ml
shared_folder_guest=/home/vagrant/ml