output dir file structure updated to comply vagrant expectations, binary added build for windows
This commit is contained in:
Родитель
8364ba3e17
Коммит
fefbffccd9
|
@ -0,0 +1,10 @@
|
|||
|
||||
Download the archive to your devbox and extract it into your packer folder.
|
||||
|
||||
The files builder-hyperv-iso.exe and provisioner-powershell.exe in the archive are Packer plugins.
|
||||
|
||||
How to install plugins you can find here: http://www.packer.io/docs/extend/plugins.html
|
||||
|
||||
File _install.cmd can install the plugins for you.
|
||||
|
||||
The file packer-post-processor-vagrant.exe is an extention of the original file with the same name to create a vagrant box from a Hyper-V atrifact.
|
Двоичный файл не отображается.
|
@ -26,6 +26,11 @@ type artifact struct {
|
|||
// in the given directory.
|
||||
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||
files := make([]string, 0, 5)
|
||||
|
||||
// we need to store output dir path to get rel path to keep dir tree :)
|
||||
// to not modify interface - put it as the first array element
|
||||
files = append(files, dir)
|
||||
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
|
|
|
@ -12,7 +12,7 @@ package common
|
|||
// extremely specific.
|
||||
type Driver interface {
|
||||
|
||||
// VBoxManage executes the given HypervManage command
|
||||
// HypervManage executes the given HypervManage command
|
||||
HypervManage(string) error
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func (s *StepCreateTempDir) Run(state multistep.StateBag) multistep.StepAction {
|
|||
ui.Say("Creating temporary directory...")
|
||||
|
||||
tempDir := os.TempDir()
|
||||
packerTempDir, err := ioutil.TempDir(tempDir, "packer")
|
||||
packerTempDir, err := ioutil.TempDir(tempDir, "packerhv")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error creating temporary directory: %s", err)
|
||||
state.Put("error", err)
|
||||
|
|
|
@ -215,10 +215,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
state.Put("ui", ui)
|
||||
|
||||
// TODO: remove the next line
|
||||
// state.Put("vmName", "PackerFull")
|
||||
// state.Put("vmName", "FullActiavated")
|
||||
|
||||
steps := []multistep.Step{
|
||||
// new(hypervcommon.StepAcceptEula),
|
||||
|
||||
new(hypervcommon.StepCreateTempDir),
|
||||
&hypervcommon.StepOutputDir{
|
||||
Force: b.config.PackerForce,
|
||||
|
@ -241,6 +242,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
new(common.StepProvision),
|
||||
new(StepInstallProductKey),
|
||||
|
||||
new(StepExportVm),
|
||||
|
||||
// new(hypervcommon.StepConfigureIp),
|
||||
// new(hypervcommon.StepSetRemoting),
|
||||
// new(hypervcommon.StepCheckRemoting),
|
||||
|
|
|
@ -28,8 +28,8 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
|
|||
ui.Say("Creating virtual machine...")
|
||||
|
||||
vmName := config.VMName
|
||||
path := config.OutputDir
|
||||
// path := state.Get("packerTempDir").(string)
|
||||
// path := config.OutputDir
|
||||
path := state.Get("packerTempDir").(string)
|
||||
|
||||
ram := config.RamSizeMB
|
||||
diskSize := config.DiskSizeGB
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All Rights Reserved.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// See License.txt in the project root for license information.
|
||||
package iso
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"path/filepath"
|
||||
hypervcommon "github.com/MSOpenTech/packer-hyperv/packer/builder/hyperv/common"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const(
|
||||
vhdDir string = "Virtual Hard Disks"
|
||||
vmDir string = "Virtual Machines"
|
||||
)
|
||||
|
||||
type StepExportVm struct {
|
||||
}
|
||||
|
||||
func (s *StepExportVm) Run(state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("config").(*iso_config)
|
||||
driver := state.Get("driver").(hypervcommon.Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
var err error
|
||||
var errorMsg string
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
tmpPath := state.Get("packerTempDir").(string)
|
||||
outputPath := config.OutputDir
|
||||
|
||||
// create temp path to export vm
|
||||
errorMsg = "Error creating temp export path: %s"
|
||||
vmExportPath , err := ioutil.TempDir(tmpPath, "export")
|
||||
if err != nil {
|
||||
err := fmt.Errorf(errorMsg, err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
ui.Say("Exporting vm...")
|
||||
errorMsg = "Error exporting vm: %s"
|
||||
|
||||
var blockBuffer bytes.Buffer
|
||||
blockBuffer.WriteString("Invoke-Command -scriptblock {")
|
||||
blockBuffer.WriteString("$vmName='" + vmName + "';")
|
||||
blockBuffer.WriteString("$path='" + vmExportPath + "';")
|
||||
blockBuffer.WriteString("Export-VM -Name $vmName -Path $path")
|
||||
blockBuffer.WriteString("}")
|
||||
|
||||
err = driver.HypervManage( blockBuffer.String() )
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf(errorMsg, err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
// copy to output dir
|
||||
|
||||
ui.Say("Coping to output dir...")
|
||||
|
||||
errorMsg = "Error copying vm: %s"
|
||||
|
||||
expPath := filepath.Join(vmExportPath,vmName)
|
||||
|
||||
blockBuffer.Reset()
|
||||
blockBuffer.WriteString("Invoke-Command -scriptblock {")
|
||||
blockBuffer.WriteString("$srcPath='" + expPath + "';")
|
||||
blockBuffer.WriteString("$dstPath='" + outputPath + "';")
|
||||
blockBuffer.WriteString("$vhdDirName='" + vhdDir + "';")
|
||||
blockBuffer.WriteString("$vmDir='" + vmDir + "';")
|
||||
blockBuffer.WriteString("cpi \"$srcPath\\$vhdDirName\" $dstPath -recurse;")
|
||||
blockBuffer.WriteString("cpi \"$srcPath\\$vmDir\" \"$dstPath\";")
|
||||
blockBuffer.WriteString("cpi \"$srcPath\\$vmDir\\*.xml\" \"$dstPath\\$vmDir\";")
|
||||
blockBuffer.WriteString("}")
|
||||
|
||||
err = driver.HypervManage( blockBuffer.String() )
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf(errorMsg, err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepExportVm) Cleanup(state multistep.StateBag) {
|
||||
// do nothing
|
||||
}
|
|
@ -205,7 +205,7 @@ func (c *comm) uploadFolder(dscPath string, srcPath string ) error {
|
|||
dst string
|
||||
}
|
||||
|
||||
tarWalk := func(path string, info os.FileInfo, prevErr error) error {
|
||||
treeWalk := func(path string, info os.FileInfo, prevErr error) error {
|
||||
// If there was a prior error, return it
|
||||
if prevErr != nil {
|
||||
return prevErr
|
||||
|
@ -230,7 +230,7 @@ func (c *comm) uploadFolder(dscPath string, srcPath string ) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
filepath.Walk(srcPath, tarWalk)
|
||||
filepath.Walk(srcPath, treeWalk)
|
||||
|
||||
var err error
|
||||
for e := l.Front(); e != nil; e = e.Next() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче