forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
builder/vmware-esxi: Add step_export
If `format` option is configured, packer exports the VM with ovftool. website: Document about OVF Tool and `format` option. post-processor/vsphere: Enable to use `mitchellh.vmware-esx` artifact type and OVF and OVA formats, fixes hashicorp#1457.
- Loading branch information
Showing
10 changed files
with
174 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package iso | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/mitchellh/multistep" | ||
"github.com/mitchellh/packer/packer" | ||
"net/url" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
type StepExport struct { | ||
Format string | ||
} | ||
|
||
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { | ||
c := state.Get("config").(*Config) | ||
ui := state.Get("ui").(packer.Ui) | ||
|
||
if c.RemoteType != "esx5" || s.Format == "" { | ||
return multistep.ActionContinue | ||
} | ||
|
||
ovftool := "ovftool" | ||
if runtime.GOOS == "windows" { | ||
ovftool = "ovftool.exe" | ||
} | ||
|
||
if _, err := exec.LookPath(ovftool); err != nil { | ||
err := fmt.Errorf("Error %s not found: %s", ovftool, err) | ||
state.Put("error", err) | ||
ui.Error(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
|
||
// Export the VM | ||
outputPath := filepath.Join(c.VMName, c.VMName+"."+s.Format) | ||
|
||
if s.Format == "ova" { | ||
os.MkdirAll(outputPath, 0755) | ||
} | ||
|
||
args := []string{ | ||
"--noSSLVerify=true", | ||
"--skipManifestCheck", | ||
"-tt=" + s.Format, | ||
"vi://" + c.RemoteUser + ":" + url.QueryEscape(c.RemotePassword) + "@" + c.RemoteHost + "/" + c.VMName, | ||
outputPath, | ||
} | ||
|
||
ui.Say("Exporting virtual machine...") | ||
ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(args, " "))) | ||
var out bytes.Buffer | ||
cmd := exec.Command(ovftool, args...) | ||
cmd.Stdout = &out | ||
if err := cmd.Run(); err != nil { | ||
err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String()) | ||
state.Put("error", err) | ||
ui.Error(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
|
||
ui.Message(fmt.Sprintf("%s", out.String())) | ||
|
||
state.Put("exportPath", outputPath) | ||
|
||
return multistep.ActionContinue | ||
} | ||
|
||
func (s *StepExport) Cleanup(state multistep.StateBag) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters