本文整理汇总了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()
}
示例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
}
}
}
示例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()
}
示例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)
}
示例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()
}
示例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)
}
示例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)
}