vagrant-windows 1.7.0.pre.1 → 1.7.0.pre.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e0d8f67d7fd5775bc1dfffb01aee0f766c5c512
4
- data.tar.gz: fd24bde9a3b09754acb450f2995a61c0292a7294
3
+ metadata.gz: 668a6e4a7bc645fa0e951e3f04a33257e4eb5890
4
+ data.tar.gz: e080e229467c6a45f6d3ae5a180e1c8b4ed92528
5
5
  SHA512:
6
- metadata.gz: 081a4d22f0f528b6672009678de4c7558c24059036a62c5d8e595073de8cc4566c38f72c78bacd3a67d5a9da6b2a2b8d96a356dc26b391adf8bb59c11a75ec57
7
- data.tar.gz: c11a66f853413fc9ca9970ce767c1a71ddd3c0193766a9cf7980b9aeb5af67dfff414720e1ea3e4116b0072925353bd780d300bbe94ab75f59372b23319f1d8e
6
+ metadata.gz: 77c523c5c5bd2a464cb4cabc5ce613f31ec4ab7f76c8765fffdc79fffd9175b90dfd59cd19cac4cdc4c3527cf5ba7392b7933e29cbcfaed50702b998c81761e2
7
+ data.tar.gz: d2b1f5f4198cdaa1e3b88480b95e69d8af18ce4f01d55836ee7a361e488a4168e821b7b9d336857b8165dca7163b6b0e57e0c63483115d7881dc0076cec33836
@@ -12,13 +12,10 @@ module VagrantWindows
12
12
  PS_GET_WSMAN_VER = '((test-wsman).productversion.split(" ") | select -last 1).split("\.")[0]'
13
13
  WQL_NET_ADAPTERS_V2 = 'SELECT * FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL'
14
14
 
15
- attr_reader :logger
16
- attr_reader :winrmshell
17
-
18
- def initialize(winrmshell)
19
- @logger = Log4r::Logger.new("vagrant_windows::communication::winrmshell")
15
+ def initialize(communicator)
16
+ @logger = Log4r::Logger.new("vagrant_windows::communication::guestnetwork")
20
17
  @logger.debug("initializing WinRMShell")
21
- @winrmshell = winrmshell
18
+ @communicator = communicator
22
19
  end
23
20
 
24
21
  # Returns an array of all NICs on the guest. Each array entry is a
@@ -33,13 +30,13 @@ module VagrantWindows
33
30
  #
34
31
  # @return [Boolean]
35
32
  def is_dhcp_enabled(nic_index)
36
- has_dhcp_enabled = false
37
- cmd = "Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter \"Index=#{nic_index} and DHCPEnabled=True\""
38
- @winrmshell.powershell(cmd) do |type, line|
39
- has_dhcp_enabled = !line.nil?
40
- end
41
- @logger.debug("NIC #{nic_index} has DHCP enabled: #{has_dhcp_enabled}")
42
- has_dhcp_enabled
33
+ cmd = <<-EOH
34
+ if (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=#{nic_index} and DHCPEnabled=True") {
35
+ exit 0
36
+ }
37
+ exit 1
38
+ EOH
39
+ @communicator.test(cmd)
43
40
  end
44
41
 
45
42
  # Configures the specified interface for DHCP
@@ -50,7 +47,7 @@ module VagrantWindows
50
47
  @logger.info("Configuring NIC #{net_connection_id} for DHCP")
51
48
  if !is_dhcp_enabled(nic_index)
52
49
  netsh = "netsh interface ip set address \"#{net_connection_id}\" dhcp"
53
- @winrmshell.powershell(netsh)
50
+ @communicator.execute(netsh)
54
51
  end
55
52
  end
56
53
 
@@ -64,7 +61,7 @@ module VagrantWindows
64
61
  @logger.info("Configuring NIC #{net_connection_id} using static ip #{ip}")
65
62
  #netsh interface ip set address "Local Area Connection 2" static 192.168.33.10 255.255.255.0
66
63
  netsh = "netsh interface ip set address \"#{net_connection_id}\" static #{ip} #{netmask}"
67
- @winrmshell.powershell(netsh)
64
+ @communicator.execute(netsh)
68
65
  end
69
66
 
70
67
  # Sets all networks on the guest to 'Work Network' mode. This is
@@ -73,7 +70,7 @@ module VagrantWindows
73
70
  def set_all_networks_to_work()
74
71
  @logger.info("Setting all networks to 'Work Network'")
75
72
  command = VagrantWindows.load_script("set_work_network.ps1")
76
- @winrmshell.powershell(command)
73
+ @communicator.execute(command)
77
74
  end
78
75
 
79
76
 
@@ -86,7 +83,7 @@ module VagrantWindows
86
83
  def wsman_version()
87
84
  @logger.debug("querying WSMan version")
88
85
  version = ''
89
- @winrmshell.powershell(PS_GET_WSMAN_VER) do |type, line|
86
+ @communicator.execute(PS_GET_WSMAN_VER) do |type, line|
90
87
  version = version + "#{line}" if type == :stdout && !line.nil?
