vagrant-mosh 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf1674d5eaceb827312236ae52fbaf863d246f95
4
+ data.tar.gz: ff03c7134727e4169d3ebc5b51986ddef90bca1d
5
+ SHA512:
6
+ metadata.gz: ff65aa296e50fe852e09272b56c12f37c8d81c1cba6d3404331f1a033e00551ef1537db75b22ecd99749a9342158e40a9807f156b19bb6427e0835287b4f1ec0
7
+ data.tar.gz: c76a0c52fcfd82ccda0615d23624a842a53434b11906c582bc8bfba99af95600fe9526ccb7d6ec391200d86e7ed085c599be80dfc58e045b485a3d8fee18e039
@@ -0,0 +1,7 @@
1
+ pkg/
2
+ tmp/
3
+ .bundle/
4
+ vendor/bundle/
5
+ .vagrant/
6
+ Gemfile.lock
7
+ .envrc
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', github: 'mitchellh/vagrant'
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ gem 'vagrant-digitalocean'
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Alex Rodionov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,90 @@
1
+ vagrant-mosh [![Gem Version](https://badge.fury.io/rb/vagrant-mosh.svg)](http://badge.fury.io/rb/vagrant-mosh)
2
+ ============
3
+
4
+ Vagrant plugin to connect to box using [Mosh](https://mosh.mit.edu/).
5
+
6
+ Installation
7
+ ------------
8
+
9
+ ```bash
10
+ $ vagrant plugin install vagrant-mosh
11
+ ```
12
+
13
+ Usage
14
+ -----
15
+
16
+ Just use it as you would normally use `ssh` command:
17
+
18
+ ```bash
19
+ $ vagrant mosh
20
+ ```
21
+
22
+ Notes
23
+ -----
24
+
25
+ 1. You have to install Mosh both on host and box by yourself.
26
+ 2. Plugin has been tested to work with VirtualBox, AWS and DigitalOcean.
27
+ 3. If you are using VirtualBox, it's required to use private/public network (that is because we need to have remote IP address from the box).
28
+
29
+ Testing
30
+ -------
31
+
32
+ Unfortunately, it's not that easy to write automated tests for it. The test should probably just run `vagrant mosh`, execute command in box and assert the result, but the way Mosh works doesn't allow to just execute the process.
33
+
34
+ Discussion on `#mosh`:
35
+
36
+ ```
37
+ p0deje: can anybody help me run mosh programmatically?
38
+ p0deje: I want to run mosh from Ruby script, execute command and return
39
+ p0deje: the script works fine for SSH, but not for Mosh
40
+ p0deje: script itself is at https://gist.github.com/p0deje/c5dbfa0d137e8c11d3f5
41
+ chris2: i guess expect doesnt like mosh's efficient redrawing
42
+ ...
43
+ chris2: perhaps you can work around by running mosh in tmux and exporting the output of tmux...
44
+ chris2: anyway, you need something that understands ANSI sequences
45
+ ```
46
+
47
+ To test it manually, there is a Vagrantfile which helps you do that:
48
+
49
+ ```bash
50
+ # start all boxes
51
+ $ bundle exec rake box:add
52
+ $ bundle exec vagrant up
53
+
54
+ $ bundle exec vagrant mosh static_ip # test VirtualBox static IP networking
55
+ $ bundle exec vagrant mosh dynamic_ip # test VirtualBox DHCP networking
56
+
57
+ # remove all boxes
58
+ $ bundle exec vagrant destroy
59
+ $ bundle exec rake box:remove
60
+ ```
61
+
62
+ Also, it's possible to test remote providers (if you have [DigitalOcean](https://www.digitalocean.com/) account):
63
+
64
+ ```bash
65
+ $ export DIGITALOCEAN_TOKEN="your_token"
66
+ $ bundle exec vagrant up digitalocean
67
+ $ bundle exec vagrant mosh digitalocean
68
+ $ bundle exec vagrant destroy digitalocean
69
+ ```
70
+
71
+ TODO
72
+ ----
73
+
74
+ 1. Try to forward UDP ports rather finding remote IP address of the box.
75
+ 2. Add tests.
76
+ 3. Refactor to work as action.
77
+
78
+ Contributing
79
+ ------------
80
+
81
+ * Fork the project.
82
+ * Make your feature addition or bug fix.
83
+ * ~~Add tests for it. This is important so I don't break it in a future version unintentionally.~~ (no automated tests exist at the moment)
84
+ * Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull.
85
+ * Send me a pull request. Bonus points for topic branches.
86
+
87
+ Copyright
88
+ ---------
89
+
90
+ Copyright (c) 2015 Alex Rodionov. See LICENSE.md for details.
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ namespace :box do
5
+ desc 'Downloads and adds vagrant box for testing.'
6
+ task :add do
7
+ sh 'bundle exec vagrant box add ubuntu/trusty64'
8
+ end
9
+
10
+ desc 'Removes testing vagrant box.'
11
+ task :remove do
12
+ sh 'bundle exec vagrant box remove --force ubuntu/trusty64'
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ Vagrant.configure('2') do |config|
2
+ config.vm.box = 'ubuntu/trusty64'
3
+ config.vm.provision 'shell', path: 'support/provision.sh'
4
+
5
+ config.vm.define 'static_ip' do |machine|
6
+ machine.vm.network :private_network, ip: '192.168.50.6'
7
+ end
8
+
9
+ config.vm.define 'dynamic_ip' do |machine|
10
+ machine.vm.network :private_network, type: 'dhcp'
11
+ end
12
+
13
+ config.vm.define 'digitalocean', autostart: false do |machine|
14
+ machine.vm.provider :digital_ocean do |provider, override|
15
+ override.ssh.private_key_path = '~/.ssh/id_rsa'
16
+ override.vm.box = 'digital_ocean'
17
+ override.vm.box_url = 'https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box'
18
+
19
+ provider.token = ENV['DIGITALOCEAN_TOKEN']
20
+ provider.image = 'ubuntu-14-04-x64'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ require 'vagrant'
2
+
3
+ require 'vagrant-mosh/plugin'
4
+ require 'vagrant-mosh/version'
@@ -0,0 +1,93 @@
1
+ module VagrantPlugins
2
+ module Mosh
3
+ class Command < Vagrant.plugin(2, :command)
4
+ def self.synopsis
5
+ 'connects to machine via Mosh'
6
+ end
7
+
8
+ def execute
9
+ opts = OptionParser.new do |o|
10
+ o.banner = 'Usage: vagrant mosh [vm-name]'
11
+ o.separator ''
12
+ end
13
+ argv = parse_options(opts)
14
+ return unless argv
15
+
16
+ with_target_vms(argv, single_target: true) do |vm|
17
+ ssh_info = vm.ssh_info
18
+ switch_to_remote_ip(ssh_info, vm) if localhost?(ssh_info[:host])
19
+ mosh_command = ['mosh', *mosh_arguments(ssh_info)].join(' ')
20
+ Vagrant::Util::SafeExec.exec(mosh_command)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def localhost?(host)
27
+ %w[localhost 127.0.0.1].include?(host)
28
+ end
29
+
30
+ def switch_to_remote_ip(ssh_info, vm)
31
+ ssh_info.delete(:port)
32
+ if ip = find_remote_ip(vm)
33
+ ssh_info[:host] = ip
34
+ else
35
+ raise "Cannot find remote box IP address. Make sure you're not using NAT."
36
+ end
37
+ end
38
+
39
+ def find_remote_ip(vm)
40
+ adapter_numbers = vm.provider.driver.read_network_interfaces.keys
41
+ adapter_numbers.map do |adapter_number|
42
+ begin
43
+ vm.provider.driver.read_guest_ip(adapter_number)
44
+ rescue Vagrant::Errors::VirtualBoxGuestPropertyNotFound
45
+ nil
46
+ end
47
+ end.compact.first
48
+ end
49
+
50
+ def mosh_arguments(ssh_info)
51
+ [
52
+ "--ssh", "'#{ssh_command(ssh_info)}'",
53
+ "#{ssh_info[:username]}@#{ssh_info[:host]}"
54
+ ]
55
+ end
56
+
57
+ # This method pretty much duplicates `Vagrant::Util::SSH.exec`.
58
+ #
59
+ # It would be great to be able to get this logic from Vagrant itself
60
+ # but it requires some core changes.
61
+ def ssh_command(ssh_info)
62
+ command_options = %W[
63
+ -o Compression=yes
64
+ -o DSAAuthentication=yes
65
+ -o LogLevel=#{ssh_info[:log_level] || 'FATAL'}
66
+ -o StrictHostKeyChecking=no
67
+ -o UserKnownHostsFile=/dev/null
68
+ ]
69
+
70
+ if ssh_info[:forward_x11]
71
+ command_options += %w[
72
+ -o ForwardX11=yes
73
+ -o ForwardX11Trusted=yes
74
+ ]
75
+ end
76
+
77
+ if ssh_info[:forward_agent]
78
+ command_options += %w[-o ForwardAgent=yes]
79
+ end
80
+
81
+ ssh_info[:private_key_path].each do |path|
82
+ command_options += ['-i', path]
83
+ end
84
+
85
+ if ssh_info[:port]
86
+ command_options += ['-p', ssh_info[:port]]
87
+ end
88
+
89
+ "ssh #{command_options.join(' ')}"
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,13 @@
1
+ module VagrantPlugins
2
+ module Mosh
3
+ class Plugin < Vagrant.plugin(2)
4
+ name 'vagrant-mosh'
5
+ description 'Plugin allows to use Mosh to connect to box.'
6
+
7
+ command :mosh do
8
+ require_relative 'command'
9
+ Command
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Mosh
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ #!/bin/bash -x
2
+
3
+ # fix locale
4
+ export LANGUAGE=en_US.UTF-8
5
+ export LANG=en_US.UTF-8
6
+ export LC_ALL=en_US.UTF-8
7
+ sudo locale-gen en_US.UTF-8
8
+ sudo dpkg-reconfigure locales
9
+
10
+ # Uncomment the following to build using package manager:
11
+ sudo apt-get install -y mosh
12
+
13
+ # Uncomment the following to build from source:
14
+ # sudo apt-get install -y libncurses5-dev libprotobuf-dev libssl-dev protobuf-compiler zlib1g-dev
15
+ # sudo apt-get install -y autoconf build-essential git pkg-config
16
+ # git clone https://github.com/keithw/mosh
17
+ # cd mosh
18
+ # ./autogen.sh
19
+ # ./configure
20
+ # make
21
+ # sudo make install
22
+ # cd ../
23
+ # rm -rf mosh/
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'vagrant-mosh/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'vagrant-mosh'
6
+ s.version = VagrantPlugins::Mosh::VERSION
7
+ s.author = 'Alex Rodionov'
8
+ s.email = 'p0deje@gmail.com'
9
+ s.homepage = 'http://github.com/p0deje/vagrant-mosh'
10
+ s.summary = 'Use Mosh to connect to box'
11
+ s.description = 'Vagrant plugin to use Mosh to connect to box'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = %w[lib]
18
+
19
+ s.add_development_dependency 'rake'
20
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-mosh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Rodionov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Vagrant plugin to use Mosh to connect to box
28
+ email: p0deje@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - LICENSE.md
37
+ - README.md
38
+ - Rakefile
39
+ - Vagrantfile
40
+ - lib/vagrant-mosh.rb
41
+ - lib/vagrant-mosh/command.rb
42
+ - lib/vagrant-mosh/plugin.rb
43
+ - lib/vagrant-mosh/version.rb
44
+ - support/provision.sh
45
+ - vagrant-mosh.gemspec
46
+ homepage: http://github.com/p0deje/vagrant-mosh
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Use Mosh to connect to box
70
+ test_files: []