utils

package
v0.0.0-...-417fa16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2014 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdWriterPrefixLen = 8
	StdWriterFdIndex   = 0
	StdWriterSizeIndex = 4
)

Variables

View Source
var (
	IAMSTATIC bool   // whether or not Docker itself was compiled statically via ./hack/make.sh binary
	INITSHA1  string // sha1sum of separate static dockerinit, if Docker itself was compiled dynamically via ./hack/make.sh dynbinary
	INITPATH  string // custom location to search for a valid dockerinit binary (available for packagers as a last resort escape hatch)
)
View Source
var ErrInvalidStdHeader = errors.New("Unrecognized input header")

Functions

func CheckLocalDns

func CheckLocalDns(resolvConf []byte) bool

CheckLocalDns looks into the /etc/resolv.conf, it returns true if there is a local nameserver or if there is no nameserver.

func CompareKernelVersion

func CompareKernelVersion(a, b *KernelVersionInfo) int

Compare two KernelVersionInfo struct. Returns -1 if a < b, = if a == b, 1 it a > b

func CopyDirectory

func CopyDirectory(source, dest string) error

FIXME: this is deprecated by CopyWithTar in archive.go

func CopyEscapable

func CopyEscapable(dst io.Writer, src io.ReadCloser) (written int64, err error)

Code c/c from io.Copy() modified to handle escape sequence

func CopyFile

func CopyFile(src, dst string) (int64, error)

func Debugf

func Debugf(format string, a ...interface{})

Debug function, if the debug flag is set, then display. Do nothing otherwise If Docker is in damon mode, also send the debug info on the socket

func DockerInitPath

func DockerInitPath(localCopy string) string

Figure out the path of our dockerinit (which may be SelfPath())

func Download

func Download(url string) (*http.Response, error)

Request a given URL and return an io.Reader

func Errorf

func Errorf(format string, a ...interface{})

func GetCallerName

func GetCallerName(depth int) string

GetCallerName introspects the call stack and returns the name of the function `depth` levels down in the stack.

func GetNameserversAsCIDR

func GetNameserversAsCIDR(resolvConf []byte) []string

GetNameserversAsCIDR returns nameservers (if any) listed in /etc/resolv.conf as CIDR blocks (e.g., "1.2.3.4/32") This function's output is intended for net.ParseCIDR

func GetReleaseVersion

func GetReleaseVersion() string

func GetResolvConf

func GetResolvConf() ([]byte, error)

GetResolvConf opens and read the content of /etc/resolv.conf. It returns it as byte slice.

func GetTotalUsedFds

func GetTotalUsedFds() int

func Go

func Go(f func() error) chan error

Go is a basic promise implementation: it wraps calls a function in a goroutine, and returns a channel which will later return the function's return value.

func HashData

func HashData(src io.Reader) (string, error)

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration returns a human-readable approximation of a duration (eg. "About a minute", "4 hours ago", etc.)

func HumanSize

func HumanSize(size int64) string

HumanSize returns a human-readable approximation of a size using SI standard (eg. "44kB", "17MB")

func IsClosedError

func IsClosedError(err error) bool

func IsGIT

func IsGIT(str string) bool

func IsURL

func IsURL(str string) bool

func NewBufReader

func NewBufReader(r io.Reader) *bufReader

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

func ParseHost

func ParseHost(defaultHost string, defaultPort int, defaultUnix, addr string) (string, error)

FIXME: Change this not to receive default value as parameter

func ParseRepositoryTag

func ParseRepositoryTag(repos string) (string, string)

Get a repos name and returns the right reposName + tag The tag can be confusing because of a port in a repository name.

Ex: localhost.localdomain:5000/samalba/hipache:latest

func PartParser

func PartParser(template, data string) (map[string]string, error)

func RAMInBytes

func RAMInBytes(size string) (bytes int64, err error)

Parses a human-readable string representing an amount of RAM in bytes, kibibytes, mebibytes or gibibytes, and returns the number of bytes, or -1 if the string is unparseable. Units are case-insensitive, and the 'b' suffix is optional.

func RandomString

func RandomString() string

func SelfPath

func SelfPath() string

Figure out the absolute path of our own binary (if it's still around).

func ShellQuoteArguments

func ShellQuoteArguments(args []string) string

Take a list of strings and escape them so they will be handled right when passed as arguments to an program via a shell

func StdCopy

func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error)

StdCopy is a modified version of io.Copy.

StdCopy will demultiplex `src`, assuming that it contains two streams, previously multiplexed together using a StdWriter instance. As it reads from `src`, StdCopy will write to `dstout` and `dsterr`.

StdCopy will read until it hits EOF on `src`. It will then return a nil error. In other words: if `err` is non nil, it indicates a real underlying error.

`written` will hold the total number of bytes written to `dstout` and `dsterr`.

func StripComments

