From e6e96ae31ba223419068c5b61e1b115d8ecda358 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Mon, 10 Sep 2018 14:17:16 +0200 Subject: [PATCH] Improve Vagrant includes for nodes and local Note: relative paths should always use VAGRANT_HOME fixes #155 --- distributed/Vagrantfile | 31 +++---------------------------- elastic/Vagrantfile | 31 +++---------------------------- env/Vagrantfile | 31 +++---------------------------- graylog/Vagrantfile | 31 +++---------------------------- influxdb/Vagrantfile | 31 +++---------------------------- standalone/Vagrantfile | 31 +++---------------------------- tools/vagrant_helper.rb | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 50 insertions(+), 168 deletions(-) create mode 100644 tools/vagrant_helper.rb diff --git a/distributed/Vagrantfile b/distributed/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/distributed/Vagrantfile +++ b/distributed/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/elastic/Vagrantfile b/elastic/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/elastic/Vagrantfile +++ b/elastic/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/env/Vagrantfile b/env/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/env/Vagrantfile +++ b/env/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/graylog/Vagrantfile b/graylog/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/graylog/Vagrantfile +++ b/graylog/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/influxdb/Vagrantfile b/influxdb/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/influxdb/Vagrantfile +++ b/influxdb/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/standalone/Vagrantfile b/standalone/Vagrantfile index 3af26ecb..0233b6e9 100644 --- a/standalone/Vagrantfile +++ b/standalone/Vagrantfile @@ -1,35 +1,11 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -VAGRANTFILE_API_VERSION = "2" -VAGRANT_REQUIRED_VERSION = "1.8.0" -VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" - -# Require 1.6.5 at least -if ! defined? Vagrant.require_version - if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) - puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION - exit 1 - end -else - Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION -end - -nodes = {} -if not File.exists?("Vagrantfile.nodes") then - puts "ERROR: Vagrantfile.nodes is missing from source tree." - exit 1 -end - -eval(IO.read("Vagrantfile.nodes"), binding) - -# allow to override the configuration -if File.exists?("Vagrantfile.local") then - eval(IO.read("Vagrantfile.local"), binding) -end +VAGRANT_HOME = File.dirname(__FILE__) unless defined? VAGRANT_HOME +require VAGRANT_HOME + "/../tools/vagrant_helper" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - nodes.each_pair do |name, options| + $nodes.each_pair do |name, options| config.vm.define name do |node_config| node_config.vm.box = options[:box_virtualbox] node_config.vm.hostname = name + "." + options[:net] @@ -125,4 +101,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end - diff --git a/tools/vagrant_helper.rb b/tools/vagrant_helper.rb new file mode 100644 index 00000000..e2e25f29 --- /dev/null +++ b/tools/vagrant_helper.rb @@ -0,0 +1,32 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +raise "VAGRANT_HOME needs to be defined prior vagrant_helper!" unless defined? VAGRANT_HOME + +VAGRANTFILE_API_VERSION = "2" unless defined? VAGRANTFILE_API_VERSION +VAGRANT_REQUIRED_VERSION = "1.8.0" unless defined? VAGRANT_REQUIRED_VERSION +VAGRANT_REQUIRED_LINKED_CLONE_VERSION = "1.8.4" unless defined? VAGRANT_REQUIRED_LINKED_CLONE_VERSION + +# Require 1.6.5 at least +if ! defined? Vagrant.require_version + if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(VAGRANT_REQUIRED_VERSION) + puts "Vagrant >= " + VAGRANT_REQUIRED_VERSION + " required. Your version is " + Vagrant::VERSION + exit 1 + end +else + Vagrant.require_version ">= " + VAGRANT_REQUIRED_VERSION +end + +nodesFile = VAGRANT_HOME + "/Vagrantfile.nodes" +localFile = VAGRANT_HOME + "/Vagrantfile.local" +nodes = {} + +raise "ERROR: Vagrantfile.nodes is missing from source tree." unless File.exists?(nodesFile) + +eval(IO.read(nodesFile), binding) + +# allow to override the configuration +eval(IO.read(localFile), binding) if File.exists?(localFile) + +# Export nodes to global scope +$nodes = nodes