• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang iaas.FindMachineById函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/tsuru/tsuru/iaas.FindMachineById函数的典型用法代码示例。如果您正苦于以下问题:Golang FindMachineById函数的具体用法?Golang FindMachineById怎么用?Golang FindMachineById使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了FindMachineById函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: machineDestroy

// title: machine destroy
// path: /iaas/machines/{machine_id}
// method: DELETE
// responses:
//   200: OK
//   400: Invalid data
//   401: Unauthorized
//   404: Not found
func machineDestroy(w http.ResponseWriter, r *http.Request, token auth.Token) (err error) {
	r.ParseForm()
	machineID := r.URL.Query().Get(":machine_id")
	if machineID == "" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "machine id is required"}
	}
	m, err := iaas.FindMachineById(machineID)
	if err != nil {
		if err == mgo.ErrNotFound {
			return &errors.HTTP{Code: http.StatusNotFound, Message: "machine not found"}
		}
		return err
	}
	iaasCtx := permission.Context(permission.CtxIaaS, m.Iaas)
	allowed := permission.Check(token, permission.PermMachineDelete, iaasCtx)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeIaas, Value: m.Iaas},
		Kind:       permission.PermMachineDelete,
		Owner:      token,
		CustomData: event.FormToCustomData(r.Form),
		Allowed:    event.Allowed(permission.PermMachineReadEvents, iaasCtx),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	return m.Destroy()
}
开发者ID:tsuru,项目名称:tsuru,代码行数:39,代码来源:iaas.go


示例2: destroyMachine

func (runBs) destroyMachine(id string) {
	if id != "" {
		machine, err := iaas.FindMachineById(id)
		if err != nil {
			log.Errorf("failed to remove machine %q: %s", id, err)
			return
		}
		err = machine.Destroy()
		if err != nil {
			log.Errorf("failed to remove machine %q: %s", id, err)
			return
		}
	}
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:14,代码来源:queue_task.go


示例3: machineDestroy

func machineDestroy(w http.ResponseWriter, r *http.Request, token auth.Token) error {
	machineId := r.URL.Query().Get(":machine_id")
	if machineId == "" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "machine id is required"}
	}
	m, err := iaas.FindMachineById(machineId)
	if err != nil {
		if err == mgo.ErrNotFound {
			return &errors.HTTP{Code: http.StatusNotFound, Message: "machine not found"}
		}
		return err
	}
	return m.Destroy()
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:14,代码来源:iaas.go


示例4: TestRemoveNodeHandlerRemoveIaaS

func (s *HandlersSuite) TestRemoveNodeHandlerRemoveIaaS(c *check.C) {
	iaas.RegisterIaasProvider("my-xxx-iaas", newTestIaaS)
	machine, err := iaas.CreateMachineForIaaS("my-xxx-iaas", map[string]string{})
	c.Assert(err, check.IsNil)
	mainDockerProvisioner.cluster, err = cluster.New(nil, &cluster.MapStorage{})
	c.Assert(err, check.IsNil)
	_, err = mainDockerProvisioner.getCluster().Register(fmt.Sprintf("http://%s:2375", machine.Address), nil)
	c.Assert(err, check.IsNil)
	b := bytes.NewBufferString(fmt.Sprintf(`{"address": "http://%s:2375", "remove_iaas": "true"}`, machine.Address))
	req, err := http.NewRequest("POST", "/node/remove", b)
	c.Assert(err, check.IsNil)
	rec := httptest.NewRecorder()
	err = removeNodeHandler(rec, req, nil)
	c.Assert(err, check.IsNil)
	nodes, err := mainDockerProvisioner.getCluster().Nodes()
	c.Assert(len(nodes), check.Equals, 0)
	_, err = iaas.FindMachineById(machine.Id)
	c.Assert(err, check.Equals, mgo.ErrNotFound)
}
开发者ID:mderaldo,项目名称:tsuru,代码行数:19,代码来源:handlers_test.go


示例5: machineDestroy

func machineDestroy(w http.ResponseWriter, r *http.Request, token auth.Token) error {
	machineId := r.URL.Query().Get(":machine_id")
	if machineId == "" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "machine id is required"}
	}
	m, err := iaas.FindMachineById(machineId)
	if err != nil {
		if err == mgo.ErrNotFound {
			return &errors.HTTP{Code: http.StatusNotFound, Message: "machine not found"}
		}
		return err
	}
	allowed := permission.Check(token, permission.PermMachineDelete,
		permission.Context(permission.CtxIaaS, m.Iaas),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	return m.Destroy()
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:20,代码来源:iaas.go


示例6: TestRemoveNodeHandlerWithoutRemoveIaaS

func (s *HandlersSuite) TestRemoveNodeHandlerWithoutRemoveIaaS(c *gocheck.C) {
	iaas.RegisterIaasProvider("some-iaas", TestIaaS{})
	machine, err := iaas.CreateMachineForIaaS("some-iaas", map[string]string{})
	c.Assert(err, gocheck.IsNil)
	dCluster, err = cluster.New(nil, &cluster.MapStorage{})
	c.Assert(err, gocheck.IsNil)
	err = dCluster.Register(fmt.Sprintf("http://%s:4243", machine.Address), nil)
	c.Assert(err, gocheck.IsNil)
	b := bytes.NewBufferString(fmt.Sprintf(`{"address": "http://%s:4243", "remove_iaas": "false"}`, machine.Address))
	req, err := http.NewRequest("POST", "/node/remove", b)
	c.Assert(err, gocheck.IsNil)
	rec := httptest.NewRecorder()
	err = removeNodeHandler(rec, req, nil)
	c.Assert(err, gocheck.IsNil)
	nodes, err := dCluster.Nodes()
	c.Assert(len(nodes), gocheck.Equals, 0)
	dbM, err := iaas.FindMachineById(machine.Id)
	c.Assert(err, gocheck.IsNil)
	c.Assert(dbM.Id, gocheck.Equals, machine.Id)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:20,代码来源:handlers_test.go


示例7: TestRemoveNodeHandlerWithRemoveIaaS

func (s *S) TestRemoveNodeHandlerWithRemoveIaaS(c *check.C) {
	iaas.RegisterIaasProvider("some-iaas", newTestIaaS)
	machine, err := iaas.CreateMachineForIaaS("some-iaas", map[string]string{"id": "m1"})
	c.Assert(err, check.IsNil)
	err = s.provisioner.AddNode(provision.AddNodeOptions{
		Address: fmt.Sprintf("http://%s:2375", machine.Address),
	})
	c.Assert(err, check.IsNil)
	u := fmt.Sprintf("/node/http://%s:2375?remove-iaas=true", machine.Address)
	req, err := http.NewRequest("DELETE", u, nil)
	c.Assert(err, check.IsNil)
	req.Header.Set("Authorization", "bearer "+s.token.GetValue())
	rec := httptest.NewRecorder()
	server := RunServer(true)
	server.ServeHTTP(rec, req)
	c.Assert(rec.Body.String(), check.Equals, "rebalancing...remove done!")
	c.Assert(rec.Code, check.Equals, http.StatusOK)
	nodes, err := s.provisioner.ListNodes(nil)
	c.Assert(err, check.IsNil)
	c.Assert(nodes, check.HasLen, 0)
	_, err = iaas.FindMachineById(machine.Id)
	c.Assert(err, check.Equals, mgo.ErrNotFound)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:23,代码来源:node_test.go



注:本文中的github.com/tsuru/tsuru/iaas.FindMachineById函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang iaas.FindMachineByIdOrAddress函数代码示例发布时间:2022-05-28
下一篇:
Golang iaas.CreateMachineForIaaS函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap