Skip to content

Commit

Permalink
Release 'v1.0.1'
Browse files Browse the repository at this point in the history
* master:
  Created 'public_address' provider capability. 'Vagrant Share' is supported now
  driver: Handled the case when 'parallels_dhcp_leases' file is inaccessible [GH-74]
  driver: 'read_bridged_interfaces' is using 'read_host_info' [GH-92]
  driver: Created method 'read_host_info'
  driver: 'read_ip_dhcp' renamed to 'read_guest_ip'
  • Loading branch information
legal90 committed Mar 11, 2014
2 parents 9f9cc3d + 2c06cf1 commit 667d3e1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 49 deletions.
15 changes: 15 additions & 0 deletions lib/vagrant-parallels/cap/public_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module VagrantPlugins
module Parallels
module Cap
module PublicAddress
def self.public_address(machine)
return nil if machine.state.id != :running

ssh_info = machine.ssh_info
return nil if !ssh_info
ssh_info[:host]
end
end
end
end
end
4 changes: 0 additions & 4 deletions lib/vagrant-parallels/driver/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def initialize(uuid=nil)
end

def_delegators :@driver,
#:clear_forwarded_ports,
:clear_shared_folders,
:compact,
:create_host_only_network,
Expand All @@ -83,11 +82,8 @@ def initialize(uuid=nil)
:enable_adapters,
:execute_command,
:export,
#:forward_ports,
:halt,
:import,
:read_ip_dhcp,
#:read_forwarded_ports,
:read_bridged_interfaces,
:read_guest_tools_version,
:read_guest_ip,
Expand Down
44 changes: 23 additions & 21 deletions lib/vagrant-parallels/driver/pd_8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,18 @@ def import(template_uuid)
end

def read_bridged_interfaces
net_list = read_virtual_networks

# Skip 'vnicXXX' and 'Default' interfaces
net_list.delete_if do |net|
net['Type'] != "bridged" or
net['Bound To'] =~ /^(vnic(.+?))$/ or
net['Network ID'] == "Default"
host_hw_info = read_host_info.fetch("Hardware info")
net_list = host_hw_info.select do |name, attrs|
# Get all network interfaces except 'vnicXXX'
attrs.fetch("type") == "net" and name !~ /^(vnic(.+?))$/
end

bridged_ifaces = []
net_list.collect do |iface|
net_list.keys.each do |iface|
info = {}
ifconfig = execute(:ifconfig, iface['Bound To'])
ifconfig = execute(:ifconfig, iface)
# Assign default values
info[:name] = iface['Bound To']
info[:name] = iface
info[:ip] = "0.0.0.0"
info[:netmask] = "0.0.0.0"
info[:status] = "Down"
Expand All @@ -220,16 +217,31 @@ def read_bridged_interfaces
bridged_ifaces
end

def read_guest_ip
mac_addr = read_mac_address.downcase
File.foreach("/Library/Preferences/Parallels/parallels_dhcp_leases") do |line|
if line.include? mac_addr
return line[/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/]
end
end

nil
end

def read_guest_tools_version
read_settings.fetch('GuestTools', {}).fetch('version', nil)
end

def read_host_info
json { execute('server', 'info', '--json', retryable: true) }
end

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

hostonly_ifaces = []
net_list.collect do |iface|
net_list.each do |iface|
info = {}
net_info = json { execute(:prlsrvctl, 'net', 'info', iface['Network ID'], '--json') }
# Really we need to work with bounded virtual interface
Expand All @@ -254,16 +266,6 @@ def read_host_only_interfaces
hostonly_ifaces
end

def read_ip_dhcp
mac_addr = read_mac_address.downcase
File.foreach("/Library/Preferences/Parallels/parallels_dhcp_leases") do |line|
if line.include? mac_addr
ip = line[/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/]
return ip
end
end
end

def read_mac_address
read_settings.fetch('Hardware', {}).fetch('net0', {}).fetch('mac', nil)
end
Expand Down
47 changes: 26 additions & 21 deletions lib/vagrant-parallels/driver/pd_9.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,18 @@ def import(template_uuid)
end

def read_bridged_interfaces
net_list = read_virtual_networks

# Skip 'vnicXXX' and 'Default' interfaces
net_list.delete_if do |net|
net['Type'] != "bridged" or
net['Bound To'] =~ /^(vnic(.+?))$/ or
net['Network ID'] == "Default"
host_hw_info = read_host_info.fetch("Hardware info")
net_list = host_hw_info.select do |name, attrs|
# Get all network interfaces except 'vnicXXX'
attrs.fetch("type") == "net" and name !~ /^(vnic(.+?))$/
end

bridged_ifaces = []
net_list.collect do |iface|
net_list.keys.each do |iface|
info = {}
ifconfig = execute(:ifconfig, iface['Bound To'])
ifconfig = execute(:ifconfig, iface)
# Assign default values
info[:name] = iface['Bound To']
info[:name] = iface
info[:ip] = "0.0.0.0"
info[:netmask] = "0.0.0.0"
info[:status] = "Down"
Expand All @@ -220,16 +217,34 @@ def read_bridged_interfaces
bridged_ifaces
end

def read_guest_ip
mac_addr = read_mac_address.downcase
leases_file = "/Library/Preferences/Parallels/parallels_dhcp_leases"
begin
File.open(leases_file).grep(/#{mac_addr}/) do |line|
return line[/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/]
end
rescue Errno::EACCES
raise Errors::DhcpLeasesNotAccessible, :leases_file => leases_file.to_s
end

nil
end

def read_guest_tools_version
read_settings.fetch('GuestTools', {}).fetch('version', nil)
end

def read_host_info
json { execute('server', 'info', '--json', retryable: true) }
end

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

hostonly_ifaces = []
net_list.collect do |iface|
net_list.each do |iface|
info = {}
net_info = json { execute(:prlsrvctl, 'net', 'info', iface['Network ID'], '--json') }
# Really we need to work with bounded virtual interface
Expand All @@ -254,16 +269,6 @@ def read_host_only_interfaces
hostonly_ifaces
end

def read_ip_dhcp
mac_addr = read_mac_address.downcase
File.foreach("/Library/Preferences/Parallels/parallels_dhcp_leases") do |line|
if line.include? mac_addr
ip = line[/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/]
return ip
end
end
end

def read_mac_address
read_settings.fetch('Hardware', {}).fetch('net0', {}).fetch('mac', nil)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant-parallels/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class VagrantParallelsError < Vagrant::Errors::VagrantError
error_namespace("vagrant_parallels.errors")
end

class DhcpLeasesNotAccessible < VagrantParallelsError
error_key(:dhcp_leases_file_not_accessible)
end

class PrlCtlError < VagrantParallelsError
error_key(:prlctl_error)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-parallels/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class Plugin < Vagrant.plugin("2")
GuestLinuxCap::MountParallelsSharedFolder
end

provider_capability("parallels", "public_address") do
require_relative "cap/public_address"
Cap::PublicAddress
end

synced_folder(:parallels) do
require File.expand_path("../synced_folder", __FILE__)
SyncedFolder
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-parallels/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def ssh_info
# we return nil.
return nil if state.id == :not_created

detected_ip = @machine.config.ssh.host || @driver.read_ip_dhcp
detected_ip = @driver.read_guest_ip

# If ip couldn't be detected then we cannot possibly SSH into it,
# and should return nil too.
return nil if detected_ip.nil?
return nil if !detected_ip

# Return ip from running machine, use ip from config if available
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module Parallels
VERSION = "1.0.0"
VERSION = "1.0.1"
end
end
6 changes: 6 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ en:
# Translations for exception classes
#-------------------------------------------------------------------------------
errors:
dhcp_leases_file_not_accessible: |-
Parallels DHCP leases file is not accessible. The Parallels provider
uses it to detect an IP address of virtual machine. This file must be
readable for the user that is running Vagrant.
Parallels DHCP leases file: %{leases_file}
mac_os_x_required: |-
Parallels provider only works on OS X (or Mac OS X).
prlctl_error: |-
Expand Down

0 comments on commit 667d3e1

Please sign in to comment.