f-33: net: add multi net in dispatch et vms #33
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
1ec1d44c1a
commit
0237acba81
15 changed files with 753 additions and 146 deletions
|
|
@ -67,16 +67,17 @@ func (s *Server) startVM(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var primary *VMInterface
|
||||
for i := range req.Interfaces {
|
||||
if req.Interfaces[i].Primary {
|
||||
primary = &req.Interfaces[i]
|
||||
break
|
||||
nics := make([]dispatcher.VMNIC, len(req.Interfaces))
|
||||
primaries := 0
|
||||
for i, iface := range req.Interfaces {
|
||||
nics[i] = dispatcher.VMNIC{Subnet: iface.Subnet, IP: iface.IP, Primary: iface.Primary}
|
||||
if iface.Primary {
|
||||
primaries++
|
||||
}
|
||||
}
|
||||
if primary == nil {
|
||||
if primaries != 1 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "one interface must be primary"})
|
||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "exactly one interface must be primary"})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +95,7 @@ func (s *Server) startVM(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
cmd := dispatcher.StartVMCommand{
|
||||
Name: req.Name,
|
||||
Subnet: primary.Subnet,
|
||||
IP: primary.IP,
|
||||
NICs: nics,
|
||||
Disks: disks,
|
||||
Memory: req.Memory,
|
||||
CPUs: req.CPUs,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue