f-79: agent: section times, renvoi de system_powerdown, attentes #79

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-25 12:42:10 +01:00
commit e6c758af78
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
13 changed files with 602 additions and 80 deletions

View file

@ -1,6 +1,7 @@
package dispatcher
import (
"errors"
"fmt"
"math/rand"
"strconv"
@ -151,24 +152,23 @@ func allocateMetadataPort(db *badger.DB) (int, error) {
}
func (c StartVMCommand) Execute(db *badger.DB, cfg *configuration.Config) error {
timeout := time.After(time.Duration(cfg.Dispatcher.TimeoutSeconds) * time.Second)
timeout := time.Now().Add(cfg.Times.VMsStart())
for _, n := range c.NICs {
for {
err := waitUntil(time.Until(timeout), cfg.Times.Poll(), func() (bool, error) {
subnetState, err := state.Get(db, "subnet/"+n.Subnet)
if err != nil {
return fmt.Errorf("subnet %q not found while waiting", n.Subnet)
return false, fmt.Errorf("subnet %q not found while waiting", n.Subnet)
}
if subnetState == state.Running {
break
}
if subnetState != state.Creating {
return fmt.Errorf("subnet %q is %s, cannot start vm %q", n.Subnet, subnetState, c.Name)
}
select {
case <-timeout:
return fmt.Errorf("timed out waiting for subnet %q to be running", n.Subnet)
case <-time.After(time.Duration(cfg.Dispatcher.PollSeconds) * time.Second):
if subnetState != state.Running && subnetState != state.Creating {
return false, fmt.Errorf("subnet %q is %s, cannot start vm %q", n.Subnet, subnetState, c.Name)
}
return subnetState == state.Running, nil
})
if errors.Is(err, errWaitTimeout) {
return fmt.Errorf("timed out waiting for subnet %q to be running", n.Subnet)
}
if err != nil {
return err
}
}
return vm.StartVM(db, c.Name, cfg)