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
go:
# Test with the first and the latest go release - to ensure compatibility
- 1.2
- release
- 1.6
- tip
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

View File

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

View File

@ -9,6 +9,7 @@ import (
"io"
"net/http"
"os"
"os/exec"
)
type StepExport struct{}
@ -20,6 +21,7 @@ func downloadFile(url, filename string, ui packer.Ui) (err error) {
if err != nil {
return err
}
defer fh.Close()
// Define a new transport which allows self-signed certs
tr := &http.Transport{
@ -101,16 +103,36 @@ func (StepExport) Run(state multistep.StateBag) multistep.StepAction {
case "xva":
// export the VM
export_filename := fmt.Sprintf("%s/%s.xva", config.OutputDir, config.VMName)
use_xe := os.Getenv("USE_XE") == "1"
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),
)
export_filename := fmt.Sprintf("%s/%s.xva", config.OutputDir, config.VMName)
ui.Say("Getting XVA " + export_url)
err = downloadFile(export_url, export_filename, ui)
}
if err != nil {
ui.Error(fmt.Sprintf("Could not download XVA: %s", err.Error()))
return multistep.ActionHalt

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ package main
import (
"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() {

View File

@ -2,7 +2,7 @@ package main
import (
"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() {