Class: VagrantLXD::SyncedFolder
- Inherits:
-
Object
- Object
- VagrantLXD::SyncedFolder
- Defined in:
- lib/vagrant-lxd/synced_folder.rb
Instance Method Summary collapse
- #disable(machine, folders, opts) ⇒ Object
- #enable(machine, folders, opts) ⇒ Object
-
#prepare(machine, folders, opts) ⇒ Object
TODO Figure out the proper way to mount folders before provisioning without using ‘#prepare` (which is deprecated).
- #usable?(machine, raise_error = false) ⇒ Boolean
Instance Method Details
#disable(machine, folders, opts) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vagrant-lxd/synced_folder.rb', line 79 def disable(machine, folders, opts) usable?(machine, true) if folders.any? machine.ui.info 'Unmounting shared folders...' folders.reject { |_, f| f[:disabled] }.each do |name, folder| machine.ui.detail "#{folder[:guestpath]} => #{folder[:hostpath]}" @driver.unmount(name, folder) end end end |
#enable(machine, folders, opts) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vagrant-lxd/synced_folder.rb', line 48 def enable(machine, folders, opts) usable?(machine, true) # Skip any folders that are already attached. # TODO This could be made less chatty by fetching the whole list # of devices up front and comparing the incoming folders to that. folders = folders.reject do |name, folder| @driver.mounted?(name, folder) end # Sanity check folder configs and bail if something's wrong. folders.each do |name, folder| validate_folder(folder) end # Ensure all folders have a config hash. folders.each do |name, folder| folder[:config] ||= {} folder[:config] = Hash[folder[:config].map { |k, v| [k.to_sym, v.to_s] }] end if folders.any? machine.ui.info 'Mounting shared folders...' folders.reject { |_, f| f[:disabled] }.each do |name, folder| details = config_summary(folder[:config]) machine.ui.detail "#{folder[:guestpath]} => #{folder[:hostpath]} #{details}".strip @driver.mount(name, folder) end end end |
#prepare(machine, folders, opts) ⇒ Object
TODO Figure out the proper way to mount folders before provisioning without using ‘#prepare` (which is deprecated). TODO Umount existing devices if they go missing from the Vagrantfile (either via deletion or setting disabled: true).
44 45 46 |
# File 'lib/vagrant-lxd/synced_folder.rb', line 44 def prepare(machine, folders, opts) enable(machine, folders, opts) end |
#usable?(machine, raise_error = false) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vagrant-lxd/synced_folder.rb', line 25 def usable?(machine, raise_error = false) return false unless machine.provider_name == :lxd return false unless machine.env.host.capability(:synced_folders) @driver ||= Driver.new(machine) if @driver.synced_folders_usable? true elsif not raise_error false else fail Vagrant::Errors::SyncedFolderUnusable, type: 'lxd' end end |