Skip to content

Commit

Permalink
Release v1.5.0
Browse files Browse the repository at this point in the history
* master:
  Bump version to 1.5.0
  Deprecate "optimize_power_consumption" setting
  action: run "SaneDefaults" only after "Import" action
  action/sane_defaults: Manage VM default settings
  action/sane_defaults: Remove set_power_consumption method
  driver: Fix method name
  Disable password restrictions before #import and #destroy actions
  driver: Retry to parse json
  • Loading branch information
legal90 committed Sep 29, 2015
2 parents 5677b20 + 5b2bb78 commit dae6fcc
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/vagrant-parallels/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def self.action_boot
b.use ClearNetworkInterfaces
b.use ForwardPorts
b.use SetHostname
b.use SaneDefaults
b.use Customize, 'pre-boot'
b.use Boot
b.use Customize, 'post-boot'
Expand Down Expand Up @@ -278,6 +277,7 @@ def self.action_up
if env1[:result]
b1.use Customize, 'pre-import'
b1.use Import
b1.use SaneDefaults
b1.use Customize, 'post-import'
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant-parallels/action/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ module Action
class Destroy
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new('vagrant_parallels::action::destroy')
end

def call(env)
# Disable requiring password for delete action [GH-67].
# It is available only since PD 10.
if env[:machine].provider.pd_version_satisfies?('>= 10')
@logger.info('Disabling password restrictions: remove-vm')
env[:machine].provider.driver.disable_password_restrictions(['remove-vm'])
end

env[:ui].info I18n.t('vagrant.actions.vm.destroy.destroying')
env[:machine].provider.driver.delete
env[:machine].id = nil
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant-parallels/action/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def initialize(app, env)
def call(env)
@machine = env[:machine]

# Disable requiring password for register and clone actions [GH-67].
# It is available only since PD 10.
if env[:machine].provider.pd_version_satisfies?('>= 10')
acts = ['clone-vm']
@logger.info("Disabling password restrictions: #{acts.join(', ')}")
env[:machine].provider.driver.disable_password_restrictions(acts)
end

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

Expand Down
62 changes: 40 additions & 22 deletions lib/vagrant-parallels/action/sane_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,57 @@ def call(env)
# helpers.
@env = env

# Disable requiring password on such operations as creating, adding,
# removing or coning the virtual machine. [GH-67]
# It is available only since PD 10.
if env[:machine].provider.pd_version_satisfies?('>= 10')
@logger.info('Disabling any password restrictions...')
env[:machine].provider.driver.disable_password_restrictions
end
settings = default_settings

@app.call(env) if settings.empty?
@env[:ui].info I18n.t('vagrant_parallels.actions.vm.sane_defaults.setting')

if env[:machine].provider.pd_version_satisfies?('>= 9')
@logger.info('Setting the power consumption mode...')
set_power_consumption
default_settings.each do |setting, value|
@env[:machine].provider.driver.execute_prlctl(
'set', @env[:machine].id, "--#{setting.to_s.gsub('_','-')}", value)
end

@app.call(env)
end

private

def set_power_consumption
# Optimization of power consumption is defined by "Longer Battery Life" state.
vm_settings = @env[:machine].provider.driver.read_settings
def default_settings
settings = {}

old_val = vm_settings.fetch('Longer battery life') == 'on' ? true : false
new_val = @env[:machine].provider_config.optimize_power_consumption
return settings if @env[:machine].provider.pd_version_satisfies?('< 9')
settings.merge!(
startup_view: 'same',
on_shutdown: 'close',
on_window_close: 'keep-running',
auto_share_camera: 'off',
smart_guard: 'off',
longer_battery_life: 'on'
)

if old_val == new_val
@logger.info('Skipping power consumption method because it is already set')
else
mode = new_val ? 'Longer battery life' : 'Better Performance'
@env[:ui].info I18n.t('vagrant_parallels.parallels.power_consumption.set_mode',
mode: mode)
@env[:machine].provider.driver.set_power_consumption_mode(new_val)
# Check the legacy option
if !@env[:machine].provider_config.optimize_power_consumption
settings[:longer_battery_life] = 'off'
end

return settings if @env[:machine].provider.pd_version_satisfies?('< 10.1.2')
settings.merge!(
shared_cloud: 'off',
shared_profile: 'off',
smart_mount: 'off',
sh_app_guest_to_host: 'off',
sh_app_host_to_guest: 'off',
time_sync: 'off'
)

return settings if @env[:machine].provider.pd_version_satisfies?('< 11')
settings.merge!(
startup_view: 'headless',
time_sync: 'on',
disable_timezone_sync: 'on'
)

settings
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/vagrant-parallels/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ def finalize!
@functional_psf = true
end

if @optimize_power_consumption == UNSET_VALUE
@optimize_power_consumption = true
end

@use_linked_clone = false if @use_linked_clone == UNSET_VALUE

@name = nil if @name == UNSET_VALUE
Expand Down Expand Up @@ -108,6 +104,10 @@ def validate(machine)
end
end

if @optimize_power_consumption != UNSET_VALUE
machine.env.ui.warn I18n.t('vagrant_parallels.config.deprecate_power_consumption')
end

{ 'Parallels Provider' => errors }
end
end
Expand Down
12 changes: 10 additions & 2 deletions lib/vagrant-parallels/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def delete_unused_host_only_networks
# Disables requiring password on such operations as creating, adding,
# removing or cloning the virtual machine.
#
def disable_password_restrictions
# @param [Array<String>] acts List of actions. Available values:
# ['create-vm', 'add-vm', 'remove-vm', 'clone-vm']
def disable_password_restrictions(acts)
raise NotImplementedError
end

Expand Down Expand Up @@ -670,7 +672,13 @@ def execute(*command, &block)
# Parses given block (JSON string) to object
def json(default=nil)
data = yield
JSON.parse(data) rescue default
begin
JSON.parse(data)
rescue JSON::ParserError
# Try to cleanup the data and parse it again [GH-204]
data = data[/(\{.*\}|\[.*\])/m]
JSON.parse(data) rescue default
end
end

# Executes a command and returns the raw result object.
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-parallels/driver/pd_10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def delete_unused_host_only_networks
end
end

def disable_password_restrictions
def disable_password_restrictions(acts)
server_info = json { execute_prlsrvctl('info', '--json') }
server_info.fetch('Require password to',[]).each do |act|
execute_prlsrvctl('set', '--require-pwd', "#{act}:off")
execute_prlsrvctl('set', '--require-pwd', "#{act}:off") if acts.include? act
end
end

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.4.3'
VERSION = '1.5.0'
end
end
16 changes: 13 additions & 3 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
en:
vagrant_parallels:
parallels:
power_consumption:
set_mode: |-
Setting power consumption mode: "%{mode}"
network_adapter: |-
Adapter %{adapter}: %{type}%{extra}
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -117,6 +114,17 @@ en:
invalid_event: |-
%{event} is not a valid event for customization. Valid events
are: %{valid_events}
deprecate_power_consumption: |-
Setting "optimize_power_consumption" has been deprecated in the Parallels
provider and will be removed in the future releases. Power consumption
is enabled by default. If you want to keep it enabled, then just remove
this setting from your Vagrantfile. Otherwise, please replace it with
this block in order to disable the power consumption:
config.vm.provider "parallels" do |prl|
prl.customize ["set", :id, "--longer-battery-life", "off"]
end
#-------------------------------------------------------------------------------
# Translations for commands. e.g. `vagrant x`
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -186,3 +194,5 @@ en:
%{guest_port} => %{host_port}
import:
importing_linked: Importing base box '%{name}' as a linked clone...
sane_defaults:
setting: Setting the default configuration for VM...
14 changes: 0 additions & 14 deletions website/docs/source/docs/configuration.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,6 @@ end
In this case the both of Parallels Tools status check and an automatic update
procedure will be skipped as well.

## Power Consumption Mode
The Parallels provider sets power consumption method as "Longer Battery
Life" by default. You can override it to "Better Performance" using this
customisation parameter:

```ruby
config.vm.provider "parallels" do |prl|
prl.optimize_power_consumption = false
end
```

P.s. Read more about power consumption modes in Parallels Desktop: [KB #9607]
(http://kb.parallels.com/en/9607)

## Customization with prlctl

Parallels Desktop includes the `prlctl` command-line utility that can be used to
Expand Down

0 comments on commit dae6fcc

Please sign in to comment.