2014-02-15 23:29:16 +00:00
|
|
|
require "vagrant"
|
2014-02-15 23:38:11 +00:00
|
|
|
|
2014-02-15 23:29:16 +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
|
2015-03-30 14:37:29 +00:00
|
|
|
|
2014-02-26 19:12:24 +00:00
|
|
|
def initialize
|
|
|
|
@ip_address_timeout = UNSET_VALUE
|
2015-01-14 14:59:01 +00:00
|
|
|
@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
|
2016-07-26 12:41:01 +00:00
|
|
|
@auto_start_action = UNSET_VALUE
|
2016-07-26 12:56:20 +00:00
|
|
|
@auto_stop_action = UNSET_VALUE
|
2016-08-18 05:41:32 +00:00
|
|
|
@enable_virtualization_extensions = UNSET_VALUE
|
2018-05-24 16:57:55 +00:00
|
|
|
@enable_checkpoints = UNSET_VALUE
|
2018-05-24 23:55:35 +00:00
|
|
|
@vm_integration_services = {}
|
2014-02-15 23:29:16 +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
|
2015-01-14 14:59:01 +00:00
|
|
|
@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
|
2015-01-14 14:59:01 +00:00
|
|
|
@vmname = nil if @vmname == UNSET_VALUE
|
2015-03-30 16:17:29 +00:00
|
|
|
@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
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
2014-02-27 07:13:09 +00:00
|
|
|
|
2018-05-24 23:55:35 +00:00
|
|
|
if !vm_integration_services.is_a?(Hash)
|
|
|
|
errors << I18n.t("vagrant_hyperv.config.invalid_integration_services_type",
|
|
|
|
received: vm_integration_services.class)
|
|
|
|
else
|
|
|
|
vm_integration_services.each do |key, value|
|
|
|
|
if ![true, false].include?(value)
|
|
|
|
errors << I18n.t("vagrant_hyperv.config.invalid_integration_services_entry",
|
|
|
|
entry_name: name, entry_value: value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-24 16:57:55 +00:00
|
|
|
if !ALLOWED_AUTO_START_ACTIONS.include?(auto_start_action)
|
2018-05-24 23:55:35 +00:00
|
|
|
errors << I18n.t("vagrant_hyperv.config.invalid_auto_start_action", action: auto_start_action,
|
2018-05-24 16:57:55 +00:00
|
|
|
allowed_actions: ALLOWED_AUTO_START_ACTIONS.join(", "))
|
|
|
|
end
|
|
|
|
|
|
|
|
if !ALLOWED_AUTO_STOP_ACTIONS.include?(auto_stop_action)
|
2018-05-24 23:55:35 +00:00
|
|
|
errors << I18n.t("vagrant_hyperv.config.invalid_auto_stop_action", action: auto_stop_action,
|
2018-05-24 16:57:55 +00:00
|
|
|
allowed_actions: ALLOWED_AUTO_STOP_ACTIONS.join(", "))
|
|
|
|
end
|
|
|
|
|
2017-03-15 17:09:18 +00:00
|
|
|
{"Hyper-V" => errors}
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|