vagrant-hypervnet 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +27 -4
- data/lib/vagrant-hypervnet/action/folder_sync.rb +28 -0
- data/lib/vagrant-hypervnet/action.rb +9 -0
- data/lib/vagrant-hypervnet/config.rb +3 -0
- data/lib/vagrant-hypervnet/scripts/add_vm_adapter.ps1 +9 -3
- data/lib/vagrant-hypervnet/scripts/connect_vm_adapter.ps1 +9 -3
- data/lib/vagrant-hypervnet/scripts/get_routes.ps1 +7 -1
- data/lib/vagrant-hypervnet/scripts/get_switch_by_address.ps1 +17 -9
- data/lib/vagrant-hypervnet/scripts/get_switch_by_name.ps1 +12 -6
- data/lib/vagrant-hypervnet/scripts/get_vm_adapters.ps1 +9 -2
- data/lib/vagrant-hypervnet/scripts/new_switch.ps1 +16 -4
- data/lib/vagrant-hypervnet/scripts/remove_vm_adapter.ps1 +8 -2
- data/lib/vagrant-hypervnet/version.rb +1 -1
- data/lib/vagrant-hypervnet.rb +6 -0
- data/locales/en.yml +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 133edcbb24475749a9bf3de3cb1bad3cb0066564b573d88fc85ca83fc49b0213
|
4
|
+
data.tar.gz: 586660e79703b88479704cbf69f6ea216d61e996de05d5a2e3956cd583073d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19f6e3e2c6bdcdeecd9603375bbf03dc59d746c3f09789cf9b0c2b9c45d3b15aa287df6e2a60129559119be77d287de4e29a6fee3e64253f8333377c773df03
|
7
|
+
data.tar.gz: 38870404a84145c4217a7f80d6141f5a676f54086f8d8c620d239bba590cd32d312a6c53bd62196e1f278a3dc31176a431b88344fe487d4ef4b8fde8d450d61c
|
data/README.md
CHANGED
@@ -25,18 +25,41 @@ $ vagrant plugin install vagrant-hypervnet
|
|
25
25
|
```ruby
|
26
26
|
Vagrant.configure("2") do |config|
|
27
27
|
|
28
|
-
#
|
28
|
+
# installs OpenSSH Server (Windows Capability) and inserts vagrant ssh key on windows guests
|
29
29
|
config.hypervnet.install_ssh_server = true
|
30
30
|
|
31
|
-
#
|
31
|
+
# installs MSYS2 and rsync on windows guests
|
32
32
|
config.hypervnet.install_rsync = true
|
33
|
+
|
34
|
+
# enablee synced_folder synchronization before provision
|
35
|
+
config.hypervnet.folder_sync_on_provision = true
|
36
|
+
|
37
|
+
# Hyper-V switch connected to vagrant management interface
|
38
|
+
config.hypervnet.default_switch = "Default Switch"
|
39
|
+
|
40
|
+
# Hyper-V internal network: a new switch is created if can't find an existent switch with the specified subnet (192.168.100.100/24)
|
41
|
+
config.vm.network :private_network, ip: "192.168.100.101", netmask: "255.255.255.0"
|
42
|
+
|
43
|
+
# Hyper-V internal network: a new switch is created if can't find an existent switch whith the specified name ("my-internal-network")
|
44
|
+
config.vm.network :private_network, ip: "192.168.102.101", netmask: "255.255.255.0" hyperv__bridge: "my-internal-network"
|
45
|
+
|
46
|
+
# Hyper-V private network: a new switch is created if can't find an existent switch whith the specified name ("my-private-network")
|
47
|
+
config.vm.network :private_network, ip: "192.168.101.101", netmask: "255.255.255.0" hyperv__private: "my-private-network"
|
48
|
+
|
49
|
+
# Hyper-V external network: the existent switch whith the specified name ("my-external-network") is connected to this vm adapter
|
50
|
+
config.vm.network :public_network, ip: "192.168.102.101", netmask: "255.255.255.0" hyperv__bridge: "my-external-network"
|
51
|
+
|
52
|
+
# rsync synched folder
|
53
|
+
config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git"
|
33
54
|
end
|
34
55
|
```
|
35
56
|
|
36
57
|
### Config options
|
37
58
|
|
38
|
-
* `install_ssh_server` (Boolean, default: `true`):
|
39
|
-
* `install_rsync` (Boolean, default: `true`):
|
59
|
+
* `install_ssh_server` (Boolean, default: `true`): installs OpenSSH Server (Windows Capability) and inserts vagrant ssh key on windows guests.
|
60
|
+
* `install_rsync` (Boolean, default: `true`): installs MSYS2 and rsync on windows guests if an rsync synced folder is defined .
|
61
|
+
* `folder_sync_on_provision` (Boolean, default: `true`): if enabled invokes synced folders synchronization before provision.
|
62
|
+
* `default_switch` (String, default: `Default Switch`): Hyper-V switch connected to interface used by vagrant to communicate with the vm.
|
40
63
|
|
41
64
|
## Usage
|
42
65
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module HyperVNet
|
5
|
+
module Action
|
6
|
+
class FolderSync
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant::hypervnet::folder_sync")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
# Continue the middleware chain.
|
15
|
+
@app.call(env)
|
16
|
+
|
17
|
+
machine = env[:machine]
|
18
|
+
if(machine.config.hypervnet.folder_sync_on_provision)
|
19
|
+
env[:ui].output(I18n.t("vagrant_hypervnet.folder_sync"))
|
20
|
+
callable = Vagrant::Action::Builder.new
|
21
|
+
callable.use Vagrant::Action::Builtin::SyncedFolders
|
22
|
+
machine.action_raw(:sync_folders, callable, env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'action/disable_builtin_network_configure'
|
2
2
|
require_relative 'action/network'
|
3
3
|
require_relative 'action/ssh_server'
|
4
|
+
require_relative 'action/folder_sync'
|
4
5
|
|
5
6
|
module VagrantPlugins
|
6
7
|
module HyperVNet
|
@@ -26,6 +27,14 @@ module VagrantPlugins
|
|
26
27
|
builder.use SshServer
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
def self.folder_sync
|
32
|
+
Vagrant::Action::Builder.new.tap do |builder|
|
33
|
+
builder.use ConfigValidate
|
34
|
+
builder.use FolderSync
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
@@ -8,12 +8,14 @@ module VagrantPlugins
|
|
8
8
|
|
9
9
|
attr_accessor :install_ssh_server
|
10
10
|
attr_accessor :install_rsync
|
11
|
+
attr_accessor :folder_sync_on_provision
|
11
12
|
attr_accessor :default_switch
|
12
13
|
|
13
14
|
def initialize
|
14
15
|
@network_adapters = []
|
15
16
|
@install_ssh_server = UNSET_VALUE
|
16
17
|
@install_rsync = UNSET_VALUE
|
18
|
+
@folder_sync_on_provision = UNSET_VALUE
|
17
19
|
@default_switch = UNSET_VALUE
|
18
20
|
|
19
21
|
network_adapter(:nat)
|
@@ -26,6 +28,7 @@ module VagrantPlugins
|
|
26
28
|
def finalize!
|
27
29
|
@install_ssh_server = true if @install_ssh_server == UNSET_VALUE
|
28
30
|
@install_rsync = true if @install_rsync == UNSET_VALUE
|
31
|
+
@folder_sync_on_provision = true if @folder_sync_on_provision == UNSET_VALUE
|
29
32
|
@default_switch = "Default Switch" if @default_switch == UNSET_VALUE
|
30
33
|
end
|
31
34
|
|
@@ -5,8 +5,14 @@ param (
|
|
5
5
|
[string]$VmId
|
6
6
|
)
|
7
7
|
|
8
|
-
|
9
|
-
$
|
10
|
-
|
8
|
+
try{
|
9
|
+
$vm = Get-VM -Id $VmId
|
10
|
+
$adapter = Add-VMNetworkAdapter -PassThru -VM $vm |
|
11
|
+
Select-Object -Property "Name", "Id"
|
12
|
+
}
|
13
|
+
catch {
|
14
|
+
Write-ErrorMessage "Failed to add adapter to VM ${VmId}: ${PSItem}"
|
15
|
+
exit 1
|
16
|
+
}
|
11
17
|
|
12
18
|
Write-OutputMessage $(ConvertTo-JSON $adapter)
|
@@ -8,6 +8,12 @@ param (
|
|
8
8
|
|
9
9
|
)
|
10
10
|
|
11
|
-
|
12
|
-
$
|
13
|
-
|
11
|
+
try {
|
12
|
+
$vm = Get-VM -Id $VmId
|
13
|
+
$switch = Get-VMSwitch -Id $SwitchId
|
14
|
+
Get-VMNetworkAdapter -VM $vm | Where-Object -Property Id -EQ -Value $Id | Connect-VMNetworkAdapter -VMSwitch $switch
|
15
|
+
}
|
16
|
+
catch {
|
17
|
+
Write-ErrorMessage "Failed to connect adapter ${Id} of VM ${VmId} to switch ${SwitchId}: ${PSItem}"
|
18
|
+
exit 1
|
19
|
+
}
|
@@ -1,5 +1,11 @@
|
|
1
1
|
#Requires -Modules VagrantMessages
|
2
2
|
|
3
|
-
|
3
|
+
try {
|
4
|
+
$routes = Get-NetRoute | Select-Object -Property "DestinationPrefix"
|
5
|
+
}
|
6
|
+
catch {
|
7
|
+
Write-ErrorMessage "Failed to get host routes: ${PSItem}"
|
8
|
+
exit 1
|
9
|
+
}
|
4
10
|
|
5
11
|
Write-OutputMessage $(ConvertTo-JSON $routes)
|
@@ -7,16 +7,24 @@ param (
|
|
7
7
|
|
8
8
|
$switches = @()
|
9
9
|
|
10
|
-
|
11
|
-
foreach($
|
12
|
-
foreach($
|
13
|
-
foreach($
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
try {
|
11
|
+
foreach($route in Get-NetRoute | Where-Object -Property DestinationPrefix -EQ -Value $DestinationPrefix) {
|
12
|
+
foreach($adapter in Get-NetAdapter -InterfaceIndex $route.ifIndex) {
|
13
|
+
foreach($vmAdapter in Get-VMNetworkAdapter -ManagementOS | Where-Object -Property DeviceId -EQ -Value $adapter.DeviceId) {
|
14
|
+
foreach($switch in Get-VMSwitch -Name $vmAdapter.SwitchName |
|
15
|
+
Select-Object -Property Name, Id,
|
16
|
+
@{Name='SwitchType';Expression={"$($_.SwitchType)"}},
|
17
|
+
@{Name='NetAdapter';Expression={$switch_adapter[$_.Name]}}) {
|
18
|
+
$switches += $switch
|
19
|
+
}
|
20
|
+
}
|
19
21
|
}
|
20
22
|
}
|
21
23
|
}
|
24
|
+
catch {
|
25
|
+
Write-ErrorMessage "Failed to find switch by IP ${DestinationPrefix}: ${PSItem}"
|
26
|
+
exit 1
|
27
|
+
}
|
28
|
+
|
29
|
+
|
22
30
|
Write-OutputMessage $(ConvertTo-JSON $switches)
|
@@ -7,11 +7,17 @@ param (
|
|
7
7
|
|
8
8
|
$switches = @()
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
$
|
15
|
-
|
10
|
+
try {
|
11
|
+
foreach($switch in Get-VMSwitch | Where-Object -Property Name -EQ -Value $Name |
|
12
|
+
Select-Object -Property Name, Id,
|
13
|
+
@{Name='SwitchType';Expression={"$($_.SwitchType)"}},
|
14
|
+
@{Name='NetAdapter';Expression={$switch_adapter[$_.Name]}}) {
|
15
|
+
$switches += $switch
|
16
|
+
}
|
17
|
+
}
|
18
|
+
catch {
|
19
|
+
Write-ErrorMessage "Failed to find switch by name ${Name}: ${PSItem}"
|
20
|
+
exit 1
|
21
|
+
}
|
16
22
|
|
17
23
|
Write-OutputMessage $(ConvertTo-JSON $switches)
|
@@ -4,8 +4,15 @@ param (
|
|
4
4
|
[parameter (Mandatory=$true)]
|
5
5
|
[string]$VmId
|
6
6
|
)
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
try {
|
9
|
+
$vm = Get-VM -Id $VmId
|
10
|
+
$adapters = Get-VMNetworkAdapter -VM $vm |
|
9
11
|
Select-Object -Property "Name", "Id", "SwitchName", "SwitchId", "MacAddress"
|
12
|
+
}
|
13
|
+
catch {
|
14
|
+
Write-ErrorMessage "Failed to get adapters of VM ${VmId}: ${PSItem}"
|
15
|
+
exit 1
|
16
|
+
}
|
10
17
|
|
11
18
|
Write-OutputMessage $(ConvertTo-JSON $adapters)
|
@@ -12,12 +12,24 @@ param (
|
|
12
12
|
|
13
13
|
)
|
14
14
|
|
15
|
-
|
15
|
+
try {
|
16
|
+
$switch = New-VMSwitch -Name $Name -SwitchType $SwitchType
|
17
|
+
}
|
18
|
+
catch {
|
19
|
+
Write-ErrorMessage "Failed to create switch ${Name}: ${PSItem}"
|
20
|
+
exit 1
|
21
|
+
}
|
16
22
|
|
17
23
|
if($IPAddress) {
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
try {
|
25
|
+
$vmAdapter = Get-VMNetworkAdapter -ManagementOS | Where-Object -Property SwitchId -EQ -Value $switch.Id
|
26
|
+
$adapter = Get-NetAdapter | Where-Object -Property DeviceId -EQ -Value $vmAdapter.DeviceId
|
27
|
+
New-NetIPAddress -IPAddress $IPAddress -PrefixLength $PrefixLength -InterfaceIndex $adapter.ifIndex
|
28
|
+
}
|
29
|
+
catch {
|
30
|
+
Write-ErrorMessage "Failed to add IP address ${IPAddress} for switch ${Name}: ${PSItem}"
|
31
|
+
exit 1
|
32
|
+
}
|
21
33
|
}
|
22
34
|
|
23
35
|
Write-OutputMessage $($switch | Select-Object -Property Name, Id,
|
@@ -5,5 +5,11 @@ param (
|
|
5
5
|
[string]$Id
|
6
6
|
)
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
try {
|
9
|
+
$vm = Get-VM -Id $VmId
|
10
|
+
Get-VMNetworkAdapter -VM $vm | Where-Object -Property Id -EQ -Value $Id | Remove-VMNetworkAdapter
|
11
|
+
}
|
12
|
+
catch {
|
13
|
+
Write-ErrorMessage "Failed to remove adapter ${Id} from VM ${VmId}: ${PSItem}"
|
14
|
+
exit 1
|
15
|
+
}
|
data/lib/vagrant-hypervnet.rb
CHANGED
@@ -84,6 +84,12 @@ module VagrantPlugins
|
|
84
84
|
end
|
85
85
|
hook.before(Vagrant::Action::Builtin::SyncedFolders, Action.ssh_server)
|
86
86
|
end
|
87
|
+
|
88
|
+
action_hook(:hypervnet, :provision) do |hook|
|
89
|
+
require_relative 'vagrant-hypervnet/action'
|
90
|
+
|
91
|
+
hook.after(Vagrant::Action::Builtin::Provision, Action.folder_sync)
|
92
|
+
end
|
87
93
|
end
|
88
94
|
end
|
89
95
|
end
|
data/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hypervnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Bompani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Vagrant plugin which extends Hyper-V provider implementing networks creation
|
14
14
|
and configuration.
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/vagrant-hypervnet.rb
|
26
26
|
- lib/vagrant-hypervnet/action.rb
|
27
27
|
- lib/vagrant-hypervnet/action/disable_builtin_network_configure.rb
|
28
|
+
- lib/vagrant-hypervnet/action/folder_sync.rb
|
28
29
|
- lib/vagrant-hypervnet/action/network.rb
|
29
30
|
- lib/vagrant-hypervnet/action/ssh_server.rb
|
30
31
|
- lib/vagrant-hypervnet/cap.rb
|