91
88
  end
92
89
  @logger.debug("wsman version: #{version}")
@@ -102,7 +99,7 @@ module VagrantWindows
102
99
  @logger.debug("querying network adapters")
103
100
  # Get all NICs that have a MAC address
104
101
  # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
105
- adapters = @winrmshell.wql(WQL_NET_ADAPTERS_V2)[:win32_network_adapter]
102
+ adapters = @communicator.execute(WQL_NET_ADAPTERS_V2, { :shell => :wql } )[:win32_network_adapter]
106
103
  @logger.debug("#{adapters.inspect}")
107
104
  return adapters
108
105
  end
@@ -117,7 +114,7 @@ module VagrantWindows
117
114
  def network_adapters_v3_winrm()
118
115
  winrs_v3_get_adapters_ps1 = VagrantWindows.load_script("winrs_v3_get_adapters.ps1")
119
116
  output = ''
120
- @winrmshell.powershell(winrs_v3_get_adapters_ps1) do |type, line|
117
+ @communicator.execute(winrs_v3_get_adapters_ps1) do |type, line|
121
118
  output = output + "#{line}" if type == :stdout && !line.nil?
122
119
  end
123
120
  adapters = []
@@ -49,9 +49,7 @@ module VagrantWindows
49
49
  def execute(command, opts={}, &block)
50
50
  # If this is a *nix command with no Windows equivilant, don't run it
51
51
  win_friendly_cmd = @linux_cmd_filter.filter(command)
52
- if (win_friendly_cmd.empty?)
53
- return { :exitcode => 0, :stderr => '', :stdout => '' }
54
- end
52
+ return 0 if win_friendly_cmd.empty?
55
53
 
56
54
  opts = {
57
55
  :error_check => true,
@@ -60,20 +58,21 @@ module VagrantWindows
60
58
  :command => win_friendly_cmd,
61
59
  :shell => :powershell
62
60
  }.merge(opts || {})
63
- exit_status = do_execute(win_friendly_cmd, opts[:shell], &block)
64
- if opts[:error_check] && exit_status != 0
65
- raise_execution_error(opts, exit_status)
66
- end
67
- exit_status
61
+
62
+ win_friendly_cmd << "\r\nexit $LASTEXITCODE" if opts[:shell] == :powershell
63
+ output = winrmshell.send(opts[:shell], win_friendly_cmd, &block)
64
+
65
+ return output if opts[:shell] == :wql
66
+ exitcode = output[:exitcode]
67
+ raise_execution_error(opts, exitcode) if opts[:error_check] && exitcode != 0
68
+ exitcode
68
69
  end
69
70
  alias_method :sudo, :execute
70
71
 
71
72
  def test(command, opts=nil)
72
73
  # If this is a *nix command with no Windows equivilant, don't run it
73
74
  win_friendly_cmd = @linux_cmd_filter.filter(command)
74
- if (win_friendly_cmd.empty?)
75
- return false
76
- end
75
+ return false if win_friendly_cmd.empty?
77
76
 
78
77
  opts = { :error_check => false }.merge(opts || {})
79
78
  execute(win_friendly_cmd, opts) == 0
@@ -98,15 +97,6 @@ module VagrantWindows
98
97
 
99
98
  protected
100
99
 
101
- def do_execute(command, shell, &block)
102
- if shell.eql? :cmd
103
- winrmshell.cmd(command, &block)[:exitcode]
104
- else
105
- command << "\r\nexit $LASTEXITCODE"
106
- winrmshell.powershell(command, &block)[:exitcode]
107
- end
108
- end
109
-
110
100
  def raise_execution_error(opts, exit_code)
111
101
  # The error classes expect the translation key to be _key, but that makes for an ugly
112
102
  # configuration parameter, so we set it here from `error_key`
@@ -53,8 +53,8 @@ module VagrantWindows
53
53
  execute_shell(command, :cmd, &block)
54
54
  end
55
55
 
56
- def wql(query)
57
- execute_wql(query)
56
+ def wql(query, &block)
57
+ execute_shell(query, :wql, &block)
58
58
  end
59
59
 
60
60
  def upload(from, to)
@@ -69,7 +69,7 @@ module VagrantWindows
69
69
  protected
70
70
 
71
71
  def execute_shell(command, shell=:powershell, &block)
72
- raise Errors::WinRMInvalidShell, :shell => shell unless shell == :cmd || shell == :powershell
72
+ raise Errors::WinRMInvalidShell, :shell => shell unless [:powershell, :cmd, :wql].include?(shell)
73
73
  begin
74
74
  execute_shell_with_retry(command, shell, &block)
75
75
  rescue => e
@@ -84,22 +84,11 @@ module VagrantWindows
84
84
  block.call(:stdout, out) if block_given? && out
85
85
  block.call(:stderr, err) if block_given? && err
86
86
  end
87
- @logger.debug("Exit status: #{output[:exitcode].inspect}")
87
+ @logger.debug("Output: #{output.inspect}")
88
88
  return output
89
89
  end
90
90
  end
91
91
 
