Cosmetic: go fmt

This commit is contained in:
Cheng Sun 2014-12-08 15:34:48 +00:00
parent 538966204c
commit 2dbe047d45
15 changed files with 1464 additions and 1529 deletions

View File

@ -2,18 +2,16 @@ package xenserver
import (
"fmt"
"os"
"github.com/mitchellh/packer/packer"
"os"
"path/filepath"
)
type LocalArtifact struct {
dir string
f []string
}
func NewArtifact(dir string) (packer.Artifact, error) {
files := make([]string, 0, 1)
visit := func(path string, info os.FileInfo, err error) error {

View File

@ -1,22 +1,20 @@
package xenserver
import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/common"
"fmt"
"log"
"errors"
"time"
"os"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
commonssh "github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer"
"log"
"os"
"time"
)
// Set the unique ID for this builder
const BuilderId = "packer.xenserver"
type config struct {
common.PackerConfig `mapstructure:",squash"`
@ -65,13 +63,11 @@ type config struct {
tpl *packer.ConfigTemplate
}
type Builder struct {
config config
runner multistep.Runner
}
func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error) {
md, err := common.DecodeConfig(&self.config, raws...)
@ -144,7 +140,6 @@ func (self *Builder) Prepare (raws ...interface{}) (params []string, retErr erro
"output_directory": &self.config.OutputDir,
}
for n, ptr := range templates {
var err error
*ptr, err = self.config.tpl.Process(*ptr, nil)
@ -319,7 +314,6 @@ func (self *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (pa
state.Put("hook", hook)
state.Put("ui", ui)
//Build the steps
steps := []multistep.Step{
/*
@ -376,7 +370,6 @@ func (self *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (pa
return artifact, nil
}
func (self *Builder) Cancel() {
if self.runner != nil {
log.Println("Cancelling the step runner...")
@ -384,4 +377,3 @@ func (self *Builder) Cancel() {
}
fmt.Println("Cancelling the builder")
}

View File

@ -1,10 +1,10 @@
package xenserver
import (
"errors"
"fmt"
"github.com/nilshell/xmlrpc"
"log"
"fmt"
"errors"
)
func check(err error) {
@ -13,7 +13,6 @@ func check(err error) {
}
}
type XenAPIClient struct {
Session interface{}
Host string
@ -23,7 +22,6 @@ type XenAPIClient struct {
RPC *xmlrpc.Client
}
type APIResult struct {
Status string
Value interface{}
@ -78,7 +76,6 @@ func (c *XenAPIClient) RPCCall (result interface{}, method string, params []inte
return err
}
func (client *XenAPIClient) Login() (err error) {
//Do loging call
result := xmlrpc.Struct{}
@ -129,7 +126,6 @@ func (client *XenAPIClient) APICall (result *APIResult, method string, params ..
return
}
func (client *XenAPIClient) GetHosts() (err error) {
result := APIResult{}
_ = client.APICall(&result, "host.get_all")
@ -138,7 +134,6 @@ func (client *XenAPIClient) GetHosts () (err error) {
return nil
}
func (client *XenAPIClient) GetPools() (pools []*Pool, err error) {
pools = make([]*Pool, 0)
result := APIResult{}
@ -157,7 +152,6 @@ func (client *XenAPIClient) GetPools () (pools []*Pool, err error) {
return pools, nil
}
func (client *XenAPIClient) GetDefaultSR() (sr *SR, err error) {
pools, err := client.GetPools()
@ -182,7 +176,6 @@ func (client *XenAPIClient) GetDefaultSR () (sr *SR, err error) {
return sr, nil
}
func (client *XenAPIClient) GetVMByUuid(vm_uuid string) (vm *VM, err error) {
vm = new(VM)
result := APIResult{}
@ -195,7 +188,6 @@ func (client *XenAPIClient) GetVMByUuid (vm_uuid string) (vm *VM, err error) {
return
}
func (client *XenAPIClient) GetVMByNameLabel(name_label string) (vms []*VM, err error) {
vms = make([]*VM, 0)
result := APIResult{}
@ -214,7 +206,6 @@ func (client *XenAPIClient) GetVMByNameLabel (name_label string) (vms []*VM, err
return vms, nil
}
func (client *XenAPIClient) GetSRByNameLabel(name_label string) (srs []*SR, err error) {
srs = make([]*SR, 0)
result := APIResult{}
@ -245,7 +236,6 @@ func (client *XenAPIClient) GetNetworkByUuid (network_uuid string) (network *Net
return
}
func (client *XenAPIClient) GetNetworkByNameLabel(name_label string) (networks []*Network, err error) {
networks = make([]*Network, 0)
result := APIResult{}
@ -282,7 +272,6 @@ func (client *XenAPIClient) GetVdiByNameLabel (name_label string) (vdis []*VDI,
return vdis, nil
}
func (client *XenAPIClient) GetSRByUuid(sr_uuid string) (sr *SR, err error) {
sr = new(SR)
result := APIResult{}
@ -427,7 +416,6 @@ func (self *VM) GetVBDs() (vbds []VBD, err error) {
return vbds, nil
}
func (self *VM) GetVIFs() (vifs []VIF, err error) {
vifs = make([]VIF, 0)
result := APIResult{}
@ -574,7 +562,6 @@ func (self *VM) SetPlatform(params map[string]string) (err error) {
return
}
func (self *VM) ConnectNetwork(network *Network, device string) (vif *VIF, err error) {
// Create the VIF
@ -630,7 +617,6 @@ func (self *SR) CreateVdi (name_label, size string) (vdi *VDI, err error) {
oc["temp"] = "temp"
vdi_rec["other_config"] = oc
result := APIResult{}
err = self.Client.APICall(&result, "VDI.create", vdi_rec)
if err != nil {
@ -688,7 +674,6 @@ func (self *Pool) GetRecord () (record map[string]interface{}, err error) {
return record, nil
}
// VBD associated functions
func (self *VBD) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
@ -748,7 +733,6 @@ func (self *VDI) GetUuid () (vdi_uuid string, err error) {
return vdi_uuid, nil
}
// Client Initiator
func NewXenAPIClient(host, username, password string) (client XenAPIClient) {

View File

@ -1,16 +1,16 @@
package xenserver
import (
"fmt"
"bytes"
gossh "code.google.com/p/go.crypto/ssh"
"fmt"
"github.com/mitchellh/multistep"
commonssh "github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"strings"
"log"
"bytes"
"net"
"io"
"log"
"net"
"strings"
)
func sshAddress(state multistep.StateBag) (string, error) {
@ -50,9 +50,6 @@ func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
}, nil
}
func execute_ssh_cmd(cmd, host, port, username, password string) (stdout string, err error) {
// Setup connection config
config := &gossh.ClientConfig{
@ -141,12 +138,9 @@ func ssh_port_forward(local_port uint, remote_port uint, remote_dest, host, user
return err
}
// Forward to a remote port
go forward(local_connection, config, host, remote_dest, remote_port)
}
return nil
}

View File

@ -7,7 +7,6 @@ import (
"time"
)
type stepBootWait struct{}
func (self *stepBootWait) Run(state multistep.StateBag) multistep.StepAction {
@ -27,4 +26,3 @@ func (self *stepBootWait) Run(state multistep.StateBag) multistep.StepAction {
}
func (self *stepBootWait) Cleanup(state multistep.StateBag) {}

View File

@ -1,10 +1,9 @@
package xenserver
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"fmt"
"log"
)
@ -20,7 +19,6 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
ui.Say("Step: Create Instance")
// Get the template to clone from
vms, err := client.GetVMByNameLabel(config.CloneTemplate)
@ -55,7 +53,6 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
return multistep.ActionHalt
}
} else {
// Use the provided name label to find the SR to use
srs, err := client.GetSRByNameLabel(config.SrName)
@ -151,10 +148,8 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
// Connect the ISO
//iso_vdi_uuid := state.Get("iso_vdi_uuid").(string)
isos, err := client.GetVdiByNameLabel(config.IsoName)
switch {
case len(isos) == 0:
log.Fatal(fmt.Sprintf("Couldn't find an ISO named '%s'. Aborting", config.IsoName))
@ -180,7 +175,6 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
return multistep.ActionContinue
}
func (self *stepCreateInstance) Cleanup(state multistep.StateBag) {
// client := state.Get("client").(*XenAPIClient)

View File

@ -1,15 +1,14 @@
package xenserver
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"net"
"fmt"
)
type stepForwardPortOverSSH struct {
RemotePort func(state multistep.StateBag) (uint, error)
RemoteDest func(state multistep.StateBag) (string, error)
@ -19,7 +18,6 @@ type stepForwardPortOverSSH struct {
ResultKey string
}
func (self *stepForwardPortOverSSH) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(config)
@ -31,7 +29,6 @@ func (self *stepForwardPortOverSSH) Run(state multistep.StateBag) multistep.Step
self.HostPortMin,
self.HostPortMax)
var sshHostPort uint
var foundPort bool
@ -54,13 +51,11 @@ func (self *stepForwardPortOverSSH) Run(state multistep.StateBag) multistep.Step
return multistep.ActionHalt
}
ui.Say(fmt.Sprintf("Creating a local port forward over SSH on local port %d", sshHostPort))
remotePort, _ := self.RemotePort(state)
remoteDest, _ := self.RemoteDest(state)
go ssh_port_forward(sshHostPort, remotePort, remoteDest, config.HostIp, config.Username, config.Password)
ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, config.HostIp))

View File

@ -1,17 +1,15 @@
package xenserver
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"fmt"
"strconv"
"log"
"strconv"
)
type stepGetVNCPort struct{}
func (self *stepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(config)
@ -37,7 +35,6 @@ func (self *stepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}
func (self *stepGetVNCPort) Cleanup(state multistep.StateBag) {
}

View File

@ -3,13 +3,13 @@ package xenserver
/* Taken from https://raw.githubusercontent.com/mitchellh/packer/master/builder/qemu/step_prepare_output_dir.go */
import (
"crypto/tls"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"fmt"
"net/http"
"crypto/tls"
"io"
"net/http"
"os"
)
type stepShutdownAndExport struct{}
@ -43,7 +43,6 @@ func downloadFile(url, filename string) (err error) {
return nil
}
func (stepShutdownAndExport) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(config)
ui := state.Get("ui").(packer.Ui)
@ -90,7 +89,6 @@ func (stepShutdownAndExport) Run(state multistep.StateBag) multistep.StepAction
downloadFile(disk_export_url, disk_export_filename)
}
ui.Say("Download complteded: " + config.OutputDir)
return multistep.ActionContinue

View File

@ -1,16 +1,15 @@
package xenserver
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
"log"
"fmt"
"time"
)
type stepStartOnHIMN struct{}
/*
* This step starts the installed guest on the Host Internal Management Network
* as there exists an API to obtain the IP allocated to the VM by XAPI.
@ -37,7 +36,6 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
return multistep.ActionHalt
}
himn := networks[0]
// Create a VIF for the HIMN
@ -51,7 +49,6 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
// Start the VM
instance.Start(false, false)
var himn_iface_ip string = ""
// Obtain the allocated IP
@ -80,7 +77,6 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
return multistep.ActionHalt
}
// Wait for the VM to boot, and check we can ping this interface
ping_cmd := fmt.Sprintf("ping -c 1 %s", himn_iface_ip)
@ -112,13 +108,11 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
func (self *stepStartOnHIMN) Cleanup(state multistep.StateBag) {}
func himnSSHIP(state multistep.StateBag) (string, error) {
ip := state.Get("himn_ssh_address").(string)
return ip, nil
}
func himnSSHPort(state multistep.StateBag) (uint, error) {
return 22, nil
}

View File

@ -1,6 +1,5 @@
package xenserver
import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
@ -25,6 +24,5 @@ func (self *stepStartVmPaused) Run(state multistep.StateBag) multistep.StepActio
return multistep.ActionContinue
}
func (self *stepStartVmPaused) Cleanup(state multistep.StateBag) {
}

View File

@ -22,7 +22,6 @@ type bootCommandTemplateData struct {
HTTPPort uint
}
type stepTypeBootCommand struct{}
func (self *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {

View File

@ -1,13 +1,12 @@
package xenserver
import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"strconv"
"os/exec"
"log"
"os"
"os/exec"
"strconv"
)
type stepUploadIso struct{}
@ -72,10 +71,8 @@ func (self *stepUploadIso) Run(state multistep.StateBag) multistep.StepAction {
// Stash the vdi uuid to be used in preference
state.Put("iso_vdi_uuid", vdi_uuid)
return multistep.ActionContinue
}
func (self *stepUploadIso) Cleanup(state multistep.StateBag) {
}

View File

@ -3,11 +3,10 @@ package xenserver
import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
"reflect"
"time"
)
type stepWait struct{}
func (self *stepWait) Run(state multistep.StateBag) multistep.StepAction {
@ -16,7 +15,6 @@ func (self *stepWait) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Step: Wait for install to complete.")
//Expect install to be configured to shutdown on completion
instance_id := state.Get("instance_uuid").(string)
@ -63,4 +61,3 @@ func (self *stepWait) Run(state multistep.StateBag) multistep.StepAction {
}
func (self *stepWait) Cleanup(state multistep.StateBag) {}

View File

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