f-28: fix: renomage api param
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9492de7a2b
commit
848f965883
13 changed files with 53 additions and 53 deletions
|
|
@ -315,7 +315,7 @@ components:
|
||||||
|
|
||||||
SubnetCreateRequest:
|
SubnetCreateRequest:
|
||||||
type: object
|
type: object
|
||||||
required: [name, vpc, gateway_ip, cidr]
|
required: [name, vpc, interface_ip, cidr]
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
|
|
@ -342,7 +342,7 @@ components:
|
||||||
type: string
|
type: string
|
||||||
description: Interface type key defined in the agent config (e.g. vms, internet, admin). Falls back to default_interface if omitted or unknown.
|
description: Interface type key defined in the agent config (e.g. vms, internet, admin). Falls back to default_interface if omitted or unknown.
|
||||||
example: vms
|
example: vms
|
||||||
gateway_ip:
|
interface_ip:
|
||||||
type: string
|
type: string
|
||||||
format: ipv4
|
format: ipv4
|
||||||
description: Gateway IP for the subnet
|
description: Gateway IP for the subnet
|
||||||
|
|
@ -377,7 +377,7 @@ components:
|
||||||
type: string
|
type: string
|
||||||
description: Resolved interface name from agent config
|
description: Resolved interface name from agent config
|
||||||
example: br-000000
|
example: br-000000
|
||||||
gateway_ip:
|
interface_ip:
|
||||||
type: string
|
type: string
|
||||||
example: "10.10.10.1"
|
example: "10.10.10.1"
|
||||||
cidr:
|
cidr:
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ type SubnetCreateRequest struct {
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
VxlanID int `json:"vxlan_id"`
|
VxlanID int `json:"vxlan_id"`
|
||||||
IfaceType string `json:"iface_type"`
|
IfaceType string `json:"iface_type"`
|
||||||
GatewayIP string `json:"gateway_ip"`
|
InterfaceIP string `json:"interface_ip"`
|
||||||
CIDR string `json:"cidr"`
|
CIDR string `json:"cidr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ type Subnet struct {
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
VxlanID int `json:"vxlan_id"`
|
VxlanID int `json:"vxlan_id"`
|
||||||
LocalIface string `json:"local_iface"`
|
LocalIface string `json:"local_iface"`
|
||||||
GatewayIP string `json:"gateway_ip"`
|
InterfaceIP string `json:"interface_ip"`
|
||||||
CIDR string `json:"cidr"`
|
CIDR string `json:"cidr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ func (s *Server) getSubnet(w http.ResponseWriter, _ *http.Request, name string)
|
||||||
sub.VxlanID, _ = strconv.Atoi(value)
|
sub.VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
sub.LocalIface = value
|
sub.LocalIface = value
|
||||||
case "gateway_ip":
|
case "interface_ip":
|
||||||
sub.GatewayIP = value
|
sub.InterfaceIP = value
|
||||||
case "cidr":
|
case "cidr":
|
||||||
sub.CIDR = value
|
sub.CIDR = value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestPostSubnet_Created(t *testing.T) {
|
||||||
Name: "sn-new",
|
Name: "sn-new",
|
||||||
VPC: "vpc-1",
|
VPC: "vpc-1",
|
||||||
IfaceType: "vms",
|
IfaceType: "vms",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -95,7 +95,7 @@ func TestPostSubnet_IfaceTypeOptional(t *testing.T) {
|
||||||
req := SubnetCreateRequest{
|
req := SubnetCreateRequest{
|
||||||
Name: "sn-opt",
|
Name: "sn-opt",
|
||||||
VPC: "vpc-1",
|
VPC: "vpc-1",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
// IfaceType omis — doit utiliser default_interface
|
// IfaceType omis — doit utiliser default_interface
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +113,7 @@ func TestPostSubnet_VPCNotFound(t *testing.T) {
|
||||||
Name: "sn-1",
|
Name: "sn-1",
|
||||||
VPC: "vpc-inexistant",
|
VPC: "vpc-inexistant",
|
||||||
IfaceType: "vms",
|
IfaceType: "vms",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -132,7 +132,7 @@ func TestPostSubnet_Duplicate(t *testing.T) {
|
||||||
Name: "sn-exist",
|
Name: "sn-exist",
|
||||||
VPC: "vpc-1",
|
VPC: "vpc-1",
|
||||||
IfaceType: "vms",
|
IfaceType: "vms",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -150,7 +150,7 @@ func TestPostSubnet_VPCDeleting(t *testing.T) {
|
||||||
Name: "sn-1",
|
Name: "sn-1",
|
||||||
VPC: "vpc-dying",
|
VPC: "vpc-dying",
|
||||||
IfaceType: "vms",
|
IfaceType: "vms",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -169,7 +169,7 @@ func TestPostSubnet_BridgeMode_Success(t *testing.T) {
|
||||||
VPC: "vpc-1",
|
VPC: "vpc-1",
|
||||||
Mode: "bridge",
|
Mode: "bridge",
|
||||||
IfaceType: "vms",
|
IfaceType: "vms",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -195,7 +195,7 @@ func TestPostSubnet_UnknownMode(t *testing.T) {
|
||||||
Name: "sn-1",
|
Name: "sn-1",
|
||||||
VPC: "vpc-1",
|
VPC: "vpc-1",
|
||||||
Mode: "vlan",
|
Mode: "vlan",
|
||||||
GatewayIP: "10.0.0.1",
|
InterfaceIP: "10.0.0.1",
|
||||||
CIDR: "10.0.0.0/24",
|
CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(req)
|
body, _ := json.Marshal(req)
|
||||||
|
|
@ -222,7 +222,7 @@ func TestGetSubnet_Found(t *testing.T) {
|
||||||
kv.AddInDB(db, "subnet/sn-1/state", "created")
|
kv.AddInDB(db, "subnet/sn-1/state", "created")
|
||||||
kv.AddInDB(db, "subnet/sn-1/vpc", "vpc-1")
|
kv.AddInDB(db, "subnet/sn-1/vpc", "vpc-1")
|
||||||
kv.AddInDB(db, "subnet/sn-1/cidr", "10.0.0.0/24")
|
kv.AddInDB(db, "subnet/sn-1/cidr", "10.0.0.0/24")
|
||||||
kv.AddInDB(db, "subnet/sn-1/gateway_ip", "10.0.0.1")
|
kv.AddInDB(db, "subnet/sn-1/interface_ip", "10.0.0.1")
|
||||||
req := httptest.NewRequest(http.MethodGet, "/subnets/sn-1", nil)
|
req := httptest.NewRequest(http.MethodGet, "/subnets/sn-1", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
s.SubnetByNameHandler(w, req)
|
s.SubnetByNameHandler(w, req)
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ func (s *Server) listSubnets(w http.ResponseWriter, _ *http.Request) {
|
||||||
subnets[name].VxlanID, _ = strconv.Atoi(value)
|
subnets[name].VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
subnets[name].LocalIface = value
|
subnets[name].LocalIface = value
|
||||||
case "gateway_ip":
|
case "interface_ip":
|
||||||
subnets[name].GatewayIP = value
|
subnets[name].InterfaceIP = value
|
||||||
case "cidr":
|
case "cidr":
|
||||||
subnets[name].CIDR = value
|
subnets[name].CIDR = value
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +71,9 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "invalid request body"})
|
json.NewEncoder(w).Encode(ErrorResponse{Error: "invalid request body"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Name == "" || req.VPC == "" || req.GatewayIP == "" || req.CIDR == "" {
|
if req.Name == "" || req.VPC == "" || req.InterfaceIP == "" || req.CIDR == "" {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "name, vpc, gateway_ip and cidr are required"})
|
json.NewEncoder(w).Encode(ErrorResponse{Error: "name, vpc, interface_ip and cidr are required"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := dispatcher.CreateSubnetCommand{
|
cmd := dispatcher.CreateSubnetCommand{
|
||||||
|
|
@ -82,7 +82,7 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
Mode: req.Mode,
|
Mode: req.Mode,
|
||||||
VxlanID: req.VxlanID,
|
VxlanID: req.VxlanID,
|
||||||
IfaceType: req.IfaceType,
|
IfaceType: req.IfaceType,
|
||||||
GatewayIP: req.GatewayIP,
|
InterfaceIP: req.InterfaceIP,
|
||||||
CIDR: req.CIDR,
|
CIDR: req.CIDR,
|
||||||
}
|
}
|
||||||
if err := s.dispatcher.Prepare(cmd); err != nil {
|
if err := s.dispatcher.Prepare(cmd); err != nil {
|
||||||
|
|
@ -118,8 +118,8 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
sub.VxlanID, _ = strconv.Atoi(value)
|
sub.VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
sub.LocalIface = value
|
sub.LocalIface = value
|
||||||
case "gateway_ip":
|
case "interface_ip":
|
||||||
sub.GatewayIP = value
|
sub.InterfaceIP = value
|
||||||
case "cidr":
|
case "cidr":
|
||||||
sub.CIDR = value
|
sub.CIDR = value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ type CreateSubnetCommand struct {
|
||||||
Mode string
|
Mode string
|
||||||
VxlanID int
|
VxlanID int
|
||||||
IfaceType string
|
IfaceType string
|
||||||
GatewayIP string
|
InterfaceIP string
|
||||||
CIDR string
|
CIDR string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) e
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/vpc", c.VPC)
|
kv.AddInDB(db, "subnet/"+c.Name+"/vpc", c.VPC)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/mode", c.Mode)
|
kv.AddInDB(db, "subnet/"+c.Name+"/mode", c.Mode)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/local_iface", localIface)
|
kv.AddInDB(db, "subnet/"+c.Name+"/local_iface", localIface)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/gateway_ip", c.GatewayIP)
|
kv.AddInDB(db, "subnet/"+c.Name+"/interface_ip", c.InterfaceIP)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR)
|
kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR)
|
||||||
if c.Mode == "vxlan" {
|
if c.Mode == "vxlan" {
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/vxlan_id", strconv.Itoa(c.VxlanID))
|
kv.AddInDB(db, "subnet/"+c.Name+"/vxlan_id", strconv.Itoa(c.VxlanID))
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestCreateSubnetCommand_Prepare_Success(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err != nil {
|
if err := cmd.Prepare(db, testCfg()); err != nil {
|
||||||
t.Fatalf("Prepare a échoué : %v", err)
|
t.Fatalf("Prepare a échoué : %v", err)
|
||||||
|
|
@ -40,7 +40,7 @@ func TestCreateSubnetCommand_Prepare_UsesIfaceTypeMapping(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
cmd.Prepare(db, testCfg())
|
cmd.Prepare(db, testCfg())
|
||||||
iface, _ := kv.GetFromDB(db, "subnet/sn-1/local_iface")
|
iface, _ := kv.GetFromDB(db, "subnet/sn-1/local_iface")
|
||||||
|
|
@ -54,7 +54,7 @@ func TestCreateSubnetCommand_Prepare_UsesDefaultIfaceWhenTypeUnknown(t *testing.
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
||||||
IfaceType: "inconnu", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "inconnu", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
cmd.Prepare(db, testCfg())
|
cmd.Prepare(db, testCfg())
|
||||||
iface, _ := kv.GetFromDB(db, "subnet/sn-1/local_iface")
|
iface, _ := kv.GetFromDB(db, "subnet/sn-1/local_iface")
|
||||||
|
|
@ -69,7 +69,7 @@ func TestCreateSubnetCommand_Prepare_Duplicate(t *testing.T) {
|
||||||
kv.AddInDB(db, "subnet/sn-exist/state", "created")
|
kv.AddInDB(db, "subnet/sn-exist/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-exist", VPC: "vpc-1", VxlanID: 100,
|
Name: "sn-exist", VPC: "vpc-1", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err == nil {
|
if err := cmd.Prepare(db, testCfg()); err == nil {
|
||||||
t.Error("Prepare devrait échouer sur un subnet déjà existant")
|
t.Error("Prepare devrait échouer sur un subnet déjà existant")
|
||||||
|
|
@ -80,7 +80,7 @@ func TestCreateSubnetCommand_Prepare_VPCNotFound(t *testing.T) {
|
||||||
_, db := newTestDispatcher(t)
|
_, db := newTestDispatcher(t)
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-inexistant", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-inexistant", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err == nil {
|
if err := cmd.Prepare(db, testCfg()); err == nil {
|
||||||
t.Error("Prepare devrait échouer si le VPC n'existe pas")
|
t.Error("Prepare devrait échouer si le VPC n'existe pas")
|
||||||
|
|
@ -92,7 +92,7 @@ func TestCreateSubnetCommand_Prepare_VPCDeleting(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-dying/state", "deleting")
|
kv.AddInDB(db, "vpc/vpc-dying/state", "deleting")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-dying", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-dying", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err == nil {
|
if err := cmd.Prepare(db, testCfg()); err == nil {
|
||||||
t.Error("Prepare devrait échouer si le VPC est en cours de suppression")
|
t.Error("Prepare devrait échouer si le VPC est en cours de suppression")
|
||||||
|
|
@ -104,7 +104,7 @@ func TestCreateSubnetCommand_Prepare_VPCDeleted(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-gone/state", "deleted")
|
kv.AddInDB(db, "vpc/vpc-gone/state", "deleted")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-gone", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-gone", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err == nil {
|
if err := cmd.Prepare(db, testCfg()); err == nil {
|
||||||
t.Error("Prepare devrait échouer si le VPC est supprimé")
|
t.Error("Prepare devrait échouer si le VPC est supprimé")
|
||||||
|
|
@ -116,7 +116,7 @@ func TestCreateSubnetCommand_Prepare_DefaultsToVxlanMode(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
Name: "sn-1", VPC: "vpc-1", VxlanID: 100,
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
cmd.Prepare(db, testCfg())
|
cmd.Prepare(db, testCfg())
|
||||||
mode, _ := kv.GetFromDB(db, "subnet/sn-1/mode")
|
mode, _ := kv.GetFromDB(db, "subnet/sn-1/mode")
|
||||||
|
|
@ -133,7 +133,7 @@ func TestCreateSubnetCommand_Prepare_BridgeMode_Success(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", Mode: "bridge",
|
Name: "sn-1", VPC: "vpc-1", Mode: "bridge",
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err != nil {
|
if err := cmd.Prepare(db, testCfg()); err != nil {
|
||||||
t.Fatalf("Prepare a échoué : %v", err)
|
t.Fatalf("Prepare a échoué : %v", err)
|
||||||
|
|
@ -153,7 +153,7 @@ func TestCreateSubnetCommand_Prepare_BridgeMode_NoVxlanID(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", Mode: "bridge",
|
Name: "sn-1", VPC: "vpc-1", Mode: "bridge",
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
cmd.Prepare(db, testCfg())
|
cmd.Prepare(db, testCfg())
|
||||||
if _, err := kv.GetFromDB(db, "subnet/sn-1/vxlan_id"); err == nil {
|
if _, err := kv.GetFromDB(db, "subnet/sn-1/vxlan_id"); err == nil {
|
||||||
|
|
@ -166,7 +166,7 @@ func TestCreateSubnetCommand_Prepare_UnknownMode(t *testing.T) {
|
||||||
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
kv.AddInDB(db, "vpc/vpc-1/state", "created")
|
||||||
cmd := CreateSubnetCommand{
|
cmd := CreateSubnetCommand{
|
||||||
Name: "sn-1", VPC: "vpc-1", Mode: "vlan",
|
Name: "sn-1", VPC: "vpc-1", Mode: "vlan",
|
||||||
IfaceType: "vms", GatewayIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24",
|
||||||
}
|
}
|
||||||
if err := cmd.Prepare(db, testCfg()); err == nil {
|
if err := cmd.Prepare(db, testCfg()); err == nil {
|
||||||
t.Error("Prepare devrait échouer pour un mode inconnu")
|
t.Error("Prepare devrait échouer pour un mode inconnu")
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData) error {
|
||||||
switch d.mode {
|
switch d.mode {
|
||||||
case "vxlan":
|
case "vxlan":
|
||||||
if err := netns.Call(d.vpc, func() error {
|
if err := netns.Call(d.vpc, func() error {
|
||||||
return netif.AddrAdd(d.bridge, d.gatewayIP)
|
return netif.AddrAdd(d.bridge, d.interfaceIP)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("add addr to bridge in netns: %w", err)
|
return fmt.Errorf("add addr to bridge in netns: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData) error {
|
||||||
|
|
||||||
switch d.mode {
|
switch d.mode {
|
||||||
case "vxlan":
|
case "vxlan":
|
||||||
if err := ebtables.DropARPToGateway(d.bridge, d.gatewayIP.String()); err != nil {
|
if err := ebtables.DropARPToGateway(d.bridge, d.interfaceIP.String()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ebtables.DropDHCP(d.bridge); err != nil {
|
if err := ebtables.DropDHCP(d.bridge); err != nil {
|
||||||
|
|
@ -133,7 +133,7 @@ func setupVxlanHost(d subnetData, vethE string) error {
|
||||||
func startDHCP(db *badger.DB, subnetName string, d subnetData) error {
|
func startDHCP(db *badger.DB, subnetName string, d subnetData) error {
|
||||||
conf := dhcp.Config{
|
conf := dhcp.Config{
|
||||||
Network: d.cidr,
|
Network: d.cidr,
|
||||||
Gateway: d.gatewayIP,
|
Gateway: d.interfaceIP,
|
||||||
Name: d.vpc + "_" + d.bridge,
|
Name: d.vpc + "_" + d.bridge,
|
||||||
ConfDir: "/etc/dnsmasq.d",
|
ConfDir: "/etc/dnsmasq.d",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ type subnetData struct {
|
||||||
mode string
|
mode string
|
||||||
vxlanID int
|
vxlanID int
|
||||||
localIface string
|
localIface string
|
||||||
gatewayIP net.IP
|
interfaceIP net.IP
|
||||||
cidr *net.IPNet
|
cidr *net.IPNet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,15 +57,15 @@ func loadSubnet(db *badger.DB, name string) (subnetData, error) {
|
||||||
}
|
}
|
||||||
d.localIface = localIface
|
d.localIface = localIface
|
||||||
|
|
||||||
gatewayIPStr, err := kv.GetFromDB(db, "subnet/"+name+"/gateway_ip")
|
interfaceIPStr, err := kv.GetFromDB(db, "subnet/"+name+"/interface_ip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, fmt.Errorf("get gateway_ip: %w", err)
|
return d, fmt.Errorf("get interface_ip: %w", err)
|
||||||
}
|
}
|
||||||
gatewayIP := net.ParseIP(gatewayIPStr)
|
interfaceIP := net.ParseIP(interfaceIPStr)
|
||||||
if gatewayIP == nil {
|
if interfaceIP == nil {
|
||||||
return d, fmt.Errorf("invalid gateway_ip: %s", gatewayIPStr)
|
return d, fmt.Errorf("invalid interface_ip: %s", interfaceIPStr)
|
||||||
}
|
}
|
||||||
d.gatewayIP = gatewayIP
|
d.interfaceIP = interfaceIP
|
||||||
|
|
||||||
cidrStr, err := kv.GetFromDB(db, "subnet/"+name+"/cidr")
|
cidrStr, err := kv.GetFromDB(db, "subnet/"+name+"/cidr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func stopDHCP(db *badger.DB, subnetName string, d subnetData) error {
|
||||||
func deleteSubnetVxlan(d subnetData) error {
|
func deleteSubnetVxlan(d subnetData) error {
|
||||||
vxlanIface := fmt.Sprintf("vxlan-%d", d.vxlanID)
|
vxlanIface := fmt.Sprintf("vxlan-%d", d.vxlanID)
|
||||||
|
|
||||||
if err := ebtables.DeleteARPToGateway(d.bridge, d.gatewayIP.String()); err != nil {
|
if err := ebtables.DeleteARPToGateway(d.bridge, d.interfaceIP.String()); err != nil {
|
||||||
return fmt.Errorf("delete ebtables arp rule: %w", err)
|
return fmt.Errorf("delete ebtables arp rule: %w", err)
|
||||||
}
|
}
|
||||||
if err := ebtables.DeleteDHCP(d.bridge); err != nil {
|
if err := ebtables.DeleteDHCP(d.bridge); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := netns.Call(d.vpcName, func() error {
|
if err := netns.Call(d.vpcName, func() error {
|
||||||
return iptables.AddMetadataRedirect(d.ip, d.gatewayIP, d.metadataPort)
|
return iptables.AddMetadataRedirect(d.ip, d.interfaceIP, d.metadataPort)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("add metadata redirect: %w", err)
|
return fmt.Errorf("add metadata redirect: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
||||||
if err := metadata.StartMetadata(metadata.NoCloudConfig{
|
if err := metadata.StartMetadata(metadata.NoCloudConfig{
|
||||||
Name: name,
|
Name: name,
|
||||||
VpcName: d.vpcName,
|
VpcName: d.vpcName,
|
||||||
BindIP: d.gatewayIP,
|
BindIP: d.interfaceIP,
|
||||||
BindPort: d.metadataPort,
|
BindPort: d.metadataPort,
|
||||||
Password: d.password,
|
Password: d.password,
|
||||||
SSHKEY: d.sshkey,
|
SSHKEY: d.sshkey,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
type vmData struct {
|
type vmData struct {
|
||||||
subnetName string
|
subnetName string
|
||||||
vpcName string
|
vpcName string
|
||||||
gatewayIP string
|
interfaceIP string
|
||||||
bridge string
|
bridge string
|
||||||
tapID int
|
tapID int
|
||||||
ip string
|
ip string
|
||||||
|
|
@ -43,11 +43,11 @@ func loadVM(db *badger.DB, name string) (vmData, error) {
|
||||||
}
|
}
|
||||||
d.vpcName = vpcName
|
d.vpcName = vpcName
|
||||||
|
|
||||||
gatewayIP, err := kv.GetFromDB(db, "subnet/"+subnetName+"/gateway_ip")
|
interfaceIP, err := kv.GetFromDB(db, "subnet/"+subnetName+"/interface_ip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, fmt.Errorf("get gateway_ip: %w", err)
|
return d, fmt.Errorf("get interface_ip: %w", err)
|
||||||
}
|
}
|
||||||
d.gatewayIP = gatewayIP
|
d.interfaceIP = interfaceIP
|
||||||
|
|
||||||
tapIDStr, err := kv.GetFromDB(db, "vm/"+name+"/tap_id")
|
tapIDStr, err := kv.GetFromDB(db, "vm/"+name+"/tap_id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func StopVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := netns.Call(d.vpcName, func() error {
|
if err := netns.Call(d.vpcName, func() error {
|
||||||
return iptables.DeleteMetadataRedirect(d.ip, d.gatewayIP, d.metadataPort)
|
return iptables.DeleteMetadataRedirect(d.ip, d.interfaceIP, d.metadataPort)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("delete metadata redirect: %w", err)
|
return fmt.Errorf("delete metadata redirect: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue