Skip to content

Commit

Permalink
Release v1.0.9.rc1
Browse files Browse the repository at this point in the history
* master:
  Unit tests modified
  Version bumped to 1.0.9.rc1
  guest_cap: Added 'unmount_parallels_shared_folders' guest capabilities for Linux and Mac OS
  Use special NOT_CREATED_ID if machine is not created
  action/network: set proper mac address on private network
  Don't provide SSH info if VM isn't running
  action: don't require valid config on destroy [hashicorp/vagrant#1629]
  config: merge customizations properly [GH-118]
  synced_folder: added "disable" method, deprecate "prepare"
  config: Added functional_psf to disable psf (Parallels Shared Folders)
  Added provider usability test
  Use Machine#state wherever possible so we update the index
  synced_folder: use 'os_friendly_id' method
  cap/nic_mac_addresses: Added 'nic_mac_addresses' provider capability
  driver: Added 'read_mac_addresses' method
  add support for bundler 1.6.x
  • Loading branch information
legal90 committed May 8, 2014
2 parents f3ad5eb + a99639e commit 2d3939d
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 31 deletions.
1 change: 0 additions & 1 deletion lib/vagrant-parallels/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def self.action_destroy

b2.use Call, DestroyConfirm do |env2, b3|
if env2[:result]
b3.use ConfigValidate
b3.use CheckAccessible
b3.use EnvSet, :force_halt => true
b3.use action_halt
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/action/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(app, env)

def call(env)
@env = env
if env[:machine].provider.state.id != :stopped
if env[:machine].state.id != :stopped
raise Vagrant::Errors::VMPowerOffToPackage
end

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/action/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def recover(env)
# We should to unregister template
unregister_template

if env[:machine].provider.state.id != :not_created
if env[:machine].state.id != :not_created
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
return if env["vagrant_parallels.error"].is_a?(VagrantPlugins::Parallels::Errors::VagrantParallelsError)

Expand Down
10 changes: 5 additions & 5 deletions lib/vagrant-parallels/action/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def hostonly_adapter(config)
end

