Beispiel #1
0
func (s *fakeGalebServer) createPool(w http.ResponseWriter, r *http.Request) {
	var pool galebClient.Pool
	pool.Status = "OK"
	json.NewDecoder(r.Body).Decode(&pool)
	poolsWithName := s.findItemByName("pool", pool.Name)
	if len(poolsWithName) > 0 {
		w.WriteHeader(http.StatusConflict)
		return
	}
	s.idCounter++
	pool.ID = s.idCounter
	pool.Links.Self.Href = fmt.Sprintf("http://%s%s/%d", r.Host, r.URL.String(), pool.ID)
	s.pools[strconv.Itoa(pool.ID)] = &pool
	w.Header().Set("Location", pool.Links.Self.Href)
	w.WriteHeader(http.StatusCreated)
}
Beispiel #2
0
func (s *fakeGalebServer) findTargetsByParent(w http.ResponseWriter, r *http.Request) {
	parentName := r.URL.Query().Get("name")
	var pool *galebClient.Pool
	var ret []interface{}
	for _, item := range s.pools {
		p := item.(*galebClient.Pool)
		if p.Name == parentName {
			pool = p
		}
	}
	for i, item := range s.targets {
		target := item.(*galebClient.Target)
		if target.BackendPool == pool.FullId() {
			ret = append(ret, s.targets[i])
		}
	}
	json.NewEncoder(w).Encode(makeSearchRsp("target", ret...))
}