Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
use *int to pass exitStatus to defer function
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-liang-sap committed Nov 18, 2020
1 parent 84b3723 commit 1a544ae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/cmd/ssh_openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func sshToOpenstackNode(nodeName, path, user, pathSSKeypair string, sshPublicKey
operate("openstack", "server add floating ip "+a.InstanceID+" "+a.FIP)
time.Sleep(5000)

defer a.cleanUpOpenstack(&sshStatus)

node := user + "@" + a.FIP
fmt.Println("(4/5) Establishing SSH connection")
fmt.Println("")
Expand All @@ -92,11 +94,10 @@ func sshToOpenstackNode(nodeName, path, user, pathSSKeypair string, sshPublicKey
sshStatus = exitError.ExitCode()
}
}
defer a.cleanUpOpenstack(sshStatus)
}

//cleanUpOpenstack clean the resource added to ssh to openstack node
func (a *OpenstackInstanceAttribute) cleanUpOpenstack(exitStatus int) {
func (a *OpenstackInstanceAttribute) cleanUpOpenstack(exitStatus *int) {
fmt.Println("")
fmt.Println("(5/5) Cleanup")

Expand All @@ -105,5 +106,5 @@ func (a *OpenstackInstanceAttribute) cleanUpOpenstack(exitStatus int) {

fmt.Println("Delete the floating IP")
operate("openstack", "floating ip delete "+a.FIP)
os.Exit(exitStatus)
os.Exit(*exitStatus)
}

0 comments on commit 1a544ae

Please sign in to comment.