Rebase and add USE_XE option to xva export

Signed-off-by: Phus Lu <phus.lu@citrix.com>
This commit is contained in:
Phus Lu 2016-07-15 09:27:11 -07:00
parent addd20360c
commit a850d3d4f0
9 changed files with 40 additions and 20 deletions

View File

@ -1,7 +1,7 @@
language: go language: go
go: go:
# Test with the first and the latest go release - to ensure compatibility # Test with the first and the latest go release - to ensure compatibility
- 1.2 - 1.6
- release - tip
script: script:
- gofmtresult=$(gofmt -s -l .); if [[ -n $gofmtresult ]]; then echo -e "Please run \"gofmt -s -w .\" before committing for the below:\n$gofmtresult"; false; fi - gofmtresult=$(gofmt -s -l .); if [[ -n $gofmtresult ]]; then echo -e "Please run \"gofmt -s -w .\" before committing for the below:\n$gofmtresult"; false; fi

View File

@ -6,15 +6,13 @@
# Determine the arch/os combos we're building for # Determine the arch/os combos we're building for
XC_OS=${XC_OS:-$(go env GOOS)} XC_OS=${XC_OS:-$(go env GOOS)}
XC_ARCH=${XC_ARCH:-$(go env GOARCH)} XC_ARCH=${XC_ARCH:-$(go env GOARCH)}
GOPATH=${GOPATH:-$(go env GOPATH)}
# Install dependencies
echo "==> Getting dependencies..."
go get ./...
# Delete the old dir # Delete the old dir
echo "==> Removing old directory..." echo "==> Removing old directory..."
rm -f bin/* rm -f bin/*
rm -rf pkg/* rm -rf pkg/*
rm -rf $GOPATH/pkg/*
mkdir -p bin/ mkdir -p bin/
gox \ gox \

View File

@ -9,6 +9,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"os/exec"
) )
type StepExport struct{} type StepExport struct{}
@ -20,6 +21,7 @@ func downloadFile(url, filename string, ui packer.Ui) (err error) {
if err != nil { if err != nil {
return err return err
} }
defer fh.Close()
// Define a new transport which allows self-signed certs // Define a new transport which allows self-signed certs
tr := &http.Transport{ tr := &http.Transport{
@ -101,16 +103,36 @@ func (StepExport) Run(state multistep.StateBag) multistep.StepAction {
case "xva": case "xva":
// export the VM // export the VM
export_url := fmt.Sprintf("https://%s/export?uuid=%s&session_id=%s",
client.Host,
instance_uuid,
client.Session.(string),
)
export_filename := fmt.Sprintf("%s/%s.xva", config.OutputDir, config.VMName) export_filename := fmt.Sprintf("%s/%s.xva", config.OutputDir, config.VMName)
ui.Say("Getting XVA " + export_url) use_xe := os.Getenv("USE_XE") == "1"
err = downloadFile(export_url, export_filename, ui) if xe, e := exec.LookPath("xe"); e == nil && use_xe {
cmd := exec.Command(
xe,
"-s", client.Host,
"-p", "443",
"-u", client.Username,
"-pw", client.Password,
"vm-export",
"vm="+instance_uuid,
"compress=true",
"filename="+export_filename,
)
ui.Say(fmt.Sprintf("Getting XVA %+v %+v", cmd.Path, cmd.Args))
err = cmd.Run()
} else {
export_url := fmt.Sprintf("https://%s/export?uuid=%s&session_id=%s",
client.Host,
instance_uuid,
client.Session.(string),
)
ui.Say("Getting XVA " + export_url)
err = downloadFile(export_url, export_filename, ui)
}
if err != nil { if err != nil {
ui.Error(fmt.Sprintf("Could not download XVA: %s", err.Error())) ui.Error(fmt.Sprintf("Could not download XVA: %s", err.Error()))
return multistep.ActionHalt return multistep.ActionHalt

View File

@ -1,10 +1,10 @@
package common package common
import ( import (
gossh "code.google.com/p/go.crypto/ssh"
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
gossh "golang.org/x/crypto/ssh"
xsclient "github.com/xenserver/go-xenserver-client" xsclient "github.com/xenserver/go-xenserver-client"
"log" "log"
"time" "time"

View File

@ -14,8 +14,8 @@ import (
hconfig "github.com/mitchellh/packer/helper/config" hconfig "github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
xscommon "github.com/rdobson/packer-builder-xenserver/builder/xenserver/common"
xsclient "github.com/xenserver/go-xenserver-client" xsclient "github.com/xenserver/go-xenserver-client"
xscommon "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common"
) )
type config struct { type config struct {

View File

@ -12,8 +12,8 @@ import (
hconfig "github.com/mitchellh/packer/helper/config" hconfig "github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
xscommon "github.com/rdobson/packer-builder-xenserver/builder/xenserver/common"
xsclient "github.com/xenserver/go-xenserver-client" xsclient "github.com/xenserver/go-xenserver-client"
xscommon "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common"
) )
type config struct { type config struct {

View File

@ -6,8 +6,8 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
xscommon "github.com/rdobson/packer-builder-xenserver/builder/xenserver/common"
xsclient "github.com/xenserver/go-xenserver-client" xsclient "github.com/xenserver/go-xenserver-client"
xscommon "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common"
) )
type stepImportInstance struct { type stepImportInstance struct {

View File

@ -2,7 +2,7 @@ package main
import ( import (
"github.com/mitchellh/packer/packer/plugin" "github.com/mitchellh/packer/packer/plugin"
"github.com/rdobson/packer-builder-xenserver/builder/xenserver/iso" "github.com/xenserver/packer-builder-xenserver/builder/xenserver/iso"
) )
func main() { func main() {

View File

@ -2,7 +2,7 @@ package main
import ( import (
"github.com/mitchellh/packer/packer/plugin" "github.com/mitchellh/packer/packer/plugin"
"github.com/rdobson/packer-builder-xenserver/builder/xenserver/xva" "github.com/xenserver/packer-builder-xenserver/builder/xenserver/xva"
) )
func main() { func main() {