本文整理汇总了Golang中github.com/tsuru/tsuru/provision.App.UnbindUnit方法的典型用法代码示例。如果您正苦于以下问题:Golang App.UnbindUnit方法的具体用法?Golang App.UnbindUnit怎么用?Golang App.UnbindUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/provision.App
的用法示例。
在下文中一共展示了App.UnbindUnit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Destroy
func (p *dockerProvisioner) Destroy(app provision.App) error {
containers, err := p.listContainersByApp(app.GetName())
if err != nil {
log.Errorf("Failed to list app containers: %s", err.Error())
return err
}
runInContainers(containers, func(c *container, _ chan *container) error {
unit := c.asUnit(app)
err := app.UnbindUnit(&unit)
if err != nil {
log.Errorf("Unable to unbind unit %q: %s", c.ID, err)
}
err = p.removeContainer(c, app)
if err != nil {
log.Errorf("Unable to destroy container %s: %s", c.ID, err.Error())
}
return nil
}, nil, true)
images, err := listAppImages(app.GetName())
if err != nil {
log.Errorf("Failed to get image ids for app %s: %s", app.GetName(), err.Error())
}
cluster := p.getCluster()
for _, imageId := range images {
err := cluster.RemoveImage(imageId)
if err != nil {
log.Errorf("Failed to remove image %s: %s", imageId, err.Error())
}
err = cluster.RemoveFromRegistry(imageId)
if err != nil {
log.Errorf("Failed to remove image %s from registry: %s", imageId, err.Error())
}
}
err = deleteAllAppImageNames(app.GetName())
if err != nil {
log.Errorf("Failed to remove image names from storage for app %s: %s", app.GetName(), err.Error())
}
r, err := getRouterForApp(app)
if err != nil {
log.Errorf("Failed to get router: %s", err.Error())
return err
}
err = r.RemoveBackend(app.GetName())
if err != nil {
log.Errorf("Failed to remove route backend: %s", err.Error())
return err
}
return nil
}
示例2: RemoveUnits
func (p *dockerProvisioner) RemoveUnits(a provision.App, units uint, processName string, w io.Writer) error {
if a == nil {
return errors.New("remove units: app should not be nil")
}
if units == 0 {
return errors.New("cannot remove zero units")
}
var err error
if w == nil {
w = ioutil.Discard
}
imgId, err := appCurrentImageName(a.GetName())
if err != nil {
return err
}
_, processName, err = processCmdForImage(processName, imgId)
if err != nil {
return err
}
containers, err := p.listContainersByProcess(a.GetName(), processName)
if err != nil {
return err
}
if len(containers) < int(units) {
return fmt.Errorf("cannot remove %d units from process %q, only %d available", units, processName, len(containers))
}
var plural string
if units > 1 {
plural = "s"
}
fmt.Fprintf(w, "\n---- Removing %d unit%s ----\n", units, plural)
coll := p.collection()
defer coll.Close()
toRemove := make([]container, 0, units)
for i := 0; i < int(units); i++ {
var containerID string
var c *container
containerID, err = p.scheduler.GetRemovableContainer(a.GetName(), processName)
if err != nil {
fmt.Println("GetRemovableContainer")
break
}
c, err = p.getContainer(containerID)
if err != nil {
fmt.Println("getContainer")
break
}
err = coll.Remove(bson.M{"id": c.ID})
if err != nil {
fmt.Println("remove")
break
}
toRemove = append(toRemove, *c)
}
if err != nil {
for _, c := range toRemove {
coll.Insert(c)
}
return err
}
runInContainers(toRemove, func(c *container, toRollback chan *container) error {
unit := c.asUnit(a)
err = a.UnbindUnit(&unit)
if err != nil {
log.Errorf("Ignored error trying to unbind unit %q: %s", c.ID, err)
}
err = p.removeContainer(c, a)
if err != nil {
log.Errorf("Ignored error trying to remove unit %q: %s", c.ID, err)
}
fmt.Fprintf(w, " ---> Removed unit %s...\n", c.shortID())
return nil
}, nil, true)
return nil
}