Skip to content

Commit

Permalink
accept vhd as well as vhdx file types on hyper-v
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed Jul 17, 2014
1 parent 5c148e4 commit efd7c61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions plugins/providers/hyperv/action/import.rb
Expand Up @@ -27,15 +27,17 @@ def call(env)
end
end

vhdx_path = nil
image_path = nil
image_ext = nil
hd_dir.each_child do |f|
if f.extname.downcase == ".vhdx"
vhdx_path = f
if %w{.vhd .vhdx}.include?(f.extname.downcase)
image_path = f
image_ext = f.extname.downcase
break
end
end

if !config_path || !vhdx_path
if !config_path || !image_path
raise Errors::BoxInvalid
end

Expand Down Expand Up @@ -64,16 +66,16 @@ def call(env)
end

env[:ui].detail("Cloning virtual hard drive...")
source_path = vhdx_path.to_s
dest_path = env[:machine].data_dir.join("disk.vhdx").to_s
source_path = image_path.to_s
dest_path = env[:machine].data_dir.join("disk.#{image_ext}").to_s
FileUtils.cp(source_path, dest_path)
vhdx_path = dest_path
image_path = dest_path

# We have to normalize the paths to be Windows paths since
# we're executing PowerShell.
options = {
vm_xml_config: config_path.to_s.gsub("/", "\\"),
vhdx_path: vhdx_path.to_s.gsub("/", "\\")
image_path: image_path.to_s.gsub("/", "\\")
}
options[:switchname] = switch if switch

Expand Down
4 changes: 2 additions & 2 deletions plugins/providers/hyperv/scripts/import_vm.ps1
Expand Up @@ -2,7 +2,7 @@ Param(
[Parameter(Mandatory=$true)]
[string]$vm_xml_config,
[Parameter(Mandatory=$true)]
[string]$vhdx_path,
[string]$image_path,

[string]$switchname=$null
)
Expand Down Expand Up @@ -119,7 +119,7 @@ foreach ($controller in $controllers) {

$addDriveParam = @{
ControllerNumber = $rx.Match($controller.node.name).value
Path = $vhdx_path
Path = $image_path
}

if ($drive.pool_id."#text") {
Expand Down

0 comments on commit efd7c61

Please sign in to comment.