Skip to content

Commit

Permalink
Release 'v1.0.3'
Browse files Browse the repository at this point in the history
* master:
  guest_cap/linux: Clear prior symlinks while 'mount_parallels_shared_folder' [GH-100]
  guest_cap/linux: Changed 'mount_parallels_shared_folder' - use advanced mount instead symlinks [GH-100]
  cap: Added 'host_address' provider capability
  driver: Added method 'read_shared_interface'
  driver: return nil if 'parallels_dhcp_leases' file does not exist [GH-99]
  • Loading branch information
legal90 committed Mar 20, 2014
2 parents 56df5e2 + 589bad6 commit a845063
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 21 deletions.
15 changes: 15 additions & 0 deletions lib/vagrant-parallels/cap/host_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module VagrantPlugins
module Parallels
module Cap
module HostAddress
def self.host_address(machine)

shared_iface = machine.provider.driver.read_shared_interface
return shared_iface[:ip] if shared_iface

nil
end
end
end
end
end
6 changes: 6 additions & 0 deletions lib/vagrant-parallels/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def read_mac_address
def read_network_interfaces
end

# Returns info about shared network interface.
#
# @return [Hash]
def read_shared_interface
end

# Returns the current state of this VM.
#
# @return [Symbol]
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-parallels/driver/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def initialize(uuid=nil)
:read_host_only_interfaces,
:read_mac_address,
:read_network_interfaces,
:read_shared_interface,
:read_settings,
:read_state,
:read_used_ports,
Expand Down
28 changes: 28 additions & 0 deletions lib/vagrant-parallels/driver/pd_8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ def read_guest_ip
end
rescue Errno::EACCES
raise Errors::DhcpLeasesNotAccessible, :leases_file => leases_file.to_s
rescue Errno::ENOENT
# File does not exist
# Perhaps, it is the fist start of Parallels Desktop
return nil
end

nil
Expand Down Expand Up @@ -307,6 +311,30 @@ def read_settings
vm.last
end

def read_shared_interface
# There should be only one Shared interface
shared_net = read_virtual_networks.detect { |net| net['Type'] == 'shared' }
return nil if !shared_net

net_info = json { execute(:prlsrvctl, 'net', 'info', shared_net['Network ID'], '--json') }
info = {
name: net_info['Bound To'],
ip: net_info['Parallels adapter']['IP address'],
netmask: net_info['Parallels adapter']['Subnet mask'],
status: "Up"
}

if net_info.key?('DHCPv4 server')
info[:dhcp] = {
ip: net_info['DHCPv4 server']['Server address'],
lower: net_info['DHCPv4 server']['IP scope start address'],
upper: net_info['DHCPv4 server']['IP scope end address']
}
end

info
end

def read_state
vm = json { execute('list', @uuid, '--json', retryable: true).gsub(/^INFO/, '') }
return nil if !vm.last
Expand Down
28 changes: 28 additions & 0 deletions lib/vagrant-parallels/driver/pd_9.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ def read_guest_ip
end
rescue Errno::EACCES
raise Errors::DhcpLeasesNotAccessible, :leases_file => leases_file.to_s
rescue Errno::ENOENT
# File does not exist
# Perhaps, it is the fist start of Parallels Desktop
return nil
end

nil
Expand Down Expand Up @@ -307,6 +311,30 @@ def read_settings
vm.last
end

def read_shared_interface
# There should be only one Shared interface
shared_net = read_virtual_networks.detect { |net| net['Type'] == 'shared' }
return nil if !shared_net

net_info = json { execute(:prlsrvctl, 'net', 'info', shared_net['Network ID'], '--json') }
info = {
name: net_info['Bound To'],
ip: net_info['Parallels adapter']['IP address'],
netmask: net_info['Parallels adapter']['Subnet mask'],
status: "Up"
}

if net_info.key?('DHCPv4 server')
info[:dhcp] = {
ip: net_info['DHCPv4 server']['Server address'],
lower: net_info['DHCPv4 server']['IP scope start address'],
upper: net_info['DHCPv4 server']['IP scope end address']
}
end

info
end

def read_state
vm = json { execute('list', @uuid, '--json', retryable: true) }
return nil if !vm.last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,72 @@ module GuestLinuxCap
class MountParallelsSharedFolder

def self.mount_parallels_shared_folder(machine, name, guestpath, options)
# Expand the guest path so we can handle things like "~/vagrant"
expanded_guest_path = machine.guest.capability(
:shell_expand_guest_path, guestpath)

machine.communicate.tap do |comm|
# clear prior symlink
if comm.test("test -L \"#{expanded_guest_path}\"", :sudo => true)
comm.sudo("rm \"#{expanded_guest_path}\"")
end
mount_commands = []

# clear prior directory if exists
if comm.test("test -d \"#{expanded_guest_path}\"", :sudo => true)
comm.sudo("rm -Rf \"#{expanded_guest_path}\"")
end
if options[:owner].is_a? Integer
mount_uid = options[:owner]
else
mount_uid = "`id -u #{options[:owner]}`"
end

if options[:group].is_a? Integer
mount_gid = options[:group]
mount_gid_old = options[:group]
else
mount_gid = "`getent group #{options[:group]} | cut -d: -f3`"
mount_gid_old = "`id -g #{options[:group]}`"
end

# First mount command uses getent to get the group
mount_options = "-o uid=#{mount_uid},gid=#{mount_gid}"
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t prl_fs #{mount_options} #{name} #{expanded_guest_path}"

# Second mount command uses the old style `id -g`
mount_options = "-o uid=#{mount_uid},gid=#{mount_gid_old}"
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t prl_fs #{mount_options} #{name} #{expanded_guest_path}"

# create intermediate directories if needed
intermediate_dir = File.dirname(expanded_guest_path)
if !comm.test("test -d \"#{intermediate_dir}\"", :sudo => true)
comm.sudo("mkdir -p \"#{intermediate_dir}\"")
# Clear prior symlink if exists
machine.communicate.sudo("test -L #{expanded_guest_path} && rm -f #{expanded_guest_path}")

# Create the guest path if it doesn't exist
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")

# Attempt to mount the folder. We retry here a few times because
# it can fail early on.
attempts = 0
while true
success = true

mount_commands.each do |command|
no_such_device = false
status = machine.communicate.sudo(command, error_check: false) do |type, data|
no_such_device = true if type == :stderr && data =~ /No such device/i
end

success = status == 0 && !no_such_device
break if success
end

# finally make the symlink
comm.sudo("ln -s \"/media/psf/#{name}\" \"#{expanded_guest_path}\"")
break if success

# Emit an upstart event if we can
if comm.test("test -x /sbin/initctl")
comm.sudo(
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
attempts += 1
if attempts > 10
raise Vagrant::Errors::LinuxMountFailed,
command: mount_commands.join("\n")
end

sleep 2
end

# Emit an upstart event if we can
if machine.communicate.test("test -x /sbin/initctl")
machine.communicate.sudo(
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
end
end
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 @@ -45,6 +45,11 @@ class Plugin < Vagrant.plugin("2")
Cap::PublicAddress
end

provider_capability("parallels", "host_address") do
require_relative "cap/host_address"
Cap::HostAddress
end

synced_folder(:parallels) do
require File.expand_path("../synced_folder", __FILE__)
SyncedFolder
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.2"
VERSION = "1.0.3"
end
end

0 comments on commit a845063

Please sign in to comment.