// RemoveVM stops VM by domain UUID
RemoveVM stops VM by domain UUID
// RemoveVM stops VM by domain UUID
func (vt *VMTool) RemoveVM(domainID string) error {
	domain, err := vt.conn.GetDomainByUUIDString(domainID)
	if err != nil && err != ErrDomainNotFound {
		return err
	}
	if domain == nil {
		return nil
	}
	state, err := domain.GetState()
	if err != nil {
		return fmt.Errorf("failed to get domain(%q) state: %v", domainID, err)
	}
	if state == DOMAIN_RUNNING {
		err = wait.PollImmediate(1*time.Second, 10*time.Second, domainStopped(domainID, domain))
		if err != nil {
			if err = domain.Destroy(); err != nil {
				glog.Warning("failed to destroy domain(%q): %v", domainID, err)
			}
		}
	}
	if err = domain.Undefine(); err != nil {
		return fmt.Errorf("failed to undefine domain(%q): %v", domainID, err)
	}
	domainUndefined := func() wait.ConditionFunc {
		return func() (bool, error) {
			_, err := vt.conn.GetDomainByUUIDString(domainID)
			if err != nil {
				if err == ErrDomainNotFound {
					return true, nil
				}
				return false, fmt.Errorf("failed to loop up domain(%q): %v", domainID, err)
			}
			return false, nil
		}
	}
	err = wait.PollImmediate(200*time.Millisecond, 5*time.Second, domainUndefined())
	if err == wait.ErrWaitTimeout {
		return fmt.Errorf("Failed to wait domain(%q) undefined state: %v", domainID, err)
	}
	return err
}
func ( vt * VMTool ) RemoveVM ( domainID string ) error { domain , err := vt . conn . GetDomainByUUIDString ( domainID ) if err != nil && err != ErrDomainNotFound { return err } if domain == nil { return nil } state , err := domain . GetState ( ) if err != nil { return fmt . Errorf ( " " , domainID , err ) } if state == DOMAIN_RUNNING { err = wait . PollImmediate ( 1 * time . Second , 10 * time . Second , domainStopped ( domainID , domain ) ) if err != nil { if err = domain . Destroy ( ) ; err != nil { glog . Warning ( " " , domainID , err ) } } } if err = domain . Undefine ( ) ; err != nil { return fmt . Errorf ( " " , domainID , err ) } domainUndefined := func ( ) wait . ConditionFunc { return func ( ) ( bool , error ) { _ , err := vt . conn . GetDomainByUUIDString ( domainID ) if err != nil { if err == ErrDomainNotFound { return true , nil } return false , fmt . Errorf ( " " , domainID , err ) } return false , nil } } err = wait . PollImmediate ( 200 * time . Millisecond , 5 * time . Second , domainUndefined ( ) ) if err == wait . ErrWaitTimeout { return fmt . Errorf ( " " , domainID , err ) } return err }
RemoveVM stops VM by domain UUID
RemoveVM stops VM by domain UUID
// TODO(Crazykev): Cleanup resources // Try to shutdown VM gracefully before try to undefined it // Undefine domain