Skip to content

Commit

Permalink
Add compatibility for Compute API /v2.1/{tenant_id}/servers POST
Browse files Browse the repository at this point in the history
Add compatibility for CIAO Compute API call /v2.1/{tenant_id}/servers
for method POST, the results should contain the 'server' variable with
the corresponding details of it, as described in
http://developer.openstack.org/api-ref-compute-v2.1.html
to be fully compatible with OpenStack.
Fixes ciao-project#20

Signed-off-by: Leoswaldo Macias <[email protected]>
  • Loading branch information
Leoswaldo Macias committed Jun 20, 2016
1 parent 18dd598 commit 542f436
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ciao-controller/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions payloads/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 542f436

Please sign in to comment.