Skip to content

Commit

Permalink
Use internal types in the API instead of duplicating the types.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
  • Loading branch information
vishh committed Jun 23, 2014
1 parent ad5286a commit 952b884
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 64 deletions.
41 changes: 5 additions & 36 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,18 @@ package libcontainer

import (
"github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/devices"
"github.com/docker/libcontainer/mount"
"github.com/docker/libcontainer/network"
)

type Mount mount.Mount
type MountConfig mount.MountConfig

type Mounts mount.Mounts

type Network struct {
// Type sets the networks type, commonly veth and loopback
Type string `json:"type,omitempty"`

// Context is a generic key value format for setting additional options that are specific to
// the network type
Context map[string]string `json:"context,omitempty"`

// Address contains the IP and mask to set on the network interface
Address string `json:"address,omitempty"`

// Gateway sets the gateway address that is used as the default for the interface
Gateway string `json:"gateway,omitempty"`

// Mtu sets the mtu value for the interface and will be mirrored on both the host and
// container's interfaces if a pair is created, specifically in the case of type veth
Mtu int `json:"mtu,omitempty"`
}
type Network network.Network

// Container defines configuration options for executing a process inside a contained environment
type Container struct {
// NoPivotRoot will use MS_MOVE and a chroot to jail the process into the container's rootfs
// This is a common option when the container is running in ramdisk
NoPivotRoot bool `json:"no_pivot_root,omitempty"`

// ReadonlyFs will remount the container's rootfs as readonly where only externally mounted
// bind mounts are writtable
ReadonlyFs bool `json:"readonly_fs,omitempty"`

// Mounts specify additional source and destination paths that will be mounted inside the container's
// rootfs and mount namespace if specified
Mounts Mounts `json:"mounts,omitempty"`

// The device nodes that should be automatically created within the container upon container start. Note, make sure that the node is marked as allowed in the cgroup as well!
DeviceNodes []*devices.Device `json:"device_nodes,omitempty"`
// Mount specific options.
MountConfig MountConfig `json:"mount_config,omitempty"`

// Hostname optionally sets the container's hostname if provided
Hostname string `json:"hostname,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion namespaces/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *Sy
if err != nil {
return err
}
if err := strategy.Create(libcontainer.GetInternalNetworkConfig(config), nspid, context); err != nil {
if err := strategy.Create((*network.Network)(config), nspid, context); err != nil {
return err
}
}
Expand Down
6 changes: 4 additions & 2 deletions namespaces/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func Init(container *libcontainer.Container, uncleanRootfs, consolePath string,

label.Init()

if err := mount.InitializeMountNamespace(rootfs, consolePath, libcontainer.GetInternalMountConfig(container)); err != nil {
if err := mount.InitializeMountNamespace(rootfs,
consolePath,
(*mount.MountConfig)(&container.MountConfig)); err != nil {
return fmt.Errorf("setup mount namespace %s", err)
}
if container.Hostname != "" {
Expand Down Expand Up @@ -166,7 +168,7 @@ func setupNetwork(container *libcontainer.Container, context map[string]string)
return err
}

err1 := strategy.Initialize(libcontainer.GetInternalNetworkConfig(config), context)
err1 := strategy.Initialize((*network.Network)(config), context)
if err1 != nil {
return err1
}
Expand Down
25 changes: 0 additions & 25 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
package libcontainer

import (
"github.com/docker/libcontainer/mount"
"github.com/docker/libcontainer/network"
"github.com/docker/libcontainer/security/capabilities"
)

func GetInternalMountConfig(container *Container) *mount.MountConfig {
out := &mount.MountConfig{
NoPivotRoot: container.NoPivotRoot,
ReadonlyFs: container.ReadonlyFs,
DeviceNodes: container.DeviceNodes,
MountLabel: container.Context["mount_label"],
Mounts: (mount.Mounts)(container.Mounts),
}
return out
}

func GetInternalNetworkConfig(net *Network) *network.Network {
return &network.Network{
Type: net.Type,
NsPath: net.Context["nspath"],
Bridge: net.Context["bridge"],
VethPrefix: net.Context["prefix"],
Address: net.Address,
Gateway: net.Gateway,
Mtu: net.Mtu,
}
}

func GetAllCapabilities() []string {
return capabilities.GetAllCapabilities()
}
Expand Down

0 comments on commit 952b884

Please sign in to comment.