mirror of https://github.com/hashicorp/packer
parent
7ab4a0084b
commit
aba932b58b
@ -0,0 +1,13 @@
|
||||
package vmware
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestESX5Driver_implDriver(t *testing.T) {
|
||||
var _ Driver = new(ESX5Driver)
|
||||
}
|
||||
|
||||
func TestESX5Driver_implRemoteDriver(t *testing.T) {
|
||||
var _ RemoteDriver = new(ESX5Driver)
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package vmware
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// OutputDir is an interface type that abstracts the creation and handling
|
||||
// of the output directory for VMware-based products. The abstraction is made
|
||||
// so that the output directory can be properly made on remote (ESXi) based
|
||||
// VMware products as well as local.
|
||||
type OutputDir interface {
|
||||
DirExists(string) (bool, error)
|
||||
MkdirAll(string) error
|
||||
RemoveAll(string) error
|
||||
}
|
||||
|
||||
// localOutputDir is an OutputDir implementation where the directory
|
||||
// is on the local machine.
|
||||
type localOutputDir struct{}
|
||||
|
||||
func (localOutputDir) DirExists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
func (localOutputDir) MkdirAll(path string) error {
|
||||
return os.MkdirAll(path, 0755)
|
||||
}
|
||||
|
||||
func (localOutputDir) RemoveAll(path string) error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package vmware
|
||||
|
||||
type RemoteDriver interface {
|
||||
Driver
|
||||
|
||||
// UploadISO uploads a local ISO to the remote side and returns the
|
||||
// new path that should be used in the VMX along with an error if it
|
||||
// exists.
|
||||
UploadISO(string) (string, error)
|
||||
|
||||
// Adds a VM to inventory specified by the path to the VMX given.
|
||||
Register(string) error
|
||||
|
||||
// Removes a VM from inventory specified by the path to the VMX given.
|
||||
Unregister(string) error
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package vmware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
// stepRemoteUpload uploads some thing from the state bag to a remote driver
|
||||
// (if it can) and stores that new remote path into the state bag.
|
||||
type stepRemoteUpload struct {
|
||||
Key string
|
||||
Message string
|
||||
}
|
||||
|
||||
func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
remote, ok := driver.(RemoteDriver)
|
||||
if !ok {
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
ui.Say(s.Message)
|
||||
path := state.Get(s.Key).(string)
|
||||
log.Printf("Remote uploading: %s", path)
|
||||
newPath, err := remote.UploadISO(path)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error uploading file: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put(s.Key, newPath)
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
|
||||
}
|
||||
Loading…
Reference in new issue