Actually implement the function for the driver
This commit is contained in:
parent
181bb0ba23
commit
d2390f464d
|
@ -224,9 +224,7 @@ func (d *HypervPS4Driver) PreserveLegacyExportBehaviour(srcPath string, dstPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *HypervPS4Driver) MoveCreatedVHDsToOutputDir(srcPath string, dstPath string) error {
|
func (d *HypervPS4Driver) MoveCreatedVHDsToOutputDir(srcPath string, dstPath string) error {
|
||||||
// Not implemented yet
|
return hyperv.MoveCreatedVHDsToOutputDir(srcPath, dstPath)
|
||||||
err := fmt.Errorf("Not implemented yet")
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *HypervPS4Driver) CompactDisks(path string) (result string, err error) {
|
func (d *HypervPS4Driver) CompactDisks(path string) (result string, err error) {
|
||||||
|
|
|
@ -28,7 +28,10 @@ func (s *StepCollateArtifacts) Run(_ context.Context, state multistep.StateBag)
|
||||||
packerTempDir = v.(string)
|
packerTempDir = v.(string)
|
||||||
}
|
}
|
||||||
// If the user has chosen to skip a full export of the VM the only
|
// If the user has chosen to skip a full export of the VM the only
|
||||||
// artifacts that they are interested in will be the VHDs
|
// artifacts that they are interested in will be the VHDs. The
|
||||||
|
// called function searches for all disks under the given source
|
||||||
|
// directory and moves them to a 'Virtual Hard Disks' folder under
|
||||||
|
// the destination directory
|
||||||
err := driver.MoveCreatedVHDsToOutputDir(packerTempDir, s.OutputDir)
|
err := driver.MoveCreatedVHDsToOutputDir(packerTempDir, s.OutputDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Error moving VHDs from build dir to output dir: %s", err)
|
err = fmt.Errorf("Error moving VHDs from build dir to output dir: %s", err)
|
||||||
|
|
|
@ -721,6 +721,54 @@ if ( $((Get-Item $srcPath).GetFileSystemInfos().Count) -eq 0 ) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MoveCreatedVHDsToOutputDir(srcPath, dstPath string) error {
|
||||||
|
|
||||||
|
var script = `
|
||||||
|
param([string]$srcPath, [string]$dstPath)
|
||||||
|
|
||||||
|
# Validate the paths returning an error if the supplied path is empty
|
||||||
|
# or if the paths don't exist
|
||||||
|
$srcPath, $dstPath | % {
|
||||||
|
if ($_) {
|
||||||
|
if (! (Test-Path $_)) {
|
||||||
|
[System.Console]::Error.WriteLine("Path $_ does not exist")
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
[System.Console]::Error.WriteLine("A supplied path is empty")
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Convert to absolute paths if required
|
||||||
|
$srcPathAbs = (Get-Item($srcPath)).FullName
|
||||||
|
$dstPathAbs = (Get-Item($dstPath)).FullName
|
||||||
|
|
||||||
|
# Get the full path to all disks under the directory or exit if none are found
|
||||||
|
$disks = Get-ChildItem -Path $srcPathAbs -Recurse -Filter *.vhd* -ErrorAction SilentlyContinue | % { $_.FullName }
|
||||||
|
if ($disks.Length -eq 0) {
|
||||||
|
[System.Console]::Error.WriteLine("No disks found under $srcPathAbs")
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up directory for VHDs in the destination directory
|
||||||
|
$vhdDstDir = Join-Path -Path $dstPathAbs -ChildPath 'Virtual Hard Disks'
|
||||||
|
if (! (Test-Path $vhdDstDir)) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $vhdDstDir
|
||||||
|
}
|
||||||
|
|
||||||
|
# Move the disks
|
||||||
|
foreach ($disk in $disks) {
|
||||||
|
Move-Item -Path $disk -Destination $vhdDstDir
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var ps powershell.PowerShellCmd
|
||||||
|
err := ps.Run(script, srcPath, dstPath)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func CompactDisks(path string) (result string, err error) {
|
func CompactDisks(path string) (result string, err error) {
|
||||||
var script = `
|
var script = `
|
||||||
param([string]$srcPath)
|
param([string]$srcPath)
|
||||||
|
|
Loading…
Reference in New Issue