do not autoremove machine on error (prevents removing existing machines)

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-01-19 13:52:25 -05:00
parent f5ba0dc1d7
commit e1d0c97770
No known key found for this signature in database
GPG Key ID: A519480096146526
2 changed files with 12 additions and 20 deletions

View File

@ -192,18 +192,10 @@ func cmdCreate(c *cli.Context) {
host, err := store.Create(name, driver, c) host, err := store.Create(name, driver, c)
if err != nil { if err != nil {
log.Errorf("Error creating host: %s", err) log.Errorf("Error creating machine: %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.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.Fatal("Error creating machine")
} }
}
if err := store.SetActive(host); err != nil { if err := store.SetActive(host); err != nil {
log.Fatalf("error setting active host: %v", err) log.Fatalf("error setting active host: %v", err)
} }

18
host.go
View File

@ -83,7 +83,7 @@ func ValidateHostName(name string) (string, error) {
return name, nil return name, nil
} }
func (h *Host) GenerateCertificates(serverIPs []string) error { func (h *Host) GenerateCertificates() error {
var ( var (
caPathExists bool caPathExists bool
privateKeyExists bool privateKeyExists bool
@ -91,6 +91,11 @@ func (h *Host) GenerateCertificates(serverIPs []string) error {
bits = 2048 bits = 2048
) )
ip, err := h.Driver.GetIP()
if err != nil {
return err
}
caCertPath := filepath.Join(h.storePath, "ca.pem") caCertPath := filepath.Join(h.storePath, "ca.pem")
privateKeyPath := filepath.Join(h.storePath, "private.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) 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) return fmt.Errorf("error generating server cert: %s", err)
} }
@ -146,13 +151,8 @@ func (h *Host) ConfigureAuth() error {
return nil return nil
} }
ip, err := d.GetIP() log.Debugf("generating certificates for %s", h.Name)
if err != nil { if err := h.GenerateCertificates(); err != nil {
return err
}
log.Debugf("generating certificates for %s", ip)
if err := h.GenerateCertificates([]string{ip}); err != nil {
return err return err
} }