Merge pull request #5123 from rickard-von-essen/cloudstack-err

cloudstack: Improved error reporting
This commit is contained in:
Rickard von Essen 2017-07-14 13:22:18 +02:00 committed by GitHub
commit 285b1391ae
5 changed files with 41 additions and 11 deletions

View File

@ -47,7 +47,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
// Retrieve the instance ID from the previously saved state.
instanceID, ok := state.Get("instance_id").(string)
if !ok || instanceID == "" {
state.Put("error", fmt.Errorf("Could not retrieve instance_id from state!"))
err := fmt.Errorf("Could not retrieve instance_id from state!")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -56,7 +58,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
cloudstack.WithProject(config.Project),
)
if err != nil {
state.Put("error", fmt.Errorf("Failed to retrieve the network object: %s", err))
err := fmt.Errorf("Failed to retrieve the network object: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -79,7 +83,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
// Associate a new public IP address.
ipAddr, err := client.Address.AssociateIpAddress(p)
if err != nil {
state.Put("error", fmt.Errorf("Failed to associate public IP address: %s", err))
err := fmt.Errorf("Failed to associate public IP address: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -107,7 +113,10 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
// Create the port forward.
forward, err := client.Firewall.CreatePortForwardingRule(p)
if err != nil {
ui.Error(fmt.Sprintf("Failed to create port forward: %s", err))
err := fmt.Errorf("Failed to create port forward: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// Store the port forward ID.
@ -117,7 +126,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
ui.Message("Creating network ACL rule...")
if network.Aclid == "" {
state.Put("error", fmt.Errorf("Failed to configure the firewall: no ACL connected to the VPC network"))
err := fmt.Errorf("Failed to configure the firewall: no ACL connected to the VPC network")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -135,7 +146,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
// Create the network ACL rule.
aclRule, err := client.NetworkACL.CreateNetworkACL(p)
if err != nil {
state.Put("error", fmt.Errorf("Failed to create network ACL rule: %s", err))
err := fmt.Errorf("Failed to create network ACL rule: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -154,7 +167,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction
fwRule, err := client.Firewall.CreateFirewallRule(p)
if err != nil {
state.Put("error", fmt.Errorf("Failed to create firewall rule: %s", err))
err := fmt.Errorf("Failed to create firewall rule: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

View File

@ -62,7 +62,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
// Retrieve the zone object.
zone, _, err := client.Zone.GetZoneByID(config.Zone)
if err != nil {
err := fmt.Errorf("Failed to get zone %s by ID: %s", config.Zone, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -80,7 +82,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
httpPort := state.Get("http_port").(uint)
httpIP, err := hostIP()
if err != nil {
err := fmt.Errorf("Failed to determine host IP: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
common.SetHTTPIP(httpIP)
@ -93,6 +97,7 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
ud, err := s.generateUserData(config.UserData, config.HTTPGetOnly)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -102,7 +107,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
// Create the new instance.
instance, err := client.VirtualMachine.DeployVirtualMachine(p)
if err != nil {
state.Put("error", fmt.Errorf("Error creating new instance %s: %s", config.InstanceName, err))
err := fmt.Errorf("Error creating new instance %s: %s", config.InstanceName, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

View File

@ -21,7 +21,9 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction
// Retrieve the instance ID from the previously saved state.
instanceID, ok := state.Get("instance_id").(string)
if !ok || instanceID == "" {
state.Put("error", fmt.Errorf("Could not retrieve instance_id from state!"))
err := fmt.Errorf("Could not retrieve instance_id from state!")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -51,6 +53,7 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction
volumeID, err := getRootVolumeID(client, instanceID)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
@ -60,7 +63,9 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction
ui.Message("Creating the new template...")
template, err := client.Template.CreateTemplate(p)
if err != nil {
state.Put("error", fmt.Errorf("Error creating the new template %s: %s", config.TemplateName, err))
err := fmt.Errorf("Error creating the new template %s: %s", config.TemplateName, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

View File

@ -134,6 +134,7 @@ func (s *stepPrepareConfig) Run(state multistep.StateBag) multistep.StepAction {
// nil interface.
if errs != nil && len(errs.Errors) > 0 {
state.Put("error", errs)
ui.Error(errs.Error())
return multistep.ActionHalt
}

View File

@ -30,7 +30,9 @@ func (s *stepShutdownInstance) Run(state multistep.StateBag) multistep.StepActio
// Shutdown the virtual machine.
_, err := client.VirtualMachine.StopVirtualMachine(p)
if err != nil {
state.Put("error", fmt.Errorf("Error shutting down instance %s: %s", config.InstanceName, err))
err := fmt.Errorf("Error shutting down instance %s: %s", config.InstanceName, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}