本文整理汇总了Golang中github.com/tsuru/tsuru/provision.App.GetCpuShare方法的典型用法代码示例。如果您正苦于以下问题:Golang App.GetCpuShare方法的具体用法?Golang App.GetCpuShare怎么用?Golang App.GetCpuShare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/provision.App
的用法示例。
在下文中一共展示了App.GetCpuShare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hostConfig
func (c *Container) hostConfig(app provision.App, isDeploy bool) (*docker.HostConfig, error) {
sharedBasedir, _ := config.GetString("docker:sharedfs:hostdir")
sharedMount, _ := config.GetString("docker:sharedfs:mountpoint")
sharedIsolation, _ := config.GetBool("docker:sharedfs:app-isolation")
sharedSalt, _ := config.GetString("docker:sharedfs:salt")
hostConfig := docker.HostConfig{
CPUShares: int64(app.GetCpuShare()),
}
if !isDeploy {
hostConfig.Memory = app.GetMemory()
hostConfig.MemorySwap = app.GetMemory() + app.GetSwap()
hostConfig.RestartPolicy = docker.AlwaysRestart()
hostConfig.PortBindings = map[docker.Port][]docker.PortBinding{
docker.Port(c.ExposedPort): {{HostIP: "", HostPort: ""}},
}
pool := app.GetPool()
driver, opts, logErr := LogOpts(pool)
if logErr != nil {
return nil, logErr
}
hostConfig.LogConfig = docker.LogConfig{
Type: driver,
Config: opts,
}
} else {
hostConfig.OomScoreAdj = 1000
}
hostConfig.SecurityOpt, _ = config.GetList("docker:security-opts")
if sharedBasedir != "" && sharedMount != "" {
if sharedIsolation {
var appHostDir string
if sharedSalt != "" {
h := crypto.SHA1.New()
io.WriteString(h, sharedSalt+c.AppName)
appHostDir = fmt.Sprintf("%x", h.Sum(nil))
} else {
appHostDir = c.AppName
}
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s/%s:%s:rw", sharedBasedir, appHostDir, sharedMount))
} else {
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:%s:rw", sharedBasedir, sharedMount))
}
}
return &hostConfig, nil
}
示例2: start
func (c *container) start(p *dockerProvisioner, app provision.App, isDeploy bool) error {
port, err := getPort()
if err != nil {
return err
}
sharedBasedir, _ := config.GetString("docker:sharedfs:hostdir")
sharedMount, _ := config.GetString("docker:sharedfs:mountpoint")
sharedIsolation, _ := config.GetBool("docker:sharedfs:app-isolation")
sharedSalt, _ := config.GetString("docker:sharedfs:salt")
hostConfig := docker.HostConfig{
Memory: app.GetMemory(),
MemorySwap: app.GetMemory() + app.GetSwap(),
CPUShares: int64(app.GetCpuShare()),
}
if !isDeploy {
hostConfig.RestartPolicy = docker.AlwaysRestart()
hostConfig.PortBindings = map[docker.Port][]docker.PortBinding{
docker.Port(port + "/tcp"): {{HostIP: "", HostPort: ""}},
}
hostConfig.LogConfig = docker.LogConfig{
Type: "syslog",
Config: map[string]string{
"syslog-address": fmt.Sprintf("udp://localhost:%d", getBsSysLogPort()),
},
}
}
hostConfig.SecurityOpt, _ = config.GetList("docker:security-opts")
if sharedBasedir != "" && sharedMount != "" {
if sharedIsolation {
var appHostDir string
if sharedSalt != "" {
h := crypto.SHA1.New()
io.WriteString(h, sharedSalt+c.AppName)
appHostDir = fmt.Sprintf("%x", h.Sum(nil))
} else {
appHostDir = c.AppName
}
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s/%s:%s:rw", sharedBasedir, appHostDir, sharedMount))
} else {
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:%s:rw", sharedBasedir, sharedMount))
}
}
err = p.getCluster().StartContainer(c.ID, &hostConfig)
if err != nil {
return err
}
initialStatus := provision.StatusStarting.String()
if isDeploy {
initialStatus = provision.StatusBuilding.String()
}
return c.setStatus(p, initialStatus, false)
}