mirror of https://github.com/docker/docs.git
commit
cd4f7321c9
|
@ -1,8 +1,8 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME: separate runtime configuration from http api configuration
|
// FIXME: separate runtime configuration from http api configuration
|
||||||
|
|
|
@ -394,9 +394,9 @@ func (container *Container) Inject(file io.Reader, pth string) error {
|
||||||
if _, err := os.Stat(path.Join(container.rwPath(), pth)); err == nil {
|
if _, err := os.Stat(path.Join(container.rwPath(), pth)); err == nil {
|
||||||
// Since err is nil, the path could be stat'd and it exists
|
// Since err is nil, the path could be stat'd and it exists
|
||||||
return fmt.Errorf("%s exists", pth)
|
return fmt.Errorf("%s exists", pth)
|
||||||
} else if ! os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
// Expect err might be that the file doesn't exist, so
|
// Expect err might be that the file doesn't exist, so
|
||||||
// if it's some other error, return that.
|
// if it's some other error, return that.
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1086,7 +1086,7 @@ func (container *Container) allocateNetwork() error {
|
||||||
Gateway: manager.bridgeNetwork.IP,
|
Gateway: manager.bridgeNetwork.IP,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
}
|
}
|
||||||
if iface !=nil && iface.IPNet.IP != nil {
|
if iface != nil && iface.IPNet.IP != nil {
|
||||||
ipNum := ipToInt(iface.IPNet.IP)
|
ipNum := ipToInt(iface.IPNet.IP)
|
||||||
manager.ipAllocator.inUse[ipNum] = struct{}{}
|
manager.ipAllocator.inUse[ipNum] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
"github.com/dotcloud/docker"
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/sysinit"
|
"github.com/dotcloud/docker/sysinit"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"github.com/dotcloud/docker/engine"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
|
@ -2,13 +2,12 @@ package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"log"
|
|
||||||
"runtime"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Handler func(*Job) string
|
type Handler func(*Job) string
|
||||||
|
|
||||||
var globalHandlers map[string]Handler
|
var globalHandlers map[string]Handler
|
||||||
|
@ -25,8 +24,8 @@ func Register(name string, handler Handler) error {
|
||||||
// It acts as a store for *containers*, and allows manipulation of these
|
// It acts as a store for *containers*, and allows manipulation of these
|
||||||
// containers by executing *jobs*.
|
// containers by executing *jobs*.
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
root string
|
root string
|
||||||
handlers map[string]Handler
|
handlers map[string]Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a new engine managing the directory specified at `root`.
|
// New initializes a new engine managing the directory specified at `root`.
|
||||||
|
@ -56,8 +55,8 @@ func New(root string) (*Engine, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eng := &Engine{
|
eng := &Engine{
|
||||||
root: root,
|
root: root,
|
||||||
handlers: globalHandlers,
|
handlers: globalHandlers,
|
||||||
}
|
}
|
||||||
return eng, nil
|
return eng, nil
|
||||||
}
|
}
|
||||||
|
@ -66,12 +65,12 @@ func New(root string) (*Engine, error) {
|
||||||
// This function mimics `Command` from the standard os/exec package.
|
// This function mimics `Command` from the standard os/exec package.
|
||||||
func (eng *Engine) Job(name string, args ...string) *Job {
|
func (eng *Engine) Job(name string, args ...string) *Job {
|
||||||
job := &Job{
|
job := &Job{
|
||||||
eng: eng,
|
eng: eng,
|
||||||
Name: name,
|
Name: name,
|
||||||
Args: args,
|
Args: args,
|
||||||
Stdin: os.Stdin,
|
Stdin: os.Stdin,
|
||||||
Stdout: os.Stdout,
|
Stdout: os.Stdout,
|
||||||
Stderr: os.Stderr,
|
Stderr: os.Stderr,
|
||||||
}
|
}
|
||||||
handler, exists := eng.handlers[name]
|
handler, exists := eng.handlers[name]
|
||||||
if exists {
|
if exists {
|
||||||
|
@ -79,4 +78,3 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
||||||
}
|
}
|
||||||
return job
|
return job
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"io/ioutil"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"testing"
|
||||||
"io/ioutil"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalTestID string
|
var globalTestID string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Register("dummy", func(job *Job) string { return ""; })
|
Register("dummy", func(job *Job) string { return "" })
|
||||||
}
|
}
|
||||||
|
|
||||||
func mkEngine(t *testing.T) *Engine {
|
func mkEngine(t *testing.T) *Engine {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A job is the fundamental unit of work in the docker engine.
|
// A job is the fundamental unit of work in the docker engine.
|
||||||
|
@ -20,17 +20,17 @@ import (
|
||||||
// One slight variation is that jobs report their status as a string. The
|
// One slight variation is that jobs report their status as a string. The
|
||||||
// string "0" indicates success, and any other strings indicates an error.
|
// string "0" indicates success, and any other strings indicates an error.
|
||||||
// This allows for richer error reporting.
|
// This allows for richer error reporting.
|
||||||
//
|
//
|
||||||
type Job struct {
|
type Job struct {
|
||||||
eng *Engine
|
eng *Engine
|
||||||
Name string
|
Name string
|
||||||
Args []string
|
Args []string
|
||||||
env []string
|
env []string
|
||||||
Stdin io.ReadCloser
|
Stdin io.ReadCloser
|
||||||
Stdout io.WriteCloser
|
Stdout io.WriteCloser
|
||||||
Stderr io.WriteCloser
|
Stderr io.WriteCloser
|
||||||
handler func(*Job) string
|
handler func(*Job) string
|
||||||
status string
|
status string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run executes the job and blocks until the job completes.
|
// Run executes the job and blocks until the job completes.
|
||||||
|
@ -57,21 +57,21 @@ func (job *Job) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (job *Job) Getenv(key string) (value string) {
|
func (job *Job) Getenv(key string) (value string) {
|
||||||
for _, kv := range job.env {
|
for _, kv := range job.env {
|
||||||
if strings.Index(kv, "=") == -1 {
|
if strings.Index(kv, "=") == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parts := strings.SplitN(kv, "=", 2)
|
parts := strings.SplitN(kv, "=", 2)
|
||||||
if parts[0] != key {
|
if parts[0] != key {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
value = ""
|
value = ""
|
||||||
} else {
|
} else {
|
||||||
value = parts[1]
|
value = parts[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (job *Job) GetenvBool(key string) (value bool) {
|
func (job *Job) GetenvBool(key string) (value bool) {
|
||||||
|
@ -109,5 +109,5 @@ func (job *Job) SetenvList(key string, value []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (job *Job) Setenv(key, value string) {
|
func (job *Job) Setenv(key, value string) {
|
||||||
job.env = append(job.env, key + "=" + value)
|
job.env = append(job.env, key+"="+value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ type NameChecker interface {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
colors = [...]string{"white", "silver", "gray", "black", "blue", "green", "cyan", "yellow", "gold", "orange", "brown", "red", "violet", "pink", "magenta", "purple", "maroon", "crimson", "plum", "fuchsia", "lavender", "slate", "navy", "azure", "aqua", "olive", "teal", "lime", "beige", "tan", "sienna"}
|
colors = [...]string{"white", "silver", "gray", "black", "blue", "green", "cyan", "yellow", "gold", "orange", "brown", "red", "violet", "pink", "magenta", "purple", "maroon", "crimson", "plum", "fuchsia", "lavender", "slate", "navy", "azure", "aqua", "olive", "teal", "lime", "beige", "tan", "sienna"}
|
||||||
animals = [...]string{"ant", "bear", "bird", "cat", "chicken", "cow", "deer", "dog", "donkey", "duck", "fish", "fox", "frog", "horse", "kangaroo", "koala", "lemur", "lion", "lizard", "monkey", "octopus", "pig", "shark", "sheep", "sloth", "spider", "squirrel", "tiger", "toad", "weasel", "whale", "wolf"}
|
animals = [...]string{"ant", "bear", "bird", "cat", "chicken", "cow", "deer", "dog", "donkey", "duck", "fish", "fox", "frog", "horse", "kangaroo", "koala", "lemur", "lion", "lizard", "monkey", "octopus", "pig", "shark", "sheep", "sloth", "spider", "squirrel", "tiger", "toad", "weasel", "whale", "wolf"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateRandomName(checker NameChecker) (string, error) {
|
func GenerateRandomName(checker NameChecker) (string, error) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ func NetworkGetRoutes() ([]*net.IPNet, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func NetworkLinkAdd(name string, linkType string) error {
|
func NetworkLinkAdd(name string, linkType string) error {
|
||||||
return fmt.Errorf("Not implemented")
|
return fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
@ -18,7 +17,6 @@ func NetworkLinkUp(iface *net.Interface) error {
|
||||||
return fmt.Errorf("Not implemented")
|
return fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error {
|
func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error {
|
||||||
return fmt.Errorf("Not implemented")
|
return fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RandomString() string {
|
func RandomString() string {
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -904,7 +904,7 @@ func StripComments(input []byte, commentMarker []byte) []byte {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNameserversAsCIDR returns nameservers (if any) listed in
|
// GetNameserversAsCIDR returns nameservers (if any) listed in
|
||||||
// /etc/resolv.conf as CIDR blocks (e.g., "1.2.3.4/32")
|
// /etc/resolv.conf as CIDR blocks (e.g., "1.2.3.4/32")
|
||||||
// This function's output is intended for net.ParseCIDR
|
// This function's output is intended for net.ParseCIDR
|
||||||
func GetNameserversAsCIDR(resolvConf []byte) []string {
|
func GetNameserversAsCIDR(resolvConf []byte) []string {
|
||||||
|
|
|
@ -453,20 +453,20 @@ search example.com`: {"1.2.3.4/32", "4.3.2.1/32"},
|
||||||
`search example.com`: {},
|
`search example.com`: {},
|
||||||
`nameserver 1.2.3.4
|
`nameserver 1.2.3.4
|
||||||
search example.com
|
search example.com
|
||||||
nameserver 4.3.2.1`: []string{"1.2.3.4/32", "4.3.2.1/32"},
|
nameserver 4.3.2.1`: {"1.2.3.4/32", "4.3.2.1/32"},
|
||||||
``: []string{},
|
``: {},
|
||||||
` nameserver 1.2.3.4 `: []string{"1.2.3.4/32"},
|
` nameserver 1.2.3.4 `: {"1.2.3.4/32"},
|
||||||
`search example.com
|
`search example.com
|
||||||
nameserver 1.2.3.4
|
nameserver 1.2.3.4
|
||||||
#nameserver 4.3.2.1`: []string{"1.2.3.4/32"},
|
#nameserver 4.3.2.1`: {"1.2.3.4/32"},
|
||||||
`search example.com
|
`search example.com
|
||||||
nameserver 1.2.3.4 # not 4.3.2.1`: []string{"1.2.3.4/32"},
|
nameserver 1.2.3.4 # not 4.3.2.1`: {"1.2.3.4/32"},
|
||||||
} {
|
} {
|
||||||
test := GetNameserversAsCIDR([]byte(resolv))
|
test := GetNameserversAsCIDR([]byte(resolv))
|
||||||
if !StrSlicesEqual(test, result) {
|
if !StrSlicesEqual(test, result) {
|
||||||
t.Fatalf("Wrong nameserver string {%s} should be %v. Input: %s", test, result, resolv)
|
t.Fatalf("Wrong nameserver string {%s} should be %v. Input: %s", test, result, resolv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StrSlicesEqual(a, b []string) bool {
|
func StrSlicesEqual(a, b []string) bool {
|
||||||
|
|
|
@ -67,7 +67,7 @@ func newTestRuntime(prefix string) (runtime *Runtime, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &DaemonConfig{
|
config := &DaemonConfig{
|
||||||
Root: root,
|
Root: root,
|
||||||
AutoRestart: false,
|
AutoRestart: false,
|
||||||
}
|
}
|
||||||
runtime, err = NewRuntimeFromDirectory(config)
|
runtime, err = NewRuntimeFromDirectory(config)
|
||||||
|
|
Loading…
Reference in New Issue