本文整理汇总了Golang中github.com/tsuru/tsuru/provision.ListPools函数的典型用法代码示例。如果您正苦于以下问题:Golang ListPools函数的具体用法?Golang ListPools怎么用?Golang ListPools使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListPools函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestRemovePoolHandler
func (s *S) TestRemovePoolHandler(c *check.C) {
opts := provision.AddPoolOptions{
Name: "pool1",
}
err := provision.AddPool(opts)
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, s.token)
c.Assert(err, check.IsNil)
p, err := provision.ListPools(bson.M{"_id": "pool1"})
c.Assert(err, check.IsNil)
c.Assert(p, check.HasLen, 0)
}
开发者ID:ggarnier,项目名称:tsuru,代码行数:16,代码来源:pool_test.go
示例17: TestRemovePoolHandler
func (s *S) TestRemovePoolHandler(c *check.C) {
opts := provision.AddPoolOptions{
Name: "pool1",
}
err := provision.AddPool(opts)
c.Assert(err, check.IsNil)
req, err := http.NewRequest("DELETE", "/pools/pool1", nil)
c.Assert(err, check.IsNil)
req.Header.Set("Authorization", "bearer "+s.token.GetValue())
rec := httptest.NewRecorder()
m := RunServer(true)
m.ServeHTTP(rec, req)
c.Assert(rec.Code, check.Equals, http.StatusOK)
p, err := provision.ListPools(bson.M{"_id": "pool1"})
c.Assert(err, check.IsNil)
c.Assert(p, check.HasLen, 0)
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:17,代码来源:pool_test.go
示例18: TestRemoveTeamsToPoolHandler
func (s *S) TestRemoveTeamsToPoolHandler(c *check.C) {
pool := provision.Pool{Name: "pool1", Teams: []string{"test"}}
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)
b := bytes.NewBufferString(`{"pool": "pool1", "teams": ["test"]}`)
req, err := http.NewRequest("DELETE", "/pool/pool1/team?:name=pool1", b)
c.Assert(err, check.IsNil)
rec := httptest.NewRecorder()
err = removeTeamToPoolHandler(rec, req, nil)
c.Assert(err, check.IsNil)
p, err := provision.ListPools(nil)
c.Assert(err, check.IsNil)
c.Assert(p[0].Teams, check.DeepEquals, []string{})
}
开发者ID:rzs840707,项目名称:tsuru,代码行数:18,代码来源:pool_test.go
示例19: 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("PUT", "/pools/pool1", b)
c.Assert(err, check.IsNil)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Authorization", "bearer "+s.token.GetValue())
rec := httptest.NewRecorder()
m := RunServer(true)
m.ServeHTTP(rec, req)
c.Assert(rec.Code, check.Equals, http.StatusOK)
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:pedrosnk,项目名称:tsuru,代码行数:19,代码来源:pool_test.go
示例20: TestAddTeamsToPool
func (s *S) TestAddTeamsToPool(c *check.C) {
pool := provision.Pool{Name: "pool1"}
opts := provision.AddPoolOptions{Name: pool.Name}
err := provision.AddPool(opts)
c.Assert(err, check.IsNil)
defer provision.RemovePool(pool.Name)
b := strings.NewReader("team=test")
req, err := http.NewRequest("POST", "/pools/pool1/team", 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()
m := RunServer(true)
m.ServeHTTP(rec, req)
c.Assert(rec.Code, check.Equals, http.StatusOK)
p, err := provision.ListPools(bson.M{"_id": "pool1"})
c.Assert(err, check.IsNil)
c.Assert(p[0].Teams, check.DeepEquals, []string{"test"})
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:19,代码来源:pool_test.go
注:本文中的github.com/tsuru/tsuru/provision.ListPools函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论