LEFT | RIGHT |
(no file at all) | |
1 // Nova double testing service - HTTP API implementation | 1 // Nova double testing service - HTTP API implementation |
2 | 2 |
3 package novaservice | 3 package novaservice |
4 | 4 |
5 import ( | 5 import ( |
6 "crypto/rand" | 6 "crypto/rand" |
7 "encoding/json" | 7 "encoding/json" |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "io/ioutil" | 10 "io/ioutil" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // handle trailing slash in the path | 290 // handle trailing slash in the path |
291 if strings.HasSuffix(path, "/") && path != "/" { | 291 if strings.HasSuffix(path, "/") && path != "/" { |
292 errNotFound.ServeHTTP(w, r) | 292 errNotFound.ServeHTTP(w, r) |
293 return | 293 return |
294 } | 294 } |
295 err = h.method(h.n, w, r) | 295 err = h.method(h.n, w, r) |
296 if err == nil { | 296 if err == nil { |
297 return | 297 return |
298 } | 298 } |
299 var resp http.Handler | 299 var resp http.Handler |
| 300 |
300 if err == testservices.RateLimitExceededError { | 301 if err == testservices.RateLimitExceededError { |
301 resp = errRateLimitExceeded | 302 resp = errRateLimitExceeded |
302 } else if err == testservices.NoMoreFloatingIPs { | 303 } else if err == testservices.NoMoreFloatingIPs { |
303 resp = errNoMoreFloatingIPs | 304 resp = errNoMoreFloatingIPs |
304 } else if err == testservices.IPLimitExceeded { | 305 } else if err == testservices.IPLimitExceeded { |
305 resp = errIPLimitExceeded | 306 resp = errIPLimitExceeded |
306 } else { | 307 } else { |
307 resp, _ = err.(http.Handler) | 308 resp, _ = err.(http.Handler) |
308 if resp == nil { | 309 if resp == nil { |
| 310 code, encodedErr := errorJSONEncode(err) |
309 resp = &errorResponse{ | 311 resp = &errorResponse{ |
310 » » » » http.StatusInternalServerError, | 312 » » » » code, |
311 » » » » `{"internalServerError":{"message":"$ERROR$",cod
e:500}}`, | 313 » » » » encodedErr, |
312 "application/json", | 314 "application/json", |
313 err.Error(), | 315 err.Error(), |
314 nil, | 316 nil, |
315 h.n, | 317 h.n, |
316 } | 318 } |
317 } | 319 } |
318 } | 320 } |
319 resp.ServeHTTP(w, r) | 321 resp.ServeHTTP(w, r) |
320 } | 322 } |
321 | 323 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 serverId := "" | 646 serverId := "" |
645 if suffix == "os-security-groups" { | 647 if suffix == "os-security-groups" { |
646 // handle GET /servers/<id>/os-security-groups | 648 // handle GET /servers/<id>/os-security-groups |
647 serverId = path.Base(strings.Replace(r.URL.Path,
"/os-security-groups", "", 1)) | 649 serverId = path.Base(strings.Replace(r.URL.Path,
"/os-security-groups", "", 1)) |
648 groups = true | 650 groups = true |
649 } else { | 651 } else { |
650 serverId = suffix | 652 serverId = suffix |
651 } | 653 } |
652 server, err := n.server(serverId) | 654 server, err := n.server(serverId) |
653 if err != nil { | 655 if err != nil { |
654 » » » » return errNotFoundJSON | 656 » » » » return err |
655 } | 657 } |
656 if groups { | 658 if groups { |
657 srvGroups := n.allServerSecurityGroups(serverId) | 659 srvGroups := n.allServerSecurityGroups(serverId) |
658 if len(srvGroups) == 0 { | 660 if len(srvGroups) == 0 { |
659 srvGroups = []nova.SecurityGroup{} | 661 srvGroups = []nova.SecurityGroup{} |
660 } | 662 } |
661 resp := struct { | 663 resp := struct { |
662 Groups []nova.SecurityGroup `json:"secur
ity_groups"` | 664 Groups []nova.SecurityGroup `json:"secur
ity_groups"` |
663 }{srvGroups} | 665 }{srvGroups} |
664 return sendJSON(http.StatusOK, resp, w, r) | 666 return sendJSON(http.StatusOK, resp, w, r) |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 } | 1036 } |
1035 for path, h := range handlers { | 1037 for path, h := range handlers { |
1036 path = strings.Replace(path, "$v", n.VersionPath, 1) | 1038 path = strings.Replace(path, "$v", n.VersionPath, 1) |
1037 path = strings.Replace(path, "$t", n.TenantId, 1) | 1039 path = strings.Replace(path, "$t", n.TenantId, 1) |
1038 if !strings.HasSuffix(path, "/") { | 1040 if !strings.HasSuffix(path, "/") { |
1039 mux.Handle(path+"/", h) | 1041 mux.Handle(path+"/", h) |
1040 } | 1042 } |
1041 mux.Handle(path, h) | 1043 mux.Handle(path, h) |
1042 } | 1044 } |
1043 } | 1045 } |
LEFT | RIGHT |