Merge pull request #7647 from tomfanning/master

Implement auto_start_action and auto_stop_action under Hyper-V
This commit is contained in:
Seth Vargo 2016-07-26 09:28:54 -07:00 committed by GitHub
commit a9d950b41c
3 changed files with 29 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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