Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #284 from leoswaldo/master
Browse files Browse the repository at this point in the history
Add compatibility for Compute API /v2.1/{tenant_id}/servers POST
  • Loading branch information
Tim Pepper authored Jun 20, 2016
2 parents 5a036d8 + d5757eb commit 9c47545
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ciao-controller/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *controller) confirmTenant(tenantID string) error {
func (c *controller) startWorkload(workloadID string, tenantID string, instances int, trace bool, label string) ([]*types.Instance, error) {
var e error

if instances == 0 {
if instances <= 0 {
return nil, errors.New("Missing number of instances to start")
}

Expand Down
28 changes: 25 additions & 3 deletions 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 @@ -878,9 +883,9 @@ func createServer(w http.ResponseWriter, r *http.Request, context *controller) {

nInstances := 1

if server.Server.MaxInstances != 0 {
if server.Server.MaxInstances > 0 {
nInstances = server.Server.MaxInstances
} else if server.Server.MinInstances != 0 {
} else if server.Server.MinInstances > 0 {
nInstances = server.Server.MinInstances
}

Expand All @@ -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 9c47545

Please sign in to comment.