func StripComments(input []byte, commentMarker []byte) []byte

StripComments parses input into lines and strips away comments.

func Trunc

func Trunc(s string, maxlen int) string

func TruncateID

func TruncateID(id string) string

TruncateID returns a shorthand version of a string identifier for convenience. A collision with other shorthands is very unlikely, but possible. In case of a collision a lookup with TruncIndex.Get() will fail, and the caller will need to use a langer prefix, or the full-length Id.

Types

type DependencyGraph

type DependencyGraph struct {
	// contains filtered or unexported fields
}

func NewDependencyGraph

func NewDependencyGraph() DependencyGraph

func (*DependencyGraph) AddDependency

func (graph *DependencyGraph) AddDependency(node, to string) error

func (*DependencyGraph) GenerateTraversalMap

func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error)

The magic happens here ::

func (*DependencyGraph) NewNode

func (graph *DependencyGraph) NewNode(id string) string

type DependencyNode

type DependencyNode struct {
	// contains filtered or unexported fields
}

func (*DependencyNode) Degree

func (node *DependencyNode) Degree() int

type Fataler

type Fataler interface {
	Fatal(args ...interface{})
}

A common interface to access the Fatal method of both testing.B and testing.T.

type JSONLog

type JSONLog struct {
	Log     string    `json:"log,omitempty"`
	Stream  string    `json:"stream,omitempty"`
	Created time.Time `json:"time"`
}

type KernelVersionInfo

type KernelVersionInfo struct {
	Kernel int
	Major  int
	Minor  int
	Flavor string
}

func GetKernelVersion

func GetKernelVersion() (*KernelVersionInfo, error)

func ParseRelease

func ParseRelease(release string) (*KernelVersionInfo, error)

func (*KernelVersionInfo) String

func (k *KernelVersionInfo) String() string

type NopFlusher

type NopFlusher struct{}

func (*NopFlusher) Flush

func (f *NopFlusher) Flush()

type NopWriter

type NopWriter struct{}

func (*NopWriter) Write

func (*NopWriter) Write(buf []byte) (int, error)

type StatusError

type StatusError struct {
	Status     string
	StatusCode int
}

An StatusError reports an unsuccessful exit by a command.

func (*StatusError) Error

func (e *StatusError) Error() string

type StdType

type StdType [StdWriterPrefixLen]byte
var (
	Stdin  StdType = StdType{0: 0}
	Stdout StdType = StdType{0: 1}
	Stderr StdType = StdType{0: 2}
)

type StdWriter

type StdWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

func NewStdWriter

func NewStdWriter(w io.Writer, t StdType) *StdWriter

NewStdWriter instanciates a new Writer. Everything written to it will be encapsulated using a custom format, and written to the underlying `w` stream. This allows multiple write streams (e.g. stdout and stderr) to be muxed into a single connection. `t` indicates the id of the stream to encapsulate. It can be utils.Stdin, utils.Stdout, utils.Stderr.

func (*StdWriter) Write

func (w *StdWriter) Write(buf []byte) (n int, err error)

type StreamWriter

type StreamWriter struct {
	// contains filtered or unexported fields
}

type TruncIndex

type TruncIndex struct {
	// contains filtered or unexported fields
}

TruncIndex allows the retrieval of string identifiers by any of their unique prefixes. This is used to retrieve image and container IDs by more convenient shorthand prefixes.

func NewTruncIndex

func NewTruncIndex() *TruncIndex

func (*TruncIndex) Add

func (idx *TruncIndex) Add(id string) error

func (*TruncIndex) Delete

func (idx *TruncIndex) Delete(id string) error

func (*TruncIndex) Get

func (idx *TruncIndex) Get(s string) (string, error)

type User

type User struct {
	Uid      string // user id
	Gid      string // primary group id
	Username string
	Name     string
	HomeDir  string
}

func UserLookup

func UserLookup(uid string) (*User, error)

UserLookup check if the given username or uid is present in /etc/passwd and returns the user struct. If the username is not found, an error is returned.

type Utsname

type Utsname syscall.Utsname

type WriteBroadcaster

type WriteBroadcaster struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWriteBroadcaster

func NewWriteBroadcaster() *WriteBroadcaster

func (*WriteBroadcaster) AddWriter

func (w *WriteBroadcaster) AddWriter(writer io.WriteCloser, stream string)

func (*WriteBroadcaster) CloseWriters

func (w *WriteBroadcaster) CloseWriters() error

func (*WriteBroadcaster) Write

func (w *WriteBroadcaster) Write(p []byte) (n int, err error)

type WriteFlusher

type WriteFlusher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWriteFlusher

func NewWriteFlusher(w io.Writer) *WriteFlusher

func (*WriteFlusher) Flush

func (wf *WriteFlusher) Flush()

Flush the stream immediately.

func (*WriteFlusher) Write

func (wf *WriteFlusher) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL