Use internal types in the API instead of duplicating the types.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
Vishnu Kannan 2014-06-23 21:11:01 +00:00
parent ad5286acd9
commit 952b884882
4 changed files with 10 additions and 64 deletions

View File

@ -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"`

View File

@ -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
}
}

View File

@ -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 != "" {
@ -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
}

View File

@ -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()
}