Convert existing validate methods to new API for kernel
This commit is contained in:
parent
a8b57ba13f
commit
3e9e422ce0
|
@ -15,15 +15,20 @@ module VagrantPlugins
|
||||||
attr_accessor :forward_x11
|
attr_accessor :forward_x11
|
||||||
attr_accessor :shell
|
attr_accessor :shell
|
||||||
|
|
||||||
def validate(env, errors)
|
def validate(env)
|
||||||
|
errors = []
|
||||||
|
|
||||||
[:username, :max_tries, :timeout].each do |field|
|
[:username, :max_tries, :timeout].each do |field|
|
||||||
value = instance_variable_get("@#{field}".to_sym)
|
value = instance_variable_get("@#{field}".to_sym)
|
||||||
errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !value
|
errors << I18n.t("vagrant.config.common.error_empty", :field => field) if !value
|
||||||
end
|
end
|
||||||
|
|
||||||
if private_key_path && !File.file?(File.expand_path(private_key_path, env.root_path))
|
if private_key_path && !File.file?(File.expand_path(private_key_path, env.root_path))
|
||||||
errors.add(I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path))
|
errors << I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return the errors
|
||||||
|
{ "ssh" => errors }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -122,26 +122,31 @@ module VagrantPlugins
|
||||||
define(DEFAULT_VM_NAME) if defined_vm_keys.empty?
|
define(DEFAULT_VM_NAME) if defined_vm_keys.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate(env, errors)
|
def validate(env)
|
||||||
errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box
|
errors = []
|
||||||
errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.boxes.find(box, :virtualbox)
|
errors << I18n.t("vagrant.config.vm.box_missing") if !box
|
||||||
errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.boxes.find(box, :virtualbox) && !base_mac
|
errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \
|
||||||
|
box && !box_url && !env.boxes.find(box, :virtualbox)
|
||||||
|
errors << I18n.t("vagrant.config.vm.base_mac_invalid") if \
|
||||||
|
env.boxes.find(box, :virtualbox) && !base_mac
|
||||||
|
|
||||||
shared_folders.each do |name, options|
|
shared_folders.each do |name, options|
|
||||||
hostpath = Pathname.new(options[:hostpath]).expand_path(env.root_path)
|
hostpath = Pathname.new(options[:hostpath]).expand_path(env.root_path)
|
||||||
|
|
||||||
if !hostpath.directory? && !options[:create]
|
if !hostpath.directory? && !options[:create]
|
||||||
errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
|
errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
|
||||||
:name => name,
|
:name => name,
|
||||||
:path => options[:hostpath]))
|
:path => options[:hostpath])
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:nfs] && (options[:owner] || options[:group])
|
if options[:nfs] && (options[:owner] || options[:group])
|
||||||
# Owner/group don't work with NFS
|
# Owner/group don't work with NFS
|
||||||
errors.add(I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group",
|
errors << I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group",
|
||||||
:name => name))
|
:name => name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
{ "vm" => errors }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -306,7 +306,7 @@ en:
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
config:
|
config:
|
||||||
common:
|
common:
|
||||||
error_empty: "`%{field}` must be filled in."
|
error_empty: "`%{field}` must be not be empty."
|
||||||
chef:
|
chef:
|
||||||
cookbooks_path_empty: "Must specify a cookbooks path for chef solo."
|
cookbooks_path_empty: "Must specify a cookbooks path for chef solo."
|
||||||
run_list_empty: "Run list must not be empty."
|
run_list_empty: "Run list must not be empty."
|
||||||
|
|
Loading…
Reference in New Issue