virtualbox_WSL2 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/virtualbox_WSL2.rb +100 -0
- data/lib/virtualbox_WSL2/version.rb +5 -0
- data/virtualbox_WSL2.gemspec +36 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 70f30e94cb832320a3d1e042d01f0d4a8f0abe8b1c3a49c3b05e9928e0508395
|
4
|
+
data.tar.gz: 00c3df3f942b1d7435248d80b82984ba5da932436b98ad7e0e889e9a1f876ee3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc16d0dd567b8de76c8b162b77dc7302f90167368e4081cb3c6ff9d4117d7b804f534dbd557dc5f147f2644ac6a6bdf10ad670b7091b8f6c6b2c6937cb361d10
|
7
|
+
data.tar.gz: f7dcc01c340587499e705881f451feddea6fceeace9da06479d355a9f333d67186fa7fa72db9ce0e5480eefb1e583f7e871533b5de005864d9d44cf22156a1ef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in virtualbox_WSL2.gemspec
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "vagrant", git: "https://github.com/hashicorp/vagrant.git", tag: "v2.2.14"
|
9
|
+
end
|
10
|
+
|
11
|
+
group :plugins do
|
12
|
+
gem "virtualbox_WSL2", path: "."
|
13
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Andrei
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# VirtualboxWSL2
|
2
|
+
|
3
|
+
Plugin allows Vagrant to properly use VirtualBox as a provider from WSL2.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'virtualbox_WSL2'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install virtualbox_WSL2
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Nothing special, just fixed `vagrant up` and `vagrant ssh` commands.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/karandash8/virtualbox_WSL2.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "virtualbox_WSL2"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
require_relative "virtualbox_WSL2/version"
|
4
|
+
|
5
|
+
module VirtualboxWSL2
|
6
|
+
include VagrantPlugins::ProviderVirtualBox::Util::CompileForwardedPorts
|
7
|
+
include VagrantPlugins::ProviderVirtualBox
|
8
|
+
|
9
|
+
module WSL2CompileForwardedPorts
|
10
|
+
include Vagrant::Util::ScopedHashOverride
|
11
|
+
|
12
|
+
# This method compiles the forwarded ports into {ForwardedPort}
|
13
|
+
# models.
|
14
|
+
def compile_forwarded_ports(config)
|
15
|
+
mappings = {}
|
16
|
+
|
17
|
+
config.vm.networks.each do |type, options|
|
18
|
+
if type == :forwarded_port
|
19
|
+
guest_port = options[:guest]
|
20
|
+
host_port = options[:host]
|
21
|
+
host_ip = options[:host_ip]
|
22
|
+
protocol = options[:protocol] || "tcp"
|
23
|
+
options = scoped_hash_override(options, :virtualbox)
|
24
|
+
id = options[:id]
|
25
|
+
|
26
|
+
# If the forwarded port was marked as disabled, ignore.
|
27
|
+
next if options[:disabled]
|
28
|
+
|
29
|
+
key = "#{host_ip}#{protocol}#{host_port}"
|
30
|
+
mappings[key] =
|
31
|
+
VagrantPlugins::ProviderVirtualBox::Model::ForwardedPort.new(id, host_port, guest_port, options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Creating the second port forwarding entry for connections from WSL2 via Windows IP
|
36
|
+
mappings.dup.each do |k, v|
|
37
|
+
if Vagrant::Util::Platform.wsl? and k.start_with?("127.0.0.1tcp") and (v.id == "ssh")
|
38
|
+
host_ip = "0.0.0.0"
|
39
|
+
host_port = v.host_port
|
40
|
+
guest_port = v.guest_port
|
41
|
+
protocol = v.protocol
|
42
|
+
id = "ssh_wsl2"
|
43
|
+
auto_correct = v.auto_correct
|
44
|
+
adapter = v.adapter
|
45
|
+
guest_ip = v.guest_ip
|
46
|
+
|
47
|
+
key = "#{host_ip}#{protocol}#{host_port}"
|
48
|
+
mappings[key] =
|
49
|
+
VagrantPlugins::ProviderVirtualBox::Model::ForwardedPort.new(id, host_port, guest_port, {:host_ip => host_ip, :protocol => protocol, :auto_correct => auto_correct, :adapter => adapter, :guest_ip => guest_ip})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
mappings.values
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module WSL2Provider
|
58
|
+
# Returns the SSH info for accessing the VirtualBox VM.
|
59
|
+
def ssh_info
|
60
|
+
# If the VM is not running that we can't possibly SSH into it
|
61
|
+
return nil if state.id != :running
|
62
|
+
|
63
|
+
# Return what we know. The host is always "127.0.0.1" because
|
64
|
+
# VirtualBox VMs are always local. The port we try to discover
|
65
|
+
# by reading the forwarded ports.
|
66
|
+
host_ip = "127.0.0.1"
|
67
|
+
|
68
|
+
# If we run on WSL2, we need to ssh through Windows IP, which is set as the default route
|
69
|
+
if Vagrant::Util::Platform.wsl?
|
70
|
+
result = Vagrant::Util::Subprocess.execute("/bin/sh", "-c", "ip route | grep default | grep -Po '\\d+.\\d+.\\d+.\\d+'")
|
71
|
+
if result.exit_code == 0
|
72
|
+
host_ip = result.stdout.strip
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return {
|
77
|
+
host: host_ip,
|
78
|
+
port: @driver.ssh_port(@machine.config.ssh.guest_port)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
module VagrantPlugins
|
85
|
+
module ProviderVirtualBox
|
86
|
+
module Util
|
87
|
+
module CompileForwardedPorts
|
88
|
+
prepend VirtualboxWSL2::WSL2CompileForwardedPorts
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module VagrantPlugins
|
95
|
+
module ProviderVirtualBox
|
96
|
+
class Provider < Vagrant.plugin("2", :provider)
|
97
|
+
prepend VirtualboxWSL2::WSL2Provider
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/virtualbox_WSL2/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "virtualbox_WSL2"
|
7
|
+
spec.version = VirtualboxWSL2::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.authors = ["Andrei Lapin"]
|
11
|
+
spec.email = ["karandash8@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Allows to use VirtualBox as a provider from WSL2."
|
14
|
+
spec.description = "On WSL2, (1) the second port forwarding entry will be created on 0.0.0.0, which would allow to ssh to
|
15
|
+
VirtualBox VM on Windows IP. (2) Windows IP will be used automatically for `vagrant ssh` command."
|
16
|
+
spec.homepage = "http://www.vagrantup.com"
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
# Uncomment to register a new dependency of your gem
|
29
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
30
|
+
spec.add_dependency "rake"
|
31
|
+
spec.add_dependency "ruby-debug-ide"
|
32
|
+
spec.add_dependency "debase"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, checkout our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtualbox_WSL2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Lapin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-12 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: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-debug-ide
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: debase
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "On WSL2, (1) the second port forwarding entry will be created on 0.0.0.0,
|
56
|
+
which would allow to ssh to \n VirtualBox VM on Windows IP.
|
57
|
+
(2) Windows IP will be used automatically for `vagrant ssh` command."
|
58
|
+
email:
|
59
|
+
- karandash8@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/virtualbox_WSL2.rb
|
72
|
+
- lib/virtualbox_WSL2/version.rb
|
73
|
+
- virtualbox_WSL2.gemspec
|
74
|
+
homepage: http://www.vagrantup.com
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.4.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.1.4
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Allows to use VirtualBox as a provider from WSL2.
|
97
|
+
test_files: []
|