Skip to content

Commit

Permalink
Release v1.3.0
Browse files Browse the repository at this point in the history
Provider priority is set higher than 'virtualbox'
Provider marked as 'parallel'
'prl_fs' mount on linux: added sanity check for mount options
action/import: Use template name detected by parsing 'config.pvs'
Add sync_folders action support
driver: Retry the 'vm_exists?' check.
network: Added support of 'name' parameter for 'private_network'

Also, there is a bunch of code refactoring.
  • Loading branch information
legal90 committed Oct 10, 2014
2 parents 1445ee3 + 7a32574 commit 5de453f
Show file tree
Hide file tree
Showing 24 changed files with 459 additions and 771 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: ruby
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq -y bsdtar
- gem install bundler -v '1.5.2'
- gem install bundler -v '1.6.6'
rvm:
- 2.0.0
script: rake test:unit
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2013 Youssef Shahin
Copyright (c) 2013-2014 Parallels IP Holdings GmbH.

MIT License

Expand Down
25 changes: 25 additions & 0 deletions lib/vagrant-parallels/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,31 @@ def self.action_simple_reboot
end
end

# This action sync folders on a running provider. It is used by the docker provider
# to link synced folders on the host machine as volumes into the docker containers
def self.action_sync_folders
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsState, :not_created do |env1, b1|
if env1[:result]
b1.use Message, I18n.t("vagrant.commands.common.vm_not_created")
next
end

b1.use Call, IsState, :running do |env2, b2|
if !env2[:result]
b2.use Message, I18n.t("vagrant.commands.common.vm_not_running")
next
end

b2.use SyncedFolders
b2.use PrepareNFSSettings
end
end
end
end


autoload :Boot, File.expand_path("../action/boot", __FILE__)
autoload :HandleGuestTools, File.expand_path("../action/handle_guest_tools", __FILE__)
autoload :HandleForwardedPortCollisions, File.expand_path("../action/handle_forwarded_port_collisions.rb", __FILE__)
Expand Down
37 changes: 14 additions & 23 deletions lib/vagrant-parallels/action/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,9 @@ def call(env)
raise Vagrant::Errors::VMPowerOffToPackage
end

name = "#{env[:root_path].basename.to_s}_#{env[:machine].name}"
name.gsub!(/[^-a-z0-9_]/i, "")
@tpl_name = gen_template_name

# Check the name is not in use
if @env[:machine].provider.driver.read_vms.has_key?(@template_name)
@template_name << rand(100000).to_s
end


@template_name = gen_template_name
@template_uuid = export
export
compact_template
unregister_template

Expand All @@ -42,21 +34,24 @@ def gen_template_name
name = @env[:machine].provider_config.name
if !name
name = "#{@env[:root_path].basename.to_s}_#{@env[:machine].name}"
name.gsub!(/[^-a-z0-9_]/i, "")
name.gsub!(/[^-a-z0-9_]/i, '')
end

tpl_name = "#{name}_box"

# Ensure that the name is not in use
if @env[:machine].provider.driver.read_vms.has_key?(tpl_name)
tpl_name << "_#{rand(1000)}"
ind = 0
while @env[:machine].provider.driver.read_vms.has_key?(tpl_name)
ind += 1
tpl_name = "#{name}_box_#{ind}"
end

tpl_name
end

def export
@env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
tpl_uuid = @env[:machine].provider.driver.export(@env["export.temp_dir"], @template_name) do |progress|
@env[:ui].info I18n.t('vagrant.actions.vm.export.exporting')
@env[:machine].provider.driver.export(@env['export.temp_dir'], @tpl_name) do |progress|
@env[:ui].clear_line
@env[:ui].report_progress(progress, 100, false)

Expand All @@ -68,13 +63,11 @@ def export
# Clear the line a final time so the next data can appear
# alone on the line.
@env[:ui].clear_line

tpl_uuid
end

def compact_template
@env[:ui].info I18n.t("vagrant_parallels.actions.vm.export.compacting")
@env[:machine].provider.driver.compact(@template_uuid) do |progress|
@env[:ui].info I18n.t('vagrant_parallels.actions.vm.export.compacting')
@env[:machine].provider.driver.compact(@tpl_name) do |progress|
@env[:ui].clear_line
@env[:ui].report_progress(progress, 100, false)
end
Expand All @@ -85,10 +78,8 @@ def compact_template
end

def unregister_template
if @env[:machine].provider.driver.registered?(@template_uuid)
@logger.info("Unregister the box template: '#{@template_uuid}'")
@env[:machine].provider.driver.unregister(@template_uuid)
end
@logger.info("Unregister the box template: '#{@tpl_name}'")
@env[:machine].provider.driver.unregister(@tpl_name)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def call(env)
if env[:machine].provider.pd_version_satisfies?('>= 10')
super
else
# Just continue if port forwarding is not supporting
# Just continue if port forwarding is not supported
@app.call(env)
end
end
Expand All @@ -22,7 +22,7 @@ def recover(env)
if env[:machine].provider.pd_version_satisfies?('>= 10')
super
end
# Do nothing if port forwarding is not supporting
# Do nothing if port forwarding is not supported
end
end
end
Expand Down
82 changes: 51 additions & 31 deletions lib/vagrant-parallels/action/import.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'nokogiri'

module VagrantPlugins
module Parallels
module Action
Expand All @@ -8,27 +10,36 @@ def initialize(app, env)
end

def call(env)
@env = env
@template_path = File.realpath(Pathname.glob(env[:machine].box.directory.join('*.pvm')).first)
@template_uuid = register_template
import
unregister_template
@machine = env[:machine]

