-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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| | ||
|
@@ -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" | ||
puts "priv-net-ip=#{@priv_net_ip}" | ||
|
||
|
||
@shared_folder_host = ENV['SHARED_FOLDER_HOST'] || @properties['SHARED_FOLDER_HOST'] || "./" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put these in as commented entries.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, just forgot to reset to the default settings before committing... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.