f-88: api: ressource /floating-ips, refus et affichage sur la VM #88
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
d6f9d77739
commit
fdabd943f2
15 changed files with 942 additions and 12 deletions
|
|
@ -44,12 +44,19 @@ func (s *Server) listVMs(w http.ResponseWriter, _ *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
floating, err := kv.ListByPrefix(s.db, "floating-ip/")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "failed to list floating ips"})
|
||||
return
|
||||
}
|
||||
result := make([]VM, 0, len(names))
|
||||
for name := range names {
|
||||
vm, err := vmFromDB(name, entries)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
attachFloatingIPs(&vm, floating)
|
||||
result = append(result, vm)
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +92,11 @@ func (s *Server) startVM(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
names[iface.Name] = i
|
||||
if iface.FloatingIP != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{Error: fmt.Sprintf("interface %d: floating_ip is read-only, attach it with /floating-ips", i)})
|
||||
return
|
||||
}
|
||||
if iface.MAC == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{Error: fmt.Sprintf("interface %d: mac is required", i)})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue