當前位置: 首頁>>代碼示例>>Golang>>正文


Golang provision.ListPools函數代碼示例

本文整理匯總了Golang中github.com/tsuru/tsuru/provision.ListPools函數的典型用法代碼示例。如果您正苦於以下問題:Golang ListPools函數的具體用法?Golang ListPools怎麽用?Golang ListPools使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ListPools函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestAddPool

func (s *S) TestAddPool(c *check.C) {
	b := bytes.NewBufferString("name=pool1")
	req, err := http.NewRequest("POST", "/pools", b)
	c.Assert(err, check.IsNil)
	req.Header.Set("Authorization", "bearer "+s.token.GetValue())
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	rec := httptest.NewRecorder()
	defer provision.RemovePool("pool1")
	m := RunServer(true)
	m.ServeHTTP(rec, req)
	c.Assert(rec.Code, check.Equals, http.StatusCreated)
	c.Assert(err, check.IsNil)
	pools, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(pools, check.HasLen, 1)
	b = bytes.NewBufferString("name=pool2&public=true")
	req, err = http.NewRequest("POST", "/pools", b)
	c.Assert(err, check.IsNil)
	req.Header.Set("Authorization", "bearer "+s.token.GetValue())
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	rec = httptest.NewRecorder()
	defer provision.RemovePool("pool2")
	m.ServeHTTP(rec, req)
	c.Assert(rec.Code, check.Equals, http.StatusCreated)
	pools, err = provision.ListPools(bson.M{"_id": "pool2"})
	c.Assert(err, check.IsNil)
	c.Assert(pools[0].Public, check.Equals, true)
}
開發者ID:pedrosnk,項目名稱:tsuru,代碼行數:28,代碼來源:pool_test.go

示例2: listPoolsToUser

func listPoolsToUser(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	u, err := t.User()
	if err != nil {
		return err
	}
	rec.Log(u.Email, "pool-list")
	teams, err := u.Teams()
	if err != nil {
		return err
	}
	var poolsByTeam []PoolsByTeam
	for _, t := range teams {
		pools, err := provision.ListPools(bson.M{"teams": t.Name})
		if err != nil {
			return err
		}
		pbt := PoolsByTeam{Team: t.Name, Pools: provision.GetPoolsNames(pools)}
		poolsByTeam = append(poolsByTeam, pbt)
	}
	publicPools, err := provision.ListPools(bson.M{"public": true})
	if err != nil {
		return err
	}
	p := map[string]interface{}{
		"pools_by_team": poolsByTeam,
		"public_pools":  publicPools,
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(p)
}
開發者ID:mderaldo,項目名稱:tsuru,代碼行數:30,代碼來源:pool.go

示例3: listPoolsToUser

func listPoolsToUser(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	u, err := t.User()
	if err != nil {
		return err
	}
	rec.Log(u.Email, "pool-list")
	teams := []string{}
	contexts := permission.ContextsForPermission(t, permission.PermAppCreate)
	for _, c := range contexts {
		if c.CtxType == permission.CtxGlobal {
			teams = nil
			break
		}
		if c.CtxType != permission.CtxTeam {
			continue
		}
		teams = append(teams, c.Value)
	}
	var filter bson.M
	if teams != nil {
		filter = bson.M{"teams": bson.M{"$in": teams}}
	}
	pools, err := provision.ListPools(filter)
	if err != nil {
		return err
	}
	poolsByTeam := []PoolsByTeam{}
	poolsByTeamMap := map[string]*PoolsByTeam{}
	for _, p := range pools {
		for _, t := range p.Teams {
			if poolsByTeamMap[t] == nil {
				poolsByTeam = append(poolsByTeam, PoolsByTeam{Team: t})
				poolsByTeamMap[t] = &poolsByTeam[len(poolsByTeam)-1]
			}
			poolsByTeamMap[t].Pools = append(poolsByTeamMap[t].Pools, p.Name)
		}
	}
	publicPools, err := provision.ListPools(bson.M{"public": true})
	if err != nil {
		return err
	}
	allowedDefault := permission.Check(t, permission.PermPoolUpdate)
	defaultPool := []provision.Pool{}
	if allowedDefault {
		defaultPool, err = provision.ListPools(bson.M{"default": true})
		if err != nil {
			return err
		}
	}
	p := map[string]interface{}{
		"pools_by_team": poolsByTeam,
		"public_pools":  publicPools,
		"default_pool":  defaultPool,
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(p)
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:57,代碼來源:pool.go

示例4: TestPoolListHandler

func (s *S) TestPoolListHandler(c *check.C) {
	team := auth.Team{Name: "angra"}
	err := s.conn.Teams().Insert(team)
	c.Assert(err, check.IsNil)
	token := userWithPermission(c, permission.Permission{
		Scheme:  permission.PermAppCreate,
		Context: permission.Context(permission.CtxTeam, "angra"),
	})
	pool := provision.Pool{Name: "pool1", Teams: []string{"angra"}}
	opts := provision.AddPoolOptions{Name: pool.Name}
	err = provision.AddPool(opts)
	c.Assert(err, check.IsNil)
	err = provision.AddTeamsToPool(pool.Name, pool.Teams)
	c.Assert(err, check.IsNil)
	defer provision.RemovePool(pool.Name)
	opts = provision.AddPoolOptions{Name: "nopool"}
	err = provision.AddPool(opts)
	c.Assert(err, check.IsNil)
	defer provision.RemovePool("nopool")
	defaultPools, err := provision.ListPools(bson.M{"default": true})
	c.Assert(err, check.IsNil)
	expected := []provision.Pool{
		defaultPools[0],
		{Name: "pool1", Teams: []string{"angra"}},
	}
	req, err := http.NewRequest("GET", "/pools", nil)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = poolList(rec, req, token)
	c.Assert(err, check.IsNil)
	var pools []provision.Pool
	err = json.NewDecoder(rec.Body).Decode(&pools)
	c.Assert(err, check.IsNil)
	c.Assert(pools, check.DeepEquals, expected)
}
開發者ID:pedrosnk,項目名稱:tsuru,代碼行數:35,代碼來源:pool_test.go

示例5: listPoolHandler

func listPoolHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	pools, err := provision.ListPools(nil)
	if err != nil {
		return err
	}
	return json.NewEncoder(w).Encode(pools)
}
開發者ID:mderaldo,項目名稱:tsuru,代碼行數:7,代碼來源:pool.go

示例6: GetPoolForApp

func (app *App) GetPoolForApp(poolName string) (string, error) {
	var query bson.M
	var poolTeam bool
	if poolName != "" {
		query = bson.M{"_id": poolName}
	} else {
		query = bson.M{"teams": app.TeamOwner}
	}
	pools, err := provision.ListPools(query)
	if err != nil {
		return "", err
	}
	if len(pools) > 1 {
		return "", stderr.New("you have access to more than one pool, please choose one in app creation")
	}
	if len(pools) == 0 {
		if poolName == "" {
			return "", nil
		}
		return "", stderr.New("pool not found")
	}
	for _, team := range pools[0].Teams {
		if team == app.TeamOwner {
			poolTeam = true
			break
		}
	}
	if !pools[0].Public && !poolTeam {
		return "", stderr.New(fmt.Sprintf("You don't have access to pool %s", poolName))
	}
	return pools[0].Name, nil
}
開發者ID:Zapelini,項目名稱:tsuru,代碼行數:32,代碼來源:app.go

示例7: TestPoolListPublicPool

func (s *S) TestPoolListPublicPool(c *check.C) {
	pool := provision.Pool{Name: "pool1", Public: true}
	opts := provision.AddPoolOptions{Name: pool.Name, Public: pool.Public}
	err := provision.AddPool(opts)
	c.Assert(err, check.IsNil)
	defer provision.RemovePool(pool.Name)
	defaultPools, err := provision.ListPools(bson.M{"default": true})
	c.Assert(err, check.IsNil)
	expected := []provision.Pool{
		defaultPools[0],
		{Name: "pool1", Public: true, Teams: []string{}},
	}
	token := userWithPermission(c, permission.Permission{
		Scheme:  permission.PermTeamCreate,
		Context: permission.Context(permission.CtxGlobal, ""),
	})
	req, err := http.NewRequest("GET", "/pools", nil)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = poolList(rec, req, token)
	c.Assert(err, check.IsNil)
	var pools []provision.Pool
	err = json.NewDecoder(rec.Body).Decode(&pools)
	c.Assert(err, check.IsNil)
	c.Assert(pools, check.DeepEquals, expected)
}
開發者ID:pedrosnk,項目名稱:tsuru,代碼行數:26,代碼來源:pool_test.go

示例8: GetDefaultPool

func (app *App) GetDefaultPool() (string, error) {
	pools, err := provision.ListPools(bson.M{"default": true})
	if err != nil {
		return "", err
	}
	if len(pools) == 0 {
		return "", stderr.New("No default pool.")
	}
	return pools[0].Name, nil
}
開發者ID:Zapelini,項目名稱:tsuru,代碼行數:10,代碼來源:app.go

示例9: GetFallbackPool

func (app *App) GetFallbackPool() (string, error) {
	query := bson.M{"$or": []bson.M{{"teams": bson.M{"$exists": false}}, {"teams": bson.M{"$size": 0}}}}
	pools, err := provision.ListPools(query)
	if err != nil {
		return "", err
	}
	if len(pools) == 0 {
		return "", stderr.New("No fallback pool.")
	}
	return pools[0].Name, nil
}
開發者ID:RichardKnop,項目名稱:tsuru,代碼行數:11,代碼來源:app.go

示例10: TestAddPoolHandler

func (s *S) TestAddPoolHandler(c *check.C) {
	b := bytes.NewBufferString(`{"name": "pool1"}`)
	req, err := http.NewRequest("POST", "/pool", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	defer provision.RemovePool("pool1")
	err = addPoolHandler(rec, req, nil)
	c.Assert(err, check.IsNil)
	pools, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(len(pools), check.Equals, 1)
}
開發者ID:rzs840707,項目名稱:tsuru,代碼行數:12,代碼來源:pool_test.go

示例11: Nodes

func (p *dockerProvisioner) Nodes(app provision.App) ([]cluster.Node, error) {
	pool := app.GetPool()
	var (
		pools []provision.Pool
		err   error
	)
	if pool == "" {
		pools, err = provision.ListPools(bson.M{"$or": []bson.M{{"teams": app.GetTeamOwner()}, {"teams": bson.M{"$in": app.GetTeamsName()}}}})
	} else {
		pools, err = provision.ListPools(bson.M{"_id": pool})
	}
	if err != nil {
		return nil, err
	}
	if len(pools) == 0 {
		query := bson.M{"default": true}
		pools, err = provision.ListPools(query)
		if err != nil {
			return nil, err
		}
	}
	if len(pools) == 0 {
		return nil, errNoDefaultPool
	}
	for _, pool := range pools {
		nodes, err := p.Cluster().NodesForMetadata(map[string]string{"pool": pool.Name})
		if err != nil {
			return nil, errNoDefaultPool
		}
		if len(nodes) > 0 {
			return nodes, nil
		}
	}
	var nameList []string
	for _, pool := range pools {
		nameList = append(nameList, pool.Name)
	}
	poolsStr := strings.Join(nameList, ", pool=")
	return nil, fmt.Errorf("No nodes found with one of the following metadata: pool=%s", poolsStr)
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:40,代碼來源:provisioner.go

示例12: TestAddPoolHandler

func (s *S) TestAddPoolHandler(c *check.C) {
	b := bytes.NewBufferString(`{"name": "pool1"}`)
	req, err := http.NewRequest("POST", "/pool", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	defer provision.RemovePool("pool1")
	err = addPoolHandler(rec, req, s.token)
	c.Assert(err, check.IsNil)
	pools, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(pools, check.HasLen, 1)
	b = bytes.NewBufferString(`{"name": "pool2", "public": true}`)
	req, err = http.NewRequest("POST", "/pool", b)
	c.Assert(err, check.IsNil)
	rec = httptest.NewRecorder()
	defer provision.RemovePool("pool2")
	err = addPoolHandler(rec, req, s.token)
	c.Assert(err, check.IsNil)
	pools, err = provision.ListPools(bson.M{"_id": "pool2"})
	c.Assert(err, check.IsNil)
	c.Assert(pools[0].Public, check.Equals, true)
}
開發者ID:ggarnier,項目名稱:tsuru,代碼行數:22,代碼來源:pool_test.go

示例13: TestRemovePoolHandler

func (s *S) TestRemovePoolHandler(c *check.C) {
	err := provision.AddPool("pool1", false)
	c.Assert(err, check.IsNil)
	b := bytes.NewBufferString(`{"pool": "pool1"}`)
	req, err := http.NewRequest("DELETE", "/pool", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = removePoolHandler(rec, req, nil)
	c.Assert(err, check.IsNil)
	p, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(len(p), check.Equals, 0)
}
開發者ID:keymon,項目名稱:tsuru,代碼行數:13,代碼來源:pool_test.go

示例14: TestPoolUpdateToPublicHandler

func (s *S) TestPoolUpdateToPublicHandler(c *check.C) {
	opts := provision.AddPoolOptions{Name: "pool1"}
	err := provision.AddPool(opts)
	c.Assert(err, check.IsNil)
	defer provision.RemovePool("pool1")
	b := bytes.NewBufferString(`{"public": true}`)
	req, err := http.NewRequest("POST", "/pool/pool1?:name=pool1", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = poolUpdateHandler(rec, req, nil)
	c.Assert(err, check.IsNil)
	p, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(p[0].Public, check.Equals, true)
}
開發者ID:rzs840707,項目名稱:tsuru,代碼行數:15,代碼來源:pool_test.go

示例15: TestAddTeamsToPoolHandler

func (s *S) TestAddTeamsToPoolHandler(c *check.C) {
	pool := provision.Pool{Name: "pool1"}
	err := provision.AddPool(pool.Name, false)
	c.Assert(err, check.IsNil)
	defer provision.RemovePool(pool.Name)
	b := bytes.NewBufferString(`{"pool": "pool1", "teams": ["test"]}`)
	req, err := http.NewRequest("POST", "/pool/team", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = addTeamToPoolHandler(rec, req, nil)
	c.Assert(err, check.IsNil)
	p, err := provision.ListPools(bson.M{"_id": "pool1"})
	c.Assert(err, check.IsNil)
	c.Assert(p[0].Teams, check.DeepEquals, []string{"test"})
}
開發者ID:keymon,項目名稱:tsuru,代碼行數:15,代碼來源:pool_test.go


注:本文中的github.com/tsuru/tsuru/provision.ListPools函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。