vagrant-windows 0.1.2 → 1.0.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/Gemfile.lock +6 -26
- data/README.md +92 -44
- data/lib/vagrant-windows/communication/winrmcommunicator.rb +213 -0
- data/lib/vagrant-windows/config/windows.rb +20 -16
- data/lib/vagrant-windows/config/winrm.rb +35 -15
- data/lib/vagrant-windows/errors.rb +17 -12
- data/lib/vagrant-windows/guest/windows.rb +45 -40
- data/lib/vagrant-windows/monkey_patches/chef_solo.rb +61 -0
- data/lib/vagrant-windows/monkey_patches/machine.rb +25 -0
- data/lib/vagrant-windows/monkey_patches/puppet.rb +100 -0
- data/lib/vagrant-windows/plugin.rb +96 -0
- data/lib/vagrant-windows/scripts/command_alias.ps1 +13 -4
- data/lib/vagrant-windows/scripts/ps_runas.ps1.erb +56 -0
- data/lib/vagrant-windows/version.rb +1 -1
- data/lib/vagrant-windows.rb +33 -0
- data/locales/en.yml +29 -0
- data/vagrant-windows.gemspec +0 -1
- metadata +17 -36
- data/lib/vagrant-windows/communication/winrm.rb +0 -185
- data/lib/vagrant-windows/monkey_patches/driver.rb +0 -57
- data/lib/vagrant-windows/monkey_patches/vm.rb +0 -16
- data/lib/vagrant-windows/winrm.rb +0 -82
- data/lib/vagrant_init.rb +0 -21
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-windows
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Paul Morton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: winrm
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,41 +20,22 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.1.1
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: vagrant
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.0.3
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.3
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
28
|
name: highline
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
30
|
requirements:
|
51
|
-
- -
|
31
|
+
- - '>='
|
52
32
|
- !ruby/object:Gem::Version
|
53
33
|
version: '0'
|
54
34
|
type: :runtime
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
37
|
requirements:
|
59
|
-
- -
|
38
|
+
- - '>='
|
60
39
|
- !ruby/object:Gem::Version
|
61
40
|
version: '0'
|
62
41
|
description: Windows Guest Support for Vagrant
|
@@ -71,42 +50,44 @@ files:
|
|
71
50
|
- Gemfile.lock
|
72
51
|
- README.md
|
73
52
|
- Rakefile
|
74
|
-
- lib/vagrant-windows
|
53
|
+
- lib/vagrant-windows.rb
|
54
|
+
- lib/vagrant-windows/communication/winrmcommunicator.rb
|
75
55
|
- lib/vagrant-windows/config/windows.rb
|
76
56
|
- lib/vagrant-windows/config/winrm.rb
|
77
57
|
- lib/vagrant-windows/errors.rb
|
78
58
|
- lib/vagrant-windows/guest/windows.rb
|
79
|
-
- lib/vagrant-windows/monkey_patches/
|
80
|
-
- lib/vagrant-windows/monkey_patches/
|
59
|
+
- lib/vagrant-windows/monkey_patches/chef_solo.rb
|
60
|
+
- lib/vagrant-windows/monkey_patches/machine.rb
|
61
|
+
- lib/vagrant-windows/monkey_patches/puppet.rb
|
62
|
+
- lib/vagrant-windows/plugin.rb
|
81
63
|
- lib/vagrant-windows/scripts/command_alias.ps1
|
82
64
|
- lib/vagrant-windows/scripts/mount_volume.ps1.erb
|
65
|
+
- lib/vagrant-windows/scripts/ps_runas.ps1.erb
|
83
66
|
- lib/vagrant-windows/version.rb
|
84
|
-
-
|
85
|
-
- lib/vagrant_init.rb
|
67
|
+
- locales/en.yml
|
86
68
|
- vagrant-windows.gemspec
|
87
69
|
homepage: ''
|
88
70
|
licenses: []
|
71
|
+
metadata: {}
|
89
72
|
post_install_message:
|
90
73
|
rdoc_options: []
|
91
74
|
require_paths:
|
92
75
|
- lib
|
93
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
77
|
requirements:
|
96
|
-
- -
|
78
|
+
- - '>='
|
97
79
|
- !ruby/object:Gem::Version
|
98
80
|
version: '0'
|
99
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
82
|
requirements:
|
102
|
-
- -
|
83
|
+
- - '>='
|
103
84
|
- !ruby/object:Gem::Version
|
104
85
|
version: '0'
|
105
86
|
requirements: []
|
106
87
|
rubyforge_project:
|
107
|
-
rubygems_version:
|
88
|
+
rubygems_version: 2.0.3
|
108
89
|
signing_key:
|
109
|
-
specification_version:
|
90
|
+
specification_version: 4
|
110
91
|
summary: A small gem that adds windows guest support to vagrant, uses WinRM as the
|
111
92
|
Communication Channel
|
112
93
|
test_files: []
|
@@ -1,185 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
|
3
|
-
require 'log4r'
|
4
|
-
#require 'em-winrm'
|
5
|
-
require 'winrm'
|
6
|
-
require 'highline'
|
7
|
-
|
8
|
-
require 'vagrant/util/ansi_escape_code_remover'
|
9
|
-
require 'vagrant/util/file_mode'
|
10
|
-
require 'vagrant/util/platform'
|
11
|
-
require 'vagrant/util/retryable'
|
12
|
-
|
13
|
-
module Vagrant
|
14
|
-
module Communication
|
15
|
-
# Provides communication with the VM via WinRM.
|
16
|
-
class WinRM < Base
|
17
|
-
|
18
|
-
include Util::ANSIEscapeCodeRemover
|
19
|
-
include Util::Retryable
|
20
|
-
|
21
|
-
attr_reader :logger
|
22
|
-
attr_reader :vm
|
23
|
-
|
24
|
-
def initialize(vm)
|
25
|
-
@vm = vm
|
26
|
-
@logger = Log4r::Logger.new("vagrant::communication::winrm")
|
27
|
-
@co = nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def ready?
|
31
|
-
logger.debug("Checking whether WinRM is ready...")
|
32
|
-
|
33
|
-
Timeout.timeout(@vm.config.winrm.timeout) do
|
34
|
-
execute "hostname"
|
35
|
-
end
|
36
|
-
|
37
|
-
# If we reached this point then we successfully connected
|
38
|
-
logger.info("WinRM is ready!")
|
39
|
-
true
|
40
|
-
rescue Timeout::Error, HTTPClient::KeepAliveDisconnected => e
|
41
|
-
#, Errors::SSHConnectionRefused, Net::SSH::Disconnect => e
|
42
|
-
# The above errors represent various reasons that WinRM may not be
|
43
|
-
# ready yet. Return false.
|
44
|
-
logger.info("WinRM not up yet: #{e.inspect}")
|
45
|
-
|
46
|
-
return false
|
47
|
-
end
|
48
|
-
|
49
|
-
# Wrap Sudo in execute.... One day we could integrate with UAC, but Icky
|
50
|
-
def sudo(command, opts=nil, &block)
|
51
|
-
execute(command,opts,&block)
|
52
|
-
end
|
53
|
-
|
54
|
-
def execute(command, opts=nil, &block)
|
55
|
-
|
56
|
-
# Connect to WinRM, giving it a few tries
|
57
|
-
logger.info("Connecting to WinRM: #{@vm.winrm.info[:host]}:#{@vm.winrm.info[:port]}")
|
58
|
-
|
59
|
-
opts = {
|
60
|
-
:error_check => true,
|
61
|
-
:error_class => Errors::VagrantError,
|
62
|
-
:error_key => :winrm_bad_exit_status,
|
63
|
-
:command => command,
|
64
|
-
:sudo => false,
|
65
|
-
:shell => :powershell
|
66
|
-
}.merge(opts || {})
|
67
|
-
|
68
|
-
# Connect via WinRM and execute the command in the shell.
|
69
|
-
exceptions = [HTTPClient::KeepAliveDisconnected]
|
70
|
-
exit_status = retryable(:tries => @vm.config.winrm.max_tries, :on => exceptions, :sleep => 10) do
|
71
|
-
logger.debug "WinRM Trying to connect"
|
72
|
-
shell_execute(command,opts[:shell], &block)
|
73
|
-
end
|
74
|
-
|
75
|
-
logger.debug("#{command} EXIT STATUS #{exit_status.inspect}")
|
76
|
-
|
77
|
-
# Check for any errors
|
78
|
-
if opts[:error_check] && exit_status != 0
|
79
|
-
# The error classes expect the translation key to be _key,
|
80
|
-
# but that makes for an ugly configuration parameter, so we
|
81
|
-
# set it here from `error_key`
|
82
|
-
error_opts = opts.merge(:_key => opts[:error_key])
|
83
|
-
raise opts[:error_class], error_opts
|
84
|
-
end
|
85
|
-
|
86
|
-
# Return the exit status
|
87
|
-
exit_status
|
88
|
-
end
|
89
|
-
|
90
|
-
def new_session
|
91
|
-
opts = {
|
92
|
-
:user => vm.config.winrm.username,
|
93
|
-
:pass => vm.config.winrm.password,
|
94
|
-
:host => vm.config.winrm.host,
|
95
|
-
:port => vm.winrm.info[:port],
|
96
|
-
:operation_timeout => vm.config.winrm.timeout,
|
97
|
-
:basic_auth_only => true
|
98
|
-
}.merge ({})
|
99
|
-
|
100
|
-
# create a session
|
101
|
-
logger.info("Attempting WinRM session with options: #{opts}")
|
102
|
-
begin
|
103
|
-
endpoint = "http://#{opts[:host]}:#{opts[:port]}/wsman"
|
104
|
-
client = ::WinRM::WinRMWebService.new(endpoint, :plaintext, opts)
|
105
|
-
client.set_timeout(opts[:operation_timeout]) if opts[:operation_timeout]
|
106
|
-
rescue ::WinRM::WinRMAuthorizationError => error
|
107
|
-
raise ::WinRM::WinRMAuthorizationError.new("#{error.message}@#{opts[:host]}")
|
108
|
-
end
|
109
|
-
|
110
|
-
client
|
111
|
-
end
|
112
|
-
|
113
|
-
def session
|
114
|
-
@session ||= new_session
|
115
|
-
end
|
116
|
-
|
117
|
-
def h
|
118
|
-
@highline ||= HighLine.new
|
119
|
-
end
|
120
|
-
|
121
|
-
def print_data(data, color = :green)
|
122
|
-
if data =~ /\n/
|
123
|
-
data.split(/\n/).each { |d| print_data(d, color) }
|
124
|
-
else
|
125
|
-
puts h.color(data.chomp, color)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def upload(from, to)
|
130
|
-
file = "winrm-upload-#{rand()}"
|
131
|
-
file_name = (session.cmd("echo %TEMP%\\#{file}"))[:data][0][:stdout].chomp
|
132
|
-
session.powershell <<-EOH
|
133
|
-
if(Test-Path #{to})
|
134
|
-
{
|
135
|
-
rm #{to}
|
136
|
-
}
|
137
|
-
EOH
|
138
|
-
Base64.encode64(IO.binread(from)).gsub("\n",'').chars.to_a.each_slice(8000-file_name.size) do |chunk|
|
139
|
-
out = session.cmd( "echo #{chunk.join} >> \"#{file_name}\"" )
|
140
|
-
end
|
141
|
-
execute "mkdir [System.IO.Path]::GetDirectoryName(\"#{to}\")"
|
142
|
-
execute <<-EOH
|
143
|
-
$base64_string = Get-Content \"#{file_name}\"
|
144
|
-
$bytes = [System.Convert]::FromBase64String($base64_string)
|
145
|
-
$new_file = [System.IO.Path]::GetFullPath(\"#{to}\")
|
146
|
-
[System.IO.File]::WriteAllBytes($new_file,$bytes)
|
147
|
-
EOH
|
148
|
-
end
|
149
|
-
|
150
|
-
protected
|
151
|
-
|
152
|
-
# Executes the command on an SSH connection within a login shell.
|
153
|
-
def shell_execute(command,shell = :powershell)
|
154
|
-
logger.info("Execute: #{command}")
|
155
|
-
exit_status = nil
|
156
|
-
|
157
|
-
if shell.eql? :cmd
|
158
|
-
output = session.cmd(command) do |out,error|
|
159
|
-
print_data(out) if out
|
160
|
-
print_data(error, :red) if error
|
161
|
-
end
|
162
|
-
elsif shell.eql? :powershell
|
163
|
-
new_command = File.read(File.expand_path("#{File.dirname(__FILE__)}/../scripts/command_alias.ps1"))
|
164
|
-
new_command << "\r\n"
|
165
|
-
new_command << command
|
166
|
-
output = session.powershell(new_command) do |out,error|
|
167
|
-
print_data(out) if out
|
168
|
-
print_data(error, :red) if error
|
169
|
-
end
|
170
|
-
else
|
171
|
-
raise Vagrant::Errors::WinRMInvalidShell, "#{shell} is not a valid type of shell"
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
exit_status = output[:exitcode]
|
176
|
-
logger.debug exit_status.inspect
|
177
|
-
|
178
|
-
# Return the final exit status
|
179
|
-
return exit_status
|
180
|
-
rescue ::WinRM::WinRMHTTPTransportError => e
|
181
|
-
raise Vagrant::Errors::WinRMTimeout, e.message
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'vagrant/driver/virtualbox_base'
|
2
|
-
require 'vagrant/driver/virtualbox'
|
3
|
-
|
4
|
-
|
5
|
-
module Vagrant
|
6
|
-
module Driver
|
7
|
-
|
8
|
-
class VirtualBox_4_2 < VirtualBoxBase
|
9
|
-
def read_mac_addresses
|
10
|
-
macs = {}
|
11
|
-
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
12
|
-
info.split("\n").each do |line|
|
13
|
-
if matcher = /^macaddress(\d+)="(.+?)"$/.match(line)
|
14
|
-
adapter = matcher[1].to_i
|
15
|
-
mac = matcher[2].to_s
|
16
|
-
macs[adapter] = mac
|
17
|
-
end
|
18
|
-
end
|
19
|
-
macs
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class VirtualBox_4_1 < VirtualBoxBase
|
24
|
-
def read_mac_addresses
|
25
|
-
macs = {}
|
26
|
-
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
27
|
-
info.split("\n").each do |line|
|
28
|
-
if matcher = /^macaddress(\d+)="(.+?)"$/.match(line)
|
29
|
-
adapter = matcher[1].to_i
|
30
|
-
mac = matcher[2].to_s
|
31
|
-
macs[adapter] = mac
|
32
|
-
end
|
33
|
-
end
|
34
|
-
macs
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class VirtualBox_4_0 < VirtualBoxBase
|
39
|
-
def read_mac_addresses
|
40
|
-
macs = {}
|
41
|
-
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
42
|
-
info.split("\n").each do |line|
|
43
|
-
if matcher = /^macaddress(\d+)="(.+?)"$/.match(line)
|
44
|
-
adapter = matcher[1].to_i
|
45
|
-
mac = matcher[2].to_s
|
46
|
-
macs[adapter] = mac
|
47
|
-
end
|
48
|
-
end
|
49
|
-
macs
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class VirtualBox < VirtualBoxBase
|
54
|
-
def_delegator :@driver, :read_mac_addresses
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
class VM
|
3
|
-
def winrm
|
4
|
-
@winrm ||= WinRM.new(self)
|
5
|
-
end
|
6
|
-
|
7
|
-
def channel
|
8
|
-
if @guest.class.eql? Vagrant::Guest::Windows
|
9
|
-
@channel ||= Communication::WinRM.new(self)
|
10
|
-
else
|
11
|
-
@channel ||= Communication::SSH.new(self)
|
12
|
-
end
|
13
|
-
@channel
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
#require 'em-winrm'
|
3
|
-
|
4
|
-
module Vagrant
|
5
|
-
# Manages WINRM access to a specific environment. Allows an environment to
|
6
|
-
# run commands, upload files, and check if a host is up.
|
7
|
-
class WinRM
|
8
|
-
include Util::SafeExec
|
9
|
-
|
10
|
-
def initialize(vm)
|
11
|
-
@vm = vm
|
12
|
-
@logger = Log4r::Logger.new("vagrant::winrm")
|
13
|
-
end
|
14
|
-
|
15
|
-
# Returns a hash of information necessary for accessing this
|
16
|
-
# virtual machine via WINRM.
|
17
|
-
#
|
18
|
-
# @return [Hash]
|
19
|
-
def info
|
20
|
-
results = {
|
21
|
-
:host => @vm.config.winrm.host,
|
22
|
-
:port => @vm.config.winrm.port || @vm.driver.ssh_port(@vm.config.winrm.guest_port),
|
23
|
-
:username => @vm.config.winrm.username
|
24
|
-
}
|
25
|
-
|
26
|
-
# This can happen if no port is set and for some reason Vagrant
|
27
|
-
# can't detect an SSH port.
|
28
|
-
raise Errors::WinRMPortNotDetected if !results[:port]
|
29
|
-
|
30
|
-
# Return the results
|
31
|
-
return results
|
32
|
-
end
|
33
|
-
|
34
|
-
# Checks if this environment's machine is up (i.e. responding to WINRM).
|
35
|
-
#
|
36
|
-
# @return [Boolean]
|
37
|
-
def up?
|
38
|
-
# We have to determine the port outside of the block since it uses
|
39
|
-
# API calls which can only be used from the main thread in JRuby on
|
40
|
-
# Windows
|
41
|
-
ssh_port = port
|
42
|
-
|
43
|
-
require 'timeout'
|
44
|
-
Timeout.timeout(@env.config.ssh.timeout) do
|
45
|
-
execute 'hostname'
|
46
|
-
end
|
47
|
-
|
48
|
-
true
|
49
|
-
rescue Timeout::Error, Errno::ECONNREFUSED
|
50
|
-
return false
|
51
|
-
end
|
52
|
-
|
53
|
-
# Returns the port which is either given in the options hash or taken from
|
54
|
-
# the config by finding it in the forwarded ports hash based on the
|
55
|
-
# `config.ssh.forwarded_port_key`.
|
56
|
-
def port(opts={})
|
57
|
-
# Check if port was specified in options hash
|
58
|
-
return opts[:port] if opts[:port]
|
59
|
-
|
60
|
-
# Check if a port was specified in the config
|
61
|
-
return @env.config.winrm.port if @env.config.winrm.port
|
62
|
-
|
63
|
-
# Check if we have an SSH forwarded port
|
64
|
-
pnum_by_name = nil
|
65
|
-
pnum_by_destination = nil
|
66
|
-
@logger.info("Looking for winrm port: #{opts}")
|
67
|
-
@logger.info("Looking for winrm port: #{env.config.winrm.inspect}")
|
68
|
-
|
69
|
-
env.vm.vm.network_adapters.each do |na|
|
70
|
-
# Look for the port number by destination...
|
71
|
-
pnum_by_destination = na.nat_driver.forwarded_ports.detect do |fp|
|
72
|
-
fp.guestport == env.config.winrm.guest_port
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
return pnum_by_destination.hostport if pnum_by_destination
|
77
|
-
|
78
|
-
# This should NEVER happen.
|
79
|
-
raise Errors::WinRMPortNotDetected
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
data/lib/vagrant_init.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#Add Windows Guest Defintion
|
2
|
-
require 'vagrant-windows/guest/windows'
|
3
|
-
|
4
|
-
#Add Configuration Items
|
5
|
-
require 'vagrant-windows/config/windows'
|
6
|
-
require 'vagrant-windows/config/winrm'
|
7
|
-
|
8
|
-
# Add WinRM Communication Channel
|
9
|
-
require 'vagrant-windows/communication/winrm'
|
10
|
-
|
11
|
-
#Monkey Patch the VM object to support multiple channels
|
12
|
-
require 'vagrant-windows/monkey_patches/vm'
|
13
|
-
|
14
|
-
#Monkey Patch the driver to support returning a mapping of mac addresses to nics
|
15
|
-
require 'vagrant-windows/monkey_patches/driver'
|
16
|
-
|
17
|
-
require 'vagrant-windows/winrm'
|
18
|
-
|
19
|
-
#Errors are good
|
20
|
-
require 'vagrant-windows/errors'
|
21
|
-
|