f-21: code: add vpc gestion in api
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 1m33s
Pre Release Workflow / build (db, amd64, linux) (push) Successful in 1m30s
Pre Release Workflow / build (metacli, amd64, linux) (push) Successful in 1m30s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / build (subnet, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / prerelease (push) Successful in 13s
Pre Release Workflow / build (dhcp, amd64, linux) (push) Successful in 1m28s
Pre Release Workflow / build (vpc, amd64, linux) (push) Successful in 1m30s
Pre Release Workflow / upload-scripts (run-dnsmasq-in-netns.sh) (push) Successful in 5s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-17 23:26:04 +02:00
commit 6dd21a465d
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 26 additions and 7 deletions

View file

@ -2,8 +2,13 @@ package agentapi
import (
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"git.g3e.fr/syonad/two/internal/vpc"
"git.g3e.fr/syonad/two/pkg/db/kv"
)
func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
@ -25,14 +30,23 @@ func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
}
}
func (s *Server) getVpc(w http.ResponseWriter, r *http.Request, name string) {
func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(VPC{Name: name, State: "created"})
}
func (s *Server) deleteVpc(w http.ResponseWriter, r *http.Request, name string) {
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {
s.queue.Submit(func() {
destroyVpc(name)
kv.AddInDB(s.db, "vpc/"+name+"/state", "deleting")
if err := vpc.DeleteVPC(s.db, name); err != nil {
fmt.Println(err)
}
if state, err := kv.GetFromDB(s.db, "vpc/"+name+"/state"); err != nil {
fmt.Println(err)
os.Exit(1)
} else if state == "deleted" {
kv.DeleteInDB(s.db, "vpc/"+name)
}
})
w.WriteHeader(http.StatusAccepted)
json.NewEncoder(w).Encode(VPC{Name: name, State: "deleting"})