From ca47dd33f8e851f03abd41ffe6faf83da9520981 Mon Sep 17 00:00:00 2001 From: jagorjat Date: Thu, 25 Dec 2014 16:57:20 +0200 Subject: [PATCH] bugfix: session gets closed if too many files to transfer, cleanup trusted hosts list. troubleshoot guide improved. --- README.md | 12 +++-- lib/vagrant-vmm/action/delete_vm.rb | 4 +- .../scripts/get_network_config.ps1 | 10 ---- lib/vagrant-vmm/scripts/sync_folders.ps1 | 53 +++++++++++++------ lib/vagrant-vmm/version.rb | 2 +- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 99bfd76..196ec53 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Travis CI: [![Build Status](https://travis-ci.org/jarig/vagrant-vmm.svg?branch=m # Vagrant Virtual Machine Manager (VMM) Plugin -**UNDER DEVELOPMENT** - Vagrant is a tool for building and distributing development environments. 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' 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. -Enable basic auth (in VM) +Enable basic auth and unencrypted connection (in VM). ``` +In elevated cmd winrm set winrm/config/service/auth @{Basic="true"} +winrm set winrm/config/service @{AllowUnencrypted="true"} ``` -Allow unencrypted connection (in VM) +### Unencrypted traffic is currently disabled in the client configuration + +Run following command on your machine as well: ``` +In elevated cmd winrm set winrm/config/service @{AllowUnencrypted="true"} ``` - ## Contributing 1. Fork it ( https://github.com/jarig/vagrant-vmm/fork ) diff --git a/lib/vagrant-vmm/action/delete_vm.rb b/lib/vagrant-vmm/action/delete_vm.rb index 8189766..026a539 100644 --- a/lib/vagrant-vmm/action/delete_vm.rb +++ b/lib/vagrant-vmm/action/delete_vm.rb @@ -13,10 +13,12 @@ def call(env) vmm_server_address: vmm_server_address, proxy_server_address: env[:machine].provider_config.proxy_server_address } + env[:ui].info("Deleting the machine...") env[:machine].provider.driver.delete_vm(options) env[:machine].provider.reset_state - + env[:ui].info("Machine removed.") + @app.call(env) end end diff --git a/lib/vagrant-vmm/scripts/get_network_config.ps1 b/lib/vagrant-vmm/scripts/get_network_config.ps1 index 93a06f9..fa00922 100644 --- a/lib/vagrant-vmm/scripts/get_network_config.ps1 +++ b/lib/vagrant-vmm/scripts/get_network_config.ps1 @@ -66,16 +66,6 @@ if ( $address_to_use -ne $null ) $ip = Read-Host 'Enter VM IP address:' } -if ( $address_to_use -as [ipaddress] ) -{ - $trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts - if ( !$trusted_hosts.Value.Contains($address_to_use) ) - { - Write-host "Adding $address_to_use to trusted host list" - $new_th_values = "$($trusted_hosts.Value),$address_to_use" - set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force - } -} $resultHash = @{ address = $address_to_use diff --git a/lib/vagrant-vmm/scripts/sync_folders.ps1 b/lib/vagrant-vmm/scripts/sync_folders.ps1 index a65af6d..1082fd8 100644 --- a/lib/vagrant-vmm/scripts/sync_folders.ps1 +++ b/lib/vagrant-vmm/scripts/sync_folders.ps1 @@ -29,6 +29,17 @@ $Dir = Split-Path $script:MyInvocation.MyCommand.Path # convert from json to ps object $folders_to_sync_obj = ConvertFrom-Json $folders_to_sync $delimiter = " || " +$creds_to_vm = Get-Creds $vm_address "Credentials for access to the VM ($vm_address) via WinRM" $winrm_vm_username $winrm_vm_password + +# add to trusted hosts +$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts +if ( !$trusted_hosts.Value.Contains($vm_address) ) +{ + Write-host "Adding $vm_address to trusted host list" + $new_th_values = "$($trusted_hosts.Value),$vm_address" + set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force +} + function Get-file-hash($source_paths, $delimiter) { $source_files = @{} @@ -63,21 +74,20 @@ function Get-remote-file-hash($source_paths, $delimiter, $session) { return Invoke-Command -Session $session -ScriptBlock ${function:Get-file-hash} -ArgumentList $source_paths, $delimiter } -$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts -if ( !$trusted_hosts.Value.Contains($vm_address) ) -{ - Write-host "Adding $vm_address to trusted host list" - $new_th_values = "$($trusted_hosts.Value),$vm_address" - set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force -} - -$creds_to_vm = Get-Creds $vm_address "Credentials for access to the VM ($vm_address) via WinRM" $winrm_vm_username $winrm_vm_password -$auth_method = "default" -if ( !$creds_to_vm.UserName.contains("\") -and !$creds_to_vm.UserName.contains("@") ) -{ - $auth_method = "basic" +function Get-session { + $session = $script:session + if ( !$session -or $session.State.ToString() -ne "Opened" ) + { + $auth_method = "default" + if ( !$creds_to_vm.UserName.contains("\") -and !$creds_to_vm.UserName.contains("@") ) + { + $auth_method = "basic" + } + $session = New-PSSession -ComputerName $vm_address -Credential $creds_to_vm -Authentication $auth_method + $script:session = $session + } + return $script:session } -$session = New-PSSession -ComputerName $vm_address -Credential $creds_to_vm -Authentication $auth_method # Compare source and destination files $remove_files = @{} @@ -92,7 +102,7 @@ foreach ( $hst_path in $folders_to_sync_obj.psobject.properties.Name ) } $source_files = Get-file-hash $folder_mappings.Keys $delimiter -$destination_files = Get-remote-file-hash $folder_mappings.Values $delimiter $session +$destination_files = Get-remote-file-hash $folder_mappings.Values $delimiter $(Get-session) if (!$destination_files) { $destination_files = @{} } @@ -116,7 +126,7 @@ foreach ( $hst_path in $folder_mappings.Keys ) } # create file share on the remote machine -Invoke-Command -Session $session -ScriptBlock { +Invoke-Command -Session $(Get-session) -ScriptBlock { $fileshare_dest = "$($env:SystemDrive)\vagrant-sync" if (Test-path $fileshare_dest) { @@ -164,7 +174,7 @@ foreach ( $hst_path in $copy_files.Keys) # copy from fileshare to the dest locations on the remote machine # as well as remove files that shouldn't be there -Invoke-Command -Session $session -ScriptBlock { +Invoke-Command -Session $(Get-session) -ScriptBlock { $remove_files = $using:remove_files $fileshare_dest = "$($env:SystemDrive)\vagrant-sync" write-host "$(&hostname) :: Distributing files from $fileshare_dest..." @@ -195,6 +205,15 @@ Invoke-Command -Session $session -ScriptBlock { Remove-PSSession -Id $session.Id +# remove vm_address from trusted hosts +$trusted_hosts = get-item wsman:\localhost\Client\TrustedHosts +if ( $trusted_hosts.Value.Contains($vm_address) ) +{ + Write-host "Removing $vm_address from trusted host list" + $new_th_values = $trusted_hosts.Value -replace ",?$vm_address", "" + set-item wsman:\localhost\Client\TrustedHosts $new_th_values -Force +} + $resultHash = $folder_mappings $result = ConvertTo-Json $resultHash Write-Output-Message $result diff --git a/lib/vagrant-vmm/version.rb b/lib/vagrant-vmm/version.rb index a9bf0fd..6e2b9bd 100644 --- a/lib/vagrant-vmm/version.rb +++ b/lib/vagrant-vmm/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module VMM - VERSION = "1.0.1" + VERSION = "1.0.2" end end