From 782f7c188c5a1deb47ed84dfb976c26487b581bf Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Mon, 20 Jun 2016 10:39:00 -0500 Subject: [PATCH] Add compatibility for Compute API /v2.1/{tenant_id}/servers POST Add compatibility for CIAO Compute API for /v2.1/{tenant_id}/servers for method POST, the calls and results should be in same format as Nova to be fully compatible with OpenStack. Fixes #20 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute.go | 24 +++++++++++++++++++++++- payloads/compute.go | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ciao-controller/compute.go b/ciao-controller/compute.go index 2ad9c5204..c2adf3d32 100644 --- a/ciao-controller/compute.go +++ b/ciao-controller/compute.go @@ -482,6 +482,11 @@ func showServerDetails(w http.ResponseWriter, r *http.Request, context *controll return } + // OpenStack compatibility: expect active status not running for API Call + if server.Server.Status == "running" { + server.Server.Status = "active" + } + b, err := json.Marshal(server) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -906,7 +911,24 @@ func createServer(w http.ResponseWriter, r *http.Request, context *controller) { } servers.TotalServers = len(instances) - b, err := json.Marshal(servers) + // set machine ID for OpenStack compatibility + server.Server.ID = instances[0].ID + + // builtServers is define to meet OpenStack compatibility on result format and keep CIAOs + builtServers := struct { + payloads.ComputeCreateServer + payloads.ComputeServers + }{ + payloads.ComputeCreateServer{ + Server: server.Server, + }, + payloads.ComputeServers{ + TotalServers: servers.TotalServers, + Servers: servers.Servers, + }, + } + + b, err := json.Marshal(builtServers) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/payloads/compute.go b/payloads/compute.go index ec657d2f0..2a0b5cf29 100644 --- a/payloads/compute.go +++ b/payloads/compute.go @@ -197,6 +197,7 @@ func NewComputeFlavorsDetails() (flavors ComputeFlavorsDetails) { // one or more instances. type ComputeCreateServer struct { Server struct { + ID string `json:"id"` Name string `json:"name"` Image string `json:"imageRef"` Workload string `json:"flavorRef"`