Define synced_folders on V2 vm config

This commit is contained in:
Mitchell Hashimoto 2013-01-23 09:21:49 -08:00
parent d114d4b658
commit 4059a4ba2f
2 changed files with 33 additions and 21 deletions

View File

@ -21,7 +21,7 @@ module VagrantPlugins
attr_accessor :host_name attr_accessor :host_name
attr_accessor :usable_port_range attr_accessor :usable_port_range
attr_reader :forwarded_ports attr_reader :forwarded_ports
attr_reader :shared_folders attr_reader :synced_folders
attr_reader :networks attr_reader :networks
attr_reader :providers attr_reader :providers
attr_reader :provisioners attr_reader :provisioners
@ -30,7 +30,7 @@ module VagrantPlugins
@forwarded_ports = [] @forwarded_ports = []
@graceful_halt_retry_count = UNSET_VALUE @graceful_halt_retry_count = UNSET_VALUE
@graceful_halt_retry_interval = UNSET_VALUE @graceful_halt_retry_interval = UNSET_VALUE
@shared_folders = {} @synced_folders = {}
@networks = [] @networks = []
@provisioners = [] @provisioners = []
@ -44,23 +44,33 @@ module VagrantPlugins
def merge(other) def merge(other)
result = super result = super
result.instance_variable_set(:@forwarded_ports, @forwarded_ports + other.forwarded_ports) result.instance_variable_set(:@forwarded_ports, @forwarded_ports + other.forwarded_ports)
result.instance_variable_set(:@shared_folders, @shared_folders.merge(other.shared_folders)) result.instance_variable_set(:@synced_folders, @synced_folders.merge(other.synced_folders))
result.instance_variable_set(:@networks, @networks + other.networks) result.instance_variable_set(:@networks, @networks + other.networks)
result.instance_variable_set(:@provisioners, @provisioners + other.provisioners) result.instance_variable_set(:@provisioners, @provisioners + other.provisioners)
result result
end end
def share_folder(name, guestpath, hostpath, opts=nil) # Defines a synced folder pair. This pair of folders will be synced
@shared_folders[name] = { # to/from the machine. Note that if the machine you're using doesn't
:guestpath => guestpath.to_s, # support multi-directional syncing (perhaps an rsync backed synced
:hostpath => hostpath.to_s, # folder) then the host is always synced to the guest but guest data
:create => false, # may not be synced back to the host.
:owner => nil, #
:group => nil, # @param [String] hostpath Path to the host folder to share. If this
:nfs => false, # is a relative path, it is relative to the location of the
:transient => false, # Vagrantfile.
:extra => nil # @param [String] guestpath Path on the guest to mount the shared
}.merge(opts || {}) # folder.
# @param [Hash] options Additional options.
def synced_folder(hostpath, guestpath, options=nil)
options ||= {}
options[:id] ||= guestpah
@synced_folders[options[:id]] = {
:guestpath => guestpath,
:hostpath => hostpath,
:options => options
}
end end
# Define a way to access the machine via a network. This exposes a # Define a way to access the machine via a network. This exposes a
@ -133,19 +143,19 @@ module VagrantPlugins
errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \ errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \
box && !box_url && !machine.box box && !box_url && !machine.box
shared_folders.each do |name, options| @synced_folders.each do |id, data|
hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path) options = data[:options]
hostpath = Pathname.new(data[:hostpath]).expand_path(machine.env.root_path)
if !hostpath.directory? && !options[:create] if !hostpath.directory? && !options[:create]
errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing", errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
:name => name, :path => data[: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 << I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group", errors << I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group",
:name => name) :path => data[:hostpath])
end end
end end

View File

@ -351,9 +351,11 @@ en:
network_ip_ends_one: |- network_ip_ends_one: |-
The host only network IP '%{ip}' must not end in a 1, as this The host only network IP '%{ip}' must not end in a 1, as this
is reserved for the host machine. is reserved for the host machine.
shared_folder_hostpath_missing: "Shared folder host path for '%{name}' doesn't exist: %{path}" shared_folder_hostpath_missing: |-
The host path of the shared folder is missing: %{path}
shared_folder_nfs_owner_group: |- shared_folder_nfs_owner_group: |-
Shared folder '%{name}': NFS does not support the owner/group settings. Shared folder that have NFS enabled do no support owner/group
attributes. Host path: %{path}
provisioner_not_found: "The provisioner '%{shortcut}' doesn't exist." provisioner_not_found: "The provisioner '%{shortcut}' doesn't exist."
provisioner_invalid_class: |- provisioner_invalid_class: |-
The provisioner '%{shortcut}' must inherit from The provisioner '%{shortcut}' must inherit from