Class: HashiCorp::VagrantVMwareDesktop::SyncedFolder
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::SyncedFolder
- Defined in:
- lib/vagrant-vmware-desktop/synced_folder.rb
Instance Method Summary collapse
- #cleanup(machine, opts) ⇒ Object
- #enable(machine, folders, _opts) ⇒ Object
-
#initialize(*args) ⇒ SyncedFolder
constructor
A new instance of SyncedFolder.
- #prepare(machine, folders, _opts) ⇒ Object
- #usable?(machine) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ SyncedFolder
Returns a new instance of SyncedFolder.
7 8 9 10 11 |
# File 'lib/vagrant-vmware-desktop/synced_folder.rb', line 7 def initialize(*args) super @logger = Log4r::Logger.new("hashicorp::provider::vmware::synced_folder") end |
Instance Method Details
#cleanup(machine, opts) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/vagrant-vmware-desktop/synced_folder.rb', line 88 def cleanup(machine, opts) if machine.id && machine.id != "" @logger.info("Clearing shared folders") machine.provider.driver.clear_shared_folders end end |
#enable(machine, folders, _opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 78 79 80 81 82 83 84 85 86 |
# File 'lib/vagrant-vmware-desktop/synced_folder.rb', line 23 def enable(machine, folders, _opts) # Verify that the machine can actually support sharing folders # if we can. if machine.guest.capability?(:verify_vmware_hgfs) machine.ui.info I18n.t("hashicorp.vagrant_vmware_desktop.waiting_for_hgfs") if !machine.guest.capability(:verify_vmware_hgfs) raise Errors::GuestMissingHGFS end end # Get the SSH info which we'll use later. We retry a few times # since sometimes it seems to return nil. ssh_info = nil 10.times do |i| ssh_info = machine.ssh_info break if ssh_info sleep 1 end if ssh_info == nil raise Errors::CannotGetSSHInfo end # short guestpaths first, so we don't step on ourselves shared_folders = folders.dup.sort_by do |id, data| if data[:guestpath] data[:guestpath].length else # A long enough path to just do this at the end. 10000 end end @logger.info("Preparing shared folders with VMX...") machine.ui.info I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folders") machine.provider.driver.enable_shared_folders shared_folders.each do |id, data| id = id.gsub(%r{[:\\/]}, machine.provider_config.shared_folder_special_char) path = data[:hostpath] guestpath = data[:guestpath] = I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folder_single", hostpath: path, guestpath: guestpath) if Vagrant::VERSION < "1.5.0" machine.ui.info() else machine.ui.detail() end machine.provider.driver.share_folder(id, path) # Remove trailing slashes guestpath = guestpath.gsub(/\/+$/, "") # Calculate the owner and group data[:owner] ||= ssh_info[:username] data[:group] ||= ssh_info[:username] # Mount it! machine.guest.capability( :mount_vmware_shared_folder, id, data[:guestpath], data) end end |
#prepare(machine, folders, _opts) ⇒ Object
19 20 21 |
# File 'lib/vagrant-vmware-desktop/synced_folder.rb', line 19 def prepare(machine, folders, _opts) # We don't do anything prior to the machine booting end |
#usable?(machine) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/vagrant-vmware-desktop/synced_folder.rb', line 13 def usable?(machine) # These synced folders only work if the provider is VMware [Plugin.provider_name, :vmware_desktop].include?(machine.provider_name) && machine.provider_config.functional_hgfs end |