vagrant-windows 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,51 +59,34 @@ module Vagrant
59
59
  end
60
60
 
61
61
  def configure_networks(networks)
62
- raise NotImplementedError, "Advanced Networking is not supported"
63
- # First, remove any previous network modifications
64
- # from the interface file.
65
- #vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
66
- #vm.channel.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
67
- #vm.channel.sudo("rm /tmp/vagrant-network-interfaces")
68
-
69
- # Accumulate the configurations to add to the interfaces file as
70
- # well as what interfaces we're actually configuring since we use that
71
- # later.
72
- #interfaces = Set.new
73
- #entries = []
74
- #networks.each do |network|
75
- # interfaces.add(network[:interface])
76
- # entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
77
- # :options => network)
78
-
79
- # entries << entry
80
- #end
81
-
82
- # Perform the careful dance necessary to reconfigure
83
- # the network interfaces
84
- #temp = Tempfile.new("vagrant")
85
- #temp.binmode
86
- #temp.write(entries.join("\n"))
87
- #temp.close
88
-
89
- #vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")
90
-
91
- # Bring down all the interfaces we're reconfiguring. By bringing down
92
- # each specifically, we avoid reconfiguring eth0 (the NAT interface) so
93
- # SSH never dies.
94
- #interfaces.each do |interface|
95
- # vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null")
96
- #end
62
+ ### HACK!!!!!
63
+ Nori.advanced_typecasting = false
64
+ if driver_mac_address = @vm.driver.read_mac_addresses
65
+ driver_mac_address = driver_mac_address.invert
66
+ end
97
67
 
98
- #vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces")
99
- #vm.channel.sudo("rm /tmp/vagrant-network-entry")
68
+ vm_interface_map = {}
69
+ @vm.channel.session.wql("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2")[:win32_network_adapter].each do |nic|
70
+ naked_mac = nic[:mac_address].gsub(':','')
71
+ if driver_mac_address[naked_mac]
72
+ vm_interface_map[driver_mac_address[naked_mac]] = { :name => nic[:net_connection_id], :mac_address => naked_mac, :index => nic[:interface_index] }
73
+ end
74
+ end
75
+ puts networks
76
+ puts vm_interface_map
77
+ networks.each do |network|
78
+ if network[:type].to_sym == :static
79
+ vm.channel.execute("netsh interface ip set address \"#{vm_interface_map[network[:interface]+1][:name]}\" static #{network[:ip]} #{network[:netmask]}")
80
+ elsif network[:type].to_sym == :dhcp
81
+ vm.channel.execute("netsh interface ip set address \"#{vm_interface_map[network[:interface]+1][:name]}\" dhcp")
82
+ end
83
+ end
100
84
 
101
- # Bring back up each network interface, reconfigured
102
- #interfaces.each do |interface|
103
- # vm.channel.sudo("/sbin/ifup eth#{interface}")
104
- #end
85
+ #netsh interface ip set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1
86
+
105
87
  end
106
88
 
89
+
107
90
  def windows_path(path)
108
91
  p = ''
109
92
  if path =~ /^\//
@@ -0,0 +1,42 @@
1
+ require 'vagrant/driver/virtualbox_base'
2
+ require 'vagrant/driver/virtualbox'
3
+
4
+
5
+ module Vagrant
6
+ module Driver
7
+
8
+ class VirtualBox_4_1 < 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_0 < 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 < VirtualBoxBase
39
+ def_delegator :@driver, :read_mac_addresses
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module VagrantWindows
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/vagrant_init.rb CHANGED
@@ -11,6 +11,9 @@ require 'vagrant-windows/communication/winrm'
11
11
  #Monkey Patch the VM object to support multiple channels
12
12
  require 'vagrant-windows/monkey_patches/vm'
13
13
 
14
+ #Monkey Patch the driver to support returning a mapping of mac addresses to nics
15
+ require 'vagrant-windows/monkey_patches/driver'
16
+
14
17
  require 'vagrant-windows/winrm'
15
18
 
16
19
  #Errors are good
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: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: winrm
@@ -76,6 +76,7 @@ files:
76
76
  - lib/vagrant-windows/config/winrm.rb
77
77
  - lib/vagrant-windows/errors.rb
78
78
  - lib/vagrant-windows/guest/windows.rb
79
+ - lib/vagrant-windows/monkey_patches/driver.rb
79
80
  - lib/vagrant-windows/monkey_patches/vm.rb
80
81
  - lib/vagrant-windows/scripts/command_alias.ps1
81
82
  - lib/vagrant-windows/scripts/mount_volume.ps1.erb