92
- def execute_wql(query)
93
- retryable(:tries => @max_tries, :on => @@exceptions_to_retry_on, :sleep => 10) do
94
- @logger.debug("#executing wql: #{query}")
95
- output = session.wql(query)
96
- @logger.debug("wql result: #{output.inspect}")
97
- return output
98
- end
99
- rescue => e
100
- raise_winrm_exception(e, :wql, query)
101
- end
102
-
103
92
  def raise_winrm_exception(winrm_exception, shell, command)
104
93
  if winrm_exception.message.include?("401") # return a more specific auth error for 401 errors
105
94
  raise Errors::WinRMAuthorizationError,
@@ -17,16 +17,16 @@ module VagrantWindows
17
17
  def validate(machine)
18
18
  errors = []
19
19
 
20
- errors << "windows.halt_timeout cannot be nil." if machine.config.windows.halt_timeout.nil?
21
- errors << "windows.halt_check_interval cannot be nil." if machine.config.windows.halt_check_interval.nil?
20
+ errors << "windows.halt_timeout cannot be nil." if @halt_timeout.nil?
21
+ errors << "windows.halt_check_interval cannot be nil." if @halt_check_interval.nil?
22
+ errors << "windows.set_work_network cannot be nil." if @set_work_network.nil?
22
23
 
23
- errors << "windows.set_work_network cannot be nil." if machine.config.windows.set_work_network.nil?
24
24
  { "Windows Guest" => errors }
25
25
  end
26
26
 
27
27
  def finalize!
28
- @halt_timeout = 30 if @halt_timeout == UNSET_VALUE
29
- @halt_check_interval = 1 if @halt_check_interval == UNSET_VALUE
28
+ @halt_timeout = 30 if @halt_timeout == UNSET_VALUE
29
+ @halt_check_interval = 1 if @halt_check_interval == UNSET_VALUE
30
30
  @set_work_network = false if @set_work_network == UNSET_VALUE
31
31
  end
32
32
 
@@ -16,7 +16,7 @@ module VagrantWindows
16
16
  @@logger.debug("networks: #{networks.inspect}")
17
17
 
18
18
  windows_machine = VagrantWindows::WindowsMachine.new(machine)
19
- guest_network = VagrantWindows::Communication::GuestNetwork.new(windows_machine.winrmshell)
19
+ guest_network = VagrantWindows::Communication::GuestNetwork.new(machine.communicate)
20
20
  if windows_machine.is_vmware?()
21
21
  @@logger.warn('Configuring secondary network adapters through VMware is not yet supported.')
22
22
  @@logger.warn('You will need to manually configure the network adapter.')
@@ -1,3 +1,3 @@
1
1
  module VagrantWindows
2
- VERSION = "1.7.0.pre.1"
2
+ VERSION = "1.7.0.pre.2"
3
3
  end
@@ -2,11 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe VagrantWindows::Communication::GuestNetwork , :integration => true do
4
4
 
5
- before(:all) do
5
+ before(:each) do
6
6
  port = (ENV['WINRM_PORT'] || 5985).to_i
7
+
8
+ @machine = stub()
7
9
  @shell = VagrantWindows::Communication::WinRMShell.new(
8
10
  "127.0.0.1", "vagrant", "vagrant", { port: port })
9
- @guestnetwork = VagrantWindows::Communication::GuestNetwork.new(@shell)
11
+
12
+ @communicator = VagrantWindows::Communication::WinRMCommunicator.new(@machine)
13
+ @communicator.winrmshell = @shell
14
+ @guestnetwork = VagrantWindows::Communication::GuestNetwork.new(@communicator)
10
15
  end
11
16
 
12
17
  describe "wsman_version" do
@@ -8,7 +8,7 @@ describe VagrantWindows::Communication::WinRMShell, :integration => true do
8
8
  "127.0.0.1", "vagrant", "vagrant", { port: port })
9
9
  end
10
10
 
11
- describe "powershell" do
11
+ describe ".powershell" do
12
12
  it "should return exit code of 0" do
13
13
  expect(@shell.powershell("exit 0")[:exitcode]).to eq(0)
14
14
  end
@@ -26,7 +26,7 @@ describe VagrantWindows::Communication::WinRMShell, :integration => true do
26
26
  end
27
27
  end
28
28
 
29
- describe "cmd" do
29
+ describe ".cmd" do
30
30
  it "should return stdout" do
31
31
  result = @shell.cmd("dir") do |type, line|
32
32
  expect(type).to eq(:stdout)
@@ -35,5 +35,12 @@ describe VagrantWindows::Communication::WinRMShell, :integration => true do
35
35
  expect(result[:exitcode]).to eq(0)
36
36
  end
37
37
  end
38
+
39
+ describe ".wql" do
40
+ it "should return query results in stdout" do
41
+ result = @shell.wql('SELECT * FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL')
42
+ expect(result[:win32_network_adapter]).to_not be_empty
43
+ end
44
+ end
38
45
 
39
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0.pre.1
4
+ version: 1.7.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Morton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-18 00:00:00.000000000 Z
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: winrm