Class: VagrantPlugins::GuestMSYS2::GuestNetwork
- Inherits:
-
Object
- Object
- VagrantPlugins::GuestMSYS2::GuestNetwork
- Defined in:
- lib/vagrant-guest-msys2/guest_network.rb
Overview
Manages the remote Windows guest network.
Constant Summary collapse
- PS_GET_WSMAN_VER =
'((test-wsman).productversion.split(" ") | select -last 1).split("\.")[0]'
- WQL_NET_ADAPTERS_V2 =
'SELECT * FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL'
Instance Method Summary collapse
-
#configure_dhcp_interface(nic_index, net_connection_id) ⇒ Object
Configures the specified interface for DHCP.
-
#configure_static_interface(nic_index, net_connection_id, ip, netmask) ⇒ Object
Configures the specified interface using a static address.
-
#initialize(communicator) ⇒ GuestNetwork
constructor
A new instance of GuestNetwork.
-
#is_dhcp_enabled(nic_index) ⇒ Boolean
Checks to see if the specified NIC is currently configured for DHCP.
-
#network_adapters ⇒ Array
Returns an array of all NICs on the guest.
-
#set_all_networks_to_work ⇒ Object
Sets all networks on the guest to ‘Work Network’ mode.
Constructor Details
#initialize(communicator) ⇒ GuestNetwork
Returns a new instance of GuestNetwork.
10 11 12 13 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 10 def initialize(communicator) @logger = Log4r::Logger.new("vagrant::windows::guestnetwork") @communicator = communicator end |
Instance Method Details
#configure_dhcp_interface(nic_index, net_connection_id) ⇒ Object
Configures the specified interface for DHCP
42 43 44 45 46 47 48 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 42 def configure_dhcp_interface(nic_index, net_connection_id) @logger.info("Configuring NIC #{net_connection_id} for DHCP") if !is_dhcp_enabled(nic_index) netsh = "netsh interface ip set address \"#{net_connection_id}\" dhcp" @communicator.execute(netsh) end end |
#configure_static_interface(nic_index, net_connection_id, ip, netmask) ⇒ Object
Configures the specified interface using a static address
56 57 58 59 60 61 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 56 def configure_static_interface(nic_index, net_connection_id, ip, netmask) @logger.info("Configuring NIC #{net_connection_id} using static ip #{ip}") #netsh interface ip set address "Local Area Connection 2" static 192.168.33.10 255.255.255.0 netsh = "netsh interface ip set address \"#{net_connection_id}\" static #{ip} #{netmask}" @communicator.execute(netsh) end |
#is_dhcp_enabled(nic_index) ⇒ Boolean
Checks to see if the specified NIC is currently configured for DHCP.
28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 28 def is_dhcp_enabled(nic_index) cmd = <<-EOH if (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=#{nic_index} and DHCPEnabled=True") { exit 0 } exit 1 EOH @communicator.test(cmd) end |
#network_adapters ⇒ Array
Returns an array of all NICs on the guest. Each array entry is a Hash of the NICs properties.
19 20 21 22 23 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 19 def network_adapters @logger.debug("querying network adapters") wsman_version == 2? network_adapters_v2_winrm : network_adapters_v3_winrm end |
#set_all_networks_to_work ⇒ Object
Sets all networks on the guest to ‘Work Network’ mode. This is to allow guest access from the host via a private IP on Win7 github.com/WinRb/vagrant-windows/issues/63
66 67 68 69 70 |
# File 'lib/vagrant-guest-msys2/guest_network.rb', line 66 def set_all_networks_to_work @logger.info("Setting all networks to 'Work Network'") command = File.read(File.("../scripts/set_work_network.ps1", __FILE__)) @communicator.execute(command) end |