本文整理汇总了Golang中github.com/tsuru/tsuru/iaas.Machine.Destroy方法的典型用法代码示例。如果您正苦于以下问题:Golang Machine.Destroy方法的具体用法?Golang Machine.Destroy怎么用?Golang Machine.Destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/iaas.Machine
的用法示例。
在下文中一共展示了Machine.Destroy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: removeNodeHandler
// removeNodeHandler calls scheduler.Unregister to unregistering a node into it.
func removeNodeHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
params, err := unmarshal(r.Body)
if err != nil {
return err
}
address, _ := params["address"]
if address == "" {
return fmt.Errorf("Node address is required.")
}
node, err := mainDockerProvisioner.Cluster().GetNode(address)
if err != nil {
return err
}
allowedNodeRemove := permission.Check(t, permission.PermNodeDelete,
permission.Context(permission.CtxPool, node.Metadata["pool"]),
)
if !allowedNodeRemove {
return permission.ErrUnauthorized
}
removeIaaS, _ := strconv.ParseBool(params["remove_iaas"])
if removeIaaS {
allowedIaasRemove := permission.Check(t, permission.PermMachineDelete,
permission.Context(permission.CtxIaaS, node.Metadata["iaas"]),
)
if !allowedIaasRemove {
return permission.ErrUnauthorized
}
}
node.CreationStatus = cluster.NodeCreationStatusDisabled
_, err = mainDockerProvisioner.Cluster().UpdateNode(node)
if err != nil {
return err
}
noRebalance, err := strconv.ParseBool(r.URL.Query().Get("no-rebalance"))
if !noRebalance {
err = mainDockerProvisioner.rebalanceContainersByHost(urlToHost(address), w)
if err != nil {
return err
}
}
err = mainDockerProvisioner.Cluster().Unregister(address)
if err != nil {
return err
}
if removeIaaS {
var m iaas.Machine
m, err = iaas.FindMachineByIdOrAddress(node.Metadata["iaas-id"], urlToHost(address))
if err != nil && err != mgo.ErrNotFound {
return err
}
return m.Destroy()
}
return nil
}
示例2: removeNodeHandler
// removeNodeHandler calls scheduler.Unregister to unregistering a node into it.
func removeNodeHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
params, err := unmarshal(r.Body)
if err != nil {
return err
}
address, _ := params["address"]
if address == "" {
return fmt.Errorf("Node address is required.")
}
nodes, err := mainDockerProvisioner.Cluster().UnfilteredNodes()
if err != nil {
return err
}
var node *cluster.Node
for i := range nodes {
if nodes[i].Address == address {
node = &nodes[i]
break
}
}
if node == nil {
return fmt.Errorf("node with address %q not found in cluster", address)
}
err = mainDockerProvisioner.Cluster().Unregister(address)
if err != nil {
return err
}
removeIaaS, _ := strconv.ParseBool(params["remove_iaas"])
if removeIaaS {
var m iaas.Machine
m, err = iaas.FindMachineByIdOrAddress(node.Metadata["iaas-id"], urlToHost(address))
if err != nil && err != mgo.ErrNotFound {
return err
}
return m.Destroy()
}
noRebalance, err := strconv.ParseBool(r.URL.Query().Get("no-rebalance"))
if !noRebalance {
return mainDockerProvisioner.rebalanceContainersByHost(urlToHost(address), w)
}
return nil
}
示例3: removeNodeHandler
// title: remove node
// path: /{provisioner}/node/{address}
// method: DELETE
// responses:
// 200: Ok
// 401: Unauthorized
// 404: Not found
func removeNodeHandler(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
r.ParseForm()
address := r.URL.Query().Get(":address")
if address == "" {
return errors.Errorf("Node address is required.")
}
prov, node, err := provision.FindNode(address)
if err != nil {
if err == provision.ErrNodeNotFound {
return &tsuruErrors.HTTP{
Code: http.StatusNotFound,
Message: err.Error(),
}
}
return err
}
nodeProv := prov.(provision.NodeProvisioner)
pool := node.Pool()
allowedNodeRemove := permission.Check(t, permission.PermNodeDelete,
permission.Context(permission.CtxPool, pool),
)
if !allowedNodeRemove {
return permission.ErrUnauthorized
}
removeIaaS, _ := strconv.ParseBool(r.URL.Query().Get("remove-iaas"))
if removeIaaS {
allowedIaasRemove := permission.Check(t, permission.PermMachineDelete,
permission.Context(permission.CtxIaaS, node.Metadata()["iaas"]),
)
if !allowedIaasRemove {
return permission.ErrUnauthorized
}
}
evt, err := event.New(&event.Opts{
Target: event.Target{Type: event.TargetTypeNode, Value: node.Address()},
Kind: permission.PermNodeDelete,
Owner: t,
CustomData: event.FormToCustomData(r.Form),
Allowed: event.Allowed(permission.PermPoolReadEvents, permission.Context(permission.CtxPool, pool)),
})
if err != nil {
return err
}
defer func() { evt.Done(err) }()
noRebalance, _ := strconv.ParseBool(r.URL.Query().Get("no-rebalance"))
err = nodeProv.RemoveNode(provision.RemoveNodeOptions{
Address: address,
Rebalance: !noRebalance,
Writer: w,
})
if err != nil {
return err
}
if removeIaaS {
var m iaas.Machine
m, err = iaas.FindMachineByIdOrAddress(node.Metadata()["iaas-id"], net.URLToHost(address))
if err != nil && err != mgo.ErrNotFound {
return nil
}
return m.Destroy()
}
return nil
}