Merge pull request #234 from ehazlett/graceful-cleanup-on-create-fail

add cleanup for create failure
This commit is contained in:
Evan Hazlett 2015-01-07 17:54:20 -08:00
commit 9c3624b170
2 changed files with 12 additions and 4 deletions

View File

@ -190,7 +190,17 @@ func cmdCreate(c *cli.Context) {
host, err := store.Create(name, driver, c)
if err != nil {
log.Errorf("Error creating host: %s", err)
if c.GlobalBool("debug") {
log.Fatal(err)
} else {
log.Warnf("Removing created machine. You can run machine with the --debug flag to avoid this.")
// we know there was an error so do not check for the error on removal
// instead we will Fatal with a message to prevent spamming with error messages
_ = store.Remove(name, true)
log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.")
log.Fatal("Error creating machine")
}
}
if err := store.SetActive(host); err != nil {
log.Fatalf("error setting active host: %v", err)

View File

@ -227,9 +227,7 @@ func (h *Host) Upgrade() error {
func (h *Host) Remove(force bool) error {
if err := h.Driver.Remove(); err != nil {
if force {
log.Errorf("Error removing host, force removing anyway: %s", err)
} else {
if !force {
return err
}
}