vagrant-guest-msys2 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af7802cda0568d6a063b68cb3452f67648159dd0
4
- data.tar.gz: fcfbc1a87759bb101f21de94f6b8810bc968c4cc
3
+ metadata.gz: a38fc1e6e11b2ea0c37d729e8b2ce316b71838f1
4
+ data.tar.gz: 472c3cc0a1d7ec4e77e83cad309a2134db629347
5
5
  SHA512:
6
- metadata.gz: a395497aeffc997adbcf174e3393db6b91c3930ef52d0417ba8a18d8e889888a73e38bdaec566db87b395c5045e7d3b38afbebd7cf30a8ef92eb62d37557f0cf
7
- data.tar.gz: 0a14c3a8f140356d7e35f77796b634c9eb23466468e71639f93613061ae78f8ad83430ca0f7d223e631858689580dec81aa202b041b540462102879682dc7520
6
+ metadata.gz: 7c529ebc4548601c0aeb4e7f88998711187527e2d365ebdfc073fee129070dac11457551864068fa9d2cc244df5eb885516eae4a0258380b361b03d5f982c68f
7
+ data.tar.gz: a1861008090af71832f1ab6d2d5293d43fb6fd9c70ac9ad9705fe112bdecfe0a177df9cd8f8c4a894a654c505c5aedc0bfd0c08c0d5842e34c99c4fad1c4b15f
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => [:test]
4
+
5
+ task :test do
6
+
7
+ end
@@ -5,17 +5,77 @@ module VagrantPlugins
5
5
  module GuestMSYS2
6
6
  module Cap
7
7
  module ConfigureNetworks
8
- @@logger = Log4r::Logger.new("vagrant::guest::windows::configure_networks")
8
+ @@logger = Log4r::Logger.new("vagrant::guest::msys2::configure_networks")
9
+
10
+ def self.configure_networks(machine, networks)
11
+ @@logger.info("Networks: #{networks.inspect}")
9
12
 
10
- def self.configure_networks(machine, networks)
11
- @@logger.debug("Networks: #{networks.inspect}")
12
- @@logger.debug("communicator: #{machine.config.vm.communicator.inspect}")
13
-
14
13
  guest_network = GuestNetwork.new(machine.communicate)
14
+
15
15
  network_adapters = guest_network.network_adapters()
16
- @@logger.debug("network_adapters: #{network_adapters}")
16
+ @@logger.info("network_adapters: #{network_adapters}")
17
17
 
18
- return
18
+ if machine.provider_name.to_s.start_with?("vmware")
19
+ machine.ui.warn("Configuring secondary network adapters through VMware ")
20
+ machine.ui.warn("on Windows is not yet supported. You will need to manually")
21
+ machine.ui.warn("configure the network adapter.")
22
+ else
23
+ vm_interface_map = create_vm_interface_map(machine, guest_network)
24
+ networks.each do |network|
25
+ interface = vm_interface_map[network[:interface]+1]
26
+ if interface.nil?
27
+ @@logger.warn("Could not find interface for network #{network.inspect}")
28
+ next
29
+ end
30
+
31
+ network_type = network[:type].to_sym
32
+ if network_type == :static
33
+ guest_network.configure_static_interface(
34
+ interface[:index],
35
+ interface[:net_connection_id],
36
+ network[:ip],
37
+ network[:netmask])
38
+ elsif network_type == :dhcp
39
+ guest_network.configure_dhcp_interface(
40
+ interface[:index],
41
+ interface[:net_connection_id])
42
+ else
43
+ raise "#{network_type} network type is not supported, try static or dhcp"
44
+ end
45
+ end
46
+ end
47
+
48
+ if machine.config.windows.set_work_network
49
+ guest_network.set_all_networks_to_work
50
+ end
51
+ end
52
+
53
+ def self.create_vm_interface_map(machine, guest_network)
54
+ if !machine.provider.capability?(:nic_mac_addresses)
55
+ raise Vagrant::Errors::CantReadMACAddresses,
56
+ provider: machine.provider_name.to_s
57
+ end
58
+
59
+ driver_mac_address = machine.provider.capability(:nic_mac_addresses).invert
60
+ @@logger.debug("mac addresses: #{driver_mac_address.inspect}")
61
+
62
+ vm_interface_map = {}
63
+ guest_network.network_adapters.each do |nic|
64
+ @@logger.debug("nic: #{nic.inspect}")
65
+ naked_mac = nic[:mac_address].gsub(':','')
66
+ # If the :net_connection_id entry is nil then it is probably a virtual connection
67
+ # and should be ignored.
68
+ if driver_mac_address[naked_mac] && !nic[:net_connection_id].nil?
69
+ vm_interface_map[driver_mac_address[naked_mac]] = {
70
+ net_connection_id: nic[:net_connection_id],
71
+ mac_address: naked_mac,
72
+ interface_index: nic[:interface_index],
73
+ index: nic[:index] }
74
+ end
75
+ end
76
+
77
+ @@logger.debug("vm_interface_map: #{vm_interface_map.inspect}")
78
+ vm_interface_map
19
79
  end
20
80
  end
21
81
  end
@@ -1,14 +1,12 @@
1
1
  require "log4r"
2
+ require "vagrant-guest-msys2/util/cap_helpers"
2
3
 
3
4
  module VagrantPlugins
4
5
  module GuestMSYS2
5
6
  # Manages the remote Windows guest network.
6
- class GuestNetwork
7
- PS_GET_WSMAN_VER = '((test-wsman).productversion.split(" ") | select -last 1).split("\.")[0]'
8
- WQL_NET_ADAPTERS_V2 = 'SELECT * FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL'
9
-
7
+ class GuestNetwork
10
8
  def initialize(communicator)
11
- @logger = Log4r::Logger.new("vagrant::windows::guestnetwork")
9
+ @logger = Log4r::Logger.new("vagrant::guest::msys2::guestnetwork")
12
10
  @communicator = communicator
13
11
  end
14
12
 
@@ -19,7 +17,34 @@ module VagrantPlugins
19
17
  def network_adapters
20
18
  @logger.debug("querying network adapters")
21
19
 
22
- wsman_version == 2? network_adapters_v2_winrm : network_adapters_v3_winrm
20
+ # Note: without JSON escape because MACAddress and NetConnectionID
21
+ # can't contain invalid characters
22
+ cmd = <<-EOH.gsub(/^ {10}/, '')
23
+ $adapters = Get-WmiObject -Class Win32_NetworkAdapter -Filter "MACAddress IS NOT NULL"
24
+ [string[]] $json= $()
25
+ foreach ($adapter in $adapters) {
26
+ $json += "{`
27
+ `"mac_address`": `"$($adapter.MACAddress)`",`
28
+ `"net_connection_id`": `"$($adapter.NetConnectionID)`",`
29
+ `"interface_index`": $([int]$adapter.InterfaceIndex),`
30
+ `"index`": $([int]$adapter.Index)`
31
+ }"
32
+ }
33
+ Write-Host "[$($json -Join ",")]"
34
+ EOH
35
+
36
+ output = ""
37
+ @communicator.execute(Util::CapHelpers.wrap_powershell(cmd)) do |type, line|
38
+ output = output + "#{line}" if type == :stdout && !line.nil?
39
+ end
40
+
41
+ adapters = []
42
+ JSON.parse(output).each do |nic|
43
+ adapters << nic.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
44
+ end
45
+
46
+ @logger.debug("#{adapters.inspect}")
47
+ return adapters
23
48
  end
24
49
 
25
50
  # Checks to see if the specified NIC is currently configured for DHCP.
@@ -32,7 +57,7 @@ module VagrantPlugins
32
57
  }
33
58
  exit 1
34
59
  EOH
35
- @communicator.test(cmd)
60
+ @communicator.test(Util::CapHelpers.wrap_powershell(cmd))
36
61
  end
37
62
 
38
63
  # Configures the specified interface for DHCP
@@ -65,62 +90,17 @@ module VagrantPlugins
65
90
  # https://github.com/WinRb/vagrant-windows/issues/63
66
91
  def set_all_networks_to_work
67
92
  @logger.info("Setting all networks to 'Work Network'")
68
- command = File.read(File.expand_path("../scripts/set_work_network.ps1", __FILE__))
69
- @communicator.execute(command)
70
- end
71
-
72
- protected
73
-
74
- # Checks the WinRS version on the guest. Usually 2 on Windows 7/2008
75
- # and 3 on Windows 8/2012.
76
- #
77
- # @return [Integer]
78
- def wsman_version
79
- @logger.debug("querying WSMan version")
80
- version = ''
81
- @communicator.execute(PS_GET_WSMAN_VER) do |type, line|
82
- version = version + "#{line}" if type == :stdout && !line.nil?
83
- end
84
- @logger.debug("wsman version: #{version}")
85
- Integer(version)
86
- end
87
-
88
- # Returns an array of all NICs on the guest. Each array entry is a
89
- # Hash of the NICs properties. This method should only be used on
90
- # guests that have WinRS version 2.
91
- #
92
- # @return [Array]
93
- def network_adapters_v2_winrm
94
- @logger.debug("querying network adapters")
95
-
96
- # Get all NICs that have a MAC address
97
- # https://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
98
- adapters = @communicator.execute(WQL_NET_ADAPTERS_V2, { shell: :wql } )[:win32_network_adapter]
99
- @logger.debug("#{adapters.inspect}")
100
- return adapters
101
- end
102
-
103
- # Returns an array of all NICs on the guest. Each array entry is a
104
- # Hash of the NICs properties. This method should only be used on
105
- # guests that have WinRS version 3.
106
- #
107
- # This method is a workaround until the WinRM gem supports WinRS version 3.
108
- #
109
- # @return [Array]
110
- def network_adapters_v3_winrm
111
- command = File.read(File.expand_path("../scripts/winrs_v3_get_adapters.ps1", __FILE__))
112
- output = ""
113
- @communicator.execute(command) do |type, line|
114
- output = output + "#{line}" if type == :stdout && !line.nil?
115
- end
116
-
117
- adapters = []
118
- JSON.parse(output).each do |nic|
119
- adapters << nic.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
120
- end
93
+
94
+ cmd = <<-EOH
95
+ # Get network connections
96
+ $networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
97
+ $connections = $networkListManager.GetNetworkConnections()
121
98
 
122
- @logger.debug("#{adapters.inspect}")
123
- return adapters
99
+ # Set network location to Private for all networks
100
+ $connections | % {$_.GetNetwork().SetCategory(1)}
101
+ EOH
102
+
103
+ @communicator.execute(Util::CapHelpers.wrap_powershell(cmd))
124
104
  end
125
105
  end
126
106
  end
@@ -17,7 +17,7 @@ if( (Test-Path "$MountPoint") -and (Test-ReparsePoint "$MountPoint") )
17
17
  {
18
18
  Write-Output "Junction already exists, so I will delete it"
19
19
  # Powershell refuses to delete junctions, oh well use cmd
20
- cmd /c rd "$MountPoint"
20
+ & cmd.exe /c rd "$MountPoint"
21
21
 
22
22
  if ( $LASTEXITCODE -ne 0 )
23
23
  {
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GuestMSYS2
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.description = "Adds MSYS2 (https://sourceforge.net/p/msys2/wiki/Home/) as a guest for Vagrant. "
15
15
  s.homepage = "https://github.com/tsmolka/vagrant-guest-msys2"
16
16
  s.required_rubygems_version = ">= 1.3.6"
17
+ s.add_dependency 'rake'
17
18
  root_path = File.dirname(__FILE__)
18
19
 
19
20
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-guest-msys2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-09 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2017-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  description: 'Adds MSYS2 (https://sourceforge.net/p/msys2/wiki/Home/) as a guest for
15
29
  Vagrant. '
16
30
  email: tsmolka@gmail.com