Beispiel #1
0
func (p *Pool) Delete(id string) (success bool, err error) {
	if _, running := p.Running[id]; running {
		p.del <- p.Running[id]
		return openstack.Delete(p.Running[id].Server.ID)
	}
	defer delete(p.Pending, id)
	return openstack.Delete(p.Pending[id].Server.ID)
}
Beispiel #2
0
func (p *Pool) Boot(username string) (id string, err error) {
	id = RandString(10)
	s, err := openstack.Boot(username, "ipy_kbnb_"+id)
	if err != nil {
		return "", err
	}
	h := Host{ID: id, User: username, Server: s.Server}
	p.Pending[id] = h
	p.Booting <- h
	go func(u, id string) {
		for {
			select {
			case <-time.After(10 * time.Minute):
				openstack.Delete(p.Pending[id].Server.ID)
				delete(p.Pending, id)
				id = RandString(10)
				s, _ := openstack.Boot(username, "ipy_kbnb_"+id)
				// log error
				h := Host{ID: id, User: username, Server: s.Server}
				p.Pending[id] = h
				p.Booting <- h
			}
		}
	}(username, id)
	return
}