Differentiate checkpoints and automatic checkpoints

Provide separate configuration settings for enabling/disabling
checkpoints and automatic checkpoints with Hyper-V provider.
This commit is contained in:
Chris Roberts 2018-07-13 15:23:09 -07:00
parent a9bc0bb800
commit 8aa74a03a0
5 changed files with 56 additions and 4 deletions

View File

@ -70,6 +70,7 @@ module VagrantPlugins
"AutoStartAction" => env[:machine].provider_config.auto_start_action,
"AutoStopAction" => env[:machine].provider_config.auto_stop_action,
"EnableCheckpoints" => env[:machine].provider_config.enable_checkpoints,
"EnableAutomaticCheckpoints" => env[:machine].provider_config.enable_automatic_checkpoints,
"VirtualizationExtensions" => !!env[:machine].provider_config.enable_virtualization_extensions,
}
options.delete_if{|_,v| v.nil? }

View File

@ -40,8 +40,10 @@ module VagrantPlugins
attr_accessor :auto_start_action
# @return [String] Automatic action on stop of host. Default: ShutDown (ShutDown, TurnOff, Save)
attr_accessor :auto_stop_action
# @return [Boolean] Enable automatic checkpoints. Default: false
# @return [Boolean] Enable checkpoints. Default: true
attr_accessor :enable_checkpoints
# @return [Boolean] Enable automatic checkpoints. Default: false
attr_accessor :enable_automatic_checkpoints
# @return [Boolean] Enable virtualization extensions
attr_accessor :enable_virtualization_extensions
# @return [Hash] Options for VMServiceIntegration
@ -60,6 +62,7 @@ module VagrantPlugins
@auto_start_action = UNSET_VALUE
@auto_stop_action = UNSET_VALUE
@enable_virtualization_extensions = UNSET_VALUE
@enable_automatic_checkpoints = UNSET_VALUE
@enable_checkpoints = UNSET_VALUE
@vm_integration_services = {}
end
@ -85,11 +88,20 @@ module VagrantPlugins
@auto_start_action = "Nothing" if @auto_start_action == UNSET_VALUE
@auto_stop_action = "ShutDown" if @auto_stop_action == UNSET_VALUE
@enable_virtualization_extensions = false if @enable_virtualization_extensions == UNSET_VALUE
if @enable_automatic_checkpoints == UNSET_VALUE
@enable_automatic_checkpoints = false
else
@enable_automatic_checkpoints = !!@enable_automatic_checkpoints
end
if @enable_checkpoints == UNSET_VALUE
@enable_checkpoints = false
@enable_checkpoints = true
else
@enable_checkpoints = !!@enable_checkpoints
end
# If automatic checkpoints are enabled, checkpoints will automatically be enabled
@enable_checkpoints ||= @enable_automatic_checkpoints
end
def validate(machine)

View File

@ -18,7 +18,9 @@ param(
[parameter (Mandatory=$false)]
[switch] $VirtualizationExtensions,
[parameter (Mandatory=$false)]
[switch] $EnableCheckpoints
[switch] $EnableCheckpoints,
[parameter (Mandatory=$false)]
[switch] $EnableAutomaticCheckpoints
)
$ErrorActionPreference = "Stop"
@ -76,6 +78,7 @@ if($SwitchID) {
Set-VagrantVMSwitch -VM $VM -SwitchName $SwitchName
} catch {
Write-ErrorMessage "Failed to configure network adapter: ${PSItem}"
exit 1
}
}
@ -93,3 +96,18 @@ try {
Write-ErrorMessage "Failed to ${CheckpointAction} checkpoints on VM: ${PSItem}"
exit 1
}
if($EnableAutomaticCheckpoints) {
$autochecks = 1
$AutoAction = "enabled"
} else {
$autochecks = 0
$AutoAction = "disable"
}
try {
Hyper-V\Set-VM -VM $VM -AutomaticCheckpointsEnabled $autochecks
} catch {
Write-ErrorMessage "Failed to ${AutoAction} automatic checkpoints on VM: ${PSItem}"
exit 1
}

View File

@ -26,6 +26,7 @@ describe VagrantPlugins::HyperV::Action::Configure do
auto_start_action: "Nothing",
auto_stop_action: "Save",
enable_checkpoints: false,
enable_automatic_checkpoints: true,
enable_virtualization_extensions: false,
vm_integration_services: vm_integration_services
)

View File

@ -163,11 +163,31 @@ describe VagrantPlugins::HyperV::Config do
end
describe "#enable_checkpoints" do
it "is false by default" do
it "is true by default" do
subject.finalize!
expect(subject.enable_checkpoints).to eq(true)
end
it "can be set" do
subject.enable_checkpoints = false
subject.finalize!
expect(subject.enable_checkpoints).to eq(false)
end
it "is enabled automatically when enable_automatic_checkpoints is enabled" do
subject.enable_checkpoints = false
subject.enable_automatic_checkpoints = true
subject.finalize!
expect(subject.enable_checkpoints).to eq(true)
end
end
describe "#enable_automatic_checkpoints" do
it "is false by default" do
subject.finalize!
expect(subject.enable_automatic_checkpoints).to eq(false)
end
it "can be set" do
subject.enable_checkpoints = true
subject.finalize!