From 344fc0ea7b3026a0caf6dade45b183ec06a43bf4 Mon Sep 17 00:00:00 2001 From: tfanning Date: Tue, 26 Jul 2016 13:41:01 +0100 Subject: [PATCH 1/2] Implement auto_start_action and auto_stop_action --- plugins/providers/hyperv/action/import.rb | 6 ++++++ plugins/providers/hyperv/config.rb | 6 ++++++ plugins/providers/hyperv/scripts/import_vm.ps1 | 12 +++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index fc3e5facc..35d843299 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -19,12 +19,16 @@ module VagrantPlugins cpus = env[:machine].provider_config.cpus vmname = env[:machine].provider_config.vmname differencing_disk = env[:machine].provider_config.differencing_disk + auto_start_action = env[:machine].provider_config.auto_start_action + auto_stop_action = env[:machine].provider_config.auto_stop_action env[:ui].output("Configured Dynamic memory allocation, maxmemory is #{maxmemory}") if maxmemory env[:ui].output("Configured startup memory is #{memory}") if memory env[:ui].output("Configured cpus number is #{cpus}") if cpus env[:ui].output("Configured vmname is #{vmname}") if vmname env[:ui].output("Configured differencing disk instead of cloning") if differencing_disk + env[:ui].output("Configured automatic start action is #{auto_start_action}") if auto_start_action + env[:ui].output("Configured automatic stop action is #{auto_stop_action}") if auto_stop_action if !vm_dir.directory? || !hd_dir.directory? raise Errors::BoxInvalid @@ -115,6 +119,8 @@ module VagrantPlugins options[:maxmemory] = maxmemory if maxmemory options[:cpus] = cpus if cpus options[:vmname] = vmname if vmname + options[:auto_start_action] = auto_start_action if auto_start_action + options[:auto_stop_action] = auto_stop_action if auto_stop_action env[:ui].detail("Creating and registering the VM...") server = env[:machine].provider.driver.import(options) diff --git a/plugins/providers/hyperv/config.rb b/plugins/providers/hyperv/config.rb index 37047756d..f1f84cb5d 100644 --- a/plugins/providers/hyperv/config.rb +++ b/plugins/providers/hyperv/config.rb @@ -12,6 +12,8 @@ module VagrantPlugins attr_accessor :vlan_id # VLAN ID for network interface for the virtual machine. @return [Integer] attr_accessor :mac # MAC address for network interface for the virtual machine. @return [String] attr_accessor :differencing_disk # Create differencing disk instead of cloning whole VHD [Boolean] + attr_accessor :auto_start_action #action on automatic start of VM. Values: Nothing, StartIfRunning, Start + attr_accessor :auto_stop_action #action on automatic stop of VM. Values: ShutDown, TurnOff, Save def initialize @ip_address_timeout = UNSET_VALUE @@ -22,6 +24,8 @@ module VagrantPlugins @vlan_id = UNSET_VALUE @mac = UNSET_VALUE @differencing_disk = UNSET_VALUE + @auto_start_action = UNSET_VALUE + @auto_stop_action = UNSET_VALUE end def finalize! @@ -35,6 +39,8 @@ module VagrantPlugins @vlan_id = nil if @vlan_id == UNSET_VALUE @mac = nil if @mac == UNSET_VALUE @differencing_disk = false if @differencing_disk == UNSET_VALUE + @auto_start_action = nil if @auto_start_action == UNSET_VALUE + @auto_stop_action = nil if @auto_stop_action == UNSET_VALUE end def validate(machine) diff --git a/plugins/providers/hyperv/scripts/import_vm.ps1 b/plugins/providers/hyperv/scripts/import_vm.ps1 index 7232be56d..feab70e2e 100644 --- a/plugins/providers/hyperv/scripts/import_vm.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm.ps1 @@ -8,7 +8,9 @@ Param( [string]$memory=$null, [string]$maxmemory=$null, [string]$cpus=$null, - [string]$vmname=$null + [string]$vmname=$null, + [string]$auto_start_action=$null, + [string]$auto_stop_action=$null ) # Include the following modules @@ -144,6 +146,14 @@ if ($notes) { $more_vm_params.Add("Notes",$notes) } +if ($auto_start_action) { + $more_vm_params.Add("AutomaticStartAction",$auto_start_action) +} + +if ($auto_stop_action) { + $more_vm_params.Add("AutomaticStopAction",$auto_stop_action) +} + # Set the values on the VM $vm | Set-VM @more_vm_params -Passthru From d350fd0d288b7951a19867c16fa50429b9f555f6 Mon Sep 17 00:00:00 2001 From: tfanning Date: Tue, 26 Jul 2016 13:56:20 +0100 Subject: [PATCH 2/2] Resolve whitespace --- plugins/providers/hyperv/action/import.rb | 6 +++--- plugins/providers/hyperv/config.rb | 6 +++--- .../providers/hyperv/scripts/import_vm.ps1 | 20 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index 35d843299..18525543e 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -20,7 +20,7 @@ module VagrantPlugins vmname = env[:machine].provider_config.vmname differencing_disk = env[:machine].provider_config.differencing_disk auto_start_action = env[:machine].provider_config.auto_start_action - auto_stop_action = env[:machine].provider_config.auto_stop_action + auto_stop_action = env[:machine].provider_config.auto_stop_action env[:ui].output("Configured Dynamic memory allocation, maxmemory is #{maxmemory}") if maxmemory env[:ui].output("Configured startup memory is #{memory}") if memory @@ -28,7 +28,7 @@ module VagrantPlugins env[:ui].output("Configured vmname is #{vmname}") if vmname env[:ui].output("Configured differencing disk instead of cloning") if differencing_disk env[:ui].output("Configured automatic start action is #{auto_start_action}") if auto_start_action - env[:ui].output("Configured automatic stop action is #{auto_stop_action}") if auto_stop_action + env[:ui].output("Configured automatic stop action is #{auto_stop_action}") if auto_stop_action if !vm_dir.directory? || !hd_dir.directory? raise Errors::BoxInvalid @@ -120,7 +120,7 @@ module VagrantPlugins options[:cpus] = cpus if cpus options[:vmname] = vmname if vmname options[:auto_start_action] = auto_start_action if auto_start_action - options[:auto_stop_action] = auto_stop_action if auto_stop_action + options[:auto_stop_action] = auto_stop_action if auto_stop_action env[:ui].detail("Creating and registering the VM...") server = env[:machine].provider.driver.import(options) diff --git a/plugins/providers/hyperv/config.rb b/plugins/providers/hyperv/config.rb index f1f84cb5d..1726bd45f 100644 --- a/plugins/providers/hyperv/config.rb +++ b/plugins/providers/hyperv/config.rb @@ -13,7 +13,7 @@ module VagrantPlugins attr_accessor :mac # MAC address for network interface for the virtual machine. @return [String] attr_accessor :differencing_disk # Create differencing disk instead of cloning whole VHD [Boolean] attr_accessor :auto_start_action #action on automatic start of VM. Values: Nothing, StartIfRunning, Start - attr_accessor :auto_stop_action #action on automatic stop of VM. Values: ShutDown, TurnOff, Save + attr_accessor :auto_stop_action #action on automatic stop of VM. Values: ShutDown, TurnOff, Save def initialize @ip_address_timeout = UNSET_VALUE @@ -25,7 +25,7 @@ module VagrantPlugins @mac = UNSET_VALUE @differencing_disk = UNSET_VALUE @auto_start_action = UNSET_VALUE - @auto_stop_action = UNSET_VALUE + @auto_stop_action = UNSET_VALUE end def finalize! @@ -40,7 +40,7 @@ module VagrantPlugins @mac = nil if @mac == UNSET_VALUE @differencing_disk = false if @differencing_disk == UNSET_VALUE @auto_start_action = nil if @auto_start_action == UNSET_VALUE - @auto_stop_action = nil if @auto_stop_action == UNSET_VALUE + @auto_stop_action = nil if @auto_stop_action == UNSET_VALUE end def validate(machine) diff --git a/plugins/providers/hyperv/scripts/import_vm.ps1 b/plugins/providers/hyperv/scripts/import_vm.ps1 index feab70e2e..659eb50aa 100644 --- a/plugins/providers/hyperv/scripts/import_vm.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm.ps1 @@ -9,8 +9,8 @@ Param( [string]$maxmemory=$null, [string]$cpus=$null, [string]$vmname=$null, - [string]$auto_start_action=$null, - [string]$auto_stop_action=$null + [string]$auto_start_action=$null, + [string]$auto_stop_action=$null ) # Include the following modules @@ -147,11 +147,11 @@ if ($notes) { } if ($auto_start_action) { - $more_vm_params.Add("AutomaticStartAction",$auto_start_action) + $more_vm_params.Add("AutomaticStartAction",$auto_start_action) } if ($auto_stop_action) { - $more_vm_params.Add("AutomaticStopAction",$auto_stop_action) + $more_vm_params.Add("AutomaticStopAction",$auto_stop_action) } # Set the values on the VM @@ -162,12 +162,12 @@ $controllers = Select-Xml -xml $vmconfig -xpath "//*[starts-with(name(.),'contro # Only set EFI secure boot for Gen 2 machines, not gen 1 if ($generation -ne 1) { - # Set EFI secure boot - if ($secure_boot_enabled -eq "True") { - Set-VMFirmware -VM $vm -EnableSecureBoot On - } else { - Set-VMFirmware -VM $vm -EnableSecureBoot Off - } + # Set EFI secure boot + if ($secure_boot_enabled -eq "True") { + Set-VMFirmware -VM $vm -EnableSecureBoot On + } else { + Set-VMFirmware -VM $vm -EnableSecureBoot Off + } } # A regular expression pattern to pull the number from controllers