Browse Source

Add json tags and comments to exedriver types

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
Michael Crosby 11 năm trước cách đây
mục cha
commit
e765c67b47
2 tập tin đã thay đổi với 28 bổ sung28 xóa
  1. 25 15
      execdriver/driver.go
  2. 3 13
      execdriver/lxc/driver.go

+ 25 - 15
execdriver/driver.go

@@ -1,11 +1,17 @@
 package execdriver
 
 import (
+	"errors"
 	"os/exec"
 	"syscall"
 	"time"
 )
 
+var (
+	ErrNotRunning         = errors.New("Process could not be started")
+	ErrWaitTimeoutReached = errors.New("Wait timeout reached")
+)
+
 type StartCallback func(*Process)
 
 type Driver interface {
@@ -19,29 +25,31 @@ type Driver interface {
 
 // Network settings of the container
 type Network struct {
-	Gateway     string
-	IPAddress   string
-	IPPrefixLen int
-	Mtu         int
+	Gateway     string `json:"gateway"`
+	IPAddress   string `json:"ip"`
+	IPPrefixLen int    `json:"ip_prefix_len"`
+	Mtu         int    `json:"mtu"`
 }
 
 // Process wrapps an os/exec.Cmd to add more metadata
 type Process struct {
 	exec.Cmd
 
-	ID         string
-	Privileged bool
-	User       string
-	Rootfs     string // root fs of the container
-	InitPath   string // dockerinit
-	Entrypoint string
-	Arguments  []string
-	WorkingDir string
-	ConfigPath string
-	Tty        bool
-	Network    *Network // if network is nil then networking is disabled
+	ID         string   `json:"id"`
+	Privileged bool     `json:"privileged"`
+	User       string   `json:"user"`
+	Rootfs     string   `json:"rootfs"`   // root fs of the container
+	InitPath   string   `json:"initpath"` // dockerinit
+	Entrypoint string   `json:"entrypoint"`
+	Arguments  []string `json:"arguments"`
+	WorkingDir string   `json:"working_dir"`
+	ConfigPath string   `json:"config_path"` // This should be able to be removed when the lxc template is moved into the driver
+	Tty        bool     `json:"tty"`
+	Network    *Network `json:"network"` // if network is nil then networking is disabled
 }
 
+// Return the pid of the process
+// If the process is nil -1 will be returned
 func (c *Process) Pid() int {
 	if c.Process == nil {
 		return -1
@@ -49,6 +57,8 @@ func (c *Process) Pid() int {
 	return c.Process.Pid
 }
 
+// Return the exit code of the process
+// if the process has not exited -1 will be returned
 func (c *Process) GetExitCode() int {
 	if c.ProcessState == nil {
 		return -1

+ 3 - 13
execdriver/lxc/driver.go

@@ -1,7 +1,6 @@
 package lxc
 
 import (
-	"errors"
 	"fmt"
 	"github.com/dotcloud/docker/execdriver"
 	"github.com/dotcloud/docker/utils"
@@ -14,15 +13,6 @@ import (
 	"time"
 )
 
-const (
-	startPath = "lxc-start"
-)
-
-var (
-	ErrNotRunning         = errors.New("Process could not be started")
-	ErrWaitTimeoutReached = errors.New("Wait timeout reached")
-)
-
 type driver struct {
 	root       string // root path for the driver to use
 	apparmor   bool
@@ -47,7 +37,7 @@ func (d *driver) Name() string {
 
 func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
 	params := []string{
-		startPath,
+		"lxc-start",
 		"-n", c.ID,
 		"-f", c.ConfigPath,
 		"--",
@@ -155,7 +145,7 @@ func (d *driver) Wait(id string, duration time.Duration) error {
 			return err
 		case <-time.After(duration):
 			killer = true
-			return ErrWaitTimeoutReached
+			return execdriver.ErrWaitTimeoutReached
 		}
 	} else {
 		return <-done
@@ -214,7 +204,7 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
 		}
 		time.Sleep(50 * time.Millisecond)
 	}
-	return ErrNotRunning
+	return execdriver.ErrNotRunning
 }
 
 func (d *driver) waitLxc(id string, kill *bool) <-chan error {