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
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:
parent
3955fb2112
commit
6dd21a465d
2 changed files with 26 additions and 7 deletions
|
|
@ -2,8 +2,13 @@ package agentapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"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) {
|
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)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(VPC{Name: name, State: "created"})
|
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() {
|
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)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
json.NewEncoder(w).Encode(VPC{Name: name, State: "deleting"})
|
json.NewEncoder(w).Encode(VPC{Name: name, State: "deleting"})
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@ package agentapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.g3e.fr/syonad/two/internal/vpc"
|
||||||
|
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -17,7 +21,7 @@ func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) listVpcs(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) listVpcs(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode([]VPC{})
|
json.NewEncoder(w).Encode([]VPC{})
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +39,11 @@ func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.queue.Submit(func() {
|
s.queue.Submit(func() {
|
||||||
createVpc(req.Name)
|
kv.AddInDB(s.db, "vpc/"+req.Name+"/state", "creating")
|
||||||
|
if err := vpc.CreateVPC(s.db, req.Name); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
json.NewEncoder(w).Encode(VPC{Name: req.Name, State: "creating"})
|
json.NewEncoder(w).Encode(VPC{Name: req.Name, State: "creating"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createVpc(name string) {}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue