Skip to content

Commit ca47dd3

Browse files
author
jagorjat
committed
bugfix: session gets closed if too many files to transfer, cleanup trusted hosts list. troubleshoot guide improved.
1 parent d7a2fb9 commit ca47dd3

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ Travis CI: [![Build Status](https://travis-ci.org/jarig/vagrant-vmm.svg?branch=m
22

33
# Vagrant Virtual Machine Manager (VMM) Plugin
44

5-
**UNDER DEVELOPMENT**
6-
75
Vagrant is a tool for building and distributing development environments.
86

97
This provider will allow you to create VMs in the remote Virtual Machine Manager.
@@ -100,17 +98,21 @@ conf.proxy_server_address = 'my-proxy-to-vmm'
10098

10199
Check that winrm is configured properly in the VM, if default username is used (vagrant/vagrant) then ensure that winrm accepts unencrypted connection and Basic auth.
102100

103-
Enable basic auth (in VM)
101+
Enable basic auth and unencrypted connection (in VM).
104102
```
103+
In elevated cmd
105104
winrm set winrm/config/service/auth @{Basic="true"}
105+
winrm set winrm/config/service @{AllowUnencrypted="true"}
106106
```
107107

108-
Allow unencrypted connection (in VM)
108+
### Unencrypted traffic is currently disabled in the client configuration
109+
110+
Run following command on your machine as well:
109111
```
112+
In elevated cmd
110113
winrm set winrm/config/service @{AllowUnencrypted="true"}
111114
```
112115

113-
114116
## Contributing
115117

116118
1. Fork it ( https://github.com/jarig/vagrant-vmm/fork )

lib/vagrant-vmm/action/delete_vm.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ def call(env)
1313
vmm_server_address: vmm_server_address,
1414
proxy_server_address: env[:machine].provider_config.proxy_server_address
1515
}
16+
1617
env[:ui].info("Deleting the machine...")
1718
env[:machine].provider.driver.delete_vm(options)
1819
env[:machine].provider.reset_state
19-
20+
env[:ui].info("Machine removed.")
21+
2022
@app.call(env)
2123
end
2224
end

lib/vagrant-vmm/scripts/get_network_config.ps1

-10
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ if ( $address_to_use -ne $null )
6666
$ip = Read-Host 'Enter VM IP address:'
6767
}
6868

69-
if ( $address_to_use -as [ipaddress] )
70-
{
71-
$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts
72-
if ( !$trusted_hosts.Value.Contains($address_to_use) )
73-
{
74-
Write-host "Adding $address_to_use to trusted host list"
75-
$new_th_values = "$($trusted_hosts.Value),$address_to_use"
76-
set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force
77-
}
78-
}
7969

8070
$resultHash = @{
8171
address = $address_to_use

lib/vagrant-vmm/scripts/sync_folders.ps1

+36-17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ $Dir = Split-Path $script:MyInvocation.MyCommand.Path
2929
# convert from json to ps object
3030
$folders_to_sync_obj = ConvertFrom-Json $folders_to_sync
3131
$delimiter = " || "
32+
$creds_to_vm = Get-Creds $vm_address "Credentials for access to the VM ($vm_address) via WinRM" $winrm_vm_username $winrm_vm_password
33+
34+
# add to trusted hosts
35+
$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts
36+
if ( !$trusted_hosts.Value.Contains($vm_address) )
37+
{
38+
Write-host "Adding $vm_address to trusted host list"
39+
$new_th_values = "$($trusted_hosts.Value),$vm_address"
40+
set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force
41+
}
42+
3243

3344
function Get-file-hash($source_paths, $delimiter) {
3445
$source_files = @{}
@@ -63,21 +74,20 @@ function Get-remote-file-hash($source_paths, $delimiter, $session) {
6374
return Invoke-Command -Session $session -ScriptBlock ${function:Get-file-hash} -ArgumentList $source_paths, $delimiter
6475
}
6576

66-
$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts
67-
if ( !$trusted_hosts.Value.Contains($vm_address) )
68-
{
69-
Write-host "Adding $vm_address to trusted host list"
70-
$new_th_values = "$($trusted_hosts.Value),$vm_address"
71-
set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force
72-
}
73-
74-
$creds_to_vm = Get-Creds $vm_address "Credentials for access to the VM ($vm_address) via WinRM" $winrm_vm_username $winrm_vm_password
75-
$auth_method = "default"
76-
if ( !$creds_to_vm.UserName.contains("\") -and !$creds_to_vm.UserName.contains("@") )
77-
{
78-
$auth_method = "basic"
77+
function Get-session {
78+
$session = $script:session
79+
if ( !$session -or $session.State.ToString() -ne "Opened" )
80+
{
81+
$auth_method = "default"
82+
if ( !$creds_to_vm.UserName.contains("\") -and !$creds_to_vm.UserName.contains("@") )
83+
{
84+
$auth_method = "basic"
85+
}
86+
$session = New-PSSession -ComputerName $vm_address -Credential $creds_to_vm -Authentication $auth_method
87+
$script:session = $session
88+
}
89+
return $script:session
7990
}
80-
$session = New-PSSession -ComputerName $vm_address -Credential $creds_to_vm -Authentication $auth_method
8191

8292
# Compare source and destination files
8393
$remove_files = @{}
@@ -92,7 +102,7 @@ foreach ( $hst_path in $folders_to_sync_obj.psobject.properties.Name )
92102
}
93103

94104
$source_files = Get-file-hash $folder_mappings.Keys $delimiter
95-
$destination_files = Get-remote-file-hash $folder_mappings.Values $delimiter $session
105+
$destination_files = Get-remote-file-hash $folder_mappings.Values $delimiter $(Get-session)
96106
if (!$destination_files) {
97107
$destination_files = @{}
98108
}
@@ -116,7 +126,7 @@ foreach ( $hst_path in $folder_mappings.Keys )
116126
}
117127

118128
# create file share on the remote machine
119-
Invoke-Command -Session $session -ScriptBlock {
129+
Invoke-Command -Session $(Get-session) -ScriptBlock {
120130
$fileshare_dest = "$($env:SystemDrive)\vagrant-sync"
121131
if (Test-path $fileshare_dest)
122132
{
@@ -164,7 +174,7 @@ foreach ( $hst_path in $copy_files.Keys)
164174

165175
# copy from fileshare to the dest locations on the remote machine
166176
# as well as remove files that shouldn't be there
167-
Invoke-Command -Session $session -ScriptBlock {
177+
Invoke-Command -Session $(Get-session) -ScriptBlock {
168178
$remove_files = $using:remove_files
169179
$fileshare_dest = "$($env:SystemDrive)\vagrant-sync"
170180
write-host "$(&hostname) :: Distributing files from $fileshare_dest..."
@@ -195,6 +205,15 @@ Invoke-Command -Session $session -ScriptBlock {
195205

196206
Remove-PSSession -Id $session.Id
197207

208+
# remove vm_address from trusted hosts
209+
$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts
210+
if ( $trusted_hosts.Value.Contains($vm_address) )
211+
{
212+
Write-host "Removing $vm_address from trusted host list"
213+
$new_th_values = $trusted_hosts.Value -replace ",?$vm_address", ""
214+
set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force
215+
}
216+
198217
$resultHash = $folder_mappings
199218
$result = ConvertTo-Json $resultHash
200219
Write-Output-Message $result

lib/vagrant-vmm/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module VagrantPlugins
22
module VMM
3-
VERSION = "1.0.1"
3+
VERSION = "1.0.2"
44
end
55
end

0 commit comments

Comments
 (0)