return {
:adapter => config[:adapter],
:hostonly => interface[:name],
:mac => config[:mac],
:nic_type => config[:nic_type],
:type => :hostonly
:adapter => config[:adapter],
:hostonly => interface[:name],
:mac_address => config[:mac],
:nic_type => config[:nic_type],
:type => :hostonly
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/action/resume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(app, env)
end

def call(env)
current_state = env[:machine].provider.state.id
current_state = env[:machine].state.id

if current_state == :suspended
env[:ui].info I18n.t("vagrant.actions.vm.resume.resuming")
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/action/suspend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(app, env)
end

def call(env)
if env[:machine].provider.state.id == :running
if env[:machine].state.id == :running
env[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending")
env[:machine].provider.driver.suspend
end
Expand Down
14 changes: 14 additions & 0 deletions lib/vagrant-parallels/cap/nic_mac_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module VagrantPlugins
module Parallels
module Cap
module NicMacAddresses
# Reads the network interface card MAC addresses and returns them.
#
# @return [Hash<String, String>] Adapter => MAC address
def self.nic_mac_addresses(machine)
machine.provider.driver.read_mac_addresses
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/vagrant-parallels/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Config < Vagrant.plugin("2", :config)
attr_accessor :check_guest_tools
attr_reader :customizations
attr_accessor :destroy_unused_network_interfaces
attr_accessor :functional_psf
attr_accessor :optimize_power_consumption
attr_accessor :name
attr_reader :network_adapters
Expand All @@ -16,6 +17,7 @@ def initialize
@check_guest_tools = UNSET_VALUE
@customizations = []
@destroy_unused_network_interfaces = UNSET_VALUE
@functional_psf = UNSET_VALUE
@network_adapters = {}
@name = UNSET_VALUE
@optimize_power_consumption = UNSET_VALUE
Expand All @@ -42,6 +44,14 @@ def cpus=(count)
customize("pre-boot", ["set", :id, "--cpus", count.to_i])
end

def merge(other)
super.tap do |result|
c = customizations.dup
c += other.customizations
result.instance_variable_set(:@customizations, c)
end
end

def finalize!
if @check_guest_tools == UNSET_VALUE
@check_guest_tools = true
Expand All @@ -51,6 +61,10 @@ def finalize!
@destroy_unused_network_interfaces = true
end

if @functional_psf == UNSET_VALUE
@functional_psf = true
end

if @optimize_power_consumption == UNSET_VALUE
@optimize_power_consumption = true
end
Expand Down
10 changes: 10 additions & 0 deletions lib/vagrant-parallels/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def read_host_only_interfaces
def read_mac_address
end

# Returns the network interface card MAC addresses
#
# @return [Hash<String, String>] Adapter => MAC address
def read_mac_addresses
end

# Returns a list of network interfaces of the VM.
#
# @return [Hash]
Expand Down Expand Up @@ -234,6 +240,10 @@ def start
def suspend
end

# Unshare folders.
def unshare_folders(names)
end

# Verifies that the driver is ready to accept work.
#
# This should raise a VagrantError if things are not ready.
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 @@ -94,6 +94,7 @@ def initialize(uuid=nil)
:read_guest_property,
:read_host_only_interfaces,
:read_mac_address,
:read_mac_addresses,
:read_network_interfaces,
:read_shared_interface,
:read_shared_folders,
Expand Down
18 changes: 18 additions & 0 deletions lib/vagrant-parallels/driver/pd_8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ def read_mac_address
read_settings.fetch('Hardware', {}).fetch('net0', {}).fetch('mac', nil)
end

def read_mac_addresses
macs = {}
read_settings.fetch('Hardware', {}).each do |device, params|
if device =~ /^net(\d+)$/
adapter = $1
mac = params.fetch('mac')
macs[adapter] = mac
end
end
macs
end

def read_network_interfaces
nics = {}

Expand Down Expand Up @@ -438,6 +450,12 @@ def unregister(uuid)
execute("unregister", uuid)
end

def unshare_folders(names)
names.each do |name|
execute("set", @uuid, "--shf-host-del", name)
end
end

def verify!
execute('--version', retryable: true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def self.mount_parallels_shared_folder(machine, name, guestpath, options)
comm.sudo("ln -s \"/Volumes/SharedFolders/#{name}\" \"#{guestpath}\"")
end
end

def self.unmount_parallels_shared_folder(machine, guestpath, options)
machine.communicate.sudo("rm #{guestpath}", error_check: false)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def self.mount_parallels_shared_folder(machine, name, guestpath, options)
end
end
end

def self.unmount_parallels_shared_folder(machine, guestpath, options)
machine.communicate.sudo("rm #{guestpath}", error_check: false)
end
end
end
end
Expand Down
19 changes: 17 additions & 2 deletions lib/vagrant-parallels/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,36 @@ class Plugin < Vagrant.plugin("2")
GuestDarwinCap::MountParallelsSharedFolder
end

guest_capability(:darwin, :unmount_parallels_shared_folder) do
require_relative "guest_cap/darwin/mount_parallels_shared_folder"
GuestDarwinCap::MountParallelsSharedFolder
end

guest_capability(:linux, :mount_parallels_shared_folder) do
require_relative "guest_cap/linux/mount_parallels_shared_folder"
GuestLinuxCap::MountParallelsSharedFolder
end

provider_capability("parallels", "public_address") do
guest_capability(:linux, :unmount_virtualbox_shared_folder) do
require_relative "guest_cap/linux/mount_virtualbox_shared_folder"
GuestLinuxCap::MountParallelsSharedFolder
end

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

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

provider_capability(:parallels, :nic_mac_addresses) do
require_relative "cap/nic_mac_addresses"
Cap::NicMacAddresses
end

synced_folder(:parallels) do
require File.expand_path("../synced_folder", __FILE__)
SyncedFolder
Expand Down
23 changes: 20 additions & 3 deletions lib/vagrant-parallels/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ module Parallels
class Provider < Vagrant.plugin("2", :provider)
attr_reader :driver

def self.usable?(raise_error=false)
# Instantiate the driver, which will determine the Parallels Desktop
# version and all that, which checks for Parallels Desktop being present
Driver::Meta.new
true
rescue VagrantPlugins::Parallels::Errors::ParallelsInvalidVersion
raise if raise_error
return false
rescue VagrantPlugins::Parallels::Errors::ParallelsNotDetected
raise if raise_error
return false
end

def initialize(machine)
@logger = Log4r::Logger.new("vagrant::provider::parallels")
@machine = machine
Expand Down Expand Up @@ -48,9 +61,8 @@ def machine_id_changed

# Returns the SSH info for accessing the Parallels VM.
def ssh_info
# If the VM is not created then we cannot possibly SSH into it, so
# we return nil.
return nil if state.id == :not_created
# If the VM is not running that we can't possibly SSH into it
return nil if state.id != :running

detected_ip = @driver.read_guest_ip

Expand Down Expand Up @@ -80,6 +92,11 @@ def state
short = state_id.to_s.gsub("_", " ")
long = I18n.t("vagrant_parallels.commands.status.#{state_id}")

# If machine is not created, then specify the special ID flag
if state_id == :not_created
state_id = Vagrant::MachineState::NOT_CREATED_ID
end

# Return the state
Vagrant::MachineState.new(state_id, short, long)
end
Expand Down
40 changes: 29 additions & 11 deletions lib/vagrant-parallels/synced_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
module VagrantPlugins
module Parallels
class SyncedFolder < Vagrant.plugin("2", :synced_folder)
def usable?(machine)
def usable?(machine, raise_errors=false)
# These synced folders only work if the provider is Parallels
machine.provider_name == :parallels
machine.provider_name == :parallels &&
machine.provider_config.functional_psf
end

def prepare(machine, folders, _opts)
def enable(machine, folders, _opts)
# Export the shared folders to the VM
defs = []
folders.each do |id, data|
hostpath = Vagrant::Util::Platform.cygwin_windows_path(data[:hostpath])
hostpath = data[:hostpath]
if !data[:hostpath_exact]
hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath)
end


defs << {
# Escape special symbols (Parallels Shared Folders specific)
name: id.split('/').delete_if{|i| i.empty?}.join('_'),
name: os_friendly_id(id),
hostpath: hostpath.to_s,
transient: data[:transient],
}
end

# We should prepare only folders with unique hostpath values.
# Anyway, duplicates will be mounted later.
defs.uniq! { |d| d[:hostpath] }
driver(machine).share_folders(defs)
end

def enable(machine, folders, _opts)
# short guestpaths first, so we don't step on ourselves
folders = folders.sort_by do |id, data|
if data[:guestpath]
Expand All @@ -48,8 +50,6 @@ def enable(machine, folders, _opts)
id = shf_config.key(data[:hostpath])

if data[:guestpath] and id
id = Pathname.new(id).to_s.split('/').drop_while{|i| i.empty?}.join('_')

# Guest path specified, so mount the folder to specified point
machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
guestpath: data[:guestpath],
Expand All @@ -74,6 +74,20 @@ def enable(machine, folders, _opts)
end
end

def disable(machine, folders, _opts)
if machine.guest.capability?(:unmount_parallels_shared_folder)
folders.each do |id, data|
machine.guest.capability(
:unmount_parallels_shared_folder,
data[:guestpath], data)
end
end

# Remove the shared folders from the VM metadata
names = folders.map { |id, _data| os_friendly_id(id) }
driver(machine).unshare_folders(names)
end

def cleanup(machine, opts)
driver(machine).clear_shared_folders if machine.id && machine.id != ""
end
Expand All @@ -84,6 +98,10 @@ def cleanup(machine, opts)
def driver(machine)
machine.provider.driver
end

def os_friendly_id(id)
id.gsub(/[\/]/,'_').sub(/^_/, '')
end
end
end
end
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.8"
VERSION = "1.0.9.rc1"
end
end
Loading

0 comments on commit 2d3939d

Please sign in to comment.