1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add ability to work with individual namespaces

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-03-21 00:23:34 +00:00
parent 443a75d5f6
commit 70f3b9f4ce
3 changed files with 25 additions and 6 deletions

View file

@ -39,7 +39,9 @@ func (c *DefaultCommandFactory) Create(container *libcontainer.Container, consol
// flags on clone, unshare, and setns // flags on clone, unshare, and setns
func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) { func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) {
for _, ns := range namespaces { for _, ns := range namespaces {
flag |= ns.Value if ns.Enabled {
flag |= ns.Value
}
} }
return flag return flag
} }

View file

@ -53,7 +53,8 @@ func (ns *Namespace) String() string {
func GetNamespace(key string) *Namespace { func GetNamespace(key string) *Namespace {
for _, ns := range namespaceList { for _, ns := range namespaceList {
if ns.Key == key { if ns.Key == key {
return ns cpy := *ns
return &cpy
} }
} }
return nil return nil
@ -62,12 +63,16 @@ func GetNamespace(key string) *Namespace {
// Contains returns true if the specified Namespace is // Contains returns true if the specified Namespace is
// in the slice // in the slice
func (n Namespaces) Contains(ns string) bool { func (n Namespaces) Contains(ns string) bool {
return n.Get(ns) != nil
}
func (n Namespaces) Get(ns string) *Namespace {
for _, nsp := range n { for _, nsp := range n {
if nsp.Key == ns { if nsp.Key == ns {
return true return nsp
} }
} }
return false return nil
} }
type ( type (

View file

@ -77,10 +77,12 @@ func createContainer(c *execdriver.Command) *libcontainer.Container {
// i.e: cgroup devices.allow *:* // i.e: cgroup devices.allow *:*
func configureCustomOptions(container *libcontainer.Container, opts []string) { func configureCustomOptions(container *libcontainer.Container, opts []string) {
for _, opt := range opts { for _, opt := range opts {
parts := strings.Split(strings.TrimSpace(opt), " ") var (
parts = strings.Split(strings.TrimSpace(opt), " ")
value = strings.TrimSpace(parts[1])
)
switch parts[0] { switch parts[0] {
case "cap": case "cap":
value := strings.TrimSpace(parts[1])
c := container.CapabilitiesMask.Get(value[1:]) c := container.CapabilitiesMask.Get(value[1:])
if c == nil { if c == nil {
continue continue
@ -93,6 +95,16 @@ func configureCustomOptions(container *libcontainer.Container, opts []string) {
default: default:
// do error here // do error here
} }
case "ns":
ns := container.Namespaces.Get(value[1:])
switch value[0] {
case '-':
ns.Enabled = false
case '+':
ns.Enabled = true
default:
// error
}
} }
} }
} }