lib/leap_cli/leapfile.rb in leap_cli-1.8.1 vs lib/leap_cli/leapfile.rb in leap_cli-1.9

- old
+ new

@@ -1,28 +1,25 @@ # # The Leapfile is the bootstrap configuration file for a LEAP provider. # # It is akin to a Gemfile, Rakefile, or Capfile (e.g. it is a ruby file that gets eval'ed) # +# Additional configuration options are defined in platform's leapfile_extensions.rb +# module LeapCli def self.leapfile @leapfile ||= Leapfile.new end class Leapfile - attr_accessor :platform_directory_path - attr_accessor :provider_directory_path - attr_accessor :custom_vagrant_vm_line - attr_accessor :leap_version - attr_accessor :log - attr_accessor :vagrant_network - attr_accessor :vagrant_basebox - attr_accessor :environment + attr_reader :platform_directory_path + attr_reader :provider_directory_path + attr_reader :environment + attr_reader :valid def initialize - @vagrant_network = '10.5.5.0/24' end # # The way the Leapfile handles pinning of environment (self.environment) is a little tricky. # If self.environment is nil, then there is no pin. If self.environment is 'default', then @@ -59,29 +56,48 @@ @platform_directory_path = File.expand_path(@platform_directory_path || '../leap_platform', @provider_directory_path) # # load the platform # - platform_file = "#{@platform_directory_path}/platform.rb" - unless File.exists?(platform_file) + platform_class = "#{@platform_directory_path}/lib/leap/platform" + platform_definition = "#{@platform_directory_path}/platform.rb" + unless File.exist?(platform_definition) Util.bail! "ERROR: The file `#{platform_file}` does not exist. Please check the value of `@platform_directory_path` in `Leapfile` or `~/.leaprc`." end - require "#{@platform_directory_path}/platform.rb" - if !Leap::Platform.compatible_with_cli?(LeapCli::VERSION) || - !Leap::Platform.version_in_range?(LeapCli::COMPATIBLE_PLATFORM_VERSION) - Util.bail! "This leap command (v#{LeapCli::VERSION}) " + - "is not compatible with the platform #{@platform_directory_path} (v#{Leap::Platform.version}).\n " + - "You need either leap command #{Leap::Platform.compatible_cli.first} to #{Leap::Platform.compatible_cli.last} or " + - "platform version #{LeapCli::COMPATIBLE_PLATFORM_VERSION.first} to #{LeapCli::COMPATIBLE_PLATFORM_VERSION.last}" + begin + require platform_class + require platform_definition + rescue LoadError + Util.log "The leap_platform at #{platform_directory_path} is not compatible with this version of leap_cli" + Util.log "You can either:" do + Util.log "Upgrade leap_platform to version " + LeapCli::COMPATIBLE_PLATFORM_VERSION.first + Util.log "Or, downgrade leap_cli to version 1.8" + end + Util.bail! + rescue StandardError => exc + Util.bail! exc.to_s end - unless @allow_production_deploy.nil? - Util::log 0, :warning, "in Leapfile: @allow_production_deploy is no longer supported." + begin + Leap::Platform.validate!(LeapCli::VERSION, LeapCli::COMPATIBLE_PLATFORM_VERSION, self) + rescue StandardError => exc + Util.bail! exc.to_s end - unless @platform_branch.nil? - Util::log 0, :warning, "in Leapfile: @platform_branch is no longer supported." + leapfile_extensions = "#{@platform_directory_path}/lib/leap_cli/leapfile_extensions.rb" + if File.exist?(leapfile_extensions) + require leapfile_extensions end - @valid = true + + # + # validate + # + instance_variables.each do |var| + var = var.to_s.sub('@', '') + if !self.respond_to?(var) + LeapCli.log :warning, "the variable `#{var}` is set in .leaprc or Leapfile, but it is not supported." + end + end + @valid = validate return @valid end end def set(property, value) @@ -103,11 +119,11 @@ # if value is nil, the line is removed. if not nil, it is added or replaced. # def edit_leaprc(property, value=nil) file_path = leaprc_path lines = [] - if File.exists?(file_path) + if File.exist?(file_path) regexp = /self\.#{Regexp.escape(property)} = .*? if @provider_directory_path == '#{Regexp.escape(@provider_directory_path)}'/ File.readlines(file_path).each do |line| unless line =~ regexp lines << line end @@ -126,14 +142,13 @@ def leaprc_path File.join(ENV['HOME'], '.leaprc') end def read_settings(file) - if File.exists? file - Util::log 2, :read, file + if File.exist? file + LeapCli.log 2, :read, file instance_eval(File.read(file), file) - validate(file) end end def find_in_directory_tree(filename, directory_tree=nil) search_dir = directory_tree || Dir.pwd @@ -144,14 +159,14 @@ search_dir = File.dirname(search_dir) 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" + def method_missing(method, *args) + if method =~ /=$/ + self.instance_variable_set('@' + method.to_s.sub('=',''), args.first) + else + self.instance_variable_get('@' + method.to_s) end end end end