Skip to content

Commit

Permalink
Merge pull request #160 from sleicht/getIpInIPv4IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
legal90 committed Dec 23, 2014
2 parents 90a992f + e2b1897 commit 2b9a6bf
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions lib/vagrant-parallels/driver/pd_10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,41 @@ def read_forwarded_ports(global=false)
end
end

def read_host_only_interfaces
net_list = read_virtual_networks
net_list.keep_if { |net| net['Type'] == "host-only" }

hostonly_ifaces = []
net_list.each do |iface|
info = {}
net_info = json { execute_prlsrvctl('net', 'info', iface['Network ID'], '--json') }
adapter = net_info['Parallels adapter']

info[:name] = net_info['Network ID']
info[:bound_to] = net_info['Bound To']
# In PD >= 10.1.2 there are new field names for an IP/Subnet
info[:ip] = adapter['IP address'] || adapter['IPv4 address']
info[:netmask] = adapter['Subnet mask'] || adapter['IPv4 subnet mask']

# Such interfaces are always in 'Up'
info[:status] = "Up"

# There may be a fake DHCPv4 parameters
# We can trust them only if adapter IP and DHCP IP are in the same subnet
dhcp_ip = net_info['DHCPv4 server']['Server address']
if network_address(info[:ip], info[:netmask]) ==
network_address(dhcp_ip, info[:netmask])
info[:dhcp] = {
ip: dhcp_ip,
lower: net_info['DHCPv4 server']['IP scope start address'],
upper: net_info['DHCPv4 server']['IP scope end address']
}
end
hostonly_ifaces << info
end
hostonly_ifaces
end

def read_network_interfaces
nics = {}

Expand Down Expand Up @@ -153,10 +188,14 @@ def read_shared_interface
net_info = json do
execute_prlsrvctl('net', 'info', read_shared_network_id, '--json')
end

adapter = net_info['Parallels adapter']

# In PD >= 10.1.2 there are new field names for an IP/Subnet
info = {
name: net_info['Bound To'],
ip: net_info['Parallels adapter']['IP address'],
netmask: net_info['Parallels adapter']['Subnet mask'],
ip: adapter['IP address'] || adapter['IPv4 address'],
netmask: adapter['Subnet mask'] || adapter['IPv4 subnet mask'],
status: 'Up',
nat: []
}
Expand Down

0 comments on commit 2b9a6bf

Please sign in to comment.