本文整理汇总了Golang中github.com/lxc/lxd/shared.IntInSlice函数的典型用法代码示例。如果您正苦于以下问题:Golang IntInSlice函数的具体用法?Golang IntInSlice怎么用?Golang IntInSlice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IntInSlice函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Init
// Init creates a container from either a fingerprint or an alias; you must
// provide at least one.
func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, ephem bool) (*Response, error) {
var tmpremote *Client
var err error
serverStatus, err := c.ServerStatus()
if err != nil {
return nil, err
}
architectures := serverStatus.Environment.Architectures
source := shared.Jmap{"type": "image"}
if image == "" {
return nil, fmt.Errorf(i18n.G("You must provide an image hash or alias name."))
}
if imgremote != c.Name {
source["type"] = "image"
source["mode"] = "pull"
tmpremote, err = NewClient(&c.Config, imgremote)
if err != nil {
return nil, err
}
fingerprint := tmpremote.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := tmpremote.GetImageInfo(fingerprint)
if err != nil {
return nil, err
}
if len(architectures) != 0 && !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(i18n.G("The image architecture is incompatible with the target server"))
}
// FIXME: InterfaceToBool is there for backward compatibility
if !shared.InterfaceToBool(imageinfo.Public) {
var secret string
resp, err := tmpremote.post("images/"+fingerprint+"/secret", nil, Async)
if err != nil {
return nil, err
}
op, err := resp.MetadataAsOperation()
if err == nil && op.Metadata != nil {
secret, err = op.Metadata.GetString("secret")
if err != nil {
return nil, err
}
} else {
// FIXME: This is a backward compatibility codepath
md := secretMd{}
if err := json.Unmarshal(resp.Metadata, &md); err != nil {
return nil, err
}
secret = md.Secret
}
source["secret"] = secret
}
source["server"] = tmpremote.BaseURL
source["fingerprint"] = fingerprint
} else {
fingerprint := c.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := c.GetImageInfo(fingerprint)
if err != nil {
return nil, fmt.Errorf(i18n.G("can't get info for image '%s': %s"), image, err)
}
if len(architectures) != 0 && !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(i18n.G("The image architecture is incompatible with the target server"))
}
source["fingerprint"] = fingerprint
}
body := shared.Jmap{"source": source}
if name != "" {
body["name"] = name
}
if profiles != nil {
body["profiles"] = *profiles
}
if config != nil {
body["config"] = config
}
//.........这里部分代码省略.........
开发者ID:djibi2,项目名称:lxd,代码行数:101,代码来源:client.go
示例2: Init
// Init creates a container from either a fingerprint or an alias; you must
// provide at least one.
func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, ephem bool) (*Response, error) {
var operation string
var tmpremote *Client
var err error
serverStatus, err := c.ServerStatus()
if err != nil {
return nil, err
}
architectures := serverStatus.Environment.Architectures
source := shared.Jmap{"type": "image"}
if image == "" {
return nil, fmt.Errorf(gettext.Gettext("You must provide an image hash or alias name."))
}
if imgremote != c.name {
source["type"] = "image"
source["mode"] = "pull"
tmpremote, err = NewClient(&c.config, imgremote)
if err != nil {
return nil, err
}
fingerprint := tmpremote.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := tmpremote.GetImageInfo(fingerprint)
if err != nil {
return nil, err
}
if len(architectures) != 0 && !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(gettext.Gettext("The image architecture is incompatible with the target server"))
}
if !shared.InterfaceToBool(imageinfo.Public) {
resp, err := tmpremote.post("images/"+fingerprint+"/secret", nil, Async)
if err != nil {
return nil, err
}
toScan := strings.Replace(resp.Operation, "/", " ", -1)
version := ""
count, err := fmt.Sscanf(toScan, " %s operations %s", &version, &operation)
if err != nil || count != 2 {
return nil, err
}
md := secretMd{}
if err := json.Unmarshal(resp.Metadata, &md); err != nil {
return nil, err
}
source["secret"] = md.Secret
}
source["server"] = tmpremote.BaseURL
source["fingerprint"] = fingerprint
} else {
fingerprint := c.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := c.GetImageInfo(fingerprint)
if err != nil {
return nil, fmt.Errorf(gettext.Gettext("can't get info for image '%s': %s"), image, err)
}
if len(architectures) != 0 && !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(gettext.Gettext("The image architecture is incompatible with the target server"))
}
source["fingerprint"] = fingerprint
}
body := shared.Jmap{"source": source}
if name != "" {
body["name"] = name
}
if profiles != nil {
body["profiles"] = *profiles
}
if config != nil {
body["config"] = config
}
if ephem {
body["ephemeral"] = ephem
}
var resp *Response
//.........这里部分代码省略.........
开发者ID:Malizor,项目名称:lxd,代码行数:101,代码来源:client.go
示例3: Init
// Init creates a container from either a fingerprint or an alias; you must
// provide at least one.
func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, ephem bool) (*Response, error) {
var operation string
var tmpremote *Client
var err error
serverStatus, err := c.ServerStatus()
if err != nil {
return nil, err
}
architectures := serverStatus.Environment.Architectures
source := shared.Jmap{"type": "image"}
if imgremote != "" {
source["type"] = "image"
source["mode"] = "pull"
tmpremote, err = NewClient(&c.config, imgremote)
if err != nil {
return nil, err
}
fingerprint := tmpremote.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := tmpremote.GetImageInfo(fingerprint)
if err != nil {
return nil, err
}
if !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(gettext.Gettext("The image architecture is incompatible with the target server"))
}
if imageinfo.Public == 0 {
resp, err := tmpremote.post("images/"+fingerprint+"/secret", nil, Async)
if err != nil {
return nil, err
}
toScan := strings.Replace(resp.Operation, "/", " ", -1)
version := ""
count, err := fmt.Sscanf(toScan, " %s operations %s", &version, &operation)
if err != nil || count != 2 {
return nil, err
}
md := secretMd{}
if err := json.Unmarshal(resp.Metadata, &md); err != nil {
return nil, err
}
source["secret"] = md.Secret
}
source["server"] = tmpremote.BaseURL
source["fingerprint"] = fingerprint
} else {
fingerprint := c.GetAlias(image)
if fingerprint == "" {
fingerprint = image
}
imageinfo, err := c.GetImageInfo(fingerprint)
if err != nil {
return nil, err
}
if !shared.IntInSlice(imageinfo.Architecture, architectures) {
return nil, fmt.Errorf(gettext.Gettext("The image architecture is incompatible with the target server"))
}
source["fingerprint"] = fingerprint
}
body := shared.Jmap{"source": source}
if name != "" {
body["name"] = name
}
if profiles != nil {
body["profiles"] = *profiles
}
if ephem {
body["ephemeral"] = ephem
}
resp, err := c.post("containers", body, Async)
if operation != "" {
_, _ = tmpremote.delete("operations/"+operation, nil, Sync)
}
if err != nil {
if LXDErrors[http.StatusNotFound] == err {
return nil, fmt.Errorf("image doesn't exist")
//.........这里部分代码省略.........
开发者ID:timwukp,项目名称:lxd,代码行数:101,代码来源:client.go
示例4: deviceTaskBalance
//.........这里部分代码省略.........
continue
}
count, err := strconv.Atoi(cpu)
if err == nil {
// Load-balance
count = min(count, len(cpus))
balancedContainers[c] = count
} else {
// Pinned
chunks := strings.Split(cpu, ",")
for _, chunk := range chunks {
if strings.Contains(chunk, "-") {
// Range
fields := strings.SplitN(chunk, "-", 2)
if len(fields) != 2 {
shared.Log.Error("Invalid limits.cpu value.", log.Ctx{"container": c.Name(), "value": cpu})
continue
}
low, err := strconv.Atoi(fields[0])
if err != nil {
shared.Log.Error("Invalid limits.cpu value.", log.Ctx{"container": c.Name(), "value": cpu})
continue
}
high, err := strconv.Atoi(fields[1])
if err != nil {
shared.Log.Error("Invalid limits.cpu value.", log.Ctx{"container": c.Name(), "value": cpu})
continue
}
for i := low; i <= high; i++ {
if !shared.IntInSlice(i, cpus) {
continue
}
_, ok := fixedContainers[i]
if ok {
fixedContainers[i] = append(fixedContainers[i], c)
} else {
fixedContainers[i] = []container{c}
}
}
} else {
// Simple entry
nr, err := strconv.Atoi(chunk)
if err != nil {
shared.Log.Error("Invalid limits.cpu value.", log.Ctx{"container": c.Name(), "value": cpu})
continue
}
if !shared.IntInSlice(nr, cpus) {
continue
}
_, ok := fixedContainers[nr]
if ok {
fixedContainers[nr] = append(fixedContainers[nr], c)
} else {
fixedContainers[nr] = []container{c}
}
}
}
}
}
开发者ID:imoapps,项目名称:lxd,代码行数:67,代码来源:devices.go
示例5: deviceTaskBalance
func deviceTaskBalance(d *Daemon) {
min := func(x, y int) int {
if x < y {
return x
}
return y
}
// Don't bother running when CGroup support isn't there
if !cgCpusetController {
return
}
// Get effective cpus list - those are all guaranteed to be online
effectiveCpus, err := cGroupGet("cpuset", "/", "cpuset.effective_cpus")
if err != nil {
// Older kernel - use cpuset.cpus
effectiveCpus, err = cGroupGet("cpuset", "/", "cpuset.cpus")
if err != nil {
shared.LogErrorf("Error reading host's cpuset.cpus")
return
}
}
err = cGroupSet("cpuset", "/lxc", "cpuset.cpus", effectiveCpus)
if err != nil && shared.PathExists("/sys/fs/cgroup/cpuset/lxc") {
shared.LogWarn("Error setting lxd's cpuset.cpus", log.Ctx{"err": err})
}
cpus, err := parseCpuset(effectiveCpus)
if err != nil {
shared.LogError("Error parsing host's cpu set", log.Ctx{"cpuset": effectiveCpus, "err": err})
return
}
// Iterate through the containers
containers, err := dbContainersList(d.db, cTypeRegular)
if err != nil {
shared.LogError("problem loading containers list", log.Ctx{"err": err})
return
}
fixedContainers := map[int][]container{}
balancedContainers := map[container]int{}
for _, name := range containers {
c, err := containerLoadByName(d, name)
if err != nil {
continue
}
conf := c.ExpandedConfig()
cpulimit, ok := conf["limits.cpu"]
if !ok || cpulimit == "" {
cpulimit = effectiveCpus
}
if !c.IsRunning() {
continue
}
count, err := strconv.Atoi(cpulimit)
if err == nil {
// Load-balance
count = min(count, len(cpus))
balancedContainers[c] = count
} else {
// Pinned
containerCpus, err := parseCpuset(cpulimit)
if err != nil {
return
}
for _, nr := range containerCpus {
if !shared.IntInSlice(nr, cpus) {
continue
}
_, ok := fixedContainers[nr]
if ok {
fixedContainers[nr] = append(fixedContainers[nr], c)
} else {
fixedContainers[nr] = []container{c}
}
}
}
}
// Balance things
pinning := map[container][]string{}
usage := map[int]deviceTaskCPU{}
for _, id := range cpus {
cpu := deviceTaskCPU{}
cpu.id = id
cpu.strId = fmt.Sprintf("%d", id)
count := 0
cpu.count = &count
usage[id] = cpu
}
for cpu, ctns := range fixedContainers {
c, ok := usage[cpu]
if !ok {
//.........这里部分代码省略.........
开发者ID:vahe,项目名称:lxd,代码行数:101,代码来源:devices.go
注:本文中的github.com/lxc/lxd/shared.IntInSlice函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论