Skip to content

Commit

Permalink
bugfix: session gets closed if too many files to transfer, cleanup tr…
Browse files Browse the repository at this point in the history
…usted hosts list. troubleshoot guide improved.
  • Loading branch information
jagorjat committed Dec 25, 2014
1 parent d7a2fb9 commit ca47dd3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant-vmm/action/delete_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions lib/vagrant-vmm/scripts/get_network_config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 36 additions & 17 deletions lib/vagrant-vmm/scripts/sync_folders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{}
Expand Down Expand Up @@ -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 = @{}
Expand All @@ -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 = @{}
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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..."
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/vagrant-vmm/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module VMM
VERSION = "1.0.1"
VERSION = "1.0.2"
end
end

0 comments on commit ca47dd3

Please sign in to comment.