Merge pull request #3362 from nathanleclaire/fix_dangling_amazonec2_ssh_key

Ensure that attempt to remove instance and SSH key both go through
This commit is contained in:
Nathan LeClaire 2016-04-25 11:48:35 -07:00
commit 4e898b1806
2 changed files with 23 additions and 4 deletions

View File

@ -748,16 +748,23 @@ func (d *Driver) Kill() error {
} }
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
multierr := mcnutils.MultiError{
Errs: []error{},
}
if err := d.terminate(); err != nil { if err := d.terminate(); err != nil {
return fmt.Errorf("unable to terminate instance: %s", err) multierr.Errs = append(multierr.Errs, err)
} }
// remove keypair
if err := d.deleteKeyPair(); err != nil { if err := d.deleteKeyPair(); err != nil {
return fmt.Errorf("unable to remove key pair: %s", err) multierr.Errs = append(multierr.Errs, err)
} }
return nil if len(multierr.Errs) == 0 {
return nil
}
return multierr
} }
func (d *Driver) getInstance() (*ec2.Instance, error) { func (d *Driver) getInstance() (*ec2.Instance, error) {

View File

@ -11,6 +11,18 @@ import (
"time" "time"
) )
type MultiError struct {
Errs []error
}
func (e MultiError) Error() string {
aggregate := ""
for _, err := range e.Errs {
aggregate += err.Error() + "\n"
}
return aggregate
}
// GetHomeDir returns the home directory // GetHomeDir returns the home directory
// TODO: Having this here just strikes me as dangerous, but some of the drivers // TODO: Having this here just strikes me as dangerous, but some of the drivers
// depend on it ;_; // depend on it ;_;