Merge pull request #9999 from chrisroberts/f-hyper-v-snaps

Enable checkpoints for snapshots if disabled
This commit is contained in:
Chris Roberts 2018-07-18 16:38:32 -07:00 committed by GitHub
commit 10faa599e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 15 deletions

View File

@ -139,17 +139,23 @@ module VagrantPlugins
next
end
b2.use Provision
b2.use Configure
b2.use SetName
b2.use NetSetVLan
b2.use NetSetMac
b2.use StartInstance
b2.use WaitForIPAddress
b2.use WaitForCommunicator, [:running]
b2.use SyncedFolderCleanup
b2.use SyncedFolders
b2.use SetHostname
b2.use Call, IsState, :saved do |env3, b3|
# When state is `:saved` it is a snapshot being restored
if !env3[:result]
b3.use Provision
b3.use Configure
b3.use SetName
b3.use NetSetVLan
b3.use NetSetMac
end
b3.use StartInstance
b3.use WaitForIPAddress
b3.use WaitForCommunicator, [:running]
b3.use SyncedFolderCleanup
b3.use SyncedFolders
b3.use SetHostname
end
end
end
end

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

@ -10,7 +10,14 @@ $ErrorActionPreference = "Stop"
try {
$VM = Hyper-V\Get-VM -Id $VmId
$ChkPnt = $VM.CheckpointType
if($ChkPnt -eq "Disabled") {
Hyper-V\Set-VM -VM $VM -CheckpointType "Standard"
}
Hyper-V\Checkpoint-VM $VM -SnapshotName $SnapName
if($ChkPnt -eq "Disabled") {
Hyper-V\Set-VM -VM $VM -CheckpointType "Disabled"
}
} catch {
Write-ErrorMessage "Failed to create snapshot: ${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!