vagrant-sshfs 0.0.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/vagrant-sshfs.rb CHANGED
@@ -4,20 +4,18 @@ rescue LoadError
4
4
  raise "The Vagrant sshfs plugin must be run within Vagrant"
5
5
  end
6
6
 
7
- require "vagrant-sshfs/version"
8
7
  require "vagrant-sshfs/errors"
8
+ require "vagrant-sshfs/version"
9
9
  require "vagrant-sshfs/plugin"
10
- require "vagrant-sshfs/actions"
11
- require "vagrant-sshfs/command"
12
10
 
13
- module Vagrant
14
- module SshFS
11
+ module VagrantPlugins
12
+ module SyncedFolderSSHFS
15
13
  # Returns the path to the source of this plugin
16
14
  def self.source_root
17
15
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
18
16
  end
19
17
 
20
- I18n.load_path << File.expand_path('locales/en.yml', source_root)
18
+ I18n.load_path << File.expand_path('locales/synced_folder_sshfs.yml', source_root)
21
19
  I18n.reload!
22
20
  end
23
21
  end
@@ -0,0 +1,29 @@
1
+ module VagrantPlugins
2
+ module GuestArch
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_install(machine)
6
+ # Attempt to install sshfs but note that it may likely fail
7
+ # because the package file list is out of date (see [1]). A
8
+ # logical answer to this problem would be to update the
9
+ # package list and then install the package, but since arch
10
+ # doesn't support partial upgrades [2] that would require
11
+ # updating all packages in the system first. Not ideal
12
+ #
13
+ # [1] https://wiki.archlinux.org/index.php/pacman#Packages_cannot_be_retrieved_on_installation
14
+ # [2] https://wiki.archlinux.org/index.php/System_maintenance#Partial_upgrades_are_unsupported
15
+
16
+ error_class = VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSInstallFailed
17
+ error_key = :install_failed_arch
18
+ cmd = "pacman --noconfirm -S sshfs"
19
+ machine.communicate.sudo(
20
+ cmd, error_class: error_class, error_key: error_key)
21
+ end
22
+
23
+ def self.sshfs_installed(machine)
24
+ machine.communicate.test("pacman -Q sshfs")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module GuestDebian
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_install(machine)
6
+ machine.communicate.sudo("apt-get install -y sshfs")
7
+ end
8
+
9
+ def self.sshfs_installed(machine)
10
+ machine.communicate.test("dpkg -l sshfs")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module GuestFedora
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_install(machine)
6
+ machine.communicate.sudo("dnf -y install fuse-sshfs")
7
+ end
8
+
9
+ def self.sshfs_installed(machine)
10
+ machine.communicate.test("rpm -q fuse-sshfs")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module GuestLinux
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_installed(machine)
6
+ machine.communicate.test("test -x /usr/bin/sshfs")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,90 @@
1
+ require "vagrant/util/retryable"
2
+
3
+ module VagrantPlugins
4
+ module GuestLinux
5
+ module Cap
6
+ class MountSSHFS
7
+ extend Vagrant::Util::Retryable
8
+
9
+ def self.sshfs_mount_folder(machine, opts)
10
+ # opts contains something like:
11
+ # { :type=>:sshfs,
12
+ # :guestpath=>"/sharedfolder",
13
+ # :hostpath=>"/guests/sharedfolder",
14
+ # :disabled=>false
15
+ # :ssh_host=>"192.168.1.1"
16
+ # :ssh_port=>"22"
17
+ # :ssh_username=>"username"
18
+ # :ssh_password=>"password"
19
+ # }
20
+
21
+ # expand the guest path so we can handle things like "~/vagrant"
22
+ expanded_guest_path = machine.guest.capability(
23
+ :shell_expand_guest_path, opts[:guestpath])
24
+
25
+ # Do the actual creating and mounting
26
+ machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
27
+
28
+ # Mount path information
29
+ hostpath = opts[:hostpath].dup
30
+ hostpath.gsub!("'", "'\\\\''")
31
+
32
+ # Log some information
33
+ machine.ui.info(I18n.t("vagrant.sshfs.actions.mounting_folder",
34
+ hostpath: hostpath, guestpath: expanded_guest_path))
35
+
36
+ # Figure out any options
37
+ # TODO - Allow options override via an option
38
+ mount_opts = '-o StrictHostKeyChecking=no '
39
+ mount_opts+= '-o allow_other '
40
+ mount_opts+= '-o noauto_cache '
41
+
42
+ # TODO some other options we might use in the future to help
43
+ # connections over low bandwidth
44
+ #options+= '-o kernel_cache -o Ciphers=arcfour -o big_writes -o auto_cache -o cache_timeout=115200 -o attr_timeout=115200 -o entry_timeout=1200 -o max_readahead=90000 '
45
+ #options+= '-o kernel_cache -o big_writes -o auto_cache -o cache_timeout=115200 -o attr_timeout=115200 -o entry_timeout=1200 -o max_readahead=90000 '
46
+ #options+= '-o cache_timeout=3600 '
47
+
48
+ username = opts[:ssh_username]
49
+ password = opts[:ssh_password]
50
+ host = opts[:ssh_host]
51
+ port = opts[:ssh_port]
52
+
53
+ echopipe = ""
54
+ if password
55
+ echopipe = "echo '#{password}' | "
56
+ mount_opts+= '-o password_stdin '
57
+ end
58
+
59
+ error_class = VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSMountFailed
60
+ cmd = echopipe
61
+ cmd+= "sshfs -p #{port} "
62
+ cmd+= mount_opts
63
+ cmd+= "#{username}@#{host}:'#{hostpath}' #{expanded_guest_path}"
64
+ retryable(on: error_class, tries: 3, sleep: 3) do
65
+ machine.communicate.sudo(
66
+ cmd, error_class: error_class, error_key: :mount_failed)
67
+ end
68
+ end
69
+
70
+ def self.sshfs_is_folder_mounted(machine, opts)
71
+ mounted = false
72
+ # expand the guest path so we can handle things like "~/vagrant"
73
+ expanded_guest_path = machine.guest.capability(
74
+ :shell_expand_guest_path, opts[:guestpath])
75
+ machine.communicate.execute("cat /proc/mounts") do |type, data|
76
+ if type == :stdout
77
+ data.each_line do |line|
78
+ if line.split()[1] == expanded_guest_path
79
+ mounted = true
80
+ break
81
+ end
82
+ end
83
+ end
84
+ end
85
+ return mounted
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,36 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_install(machine)
6
+ # Install epel rpm if not installed
7
+ if !epel_installed(machine)
8
+ epel_install(machine)
9
+ end
10
+
11
+ # Install sshfs (comes from epel repos)
12
+ machine.communicate.sudo("yum -y install fuse-sshfs")
13
+ end
14
+
15
+ def self.sshfs_installed(machine)
16
+ machine.communicate.test("rpm -q fuse-sshfs")
17
+ end
18
+
19
+ protected
20
+
21
+ def self.epel_installed(machine)
22
+ machine.communicate.test("rpm -q epel-release")
23
+ end
24
+
25
+ def self.epel_install(machine)
26
+ case machine.guest.capability("flavor")
27
+ when :rhel_7
28
+ machine.communicate.sudo("rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm")
29
+ when :rhel # rhel6
30
+ machine.communicate.sudo("rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module GuestSUSE
3
+ module Cap
4
+ class SSHFSClient
5
+ def self.sshfs_install(machine)
6
+ machine.communicate.sudo("zypper -n install sshfs")
7
+ end
8
+
9
+ def self.sshfs_installed(machine)
10
+ machine.communicate.test("rpm -q sshfs")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,25 +1,45 @@
1
- module Vagrant
2
- module SshFS
3
- class Command < Vagrant.plugin(2, :command)
4
- def self.synopsis
5
- "mounts sshfs shared folders"
6
- end
1
+ module VagrantPlugins
2
+ module SyncedFolderSSHFS
3
+ module Command
4
+ class SSHFS < Vagrant.plugin("2", :command)
5
+
6
+ include Vagrant::Action::Builtin::MixinSyncedFolders
7
7
 
8
- def execute
9
- with_target_vms do |machine|
10
- get_builder(machine).mount!
8
+ def self.synopsis
9
+ "mounts SSHFS shared folder mounts into the remote machine"
11
10
  end
12
11
 
13
- 0
14
- end
12
+ def execute
13
+ opts = OptionParser.new do |o|
14
+ o.banner = "Usage: vagrant sshfs"
15
+ o.separator ""
16
+ o.separator "Mount all sshfs synced folders into the vagrant box"
17
+ o.separator ""
18
+ end
19
+
20
+ # Parse the options and return if we don't have any target.
21
+ argv = parse_options(opts)
22
+ return if !argv
23
+
24
+ # Go through each machine and perform the rsync
25
+ error = false
26
+ with_target_vms(argv) do |machine|
27
+
28
+ # Is the machine up yet?
29
+ if !machine.communicate.ready?
30
+ machine.ui.error(I18n.t("vagrant.sshfs.errors.communicator_not_ready"))
31
+ error = true
32
+ next
33
+ end
15
34
 
16
- private
35
+ # Determine the sshfs synced folders for this machine
36
+ folders = synced_folders(machine, cached: false)[:sshfs]
37
+ next if !folders || folders.empty?
17
38
 
18
- def get_builder(machine)
19
- if machine.config.sshfs.mount_on_guest
20
- Builders::Guest.new(machine, @env.ui)
21
- else
22
- Builders::Host.new(machine, @env.ui)
39
+ # Sync them!
40
+ SyncedFolder.new.enable(machine, folders, {})
41
+ end
42
+ return error ? 1 : 0
23
43
  end
24
44
  end
25
45
  end
@@ -1,7 +1,22 @@
1
- module Vagrant
2
- module SshFS
3
- class Error < Errors::VagrantError
4
- error_namespace("vagrant.config.sshfs.error")
1
+ module VagrantPlugins
2
+ module SyncedFolderSSHFS
3
+ module Errors
4
+ # A convenient superclass for all our errors.
5
+ class SSHFSError < Vagrant::Errors::VagrantError
6
+ error_namespace("vagrant.sshfs.errors")
7
+ end
8
+
9
+ class SSHFSMountFailed < SSHFSError
10
+ error_key(:mount_failed)
11
+ end
12
+
13
+ class SSHFSInstallFailed < SSHFSError
14
+ error_key(:install_failed)
15
+ end
16
+
17
+ class SSHFSNotInstalledInGuest < SSHFSError
18
+ error_key(:sshfs_not_in_guest)
19
+ end
5
20
  end
6
21
  end
7
22
  end
@@ -1,45 +1,85 @@
1
- module Vagrant
2
- module SshFS
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderSSHFS
5
+ # This plugin implements SSHFS synced folders.
3
6
  class Plugin < Vagrant.plugin("2")
4
- name "vagrant-sshfs"
5
- description "A Vagrant plugin that mounts sshfs in the host machine."
7
+ name "SSHFS synced folders"
8
+ description <<-EOF
9
+ The SSHFS synced folders plugin enables you to use SSHFS as a synced folder
10
+ implementation.
11
+ EOF
12
+
13
+ synced_folder("sshfs", 5) do
14
+ require_relative "synced_folder"
15
+ SyncedFolder
16
+ end
17
+
18
+ command("sshfs", primary: false) do
19
+ require_relative "command"
20
+ Command::SSHFS
21
+ end
22
+
23
+ guest_capability("linux", "sshfs_mount_folder") do
24
+ require_relative "cap/linux/sshfs_mount"
25
+ VagrantPlugins::GuestLinux::Cap::MountSSHFS
26
+ end
27
+
28
+ guest_capability("linux", "sshfs_is_folder_mounted") do
29
+ require_relative "cap/linux/sshfs_mount"
30
+ VagrantPlugins::GuestLinux::Cap::MountSSHFS
31
+ end
6
32
 
7
- config "sshfs" do
8
- require "vagrant-sshfs/config"
9
- Config
33
+ guest_capability("redhat", "sshfs_installed") do
34
+ require_relative "cap/redhat/sshfs_client"
35
+ VagrantPlugins::GuestRedHat::Cap::SSHFSClient
10
36
  end
11
37
 
12
- action_hook(:sshfs, :machine_action_up) do |hook|
13
- hook.append(Vagrant::SshFS::Actions::Up)
38
+ guest_capability("redhat", "sshfs_install") do
39
+ require_relative "cap/redhat/sshfs_client"
40
+ VagrantPlugins::GuestRedHat::Cap::SSHFSClient
14
41
  end
15
42
 
16
- action_hook(:sshfs, :machine_action_reload) do |hook|
17
- hook.append(Vagrant::SshFS::Actions::Reload)
43
+ guest_capability("fedora", "sshfs_installed") do
44
+ require_relative "cap/fedora/sshfs_client"
45
+ VagrantPlugins::GuestFedora::Cap::SSHFSClient
18
46
  end
19
47
 
20
- action_hook(:sshfs, :machine_action_provision) do |hook|
21
- hook.append(Vagrant::SshFS::Actions::Provision)
48
+ guest_capability("fedora", "sshfs_install") do
49
+ require_relative "cap/fedora/sshfs_client"
50
+ VagrantPlugins::GuestFedora::Cap::SSHFSClient
22
51
  end
23
52
 
24
- action_hook(:sshfs, :machine_action_suspend) do |hook|
25
- hook.append(Vagrant::SshFS::Actions::Suspend)
53
+ guest_capability("debian", "sshfs_installed") do
54
+ require_relative "cap/debian/sshfs_client"
55
+ VagrantPlugins::GuestDebian::Cap::SSHFSClient
26
56
  end
27
57
 
28
- action_hook(:sshfs, :machine_action_resume) do |hook|
29
- hook.append(Vagrant::SshFS::Actions::Resume)
58
+ guest_capability("debian", "sshfs_install") do
59
+ require_relative "cap/debian/sshfs_client"
60
+ VagrantPlugins::GuestDebian::Cap::SSHFSClient
30
61
  end
31
62
 
32
- action_hook(:sshfs, :machine_action_halt) do |hook|
33
- hook.append(Vagrant::SshFS::Actions::Halt)
63
+ guest_capability("arch", "sshfs_installed") do
64
+ require_relative "cap/arch/sshfs_client"
65
+ VagrantPlugins::GuestArch::Cap::SSHFSClient
34
66
  end
35
67
 
36
- action_hook(:sshfs, :machine_action_destroy) do |hook|
37
- hook.append(Vagrant::SshFS::Actions::Destroy)
68
+ guest_capability("arch", "sshfs_install") do
69
+ require_relative "cap/arch/sshfs_client"
70
+ VagrantPlugins::GuestArch::Cap::SSHFSClient
38
71
  end
39
72
 
40
- command "sshfs" do
41
- Vagrant::SshFS::Command
73
+ guest_capability("suse", "sshfs_installed") do
74
+ require_relative "cap/suse/sshfs_client"
75
+ VagrantPlugins::GuestSUSE::Cap::SSHFSClient
42
76
  end
77
+
78
+ guest_capability("suse", "sshfs_install") do
79
+ require_relative "cap/suse/sshfs_client"
80
+ VagrantPlugins::GuestSUSE::Cap::SSHFSClient
81
+ end
82
+
43
83
  end
44
84
  end
45
85
  end