Skip to content

Commit

Permalink
Merge pull request #4355 from josedonizetti/fix-kvm-remove-when-domai…
Browse files Browse the repository at this point in the history
…n-is-not-defined

Fix kvm remove when domain is not defined
  • Loading branch information
tstromberg authored May 29, 2019
2 parents 05332bd + c099130 commit dbc64c0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pkg/drivers/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ func (d *Driver) Remove() error {
return errors.Wrap(err, "destroying running domain")
}

return dom.Undefine()
if err := d.undefineDomain(conn, dom); err != nil {
return errors.Wrap(err, "undefine domain")
}

return nil
}

func (d *Driver) destroyRunningDomain(dom *libvirt.Domain) error {
Expand All @@ -467,3 +471,25 @@ func (d *Driver) destroyRunningDomain(dom *libvirt.Domain) error {

return dom.Destroy()
}

func (d *Driver) undefineDomain(conn *libvirt.Connect, dom *libvirt.Domain) error {
definedDomains, err := conn.ListDefinedDomains()
if err != nil {
return errors.Wrap(err, "list defined domains")
}

var found bool
for _, domain := range definedDomains {
if domain == d.MachineName {
found = true
break
}
}

if !found {
log.Warnf("Domain %s not defined, skipping undefine...", d.MachineName)
return nil
}

return dom.Undefine()
}

0 comments on commit dbc64c0

Please sign in to comment.