# Register template to be able to clone it further
register_template(template_path.to_s)

# Get template name. It might be changed during registration if name
# collision has been occurred
tpl_name = template_name(template_path)

# Import VM, e.q. clone it from registered template
import(env, tpl_name)

# Hide template since we dont need it anymore
unregister_template(tpl_name)

# Flag as erroneous and return if import failed
raise VagrantPlugins::Parallels::Errors::VMImportFailure if !env[:machine].id
raise Errors::VMImportFailure if !@machine.id

# Import completed successfully. Continue the chain
@app.call(env)
end

def recover(env)
@env = env
# We should to unregister template
unregister_template
tpl_name = template_name(template_path)
unregister_template(tpl_name)

if env[:machine].state.id != :not_created
if @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)
return if env["vagrant_parallels.error"].is_a?(Errors::VagrantParallelsError)

# If we're not supposed to destroy on error then just return
return if !env[:destroy_on_error]
Expand All @@ -45,42 +56,51 @@ def recover(env)

protected

def register_template
if !@env[:machine].provider.driver.read_vms_paths.has_key?(@template_path)
@logger.info("Register the box template: '#{@template_path}'")
regen_uuid = @env[:machine].provider_config.regen_box_uuid
def register_template(tpl_path_s)
@logger.info("Register the box template: '#{tpl_path_s}'")
regen_uuid = @machine.provider_config.regen_box_uuid

@env[:machine].provider.driver.register(@template_path, regen_uuid)
end
@machine.provider.driver.register(tpl_path_s, regen_uuid)
end

# Return the uuid of registered template
@env[:machine].provider.driver.read_vms_paths[@template_path]
def template_path
Pathname.glob(@machine.box.directory.join('*.pvm')).first
end

def import
@env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
:name => @env[:machine].box.name)
def template_name(tpl_path)
# Get template name from XML-based configuration file
tpl_config = tpl_path.join('config.pvs')
xml = Nokogiri::XML(File.open(tpl_config))
name = xml.xpath('//ParallelsVirtualMachine/Identification/VmName').text

if !name
raise Errors::ParallelsTplNameNotFound, config_path: tpl_config
end

name
end

def import(env, tpl_name)
env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
:name => @machine.box.name)
# Import the virtual machine
@env[:machine].id = @env[:machine].provider.driver.import(@template_uuid) do |progress|
@env[:ui].clear_line
@env[:ui].report_progress(progress, 100, false)
@machine.id = @machine.provider.driver.import(tpl_name) do |progress|
env[:ui].clear_line
env[:ui].report_progress(progress, 100, false)

# # If we got interrupted, then the import could have been interrupted.
# Just rise an exception and then 'recover' will be called to cleanup.
raise Vagrant::Errors::VagrantInterrupt if @env[:interrupted]
raise Vagrant::Errors::VagrantInterrupt if env[:interrupted]
end

# Clear the line one last time since the progress meter doesn't disappear
# immediately.
@env[:ui].clear_line
env[:ui].clear_line
end

def unregister_template
if @env[:machine].provider.driver.registered?(@template_uuid)
@logger.info("Unregister the box template: '#{@template_uuid}'")
@env[:machine].provider.driver.unregister(@template_uuid)
end
def unregister_template(tpl_name)
@logger.info("Unregister the box template: '#{tpl_name}'")
@machine.provider.driver.unregister(tpl_name)
end
end
end
Expand Down
27 changes: 14 additions & 13 deletions lib/vagrant-parallels/action/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def hostonly_config(options)
options = {
auto_config: true,
mac: nil,
name: nil,
nic_type: nil,
netmask: "255.255.255.0",
type: :static
Expand Down Expand Up @@ -293,6 +294,7 @@ def hostonly_config(options)
auto_config: options[:auto_config],
ip: options[:ip],
mac: options[:mac],
name: options[:name],
netmask: options[:netmask],
nic_type: options[:nic_type],
type: options[:type]
Expand All @@ -306,12 +308,6 @@ def hostonly_adapter(config)
if !interface
@logger.info("Network not found. Creating if we can.")

# It is an error if a specific host only network name was specified
# but the network wasn't found.
if config[:name]
raise Vagrant::Errors::NetworkNotFound, :name => config[:name]
end

# Create a new network
interface = hostonly_create_network(config)
@logger.info("Created network: #{interface[:name]}")
Expand Down Expand Up @@ -414,7 +410,7 @@ def next_network_id
# This creates a host only network for the given configuration.
def hostonly_create_network(config)
options = {
network_id: next_network_id,
network_id: config[:name] || next_network_id,
adapter_ip: config[:adapter_ip],
netmask: config[:netmask],
}
Expand All @@ -432,15 +428,20 @@ def hostonly_create_network(config)

# This finds a matching host only network for the given configuration.
def hostonly_find_matching_network(config)
this_netaddr = network_address(config[:ip], config[:netmask])
existing = @env[:machine].provider.driver.read_host_only_interfaces

@env[:machine].provider.driver.read_host_only_interfaces.each do |interface|
return interface if config[:name] && config[:name] == interface[:name]
return interface if this_netaddr == \
network_address(interface[:ip], interface[:netmask])
if config[:name]
# Search networks strongly by specified name
matched_iface = existing.detect { |i| config[:name] == i[:name] }
else
# Name is not specified - search by network address
this_netaddr = network_address(config[:ip], config[:netmask])
matched_iface = existing.detect do |i|
this_netaddr == network_address(i[:ip], i[:netmask])
end
end

nil
matched_iface || nil
end
end
end
Expand Down
Loading

0 comments on commit 5de453f

Please sign in to comment.