Replace all Fatal calls with Error calls
This commit is contained in:
parent
efbc365b6d
commit
c88168f4ba
@ -4,15 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/nilshell/xmlrpc"
|
||||
"log"
|
||||
)
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type XenAPIClient struct {
|
||||
Session interface{}
|
||||
Host string
|
||||
@ -118,7 +111,6 @@ func (client *XenAPIClient) APICall(result *APIResult, method string, params ...
|
||||
if result.Status != "Success" {
|
||||
fmt.Println("Encountered an API error: ", result.Status)
|
||||
fmt.Println(res["ErrorDescription"])
|
||||
log.Fatal(res["ErrorDescription"])
|
||||
return errors.New("API Error occurred")
|
||||
} else {
|
||||
result.Value = res["Value"]
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
type stepCreateInstance struct {
|
||||
@ -25,10 +24,10 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
|
||||
switch {
|
||||
case len(vms) == 0:
|
||||
log.Fatal(fmt.Sprintf("Couldn't find a template with the name-label '%s'. Aborting.", config.CloneTemplate))
|
||||
ui.Error(fmt.Sprintf("Couldn't find a template with the name-label '%s'. Aborting.", config.CloneTemplate))
|
||||
return multistep.ActionHalt
|
||||
case len(vms) > 1:
|
||||
log.Fatal(fmt.Sprintf("Found more than one template with the name '%s'. The name must be unique. Aborting.", config.CloneTemplate))
|
||||
ui.Error(fmt.Sprintf("Found more than one template with the name '%s'. The name must be unique. Aborting.", config.CloneTemplate))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -49,7 +48,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
sr = default_sr
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Error getting default SR: %s", err.Error()))
|
||||
ui.Error(fmt.Sprintf("Error getting default SR: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -58,16 +57,16 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
srs, err := client.GetSRByNameLabel(config.SrName)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Error getting default SR: %s", err.Error()))
|
||||
ui.Error(fmt.Sprintf("Error getting default SR: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(srs) == 0:
|
||||
log.Fatal(fmt.Sprintf("Couldn't find a SR with the specified name-label '%s'. Aborting.", config.SrName))
|
||||
ui.Error(fmt.Sprintf("Couldn't find a SR with the specified name-label '%s'. Aborting.", config.SrName))
|
||||
return multistep.ActionHalt
|
||||
case len(srs) > 1:
|
||||
log.Fatal(fmt.Sprintf("Found more than one SR with the name '%s'. The name must be unique. Aborting.", config.SrName))
|
||||
ui.Error(fmt.Sprintf("Found more than one SR with the name '%s'. The name must be unique. Aborting.", config.SrName))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
pifs, err := client.GetPIFs()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Error getting PIFs %s", err.Error()))
|
||||
ui.Error(fmt.Sprintf("Error getting PIFs %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -99,7 +98,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
pif_rec, err := pif.GetRecord()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Error getting PIF record: %s", err.Error()))
|
||||
ui.Error(fmt.Sprintf("Error getting PIF record: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -110,7 +109,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
}
|
||||
|
||||
if network.Ref == "" {
|
||||
log.Fatal("Error: couldn't find management network. Aborting.")
|
||||
ui.Error("Error: couldn't find management network. Aborting.")
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -120,16 +119,16 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
networks, err := client.GetNetworkByNameLabel(config.NetworkName)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Sprintf("Error occured getting Network by name-label: %s", err.Error()))
|
||||
ui.Error(fmt.Sprintf("Error occured getting Network by name-label: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(networks) == 0:
|
||||
log.Fatal(fmt.Sprintf("Couldn't find a network with the specified name-label '%s'. Aborting.", config.NetworkName))
|
||||
ui.Error(fmt.Sprintf("Couldn't find a network with the specified name-label '%s'. Aborting.", config.NetworkName))
|
||||
return multistep.ActionHalt
|
||||
case len(networks) > 1:
|
||||
log.Fatal(fmt.Sprintf("Found more than one SR with the name '%s'. The name must be unique. Aborting.", config.NetworkName))
|
||||
ui.Error(fmt.Sprintf("Found more than one SR with the name '%s'. The name must be unique. Aborting.", config.NetworkName))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -152,10 +151,10 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||
|
||||
switch {
|
||||
case len(isos) == 0:
|
||||
log.Fatal(fmt.Sprintf("Couldn't find an ISO named '%s'. Aborting", config.IsoName))
|
||||
ui.Error(fmt.Sprintf("Couldn't find an ISO named '%s'. Aborting", config.IsoName))
|
||||
return multistep.ActionHalt
|
||||
case len(isos) > 1:
|
||||
log.Fatal(fmt.Sprintf("Found more than one VDI with name '%s'. Name must be unique. Aborting.", config.IsoName))
|
||||
ui.Error(fmt.Sprintf("Found more than one VDI with name '%s'. Name must be unique. Aborting.", config.IsoName))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (self *stepForwardPortOverSSH) Run(state multistep.StateBag) multistep.Step
|
||||
}
|
||||
|
||||
if !foundPort {
|
||||
log.Fatal("Error: unable to find free host port. Try providing a larger range")
|
||||
ui.Error("Error: unable to find free host port. Try providing a larger range")
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -25,8 +24,8 @@ func (self *stepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
|
||||
remote_port, err := strconv.ParseUint(remote_vncport, 10, 16)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(fmt.Sprintf("Unable to convert '%s' to an int", remote_vncport))
|
||||
ui.Error(fmt.Sprintf("Unable to convert '%s' to an int", remote_vncport))
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
|
||||
// Find the HIMN Ref
|
||||
networks, err := client.GetNetworkByNameLabel("Host internal management network")
|
||||
if err != nil || len(networks) == 0 {
|
||||
log.Fatal("Unable to find a host internal management network")
|
||||
log.Fatal(err.Error())
|
||||
ui.Error("Unable to find a host internal management network")
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
|
||||
// Create a VIF for the HIMN
|
||||
himn_vif, err := instance.ConnectNetwork(himn, "0")
|
||||
if err != nil {
|
||||
log.Fatal("Error creating VIF")
|
||||
log.Fatal(err.Error())
|
||||
ui.Error("Error creating VIF")
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
|
||||
state.Put("himn_ssh_address", himn_iface_ip)
|
||||
ui.Say("Stored VM's IP " + himn_iface_ip)
|
||||
} else {
|
||||
log.Fatal("Unable to find an IP on the Host-internal management interface")
|
||||
ui.Error("Unable to find an IP on the Host-internal management interface")
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
@ -95,8 +95,8 @@ func (self *stepStartOnHIMN) Run(state multistep.StateBag) multistep.StepAction
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Unable to ping interface. Something is wrong. Has the VM not booted?")
|
||||
log.Fatal(err.Error())
|
||||
ui.Error("Unable to ping interface. Something is wrong. Has the VM not booted?")
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user