vagrant/plugins/providers/hyperv/config.rb

119 lines
4.5 KiB
Ruby
Raw Normal View History

require "vagrant"
2014-02-15 23:38:11 +00:00
module VagrantPlugins
module HyperV
class Config < Vagrant.plugin("2", :config)
2018-05-24 16:57:55 +00:00
# Allowed automatic start actions for VM
ALLOWED_AUTO_START_ACTIONS = [
"Nothing".freeze,
"StartIfRunning".freeze,
"Start".freeze
].freeze
# Allowed automatic stop actions for VM
ALLOWED_AUTO_STOP_ACTIONS = [
"ShutDown".freeze,
"TurnOff".freeze,
"Save".freeze
].freeze
# @return [Integer] Seconds to wait for an IP address when booting
attr_accessor :ip_address_timeout
# @return [Integer] Memory size in MB
attr_accessor :memory
# @return [Integer] Maximum memory size in MB. Enables dynamic memory.
attr_accessor :maxmemory
# @return [Integer] Number of CPUs
attr_accessor :cpus
# @return [String] Name of the VM (Shown in the Hyper-V Manager)
attr_accessor :vmname
# @return [Integer] VLAN ID for network interface
attr_accessor :vlan_id
# @return [String] MAC address for network interface
attr_accessor :mac
# @return [Boolean] Create linked clone instead of full clone
# @note **DEPRECATED** use #linked_clone instead
attr_accessor :differencing_disk
# @return [Boolean] Create linked clone instead of full clone
attr_accessor :linked_clone
# @return [String] Automatic action on start of host. Default: Nothing (Nothing, StartIfRunning, Start)
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
attr_accessor :enable_checkpoints
# @return [Boolean] Enable virtualization extensions
attr_accessor :enable_virtualization_extensions
# @return [Hash] Options for VMServiceIntegration
attr_accessor :vm_integration_services
2014-02-26 19:12:24 +00:00
def initialize
@ip_address_timeout = UNSET_VALUE
@memory = UNSET_VALUE
@maxmemory = UNSET_VALUE
@cpus = UNSET_VALUE
@vmname = UNSET_VALUE
2017-03-15 17:09:18 +00:00
@vlan_id = UNSET_VALUE
@mac = UNSET_VALUE
2018-05-24 16:57:55 +00:00
@linked_clone = UNSET_VALUE
2016-03-01 15:23:38 +00:00
@differencing_disk = UNSET_VALUE
@auto_start_action = UNSET_VALUE
2016-07-26 12:56:20 +00:00
@auto_stop_action = UNSET_VALUE
@enable_virtualization_extensions = UNSET_VALUE
2018-05-24 16:57:55 +00:00
@enable_checkpoints = UNSET_VALUE
@vm_integration_services = {
2017-03-15 17:09:18 +00:00
guest_service_interface: UNSET_VALUE,
heartbeat: UNSET_VALUE,
key_value_pair_exchange: UNSET_VALUE,
shutdown: UNSET_VALUE,
time_synchronization: UNSET_VALUE,
vss: UNSET_VALUE
2017-03-15 17:09:18 +00:00
}
end
def finalize!
2018-05-24 16:57:55 +00:00
@linked_clone = false if @linked_clone == UNSET_VALUE
@differencing_disk = false if @differencing_disk == UNSET_VALUE
@linked_clone ||= @differencing_disk
@differencing_disk ||= @linked_clone
2014-02-26 19:12:24 +00:00
if @ip_address_timeout == UNSET_VALUE
@ip_address_timeout = 120
end
@memory = nil if @memory == UNSET_VALUE
@maxmemory = nil if @maxmemory == UNSET_VALUE
2016-03-01 15:23:38 +00:00
@cpus = nil if @cpus == UNSET_VALUE
@vmname = nil if @vmname == UNSET_VALUE
@vlan_id = nil if @vlan_id == UNSET_VALUE
2015-09-22 10:35:55 +00:00
@mac = nil if @mac == UNSET_VALUE
2017-03-15 17:09:18 +00:00
2018-05-24 16:57:55 +00:00
@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_checkpoints == UNSET_VALUE
@enable_checkpoints = false
else
@enable_checkpoints = !!@enable_checkpoints
end
@vm_integration_services.delete_if{|_, v| v == UNSET_VALUE }
@vm_integration_services = nil if @vm_integration_services.empty?
end
def validate(machine)
errors = _detected_errors
2014-02-27 07:13:09 +00:00
2018-05-24 16:57:55 +00:00
if !ALLOWED_AUTO_START_ACTIONS.include?(auto_start_action)
errors << I18n.t("vagrant.hyperv.config.invalid_auto_start_action", action: auto_start_action,
allowed_actions: ALLOWED_AUTO_START_ACTIONS.join(", "))
end
if !ALLOWED_AUTO_STOP_ACTIONS.include?(auto_stop_action)
errors << I18n.t("vagrant.hyperv.config.invalid_auto_stop_action", action: auto_stop_action,
allowed_actions: ALLOWED_AUTO_STOP_ACTIONS.join(", "))
end
2017-03-15 17:09:18 +00:00
{"Hyper-V" => errors}
end
end
end
end