From 656f9f9056a59cca2edf7939d14390127eca152b Mon Sep 17 00:00:00 2001 From: elijah Date: Sun, 10 Feb 2013 12:31:08 -0800 Subject: moved vagrant config to Leapfile, added ~/.leaprc support. --- lib/leap_cli/commands/new.rb | 1 + lib/leap_cli/config/manager.rb | 8 +------- lib/leap_cli/leapfile.rb | 26 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/leap_cli/commands/new.rb b/lib/leap_cli/commands/new.rb index c4a067e..b6eb4f1 100644 --- a/lib/leap_cli/commands/new.rb +++ b/lib/leap_cli/commands/new.rb @@ -88,6 +88,7 @@ module LeapCli; module Commands ## Optional: # @custom_vagrant_vm_line = "config.vm.boot_mode = :gui" # @log = "/tmp/leap.log" +# @vagrant_network = '10.5.5.0/24' ] end diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 79a5c0e..b90c741 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -284,14 +284,8 @@ module LeapCli end end - # - # TODO: apply JSON spec - # - PRIVATE_IP_RANGES = /(^127\.0\.0\.1)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/ def validate_provider(provider) - Util::assert! provider.vagrant.network =~ PRIVATE_IP_RANGES do - log 0, :error, 'in provider.json: vagrant.network is not a local private network' - end + # nothing yet. end end diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index 439b60c..c24f939 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -15,6 +15,11 @@ module LeapCli attr_accessor :custom_vagrant_vm_line attr_accessor :leap_version attr_accessor :log + attr_accessor :vagrant_network + + def initialize + @vagrant_network = '10.5.5.0/24' + end def load directory = File.expand_path(find_in_directory_tree('Leapfile')) @@ -22,8 +27,8 @@ module LeapCli return nil else self.provider_directory_path = directory - leapfile = directory + '/Leapfile' - instance_eval(File.read(leapfile), leapfile) + read_settings(directory + '/Leapfile') + read_settings(ENV['HOME'] + '/.leaprc') self.platform_directory_path = File.expand_path(self.platform_directory_path || '../leap_platform', self.provider_directory_path) return true end @@ -31,6 +36,14 @@ module LeapCli private + def read_settings(file) + if File.exists? file + Util::log 2, :read, file + instance_eval(File.read(file), file) + validate(file) + end + end + def find_in_directory_tree(filename) search_dir = Dir.pwd while search_dir != "/" @@ -41,6 +54,15 @@ module LeapCli end return search_dir end + + PRIVATE_IP_RANGES = /(^127\.0\.0\.1)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/ + + def validate(file) + Util::assert! vagrant_network =~ PRIVATE_IP_RANGES do + Util::log 0, :error, "in #{file}: vagrant_network is not a local private network" + end + end + end end -- cgit v1.2.3