Class: VagrantPlugins::VMM::SyncedFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vmm/synced_folder.rb

Instance Method Summary collapse

Instance Method Details

#cleanup(machine, opts) ⇒ Object

This is called after destroying the machine during a ‘vagrant destroy` and also prior to syncing folders during a `vagrant up`.

No return value.

Parameters:

  • machine (Machine)
  • opts (Hash)


84
85
# File 'lib/vagrant-vmm/synced_folder.rb', line 84

def cleanup(machine, opts)
end

#disable(machine, folders, opts) ⇒ Object

This is called to remove the synced folders from a running machine.

This is not guaranteed to be called, but this should be implemented by every synced folder implementation.

Parameters:

  • machine (Machine)

    The machine to modify.

  • folders (Hash)

    The folders to remove. This will not contain any folders that should remain.

  • opts (Hash)

    Any options for the synced folders.



73
74
# File 'lib/vagrant-vmm/synced_folder.rb', line 73

def disable(machine, folders, opts)
end

#enable(machine, folders, opts) ⇒ Object

This is called after the machine is booted and after networks are setup.

This might be called with new folders while the machine is running. If so, then this should add only those folders without removing any existing ones.

No return value.



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
# File 'lib/vagrant-vmm/synced_folder.rb', line 37

def enable(machine, folders, opts)
  machine.ui.output('Syncing folders with the VM via WinRM')

  # generate options
  options = {
    vm_address: machine.provider_config.vm_address,
    folders_to_sync: {},
    winrm_vm_username: machine.config.winrm.username,
    winrm_vm_password: machine.config.winrm.password
  }
  #
  folders.each do |id, data|
    if data[:guestpath]
      # record in options
      options[:folders_to_sync][data[:hostpath]] = data[:guestpath]
    else
      # If no guest path is specified, then automounting is disabled
      machine.ui.detail("No guest path specified for: #{data[:hostpath]}")
    end
  end
  # escape quotes
  options[:folders_to_sync] = options[:folders_to_sync].to_json.gsub('"','\\"')
  res = machine.provider.driver.sync_folders(options)
  machine.ui.detail("Synced finished.")
end

#usable?(machine, raise_error = false) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-vmm/synced_folder.rb', line 13

def usable?(machine, raise_error=false)
  return false if machine.provider_name != :vmm

  if !Vagrant::Util::Platform.windows?
    raise Errors::WindowsRequired
    return false
  end

  if !Vagrant::Util::PowerShell.available?
    raise Errors::PowerShellRequired
    return false
  end

  true
end