From 78c02daf474d798eea2da94286b30171d8deb98f Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Mon, 21 Jan 2013 18:39:52 -0800 Subject: [PATCH] container.Name -> container.Id --- container.go | 20 ++++++++++---------- docker.go | 26 +++++++++++++------------- docker_test.go | 2 +- lxc_template.go | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/container.go b/container.go index d89f99e474..9713784a9d 100644 --- a/container.go +++ b/container.go @@ -14,7 +14,7 @@ import ( ) type Container struct { - Name string + Id string Root string Path string Args []string @@ -34,9 +34,9 @@ type Config struct { Ram int64 } -func createContainer(name string, root string, command string, args []string, layers []string, config *Config) (*Container, error) { +func createContainer(id string, root string, command string, args []string, layers []string, config *Config) (*Container, error) { container := &Container{ - Name: name, + Id: id, Root: root, Path: command, Args: args, @@ -110,7 +110,7 @@ func (container *Container) Start() error { } params := []string{ - "-n", container.Name, + "-n", container.Id, "-f", container.lxcConfigPath, "--", container.Path, @@ -134,7 +134,7 @@ func (container *Container) Start() error { // // This is a rare race condition that happens for short lived programs for retries := 0; retries < 3; retries++ { - err := exec.Command("/usr/bin/lxc-wait", "-n", container.Name, "-s", "RUNNING|STOPPED").Run() + err := exec.Command("/usr/bin/lxc-wait", "-n", container.Id, "-s", "RUNNING|STOPPED").Run() if err == nil { return nil } @@ -184,7 +184,7 @@ func (container *Container) monitor() { container.stdout.Close() container.stderr.Close() if err := container.Filesystem.Umount(); err != nil { - log.Printf("%v: Failed to umount filesystem: %v", container.Name, err) + log.Printf("%v: Failed to umount filesystem: %v", container.Id, err) } // Report status back @@ -193,12 +193,12 @@ func (container *Container) monitor() { func (container *Container) kill() error { // This will cause the main container process to receive a SIGKILL - if err := exec.Command("/usr/bin/lxc-stop", "-n", container.Name).Run(); err != nil { + if err := exec.Command("/usr/bin/lxc-stop", "-n", container.Id).Run(); err != nil { return err } // Wait for the container to be actually stopped - if err := exec.Command("/usr/bin/lxc-wait", "-n", container.Name, "-s", "STOPPED").Run(); err != nil { + if err := exec.Command("/usr/bin/lxc-wait", "-n", container.Id, "-s", "STOPPED").Run(); err != nil { return err } return nil @@ -217,13 +217,13 @@ func (container *Container) Stop() error { } // 1. Send a SIGTERM - if err := exec.Command("/usr/bin/lxc-kill", "-n", container.Name, "15").Run(); err != nil { + if err := exec.Command("/usr/bin/lxc-kill", "-n", container.Id, "15").Run(); err != nil { return err } // 2. Wait for the process to exit on its own if err := container.WaitTimeout(10 * time.Second); err != nil { - log.Printf("Container %v failed to exit within 10 seconds of SIGTERM", container.Name) + log.Printf("Container %v failed to exit within 10 seconds of SIGTERM", container.Id) } // 3. Force kill diff --git a/docker.go b/docker.go index 3bdf694664..a1f64c6a95 100644 --- a/docker.go +++ b/docker.go @@ -22,34 +22,34 @@ func (docker *Docker) List() []*Container { return containers } -func (docker *Docker) getContainerElement(name string) *list.Element { +func (docker *Docker) getContainerElement(id string) *list.Element { for e := docker.containers.Front(); e != nil; e = e.Next() { container := e.Value.(*Container) - if container.Name == name { + if container.Id == id { return e } } return nil } -func (docker *Docker) Get(name string) *Container { - e := docker.getContainerElement(name) +func (docker *Docker) Get(id string) *Container { + e := docker.getContainerElement(id) if e == nil { return nil } return e.Value.(*Container) } -func (docker *Docker) Exists(name string) bool { - return docker.Get(name) != nil +func (docker *Docker) Exists(id string) bool { + return docker.Get(id) != nil } -func (docker *Docker) Create(name string, command string, args []string, layers []string, config *Config) (*Container, error) { - if docker.Exists(name) { - return nil, fmt.Errorf("Container %v already exists", name) +func (docker *Docker) Create(id string, command string, args []string, layers []string, config *Config) (*Container, error) { + if docker.Exists(id) { + return nil, fmt.Errorf("Container %v already exists", id) } - root := path.Join(docker.repository, name) - container, err := createContainer(name, root, command, args, layers, config) + root := path.Join(docker.repository, id) + container, err := createContainer(id, root, command, args, layers, config) if err != nil { return nil, err } @@ -58,9 +58,9 @@ func (docker *Docker) Create(name string, command string, args []string, layers } func (docker *Docker) Destroy(container *Container) error { - element := docker.getContainerElement(container.Name) + element := docker.getContainerElement(container.Id) if element == nil { - return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Name) + return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id) } if err := container.Stop(); err != nil { diff --git a/docker_test.go b/docker_test.go index 3633ea5a3a..9011a16eac 100644 --- a/docker_test.go +++ b/docker_test.go @@ -51,7 +51,7 @@ func TestCreate(t *testing.T) { } // Make sure the container List() returns is the right one - if docker.List()[0].Name != "test_create" { + if docker.List()[0].Id != "test_create" { t.Errorf("Unexpected container %v returned by List", docker.List()[0]) } diff --git a/lxc_template.go b/lxc_template.go index af9855c663..38aba72b31 100644 --- a/lxc_template.go +++ b/lxc_template.go @@ -9,7 +9,7 @@ const LxcTemplate = ` {{if .Config.Hostname}} lxc.utsname = {{.Config.Hostname}} {{else}} -lxc.utsname = {{.Name}} +lxc.utsname = {{.Id}} {{end}} #lxc.aa_profile = unconfined