本文整理匯總了Golang中github.com/docker/libcontainer.Config.Namespaces方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Namespaces方法的具體用法?Golang Config.Namespaces怎麽用?Golang Config.Namespaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/libcontainer.Config
的用法示例。
在下文中一共展示了Config.Namespaces方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readLibcontainerConfig
// TODO(vmarmol): Switch to getting this from libcontainer once we have a solid API.
func (self *dockerContainerHandler) readLibcontainerConfig() (*libcontainer.Config, error) {
out, err := ioutil.ReadFile(self.libcontainerConfigPath)
if err != nil {
return nil, fmt.Errorf("failed to read libcontainer config from %q: %v", self.libcontainerConfigPath, err)
}
var config libcontainer.Config
err = json.Unmarshal(out, &config)
if err != nil {
// TODO(vmarmol): Remove this once it becomes the standard.
// Try to parse the old config. The main difference is that namespaces used to be a map, now it is a slice of structs.
// The JSON marshaler will use the non-nested field before the nested one.
type oldLibcontainerConfig struct {
libcontainer.Config
OldNamespaces map[string]bool `json:"namespaces,omitempty"`
}
var oldConfig oldLibcontainerConfig
err2 := json.Unmarshal(out, &oldConfig)
if err2 != nil {
// Use original error.
return nil, fmt.Errorf("failed to parse libcontainer config at %q: %v", self.libcontainerConfigPath, err)
}
// Translate the old config into the new config.
config = oldConfig.Config
for ns := range oldConfig.OldNamespaces {
config.Namespaces = append(config.Namespaces, libcontainer.Namespace{
Type: libcontainer.NamespaceType(ns),
})
}
}
// Replace cgroup parent and name with our own since we may be running in a different context.
config.Cgroups.Name = self.cgroup.Name
config.Cgroups.Parent = self.cgroup.Parent
return &config, nil
}