Rename Container -> Config.

Docker-DCO-1.1-Signed-off-by: Victor Marmol <vmarmol@google.com> (github: vmarmol)
This commit is contained in:
Victor Marmol 2014-06-23 16:54:35 -07:00
parent e783cac215
commit 60b381e600
11 changed files with 28 additions and 28 deletions

View File

@ -10,8 +10,8 @@ type MountConfig mount.MountConfig
type Network network.Network type Network network.Network
// Container defines configuration options for executing a process inside a contained environment // Config defines configuration options for executing a process inside a contained environment.
type Container struct { type Config struct {
// Mount specific options. // Mount specific options.
MountConfig *MountConfig `json:"mount_config,omitempty"` MountConfig *MountConfig `json:"mount_config,omitempty"`

View File

@ -32,14 +32,14 @@ func containsDevice(expected *devices.Device, values []*devices.Device) bool {
return false return false
} }
func TestContainerJsonFormat(t *testing.T) { func TestConfigJsonFormat(t *testing.T) {
f, err := os.Open("sample_configs/attach_to_bridge.json") f, err := os.Open("sample_configs/attach_to_bridge.json")
if err != nil { if err != nil {
t.Fatal("Unable to open container.json") t.Fatal("Unable to open container.json")
} }
defer f.Close() defer f.Close()
var container *Container var container *Config
if err := json.NewDecoder(f).Decode(&container); err != nil { if err := json.NewDecoder(f).Decode(&container); err != nil {
t.Fatalf("failed to decode container config: %s", err) t.Fatalf("failed to decode container config: %s", err)
} }

View File

@ -7,4 +7,4 @@ import (
"github.com/docker/libcontainer" "github.com/docker/libcontainer"
) )
type CreateCommand func(container *libcontainer.Container, console, rootfs, dataPath, init string, childPipe *os.File, args []string) *exec.Cmd type CreateCommand func(container *libcontainer.Config, console, rootfs, dataPath, init string, childPipe *os.File, args []string) *exec.Cmd

View File

@ -19,7 +19,7 @@ import (
// Move this to libcontainer package. // Move this to libcontainer package.
// Exec performes setup outside of a namespace so that a container can be // Exec performes setup outside of a namespace so that a container can be
// executed. Exec is a high level function for working with container namespaces. // executed. Exec is a high level function for working with container namespaces.
func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) {
var ( var (
master *os.File master *os.File
console string console string
@ -105,7 +105,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str
// root: the path to the container json file and information // root: the path to the container json file and information
// pipe: sync pipe to syncronize the parent and child processes // pipe: sync pipe to syncronize the parent and child processes
// args: the arguemnts to pass to the container to run as the user's program // args: the arguemnts to pass to the container to run as the user's program
func DefaultCreateCommand(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { func DefaultCreateCommand(container *libcontainer.Config, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd {
// get our binary name from arg0 so we can always reexec ourself // get our binary name from arg0 so we can always reexec ourself
env := []string{ env := []string{
"console=" + console, "console=" + console,
@ -137,7 +137,7 @@ func DefaultCreateCommand(container *libcontainer.Container, console, rootfs, da
// SetupCgroups applies the cgroup restrictions to the process running in the contaienr based // SetupCgroups applies the cgroup restrictions to the process running in the contaienr based
// on the container's configuration // on the container's configuration
func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) { func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) {
if container.Cgroups != nil { if container.Cgroups != nil {
c := container.Cgroups c := container.Cgroups
if systemd.UseSystemd() { if systemd.UseSystemd() {
@ -150,7 +150,7 @@ func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveC
// InitializeNetworking creates the container's network stack outside of the namespace and moves // InitializeNetworking creates the container's network stack outside of the namespace and moves
// interfaces into the container's net namespaces if necessary // interfaces into the container's net namespaces if necessary
func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error { func InitializeNetworking(container *libcontainer.Config, nspid int, pipe *SyncPipe) error {
context := map[string]string{} context := map[string]string{}
for _, config := range container.Networks { for _, config := range container.Networks {
strategy, err := network.GetStrategy(config.Type) strategy, err := network.GetStrategy(config.Type)

View File

@ -13,7 +13,7 @@ import (
) )
// ExecIn uses an existing pid and joins the pid's namespaces with the new command. // ExecIn uses an existing pid and joins the pid's namespaces with the new command.
func ExecIn(container *libcontainer.Container, nspid int, args []string) error { func ExecIn(container *libcontainer.Config, nspid int, args []string) error {
// TODO(vmarmol): If this gets too long, send it over a pipe to the child. // TODO(vmarmol): If this gets too long, send it over a pipe to the child.
// Marshall the container into JSON since it won't be available in the namespace. // Marshall the container into JSON since it won't be available in the namespace.
containerJson, err := json.Marshal(container) containerJson, err := json.Marshal(container)
@ -31,7 +31,7 @@ func ExecIn(container *libcontainer.Container, nspid int, args []string) error {
} }
// NsEnter is run after entering the namespace. // NsEnter is run after entering the namespace.
func NsEnter(container *libcontainer.Container, nspid int, args []string) error { func NsEnter(container *libcontainer.Config, nspid int, args []string) error {
// clear the current processes env and replace it with the environment // clear the current processes env and replace it with the environment
// defined on the container // defined on the container
if err := LoadContainerEnvironment(container); err != nil { if err := LoadContainerEnvironment(container); err != nil {

View File

@ -27,7 +27,7 @@ import (
// Move this to libcontainer package. // Move this to libcontainer package.
// Init is the init process that first runs inside a new namespace to setup mounts, users, networking, // Init is the init process that first runs inside a new namespace to setup mounts, users, networking,
// and other options required for the new container. // and other options required for the new container.
func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error {
rootfs, err := utils.ResolveRootfs(uncleanRootfs) rootfs, err := utils.ResolveRootfs(uncleanRootfs)
if err != nil { if err != nil {
return err return err
@ -161,7 +161,7 @@ func SetupUser(u string) error {
// setupVethNetwork uses the Network config if it is not nil to initialize // setupVethNetwork uses the Network config if it is not nil to initialize
// the new veth interface inside the container for use by changing the name to eth0 // the new veth interface inside the container for use by changing the name to eth0
// setting the MTU and IP address along with the default gateway // setting the MTU and IP address along with the default gateway
func setupNetwork(container *libcontainer.Container, context map[string]string) error { func setupNetwork(container *libcontainer.Config, context map[string]string) error {
for _, config := range container.Networks { for _, config := range container.Networks {
strategy, err := network.GetStrategy(config.Type) strategy, err := network.GetStrategy(config.Type)
if err != nil { if err != nil {
@ -176,7 +176,7 @@ func setupNetwork(container *libcontainer.Container, context map[string]string)
return nil return nil
} }
func setupRoute(container *libcontainer.Container) error { func setupRoute(container *libcontainer.Config) error {
for _, config := range container.Routes { for _, config := range container.Routes {
if err := netlink.AddRoute(config.Destination, config.Source, config.Gateway, config.InterfaceName); err != nil { if err := netlink.AddRoute(config.Destination, config.Source, config.Gateway, config.InterfaceName); err != nil {
return err return err
@ -188,7 +188,7 @@ func setupRoute(container *libcontainer.Container) error {
// FinalizeNamespace drops the caps, sets the correct user // FinalizeNamespace drops the caps, sets the correct user
// and working dir, and closes any leaky file descriptors // and working dir, and closes any leaky file descriptors
// before execing the command inside the namespace // before execing the command inside the namespace
func FinalizeNamespace(container *libcontainer.Container) error { func FinalizeNamespace(container *libcontainer.Config) error {
// Ensure that all non-standard fds we may have accidentally // Ensure that all non-standard fds we may have accidentally
// inherited are marked close-on-exec so they stay out of the // inherited are marked close-on-exec so they stay out of the
// container // container
@ -228,7 +228,7 @@ func FinalizeNamespace(container *libcontainer.Container) error {
return nil return nil
} }
func LoadContainerEnvironment(container *libcontainer.Container) error { func LoadContainerEnvironment(container *libcontainer.Config) error {
os.Clearenv() os.Clearenv()
for _, pair := range container.Env { for _, pair := range container.Env {
p := strings.SplitN(pair, "=", 2) p := strings.SplitN(pair, "=", 2)

View File

@ -7,19 +7,19 @@ import (
"github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups"
) )
func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) {
return -1, ErrUnsupported return -1, ErrUnsupported
} }
func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error {
return ErrUnsupported return ErrUnsupported
} }
func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error { func InitializeNetworking(container *libcontainer.Config, nspid int, pipe *SyncPipe) error {
return ErrUnsupported return ErrUnsupported
} }
func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) { func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) {
return nil, ErrUnsupported return nil, ErrUnsupported
} }

View File

@ -48,7 +48,7 @@ func execAction(context *cli.Context) {
// error. // error.
// //
// Signals sent to the current process will be forwarded to container. // Signals sent to the current process will be forwarded to container.
func startContainer(container *libcontainer.Container, term namespaces.Terminal, dataPath string, args []string) (int, error) { func startContainer(container *libcontainer.Config, term namespaces.Terminal, dataPath string, args []string) (int, error) {
var ( var (
cmd *exec.Cmd cmd *exec.Cmd
sigc = make(chan os.Signal, 10) sigc = make(chan os.Signal, 10)
@ -56,7 +56,7 @@ func startContainer(container *libcontainer.Container, term namespaces.Terminal,
signal.Notify(sigc) signal.Notify(sigc)
createCommand := func(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { createCommand := func(container *libcontainer.Config, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd {
cmd = namespaces.DefaultCreateCommand(container, console, rootfs, dataPath, init, pipe, args) cmd = namespaces.DefaultCreateCommand(container, console, rootfs, dataPath, init, pipe, args)
if logPath != "" { if logPath != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("log=%s", logPath)) cmd.Env = append(cmd.Env, fmt.Sprintf("log=%s", logPath))

View File

@ -30,7 +30,7 @@ func specAction(context *cli.Context) {
} }
// returns the container spec in json format. // returns the container spec in json format.
func getContainerSpec(container *libcontainer.Container) (string, error) { func getContainerSpec(container *libcontainer.Config) (string, error) {
spec, err := json.MarshalIndent(container, "", "\t") spec, err := json.MarshalIndent(container, "", "\t")
if err != nil { if err != nil {
return "", err return "", err

View File

@ -31,7 +31,7 @@ func statsAction(context *cli.Context) {
} }
// returns the container stats in json format. // returns the container stats in json format.
func getContainerStats(container *libcontainer.Container) (string, error) { func getContainerStats(container *libcontainer.Config) (string, error) {
stats, err := fs.GetStats(container.Cgroups) stats, err := fs.GetStats(container.Cgroups)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -11,14 +11,14 @@ import (
"github.com/docker/libcontainer" "github.com/docker/libcontainer"
) )
func loadContainer() (*libcontainer.Container, error) { func loadContainer() (*libcontainer.Config, error) {
f, err := os.Open(filepath.Join(dataPath, "container.json")) f, err := os.Open(filepath.Join(dataPath, "container.json"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer f.Close() defer f.Close()
var container *libcontainer.Container var container *libcontainer.Config
if err := json.NewDecoder(f).Decode(&container); err != nil { if err := json.NewDecoder(f).Decode(&container); err != nil {
return nil, err return nil, err
} }
@ -51,8 +51,8 @@ func openLog(name string) error {
return nil return nil
} }
func loadContainerFromJson(rawData string) (*libcontainer.Container, error) { func loadContainerFromJson(rawData string) (*libcontainer.Config, error) {
var container *libcontainer.Container var container *libcontainer.Config
if err := json.Unmarshal([]byte(rawData), &container); err != nil { if err := json.Unmarshal([]byte(rawData), &container); err != nil {
return nil, err return nil, err