Compare commits
No commits in common. "7e3bf7cdd351d2a43107aff9255183dc05ab0c4e" and "0f70b32076c12aba795248debca01275fb14dfee" have entirely different histories.
7e3bf7cdd3
...
0f70b32076
9 changed files with 14 additions and 112 deletions
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
agentapi "git.g3e.fr/syonad/two/internal/api/agent"
|
agentapi "git.g3e.fr/syonad/two/internal/api/agent"
|
||||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
agentmetrics "git.g3e.fr/syonad/two/internal/prometheus/agent"
|
agentmetrics "git.g3e.fr/syonad/two/internal/prometheus/agent"
|
||||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||||
promserver "git.g3e.fr/syonad/two/pkg/prometheus"
|
promserver "git.g3e.fr/syonad/two/pkg/prometheus"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
"github.com/dgraph-io/badger/v4"
|
"github.com/dgraph-io/badger/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,9 @@ package agentapi
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) SubnetByNameHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) SubnetByNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -29,36 +27,9 @@ func (s *Server) SubnetByNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getSubnet(w http.ResponseWriter, _ *http.Request, name string) {
|
func (s *Server) getSubnet(w http.ResponseWriter, r *http.Request, name string) {
|
||||||
entries, err := kv.ListByPrefix(s.db, "subnet/"+name+"/")
|
|
||||||
if err != nil || len(entries) == 0 {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "subnet not found"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sub := Subnet{Name: name}
|
|
||||||
for key, value := range entries {
|
|
||||||
parts := strings.Split(key, "/")
|
|
||||||
if len(parts) != 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch parts[2] {
|
|
||||||
case "state":
|
|
||||||
sub.State = value
|
|
||||||
case "vpc":
|
|
||||||
sub.VPC = value
|
|
||||||
case "vxlan_id":
|
|
||||||
sub.VxlanID, _ = strconv.Atoi(value)
|
|
||||||
case "local_iface":
|
|
||||||
sub.LocalIface = value
|
|
||||||
case "gateway_ip":
|
|
||||||
sub.GatewayIP = value
|
|
||||||
case "cidr":
|
|
||||||
sub.CIDR = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(sub)
|
json.NewEncoder(w).Encode(Subnet{Name: name, State: "created"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) deleteSubnet(w http.ResponseWriter, r *http.Request, name string) {
|
func (s *Server) deleteSubnet(w http.ResponseWriter, r *http.Request, name string) {
|
||||||
|
|
@ -66,3 +37,4 @@ func (s *Server) deleteSubnet(w http.ResponseWriter, r *http.Request, name strin
|
||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
json.NewEncoder(w).Encode(Subnet{Name: name, State: "deleting"})
|
json.NewEncoder(w).Encode(Subnet{Name: name, State: "deleting"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,8 @@ package agentapi
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) SubnetsHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) SubnetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -22,44 +19,9 @@ func (s *Server) SubnetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) listSubnets(w http.ResponseWriter, _ *http.Request) {
|
func (s *Server) listSubnets(w http.ResponseWriter, r *http.Request) {
|
||||||
entries, err := kv.ListByPrefix(s.db, "subnet/")
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "failed to list subnets"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subnets := make(map[string]*Subnet)
|
|
||||||
for key, value := range entries {
|
|
||||||
parts := strings.Split(key, "/")
|
|
||||||
if len(parts) != 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := parts[1]
|
|
||||||
if _, ok := subnets[name]; !ok {
|
|
||||||
subnets[name] = &Subnet{Name: name}
|
|
||||||
}
|
|
||||||
switch parts[2] {
|
|
||||||
case "state":
|
|
||||||
subnets[name].State = value
|
|
||||||
case "vpc":
|
|
||||||
subnets[name].VPC = value
|
|
||||||
case "vxlan_id":
|
|
||||||
subnets[name].VxlanID, _ = strconv.Atoi(value)
|
|
||||||
case "local_iface":
|
|
||||||
subnets[name].LocalIface = value
|
|
||||||
case "gateway_ip":
|
|
||||||
subnets[name].GatewayIP = value
|
|
||||||
case "cidr":
|
|
||||||
subnets[name].CIDR = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result := make([]Subnet, 0, len(subnets))
|
|
||||||
for _, sub := range subnets {
|
|
||||||
result = append(result, *sub)
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(result)
|
json.NewEncoder(w).Encode([]Subnet{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
"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) {
|
||||||
|
|
@ -29,14 +28,8 @@ func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
||||||
state, err := kv.GetFromDB(s.db, "vpc/"+name+"/state")
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "vpc not found"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(VPC{Name: name, State: state})
|
json.NewEncoder(w).Encode(VPC{Name: name, State: "created"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
||||||
|
|
@ -44,3 +37,4 @@ func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string)
|
||||||
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"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,8 @@ package agentapi
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
|
"git.g3e.fr/syonad/two/internal/dispatcher"
|
||||||
"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) {
|
||||||
|
|
@ -22,32 +20,8 @@ func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) listVpcs(w http.ResponseWriter, _ *http.Request) {
|
func (s *Server) listVpcs(w http.ResponseWriter, _ *http.Request) {
|
||||||
entries, err := kv.ListByPrefix(s.db, "vpc/")
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "failed to list vpcs"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vpcs := make(map[string]*VPC)
|
|
||||||
for key, value := range entries {
|
|
||||||
parts := strings.Split(key, "/")
|
|
||||||
if len(parts) != 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := parts[1]
|
|
||||||
if _, ok := vpcs[name]; !ok {
|
|
||||||
vpcs[name] = &VPC{Name: name}
|
|
||||||
}
|
|
||||||
if parts[2] == "state" {
|
|
||||||
vpcs[name].State = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result := make([]VPC, 0, len(vpcs))
|
|
||||||
for _, v := range vpcs {
|
|
||||||
result = append(result, *v)
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(result)
|
json.NewEncoder(w).Encode([]VPC{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue