From e1d0c97770afa5db16f48a5455c2c71282aa75d2 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Mon, 19 Jan 2015 13:52:25 -0500 Subject: [PATCH] do not autoremove machine on error (prevents removing existing machines) Signed-off-by: Evan Hazlett --- commands.go | 14 +++----------- host.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/commands.go b/commands.go index 5374de9531..bc4f4bef2a 100644 --- a/commands.go +++ b/commands.go @@ -192,17 +192,9 @@ 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") - } + log.Errorf("Error creating machine: %s", err) + 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) diff --git a/host.go b/host.go index f0d882b8cd..61f4145c9c 100644 --- a/host.go +++ b/host.go @@ -83,7 +83,7 @@ func ValidateHostName(name string) (string, error) { return name, nil } -func (h *Host) GenerateCertificates(serverIPs []string) error { +func (h *Host) GenerateCertificates() error { var ( caPathExists bool privateKeyExists bool @@ -91,6 +91,11 @@ func (h *Host) GenerateCertificates(serverIPs []string) error { bits = 2048 ) + ip, err := h.Driver.GetIP() + if err != nil { + return err + } + caCertPath := filepath.Join(h.storePath, "ca.pem") privateKeyPath := filepath.Join(h.storePath, "private.pem") @@ -125,7 +130,7 @@ func (h *Host) GenerateCertificates(serverIPs []string) error { log.Debugf("generating server cert: %s", serverCertPath) - if err := utils.GenerateCert(serverIPs, serverCertPath, serverKeyPath, caCertPath, privateKeyPath, org, bits); err != nil { + if err := utils.GenerateCert([]string{ip}, serverCertPath, serverKeyPath, caCertPath, privateKeyPath, org, bits); err != nil { return fmt.Errorf("error generating server cert: %s", err) } @@ -146,13 +151,8 @@ func (h *Host) ConfigureAuth() error { return nil } - ip, err := d.GetIP() - if err != nil { - return err - } - - log.Debugf("generating certificates for %s", ip) - if err := h.GenerateCertificates([]string{ip}); err != nil { + log.Debugf("generating certificates for %s", h.Name) + if err := h.GenerateCertificates(); err != nil { return err }