diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index 18525543e..97351e12a 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -35,9 +35,17 @@ module VagrantPlugins end config_path = nil + config_type = nil vm_dir.each_child do |f| - if f.extname.downcase == ".xml" + + if f.extname.downcase == '.xml' config_path = f + config_type = 'xml' + break + end + if f.extname.downcase == '.vmcx' + config_path = f + config_type = 'vmcx' break end end @@ -111,7 +119,8 @@ module VagrantPlugins # We have to normalize the paths to be Windows paths since # we're executing PowerShell. options = { - vm_xml_config: config_path.to_s.gsub("/", "\\"), + vm_config: config_path.to_s.gsub("/", "\\"), + vm_config_type: config_type, image_path: image_path.to_s.gsub("/", "\\") } options[:switchname] = switch if switch diff --git a/plugins/providers/hyperv/driver.rb b/plugins/providers/hyperv/driver.rb index 604c46bbd..73fb2eb74 100644 --- a/plugins/providers/hyperv/driver.rb +++ b/plugins/providers/hyperv/driver.rb @@ -74,7 +74,12 @@ module VagrantPlugins end def import(options) - execute('import_vm.ps1', options) + config_type = options.delete(:vm_config_type) + if config_type === "vmcx" + execute('import_vm_vmcx.ps1', options) + else + execute('import_vm_xml.ps1', options) + end end def net_set_vlan(vlan_id) diff --git a/plugins/providers/hyperv/scripts/import_vm.ps1 b/plugins/providers/hyperv/scripts/import_vm_xml.ps1 similarity index 98% rename from plugins/providers/hyperv/scripts/import_vm.ps1 rename to plugins/providers/hyperv/scripts/import_vm_xml.ps1 index 659eb50aa..18d99d203 100644 --- a/plugins/providers/hyperv/scripts/import_vm.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm_xml.ps1 @@ -1,6 +1,6 @@ Param( [Parameter(Mandatory=$true)] - [string]$vm_xml_config, + [string]$vm_config, [Parameter(Mandatory=$true)] [string]$image_path, @@ -17,7 +17,7 @@ Param( $Dir = Split-Path $script:MyInvocation.MyCommand.Path . ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1")) -[xml]$vmconfig = Get-Content -Path $vm_xml_config +[xml]$vmconfig = Get-Content -Path $vm_config $generation = [int]($vmconfig.configuration.properties.subtype.'#text')+1