Stock de stacks prêtes par lab dans Redis (prise atomique en Lua, ménage par comparaison avec Heat, disjoncteur), files gérées par Horizon, séances planifiables. Correcteur Go sur l'hyperviseur : socket Unix, commandes lues dans le lab.yaml uniquement, exécution par l'agent invité QEMU. Une création de stack ratée est supprimée et réessayée deux fois, puis la session passe en échec, visible du prof. Corrige aussi trois défauts des étapes précédentes : la console se coupait à la première frappe d'un navigateur (trames texte), l'élève ne pouvait pas rejoindre une séance, la déconnexion n'avait pas de jeton CSRF. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type attendu struct {
|
|
CodeRetour int `yaml:"code_retour"`
|
|
SortieContient string `yaml:"sortie_contient"`
|
|
}
|
|
|
|
func (a attendu) satisfait(code int, sortie string) bool {
|
|
if code != a.CodeRetour {
|
|
return false
|
|
}
|
|
return a.SortieContient == "" || strings.Contains(sortie, a.SortieContient)
|
|
}
|
|
|
|
type verification struct {
|
|
ID string `yaml:"id"`
|
|
Machine string `yaml:"machine"`
|
|
Commande string `yaml:"commande"`
|
|
Attendu attendu `yaml:"attendu"`
|
|
}
|
|
|
|
type lab struct {
|
|
Machines []struct {
|
|
Nom string `yaml:"nom"`
|
|
} `yaml:"machines"`
|
|
Verifications []verification `yaml:"verifications"`
|
|
}
|
|
|
|
// L'identifiant a déjà été validé (^[a-z0-9][a-z0-9-]*$) : pas de « .. »
|
|
// possible dans le chemin.
|
|
func chargerLab(dossier, id string) (*lab, error) {
|
|
contenu, err := os.ReadFile(filepath.Join(dossier, id, "lab.yaml"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var l lab
|
|
if err := yaml.Unmarshal(contenu, &l); err != nil {
|
|
return nil, err
|
|
}
|
|
return &l, nil
|
|
}
|
|
|
|
func (l *lab) verification(id string) (verification, bool) {
|
|
for _, v := range l.Verifications {
|
|
if v.ID == id {
|
|
return v, true
|
|
}
|
|
}
|
|
return verification{}, false
|
|
}
|
|
|
|
// Le portail nomme chaque VM « {préfixe}-{machine} » (GenerateurTemplateHeat).
|
|
// On retrouve la machine par le suffixe le plus long : avec des machines
|
|
// « a » et « pc-a », le nom « …-pc-a » désigne bien pc-a, pas a.
|
|
func (l *lab) machineDuNom(nomInstance string) string {
|
|
trouvee := ""
|
|
for _, m := range l.Machines {
|
|
if strings.HasSuffix(nomInstance, "-"+m.Nom) && len(m.Nom) > len(trouvee) {
|
|
trouvee = m.Nom
|
|
}
|
|
}
|
|
return trouvee
|
|
}
|