id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
149,800
gosuri/uilive
writer.go
Start
func (w *Writer) Start() { if w.ticker == nil { w.ticker = time.NewTicker(w.RefreshInterval) w.tdone = make(chan bool, 1) } go w.Listen() }
go
func (w *Writer) Start() { if w.ticker == nil { w.ticker = time.NewTicker(w.RefreshInterval) w.tdone = make(chan bool, 1) } go w.Listen() }
[ "func", "(", "w", "*", "Writer", ")", "Start", "(", ")", "{", "if", "w", ".", "ticker", "==", "nil", "{", "w", ".", "ticker", "=", "time", ".", "NewTicker", "(", "w", ".", "RefreshInterval", ")", "\n", "w", ".", "tdone", "=", "make", "(", "chan", "bool", ",", "1", ")", "\n", "}", "\n\n", "go", "w", ".", "Listen", "(", ")", "\n", "}" ]
// Start starts the listener in a non-blocking manner
[ "Start", "starts", "the", "listener", "in", "a", "non", "-", "blocking", "manner" ]
810653011da975cf3ac54bf7aea22d5c9e49e317
https://github.com/gosuri/uilive/blob/810653011da975cf3ac54bf7aea22d5c9e49e317/writer.go#L107-L114
149,801
gosuri/uilive
writer.go
Listen
func (w *Writer) Listen() { for { select { case <-w.ticker.C: if w.ticker != nil { w.Flush() } case <-w.tdone: w.mtx.Lock() w.ticker.Stop() w.ticker = nil w.mtx.Unlock() return } } }
go
func (w *Writer) Listen() { for { select { case <-w.ticker.C: if w.ticker != nil { w.Flush() } case <-w.tdone: w.mtx.Lock() w.ticker.Stop() w.ticker = nil w.mtx.Unlock() return } } }
[ "func", "(", "w", "*", "Writer", ")", "Listen", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "w", ".", "ticker", ".", "C", ":", "if", "w", ".", "ticker", "!=", "nil", "{", "w", ".", "Flush", "(", ")", "\n", "}", "\n", "case", "<-", "w", ".", "tdone", ":", "w", ".", "mtx", ".", "Lock", "(", ")", "\n", "w", ".", "ticker", ".", "Stop", "(", ")", "\n", "w", ".", "ticker", "=", "nil", "\n", "w", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Listen listens for updates to the writer's buffer and flushes to the out provided. It blocks the runtime.
[ "Listen", "listens", "for", "updates", "to", "the", "writer", "s", "buffer", "and", "flushes", "to", "the", "out", "provided", ".", "It", "blocks", "the", "runtime", "." ]
810653011da975cf3ac54bf7aea22d5c9e49e317
https://github.com/gosuri/uilive/blob/810653011da975cf3ac54bf7aea22d5c9e49e317/writer.go#L123-L138
149,802
gosuri/uilive
writer.go
Write
func (w *Writer) Write(buf []byte) (n int, err error) { w.mtx.Lock() defer w.mtx.Unlock() return w.buf.Write(buf) }
go
func (w *Writer) Write(buf []byte) (n int, err error) { w.mtx.Lock() defer w.mtx.Unlock() return w.buf.Write(buf) }
[ "func", "(", "w", "*", "Writer", ")", "Write", "(", "buf", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "w", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "w", ".", "buf", ".", "Write", "(", "buf", ")", "\n", "}" ]
// Write save the contents of buf to the writer b. The only errors returned are ones encountered while writing to the underlying buffer.
[ "Write", "save", "the", "contents", "of", "buf", "to", "the", "writer", "b", ".", "The", "only", "errors", "returned", "are", "ones", "encountered", "while", "writing", "to", "the", "underlying", "buffer", "." ]
810653011da975cf3ac54bf7aea22d5c9e49e317
https://github.com/gosuri/uilive/blob/810653011da975cf3ac54bf7aea22d5c9e49e317/writer.go#L141-L145
149,803
ory/dockertest
docker/pkg/jsonmessage/jsonmessage.go
Display
func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error { if jm.Error != nil { if jm.Error.Code == 401 { return fmt.Errorf("authentication is required") } return jm.Error } var endl string if termInfo != nil && jm.Stream == "" && jm.Progress != nil { clearLine(out, termInfo) endl = "\r" fmt.Fprintf(out, endl) } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal return nil } if jm.TimeNano != 0 { fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(RFC3339NanoFixed)) } else if jm.Time != 0 { fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(RFC3339NanoFixed)) } if jm.ID != "" { fmt.Fprintf(out, "%s: ", jm.ID) } if jm.From != "" { fmt.Fprintf(out, "(from %s) ", jm.From) } if jm.Progress != nil && termInfo != nil { fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) } else if jm.ProgressMessage != "" { //deprecated fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) } else if jm.Stream != "" { fmt.Fprintf(out, "%s%s", jm.Stream, endl) } else { fmt.Fprintf(out, "%s%s\n", jm.Status, endl) } return nil }
go
func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error { if jm.Error != nil { if jm.Error.Code == 401 { return fmt.Errorf("authentication is required") } return jm.Error } var endl string if termInfo != nil && jm.Stream == "" && jm.Progress != nil { clearLine(out, termInfo) endl = "\r" fmt.Fprintf(out, endl) } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal return nil } if jm.TimeNano != 0 { fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(RFC3339NanoFixed)) } else if jm.Time != 0 { fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(RFC3339NanoFixed)) } if jm.ID != "" { fmt.Fprintf(out, "%s: ", jm.ID) } if jm.From != "" { fmt.Fprintf(out, "(from %s) ", jm.From) } if jm.Progress != nil && termInfo != nil { fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) } else if jm.ProgressMessage != "" { //deprecated fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) } else if jm.Stream != "" { fmt.Fprintf(out, "%s%s", jm.Stream, endl) } else { fmt.Fprintf(out, "%s%s\n", jm.Status, endl) } return nil }
[ "func", "(", "jm", "*", "JSONMessage", ")", "Display", "(", "out", "io", ".", "Writer", ",", "termInfo", "termInfo", ")", "error", "{", "if", "jm", ".", "Error", "!=", "nil", "{", "if", "jm", ".", "Error", ".", "Code", "==", "401", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "jm", ".", "Error", "\n", "}", "\n", "var", "endl", "string", "\n", "if", "termInfo", "!=", "nil", "&&", "jm", ".", "Stream", "==", "\"", "\"", "&&", "jm", ".", "Progress", "!=", "nil", "{", "clearLine", "(", "out", ",", "termInfo", ")", "\n", "endl", "=", "\"", "\\r", "\"", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "endl", ")", "\n", "}", "else", "if", "jm", ".", "Progress", "!=", "nil", "&&", "jm", ".", "Progress", ".", "String", "(", ")", "!=", "\"", "\"", "{", "//disable progressbar in non-terminal", "return", "nil", "\n", "}", "\n", "if", "jm", ".", "TimeNano", "!=", "0", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "time", ".", "Unix", "(", "0", ",", "jm", ".", "TimeNano", ")", ".", "Format", "(", "RFC3339NanoFixed", ")", ")", "\n", "}", "else", "if", "jm", ".", "Time", "!=", "0", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "time", ".", "Unix", "(", "jm", ".", "Time", ",", "0", ")", ".", "Format", "(", "RFC3339NanoFixed", ")", ")", "\n", "}", "\n", "if", "jm", ".", "ID", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "jm", ".", "ID", ")", "\n", "}", "\n", "if", "jm", ".", "From", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "jm", ".", "From", ")", "\n", "}", "\n", "if", "jm", ".", "Progress", "!=", "nil", "&&", "termInfo", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "jm", ".", "Status", ",", "jm", ".", "Progress", ".", "String", "(", ")", ",", "endl", ")", "\n", "}", "else", "if", "jm", ".", "ProgressMessage", "!=", "\"", "\"", "{", "//deprecated", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "jm", ".", "Status", ",", "jm", ".", "ProgressMessage", ",", "endl", ")", "\n", "}", "else", "if", "jm", ".", "Stream", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "jm", ".", "Stream", ",", "endl", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\\n", "\"", ",", "jm", ".", "Status", ",", "endl", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Display displays the JSONMessage to `out`. `termInfo` is non-nil if `out` // is a terminal. If this is the case, it will erase the entire current line // when displaying the progressbar.
[ "Display", "displays", "the", "JSONMessage", "to", "out", ".", "termInfo", "is", "non", "-", "nil", "if", "out", "is", "a", "terminal", ".", "If", "this", "is", "the", "case", "it", "will", "erase", "the", "entire", "current", "line", "when", "displaying", "the", "progressbar", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/pkg/jsonmessage/jsonmessage.go#L207-L243
149,804
ory/dockertest
docker/client_unix.go
initializeNativeClient
func (c *Client) initializeNativeClient(trFunc func() *http.Transport) { if c.endpointURL.Scheme != unixProtocol { return } sockPath := c.endpointURL.Path tr := trFunc() tr.Dial = func(network, addr string) (net.Conn, error) { return c.Dialer.Dial(unixProtocol, sockPath) } tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return c.Dialer.Dial(unixProtocol, sockPath) } c.HTTPClient.Transport = tr }
go
func (c *Client) initializeNativeClient(trFunc func() *http.Transport) { if c.endpointURL.Scheme != unixProtocol { return } sockPath := c.endpointURL.Path tr := trFunc() tr.Dial = func(network, addr string) (net.Conn, error) { return c.Dialer.Dial(unixProtocol, sockPath) } tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return c.Dialer.Dial(unixProtocol, sockPath) } c.HTTPClient.Transport = tr }
[ "func", "(", "c", "*", "Client", ")", "initializeNativeClient", "(", "trFunc", "func", "(", ")", "*", "http", ".", "Transport", ")", "{", "if", "c", ".", "endpointURL", ".", "Scheme", "!=", "unixProtocol", "{", "return", "\n", "}", "\n", "sockPath", ":=", "c", ".", "endpointURL", ".", "Path", "\n\n", "tr", ":=", "trFunc", "(", ")", "\n\n", "tr", ".", "Dial", "=", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "c", ".", "Dialer", ".", "Dial", "(", "unixProtocol", ",", "sockPath", ")", "\n", "}", "\n", "tr", ".", "DialContext", "=", "func", "(", "ctx", "context", ".", "Context", ",", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "c", ".", "Dialer", ".", "Dial", "(", "unixProtocol", ",", "sockPath", ")", "\n", "}", "\n", "c", ".", "HTTPClient", ".", "Transport", "=", "tr", "\n", "}" ]
// initializeNativeClient initializes the native Unix domain socket client on // Unix-style operating systems
[ "initializeNativeClient", "initializes", "the", "native", "Unix", "domain", "socket", "client", "on", "Unix", "-", "style", "operating", "systems" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client_unix.go#L17-L32
149,805
ory/dockertest
docker/distribution.go
InspectDistribution
func (c *Client) InspectDistribution(name string) (*registry.DistributionInspect, error) { path := "/distribution/" + name + "/json" resp, err := c.do("GET", path, doOptions{}) if err != nil { return nil, err } defer resp.Body.Close() var distributionInspect registry.DistributionInspect if err := json.NewDecoder(resp.Body).Decode(&distributionInspect); err != nil { return nil, err } return &distributionInspect, nil }
go
func (c *Client) InspectDistribution(name string) (*registry.DistributionInspect, error) { path := "/distribution/" + name + "/json" resp, err := c.do("GET", path, doOptions{}) if err != nil { return nil, err } defer resp.Body.Close() var distributionInspect registry.DistributionInspect if err := json.NewDecoder(resp.Body).Decode(&distributionInspect); err != nil { return nil, err } return &distributionInspect, nil }
[ "func", "(", "c", "*", "Client", ")", "InspectDistribution", "(", "name", "string", ")", "(", "*", "registry", ".", "DistributionInspect", ",", "error", ")", "{", "path", ":=", "\"", "\"", "+", "name", "+", "\"", "\"", "\n", "resp", ",", "err", ":=", "c", ".", "do", "(", "\"", "\"", ",", "path", ",", "doOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "var", "distributionInspect", "registry", ".", "DistributionInspect", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "distributionInspect", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "distributionInspect", ",", "nil", "\n", "}" ]
// InspectDistribution returns image digest and platform information by contacting the registry
[ "InspectDistribution", "returns", "image", "digest", "and", "platform", "information", "by", "contacting", "the", "registry" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/distribution.go#L14-L26
149,806
ory/dockertest
docker/pkg/system/lcow.go
IsOSSupported
func IsOSSupported(os string) bool { if runtime.GOOS == os { return true } if LCOWSupported() && os == "linux" { return true } return false }
go
func IsOSSupported(os string) bool { if runtime.GOOS == os { return true } if LCOWSupported() && os == "linux" { return true } return false }
[ "func", "IsOSSupported", "(", "os", "string", ")", "bool", "{", "if", "runtime", ".", "GOOS", "==", "os", "{", "return", "true", "\n", "}", "\n", "if", "LCOWSupported", "(", ")", "&&", "os", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsOSSupported determines if an operating system is supported by the host
[ "IsOSSupported", "determines", "if", "an", "operating", "system", "is", "supported", "by", "the", "host" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/pkg/system/lcow.go#L61-L69
149,807
ory/dockertest
docker/event.go
AddEventListener
func (c *Client) AddEventListener(listener chan<- *APIEvents) error { var err error if !c.eventMonitor.isEnabled() { err = c.eventMonitor.enableEventMonitoring(c) if err != nil { return err } } return c.eventMonitor.addListener(listener) }
go
func (c *Client) AddEventListener(listener chan<- *APIEvents) error { var err error if !c.eventMonitor.isEnabled() { err = c.eventMonitor.enableEventMonitoring(c) if err != nil { return err } } return c.eventMonitor.addListener(listener) }
[ "func", "(", "c", "*", "Client", ")", "AddEventListener", "(", "listener", "chan", "<-", "*", "APIEvents", ")", "error", "{", "var", "err", "error", "\n", "if", "!", "c", ".", "eventMonitor", ".", "isEnabled", "(", ")", "{", "err", "=", "c", ".", "eventMonitor", ".", "enableEventMonitoring", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "c", ".", "eventMonitor", ".", "addListener", "(", "listener", ")", "\n", "}" ]
// AddEventListener adds a new listener to container events in the Docker API. // // The parameter is a channel through which events will be sent.
[ "AddEventListener", "adds", "a", "new", "listener", "to", "container", "events", "in", "the", "Docker", "API", ".", "The", "parameter", "is", "a", "channel", "through", "which", "events", "will", "be", "sent", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/event.go#L95-L104
149,808
ory/dockertest
docker/event.go
RemoveEventListener
func (c *Client) RemoveEventListener(listener chan *APIEvents) error { err := c.eventMonitor.removeListener(listener) if err != nil { return err } if c.eventMonitor.listernersCount() == 0 { c.eventMonitor.disableEventMonitoring() } return nil }
go
func (c *Client) RemoveEventListener(listener chan *APIEvents) error { err := c.eventMonitor.removeListener(listener) if err != nil { return err } if c.eventMonitor.listernersCount() == 0 { c.eventMonitor.disableEventMonitoring() } return nil }
[ "func", "(", "c", "*", "Client", ")", "RemoveEventListener", "(", "listener", "chan", "*", "APIEvents", ")", "error", "{", "err", ":=", "c", ".", "eventMonitor", ".", "removeListener", "(", "listener", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "c", ".", "eventMonitor", ".", "listernersCount", "(", ")", "==", "0", "{", "c", ".", "eventMonitor", ".", "disableEventMonitoring", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveEventListener removes a listener from the monitor.
[ "RemoveEventListener", "removes", "a", "listener", "from", "the", "monitor", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/event.go#L107-L116
149,809
ory/dockertest
docker/event.go
transformEvent
func transformEvent(event *APIEvents) { // if event version is <= 1.21 there will be no Action and no Type if event.Action == "" && event.Type == "" { event.Action = event.Status event.Actor.ID = event.ID event.Actor.Attributes = map[string]string{} switch event.Status { case "delete", "import", "pull", "push", "tag", "untag": event.Type = "image" default: event.Type = "container" if event.From != "" { event.Actor.Attributes["image"] = event.From } } } else { if event.Status == "" { if event.Type == "image" || event.Type == "container" { event.Status = event.Action } else { // Because just the Status has been overloaded with different Types // if an event is not for an image or a container, we prepend the type // to avoid problems for people relying on actions being only for // images and containers event.Status = event.Type + ":" + event.Action } } if event.ID == "" { event.ID = event.Actor.ID } if event.From == "" { event.From = event.Actor.Attributes["image"] } } }
go
func transformEvent(event *APIEvents) { // if event version is <= 1.21 there will be no Action and no Type if event.Action == "" && event.Type == "" { event.Action = event.Status event.Actor.ID = event.ID event.Actor.Attributes = map[string]string{} switch event.Status { case "delete", "import", "pull", "push", "tag", "untag": event.Type = "image" default: event.Type = "container" if event.From != "" { event.Actor.Attributes["image"] = event.From } } } else { if event.Status == "" { if event.Type == "image" || event.Type == "container" { event.Status = event.Action } else { // Because just the Status has been overloaded with different Types // if an event is not for an image or a container, we prepend the type // to avoid problems for people relying on actions being only for // images and containers event.Status = event.Type + ":" + event.Action } } if event.ID == "" { event.ID = event.Actor.ID } if event.From == "" { event.From = event.Actor.Attributes["image"] } } }
[ "func", "transformEvent", "(", "event", "*", "APIEvents", ")", "{", "// if event version is <= 1.21 there will be no Action and no Type", "if", "event", ".", "Action", "==", "\"", "\"", "&&", "event", ".", "Type", "==", "\"", "\"", "{", "event", ".", "Action", "=", "event", ".", "Status", "\n", "event", ".", "Actor", ".", "ID", "=", "event", ".", "ID", "\n", "event", ".", "Actor", ".", "Attributes", "=", "map", "[", "string", "]", "string", "{", "}", "\n", "switch", "event", ".", "Status", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "event", ".", "Type", "=", "\"", "\"", "\n", "default", ":", "event", ".", "Type", "=", "\"", "\"", "\n", "if", "event", ".", "From", "!=", "\"", "\"", "{", "event", ".", "Actor", ".", "Attributes", "[", "\"", "\"", "]", "=", "event", ".", "From", "\n", "}", "\n", "}", "\n", "}", "else", "{", "if", "event", ".", "Status", "==", "\"", "\"", "{", "if", "event", ".", "Type", "==", "\"", "\"", "||", "event", ".", "Type", "==", "\"", "\"", "{", "event", ".", "Status", "=", "event", ".", "Action", "\n", "}", "else", "{", "// Because just the Status has been overloaded with different Types", "// if an event is not for an image or a container, we prepend the type", "// to avoid problems for people relying on actions being only for", "// images and containers", "event", ".", "Status", "=", "event", ".", "Type", "+", "\"", "\"", "+", "event", ".", "Action", "\n", "}", "\n", "}", "\n", "if", "event", ".", "ID", "==", "\"", "\"", "{", "event", ".", "ID", "=", "event", ".", "Actor", ".", "ID", "\n", "}", "\n", "if", "event", ".", "From", "==", "\"", "\"", "{", "event", ".", "From", "=", "event", ".", "Actor", ".", "Attributes", "[", "\"", "\"", "]", "\n", "}", "\n", "}", "\n", "}" ]
// transformEvent takes an event and determines what version it is from // then populates both versions of the event
[ "transformEvent", "takes", "an", "event", "and", "determines", "what", "version", "it", "is", "from", "then", "populates", "both", "versions", "of", "the", "event" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/event.go#L376-L410
149,810
ory/dockertest
docker/container.go
Proto
func (p Port) Proto() string { parts := strings.Split(string(p), "/") if len(parts) == 1 { return "tcp" } return parts[1] }
go
func (p Port) Proto() string { parts := strings.Split(string(p), "/") if len(parts) == 1 { return "tcp" } return parts[1] }
[ "func", "(", "p", "Port", ")", "Proto", "(", ")", "string", "{", "parts", ":=", "strings", ".", "Split", "(", "string", "(", "p", ")", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "==", "1", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "parts", "[", "1", "]", "\n", "}" ]
// Proto returns the name of the protocol.
[ "Proto", "returns", "the", "name", "of", "the", "protocol", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/container.go#L109-L115
149,811
ory/dockertest
docker/container.go
String
func (s *State) String() string { if s.Running { if s.Paused { return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) } if s.Restarting { return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) } return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) } if s.RemovalInProgress { return "Removal In Progress" } if s.Dead { return "Dead" } if s.StartedAt.IsZero() { return "Created" } if s.FinishedAt.IsZero() { return "" } return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) }
go
func (s *State) String() string { if s.Running { if s.Paused { return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) } if s.Restarting { return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) } return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) } if s.RemovalInProgress { return "Removal In Progress" } if s.Dead { return "Dead" } if s.StartedAt.IsZero() { return "Created" } if s.FinishedAt.IsZero() { return "" } return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) }
[ "func", "(", "s", "*", "State", ")", "String", "(", ")", "string", "{", "if", "s", ".", "Running", "{", "if", "s", ".", "Paused", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "units", ".", "HumanDuration", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Sub", "(", "s", ".", "StartedAt", ")", ")", ")", "\n", "}", "\n", "if", "s", ".", "Restarting", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "ExitCode", ",", "units", ".", "HumanDuration", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Sub", "(", "s", ".", "FinishedAt", ")", ")", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "units", ".", "HumanDuration", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Sub", "(", "s", ".", "StartedAt", ")", ")", ")", "\n", "}", "\n\n", "if", "s", ".", "RemovalInProgress", "{", "return", "\"", "\"", "\n", "}", "\n\n", "if", "s", ".", "Dead", "{", "return", "\"", "\"", "\n", "}", "\n\n", "if", "s", ".", "StartedAt", ".", "IsZero", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n\n", "if", "s", ".", "FinishedAt", ".", "IsZero", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "ExitCode", ",", "units", ".", "HumanDuration", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Sub", "(", "s", ".", "FinishedAt", ")", ")", ")", "\n", "}" ]
// String returns a human-readable description of the state
[ "String", "returns", "a", "human", "-", "readable", "description", "of", "the", "state" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/container.go#L150-L179
149,812
ory/dockertest
docker/container.go
StateString
func (s *State) StateString() string { if s.Running { if s.Paused { return "paused" } if s.Restarting { return "restarting" } return "running" } if s.Dead { return "dead" } if s.StartedAt.IsZero() { return "created" } return "exited" }
go
func (s *State) StateString() string { if s.Running { if s.Paused { return "paused" } if s.Restarting { return "restarting" } return "running" } if s.Dead { return "dead" } if s.StartedAt.IsZero() { return "created" } return "exited" }
[ "func", "(", "s", "*", "State", ")", "StateString", "(", ")", "string", "{", "if", "s", ".", "Running", "{", "if", "s", ".", "Paused", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "s", ".", "Restarting", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "}", "\n\n", "if", "s", ".", "Dead", "{", "return", "\"", "\"", "\n", "}", "\n\n", "if", "s", ".", "StartedAt", ".", "IsZero", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "\"", "\"", "\n", "}" ]
// StateString returns a single string to describe state
[ "StateString", "returns", "a", "single", "string", "to", "describe", "state" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/container.go#L182-L202
149,813
ory/dockertest
docker/container.go
PortMappingAPI
func (settings *NetworkSettings) PortMappingAPI() []APIPort { var mapping []APIPort for port, bindings := range settings.Ports { p, _ := parsePort(port.Port()) if len(bindings) == 0 { mapping = append(mapping, APIPort{ PrivatePort: int64(p), Type: port.Proto(), }) continue } for _, binding := range bindings { p, _ := parsePort(port.Port()) h, _ := parsePort(binding.HostPort) mapping = append(mapping, APIPort{ PrivatePort: int64(p), PublicPort: int64(h), Type: port.Proto(), IP: binding.HostIP, }) } } return mapping }
go
func (settings *NetworkSettings) PortMappingAPI() []APIPort { var mapping []APIPort for port, bindings := range settings.Ports { p, _ := parsePort(port.Port()) if len(bindings) == 0 { mapping = append(mapping, APIPort{ PrivatePort: int64(p), Type: port.Proto(), }) continue } for _, binding := range bindings { p, _ := parsePort(port.Port()) h, _ := parsePort(binding.HostPort) mapping = append(mapping, APIPort{ PrivatePort: int64(p), PublicPort: int64(h), Type: port.Proto(), IP: binding.HostIP, }) } } return mapping }
[ "func", "(", "settings", "*", "NetworkSettings", ")", "PortMappingAPI", "(", ")", "[", "]", "APIPort", "{", "var", "mapping", "[", "]", "APIPort", "\n", "for", "port", ",", "bindings", ":=", "range", "settings", ".", "Ports", "{", "p", ",", "_", ":=", "parsePort", "(", "port", ".", "Port", "(", ")", ")", "\n", "if", "len", "(", "bindings", ")", "==", "0", "{", "mapping", "=", "append", "(", "mapping", ",", "APIPort", "{", "PrivatePort", ":", "int64", "(", "p", ")", ",", "Type", ":", "port", ".", "Proto", "(", ")", ",", "}", ")", "\n", "continue", "\n", "}", "\n", "for", "_", ",", "binding", ":=", "range", "bindings", "{", "p", ",", "_", ":=", "parsePort", "(", "port", ".", "Port", "(", ")", ")", "\n", "h", ",", "_", ":=", "parsePort", "(", "binding", ".", "HostPort", ")", "\n", "mapping", "=", "append", "(", "mapping", ",", "APIPort", "{", "PrivatePort", ":", "int64", "(", "p", ")", ",", "PublicPort", ":", "int64", "(", "h", ")", ",", "Type", ":", "port", ".", "Proto", "(", ")", ",", "IP", ":", "binding", ".", "HostIP", ",", "}", ")", "\n", "}", "\n", "}", "\n", "return", "mapping", "\n", "}" ]
// PortMappingAPI translates the port mappings as contained in NetworkSettings // into the format in which they would appear when returned by the API
[ "PortMappingAPI", "translates", "the", "port", "mappings", "as", "contained", "in", "NetworkSettings", "into", "the", "format", "in", "which", "they", "would", "appear", "when", "returned", "by", "the", "API" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/container.go#L253-L276
149,814
ory/dockertest
docker/client.go
NewClient
func NewClient(endpoint string) (*Client, error) { client, err := NewVersionedClient(endpoint, "") if err != nil { return nil, err } client.SkipServerVersionCheck = true return client, nil }
go
func NewClient(endpoint string) (*Client, error) { client, err := NewVersionedClient(endpoint, "") if err != nil { return nil, err } client.SkipServerVersionCheck = true return client, nil }
[ "func", "NewClient", "(", "endpoint", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "client", ",", "err", ":=", "NewVersionedClient", "(", "endpoint", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "client", ".", "SkipServerVersionCheck", "=", "true", "\n", "return", "client", ",", "nil", "\n", "}" ]
// NewClient returns a Client instance ready for communication with the given // server endpoint. It will use the latest remote API version available in the // server.
[ "NewClient", "returns", "a", "Client", "instance", "ready", "for", "communication", "with", "the", "given", "server", "endpoint", ".", "It", "will", "use", "the", "latest", "remote", "API", "version", "available", "in", "the", "server", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L165-L172
149,815
ory/dockertest
docker/client.go
NewTLSClient
func NewTLSClient(endpoint string, cert, key, ca string) (*Client, error) { client, err := NewVersionedTLSClient(endpoint, cert, key, ca, "") if err != nil { return nil, err } client.SkipServerVersionCheck = true return client, nil }
go
func NewTLSClient(endpoint string, cert, key, ca string) (*Client, error) { client, err := NewVersionedTLSClient(endpoint, cert, key, ca, "") if err != nil { return nil, err } client.SkipServerVersionCheck = true return client, nil }
[ "func", "NewTLSClient", "(", "endpoint", "string", ",", "cert", ",", "key", ",", "ca", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "client", ",", "err", ":=", "NewVersionedTLSClient", "(", "endpoint", ",", "cert", ",", "key", ",", "ca", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "client", ".", "SkipServerVersionCheck", "=", "true", "\n", "return", "client", ",", "nil", "\n", "}" ]
// NewTLSClient returns a Client instance ready for TLS communications with the givens // server endpoint, key and certificates . It will use the latest remote API version // available in the server.
[ "NewTLSClient", "returns", "a", "Client", "instance", "ready", "for", "TLS", "communications", "with", "the", "givens", "server", "endpoint", "key", "and", "certificates", ".", "It", "will", "use", "the", "latest", "remote", "API", "version", "available", "in", "the", "server", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L177-L184
149,816
ory/dockertest
docker/client.go
NewVersionedClient
func NewVersionedClient(endpoint string, apiVersionString string) (*Client, error) { u, err := parseEndpoint(endpoint, false) if err != nil { return nil, err } var requestedAPIVersion APIVersion if strings.Contains(apiVersionString, ".") { requestedAPIVersion, err = NewAPIVersion(apiVersionString) if err != nil { return nil, err } } c := &Client{ HTTPClient: defaultClient(), Dialer: &net.Dialer{}, endpoint: endpoint, endpointURL: u, eventMonitor: new(eventMonitoringState), requestedAPIVersion: requestedAPIVersion, } c.initializeNativeClient(defaultTransport) return c, nil }
go
func NewVersionedClient(endpoint string, apiVersionString string) (*Client, error) { u, err := parseEndpoint(endpoint, false) if err != nil { return nil, err } var requestedAPIVersion APIVersion if strings.Contains(apiVersionString, ".") { requestedAPIVersion, err = NewAPIVersion(apiVersionString) if err != nil { return nil, err } } c := &Client{ HTTPClient: defaultClient(), Dialer: &net.Dialer{}, endpoint: endpoint, endpointURL: u, eventMonitor: new(eventMonitoringState), requestedAPIVersion: requestedAPIVersion, } c.initializeNativeClient(defaultTransport) return c, nil }
[ "func", "NewVersionedClient", "(", "endpoint", "string", ",", "apiVersionString", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "u", ",", "err", ":=", "parseEndpoint", "(", "endpoint", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "requestedAPIVersion", "APIVersion", "\n", "if", "strings", ".", "Contains", "(", "apiVersionString", ",", "\"", "\"", ")", "{", "requestedAPIVersion", ",", "err", "=", "NewAPIVersion", "(", "apiVersionString", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "c", ":=", "&", "Client", "{", "HTTPClient", ":", "defaultClient", "(", ")", ",", "Dialer", ":", "&", "net", ".", "Dialer", "{", "}", ",", "endpoint", ":", "endpoint", ",", "endpointURL", ":", "u", ",", "eventMonitor", ":", "new", "(", "eventMonitoringState", ")", ",", "requestedAPIVersion", ":", "requestedAPIVersion", ",", "}", "\n", "c", ".", "initializeNativeClient", "(", "defaultTransport", ")", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewVersionedClient returns a Client instance ready for communication with // the given server endpoint, using a specific remote API version.
[ "NewVersionedClient", "returns", "a", "Client", "instance", "ready", "for", "communication", "with", "the", "given", "server", "endpoint", "using", "a", "specific", "remote", "API", "version", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L200-L222
149,817
ory/dockertest
docker/client.go
NewVersionedTLSClient
func NewVersionedTLSClient(endpoint string, cert, key, ca, apiVersionString string) (*Client, error) { var certPEMBlock []byte var keyPEMBlock []byte var caPEMCert []byte if _, err := os.Stat(cert); !os.IsNotExist(err) { certPEMBlock, err = ioutil.ReadFile(cert) if err != nil { return nil, err } } if _, err := os.Stat(key); !os.IsNotExist(err) { keyPEMBlock, err = ioutil.ReadFile(key) if err != nil { return nil, err } } if _, err := os.Stat(ca); !os.IsNotExist(err) { caPEMCert, err = ioutil.ReadFile(ca) if err != nil { return nil, err } } return NewVersionedTLSClientFromBytes(endpoint, certPEMBlock, keyPEMBlock, caPEMCert, apiVersionString) }
go
func NewVersionedTLSClient(endpoint string, cert, key, ca, apiVersionString string) (*Client, error) { var certPEMBlock []byte var keyPEMBlock []byte var caPEMCert []byte if _, err := os.Stat(cert); !os.IsNotExist(err) { certPEMBlock, err = ioutil.ReadFile(cert) if err != nil { return nil, err } } if _, err := os.Stat(key); !os.IsNotExist(err) { keyPEMBlock, err = ioutil.ReadFile(key) if err != nil { return nil, err } } if _, err := os.Stat(ca); !os.IsNotExist(err) { caPEMCert, err = ioutil.ReadFile(ca) if err != nil { return nil, err } } return NewVersionedTLSClientFromBytes(endpoint, certPEMBlock, keyPEMBlock, caPEMCert, apiVersionString) }
[ "func", "NewVersionedTLSClient", "(", "endpoint", "string", ",", "cert", ",", "key", ",", "ca", ",", "apiVersionString", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "var", "certPEMBlock", "[", "]", "byte", "\n", "var", "keyPEMBlock", "[", "]", "byte", "\n", "var", "caPEMCert", "[", "]", "byte", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "cert", ")", ";", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "certPEMBlock", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "cert", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "key", ")", ";", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "keyPEMBlock", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "ca", ")", ";", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "caPEMCert", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "ca", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "NewVersionedTLSClientFromBytes", "(", "endpoint", ",", "certPEMBlock", ",", "keyPEMBlock", ",", "caPEMCert", ",", "apiVersionString", ")", "\n", "}" ]
// NewVersionedTLSClient returns a Client instance ready for TLS communications with the givens // server endpoint, key and certificates, using a specific remote API version.
[ "NewVersionedTLSClient", "returns", "a", "Client", "instance", "ready", "for", "TLS", "communications", "with", "the", "givens", "server", "endpoint", "key", "and", "certificates", "using", "a", "specific", "remote", "API", "version", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L239-L262
149,818
ory/dockertest
docker/client.go
SetTimeout
func (c *Client) SetTimeout(t time.Duration) { if c.HTTPClient != nil { c.HTTPClient.Timeout = t } }
go
func (c *Client) SetTimeout(t time.Duration) { if c.HTTPClient != nil { c.HTTPClient.Timeout = t } }
[ "func", "(", "c", "*", "Client", ")", "SetTimeout", "(", "t", "time", ".", "Duration", ")", "{", "if", "c", ".", "HTTPClient", "!=", "nil", "{", "c", ".", "HTTPClient", ".", "Timeout", "=", "t", "\n", "}", "\n", "}" ]
// SetTimeout takes a timeout and applies it to the HTTPClient. It should not // be called concurrently with any other Client methods.
[ "SetTimeout", "takes", "a", "timeout", "and", "applies", "it", "to", "the", "HTTPClient", ".", "It", "should", "not", "be", "called", "concurrently", "with", "any", "other", "Client", "methods", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L355-L359
149,819
ory/dockertest
docker/client.go
chooseError
func chooseError(ctx context.Context, err error) error { select { case <-ctx.Done(): return ctx.Err() default: return err } }
go
func chooseError(ctx context.Context, err error) error { select { case <-ctx.Done(): return ctx.Err() default: return err } }
[ "func", "chooseError", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "error", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "return", "err", "\n", "}", "\n", "}" ]
// if error in context, return that instead of generic http error
[ "if", "error", "in", "context", "return", "that", "instead", "of", "generic", "http", "error" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L511-L518
149,820
ory/dockertest
docker/client.go
getFakeNativeURL
func (c *Client) getFakeNativeURL(path string) string { u := *c.endpointURL // Copy. // Override URL so that net/http will not complain. u.Scheme = "http" u.Host = "unix.sock" // Doesn't matter what this is - it's not used. u.Path = "" urlStr := strings.TrimRight(u.String(), "/") if c.requestedAPIVersion != nil { return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, path) } return fmt.Sprintf("%s%s", urlStr, path) }
go
func (c *Client) getFakeNativeURL(path string) string { u := *c.endpointURL // Copy. // Override URL so that net/http will not complain. u.Scheme = "http" u.Host = "unix.sock" // Doesn't matter what this is - it's not used. u.Path = "" urlStr := strings.TrimRight(u.String(), "/") if c.requestedAPIVersion != nil { return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, path) } return fmt.Sprintf("%s%s", urlStr, path) }
[ "func", "(", "c", "*", "Client", ")", "getFakeNativeURL", "(", "path", "string", ")", "string", "{", "u", ":=", "*", "c", ".", "endpointURL", "// Copy.", "\n\n", "// Override URL so that net/http will not complain.", "u", ".", "Scheme", "=", "\"", "\"", "\n", "u", ".", "Host", "=", "\"", "\"", "// Doesn't matter what this is - it's not used.", "\n", "u", ".", "Path", "=", "\"", "\"", "\n", "urlStr", ":=", "strings", ".", "TrimRight", "(", "u", ".", "String", "(", ")", ",", "\"", "\"", ")", "\n", "if", "c", ".", "requestedAPIVersion", "!=", "nil", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "urlStr", ",", "c", ".", "requestedAPIVersion", ",", "path", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "urlStr", ",", "path", ")", "\n", "}" ]
// getFakeNativeURL returns the URL needed to make an HTTP request over a UNIX // domain socket to the given path.
[ "getFakeNativeURL", "returns", "the", "URL", "needed", "to", "make", "an", "HTTP", "request", "over", "a", "UNIX", "domain", "socket", "to", "the", "given", "path", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L860-L872
149,821
ory/dockertest
docker/client.go
defaultTransport
func defaultTransport() *http.Transport { transport := defaultPooledTransport() transport.DisableKeepAlives = true transport.MaxIdleConnsPerHost = -1 return transport }
go
func defaultTransport() *http.Transport { transport := defaultPooledTransport() transport.DisableKeepAlives = true transport.MaxIdleConnsPerHost = -1 return transport }
[ "func", "defaultTransport", "(", ")", "*", "http", ".", "Transport", "{", "transport", ":=", "defaultPooledTransport", "(", ")", "\n", "transport", ".", "DisableKeepAlives", "=", "true", "\n", "transport", ".", "MaxIdleConnsPerHost", "=", "-", "1", "\n", "return", "transport", "\n", "}" ]
// defaultTransport returns a new http.Transport with similar default values to // http.DefaultTransport, but with idle connections and keepalives disabled.
[ "defaultTransport", "returns", "a", "new", "http", ".", "Transport", "with", "similar", "default", "values", "to", "http", ".", "DefaultTransport", "but", "with", "idle", "connections", "and", "keepalives", "disabled", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client.go#L1058-L1063
149,822
ory/dockertest
docker/env.go
Get
func (env *Env) Get(key string) (value string) { return env.Map()[key] }
go
func (env *Env) Get(key string) (value string) { return env.Map()[key] }
[ "func", "(", "env", "*", "Env", ")", "Get", "(", "key", "string", ")", "(", "value", "string", ")", "{", "return", "env", ".", "Map", "(", ")", "[", "key", "]", "\n", "}" ]
// Get returns the string value of the given key.
[ "Get", "returns", "the", "string", "value", "of", "the", "given", "key", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L19-L21
149,823
ory/dockertest
docker/env.go
Exists
func (env *Env) Exists(key string) bool { _, exists := env.Map()[key] return exists }
go
func (env *Env) Exists(key string) bool { _, exists := env.Map()[key] return exists }
[ "func", "(", "env", "*", "Env", ")", "Exists", "(", "key", "string", ")", "bool", "{", "_", ",", "exists", ":=", "env", ".", "Map", "(", ")", "[", "key", "]", "\n", "return", "exists", "\n", "}" ]
// Exists checks whether the given key is defined in the internal Env // representation.
[ "Exists", "checks", "whether", "the", "given", "key", "is", "defined", "in", "the", "internal", "Env", "representation", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L25-L28
149,824
ory/dockertest
docker/env.go
GetBool
func (env *Env) GetBool(key string) (value bool) { s := strings.ToLower(strings.Trim(env.Get(key), " \t")) if s == "" || s == "0" || s == "no" || s == "false" || s == "none" { return false } return true }
go
func (env *Env) GetBool(key string) (value bool) { s := strings.ToLower(strings.Trim(env.Get(key), " \t")) if s == "" || s == "0" || s == "no" || s == "false" || s == "none" { return false } return true }
[ "func", "(", "env", "*", "Env", ")", "GetBool", "(", "key", "string", ")", "(", "value", "bool", ")", "{", "s", ":=", "strings", ".", "ToLower", "(", "strings", ".", "Trim", "(", "env", ".", "Get", "(", "key", ")", ",", "\"", "\\t", "\"", ")", ")", "\n", "if", "s", "==", "\"", "\"", "||", "s", "==", "\"", "\"", "||", "s", "==", "\"", "\"", "||", "s", "==", "\"", "\"", "||", "s", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// GetBool returns a boolean representation of the given key. The key is false // whenever its value if 0, no, false, none or an empty string. Any other value // will be interpreted as true.
[ "GetBool", "returns", "a", "boolean", "representation", "of", "the", "given", "key", ".", "The", "key", "is", "false", "whenever", "its", "value", "if", "0", "no", "false", "none", "or", "an", "empty", "string", ".", "Any", "other", "value", "will", "be", "interpreted", "as", "true", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L33-L39
149,825
ory/dockertest
docker/env.go
SetBool
func (env *Env) SetBool(key string, value bool) { if value { env.Set(key, "1") } else { env.Set(key, "0") } }
go
func (env *Env) SetBool(key string, value bool) { if value { env.Set(key, "1") } else { env.Set(key, "0") } }
[ "func", "(", "env", "*", "Env", ")", "SetBool", "(", "key", "string", ",", "value", "bool", ")", "{", "if", "value", "{", "env", ".", "Set", "(", "key", ",", "\"", "\"", ")", "\n", "}", "else", "{", "env", ".", "Set", "(", "key", ",", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// SetBool defines a boolean value to the given key.
[ "SetBool", "defines", "a", "boolean", "value", "to", "the", "given", "key", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L42-L48
149,826
ory/dockertest
docker/env.go
GetInt
func (env *Env) GetInt(key string) int { return int(env.GetInt64(key)) }
go
func (env *Env) GetInt(key string) int { return int(env.GetInt64(key)) }
[ "func", "(", "env", "*", "Env", ")", "GetInt", "(", "key", "string", ")", "int", "{", "return", "int", "(", "env", ".", "GetInt64", "(", "key", ")", ")", "\n", "}" ]
// GetInt returns the value of the provided key, converted to int. // // It the value cannot be represented as an integer, it returns -1.
[ "GetInt", "returns", "the", "value", "of", "the", "provided", "key", "converted", "to", "int", ".", "It", "the", "value", "cannot", "be", "represented", "as", "an", "integer", "it", "returns", "-", "1", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L53-L55
149,827
ory/dockertest
docker/env.go
SetInt
func (env *Env) SetInt(key string, value int) { env.Set(key, strconv.Itoa(value)) }
go
func (env *Env) SetInt(key string, value int) { env.Set(key, strconv.Itoa(value)) }
[ "func", "(", "env", "*", "Env", ")", "SetInt", "(", "key", "string", ",", "value", "int", ")", "{", "env", ".", "Set", "(", "key", ",", "strconv", ".", "Itoa", "(", "value", ")", ")", "\n", "}" ]
// SetInt defines an integer value to the given key.
[ "SetInt", "defines", "an", "integer", "value", "to", "the", "given", "key", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L58-L60
149,828
ory/dockertest
docker/env.go
GetInt64
func (env *Env) GetInt64(key string) int64 { s := strings.Trim(env.Get(key), " \t") val, err := strconv.ParseInt(s, 10, 64) if err != nil { return -1 } return val }
go
func (env *Env) GetInt64(key string) int64 { s := strings.Trim(env.Get(key), " \t") val, err := strconv.ParseInt(s, 10, 64) if err != nil { return -1 } return val }
[ "func", "(", "env", "*", "Env", ")", "GetInt64", "(", "key", "string", ")", "int64", "{", "s", ":=", "strings", ".", "Trim", "(", "env", ".", "Get", "(", "key", ")", ",", "\"", "\\t", "\"", ")", "\n", "val", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "s", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n", "return", "val", "\n", "}" ]
// GetInt64 returns the value of the provided key, converted to int64. // // It the value cannot be represented as an integer, it returns -1.
[ "GetInt64", "returns", "the", "value", "of", "the", "provided", "key", "converted", "to", "int64", ".", "It", "the", "value", "cannot", "be", "represented", "as", "an", "integer", "it", "returns", "-", "1", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L65-L72
149,829
ory/dockertest
docker/env.go
GetList
func (env *Env) GetList(key string) []string { sval := env.Get(key) if sval == "" { return nil } var l []string if err := json.Unmarshal([]byte(sval), &l); err != nil { l = append(l, sval) } return l }
go
func (env *Env) GetList(key string) []string { sval := env.Get(key) if sval == "" { return nil } var l []string if err := json.Unmarshal([]byte(sval), &l); err != nil { l = append(l, sval) } return l }
[ "func", "(", "env", "*", "Env", ")", "GetList", "(", "key", "string", ")", "[", "]", "string", "{", "sval", ":=", "env", ".", "Get", "(", "key", ")", "\n", "if", "sval", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "var", "l", "[", "]", "string", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "sval", ")", ",", "&", "l", ")", ";", "err", "!=", "nil", "{", "l", "=", "append", "(", "l", ",", "sval", ")", "\n", "}", "\n", "return", "l", "\n", "}" ]
// GetList returns a list of strings matching the provided key. It handles the // list as a JSON representation of a list of strings. // // If the given key matches to a single string, it will return a list // containing only the value that matches the key.
[ "GetList", "returns", "a", "list", "of", "strings", "matching", "the", "provided", "key", ".", "It", "handles", "the", "list", "as", "a", "JSON", "representation", "of", "a", "list", "of", "strings", ".", "If", "the", "given", "key", "matches", "to", "a", "single", "string", "it", "will", "return", "a", "list", "containing", "only", "the", "value", "that", "matches", "the", "key", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L106-L116
149,830
ory/dockertest
docker/env.go
SetList
func (env *Env) SetList(key string, value []string) error { return env.SetJSON(key, value) }
go
func (env *Env) SetList(key string, value []string) error { return env.SetJSON(key, value) }
[ "func", "(", "env", "*", "Env", ")", "SetList", "(", "key", "string", ",", "value", "[", "]", "string", ")", "error", "{", "return", "env", ".", "SetJSON", "(", "key", ",", "value", ")", "\n", "}" ]
// SetList stores the given list in the provided key, after serializing it to // JSON format.
[ "SetList", "stores", "the", "given", "list", "in", "the", "provided", "key", "after", "serializing", "it", "to", "JSON", "format", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L120-L122
149,831
ory/dockertest
docker/env.go
Set
func (env *Env) Set(key, value string) { *env = append(*env, key+"="+value) }
go
func (env *Env) Set(key, value string) { *env = append(*env, key+"="+value) }
[ "func", "(", "env", "*", "Env", ")", "Set", "(", "key", ",", "value", "string", ")", "{", "*", "env", "=", "append", "(", "*", "env", ",", "key", "+", "\"", "\"", "+", "value", ")", "\n", "}" ]
// Set defines the value of a key to the given string.
[ "Set", "defines", "the", "value", "of", "a", "key", "to", "the", "given", "string", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/env.go#L125-L127
149,832
ory/dockertest
docker/client_windows.go
initializeNativeClient
func (c *Client) initializeNativeClient(trFunc func() *http.Transport) { if c.endpointURL.Scheme != namedPipeProtocol { return } namedPipePath := c.endpointURL.Path dialFunc := func(network, addr string) (net.Conn, error) { timeout := namedPipeConnectTimeout return winio.DialPipe(namedPipePath, &timeout) } tr := trFunc() tr.Dial = dialFunc tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return dialFunc(network, addr) } c.Dialer = &pipeDialer{dialFunc} c.HTTPClient.Transport = tr }
go
func (c *Client) initializeNativeClient(trFunc func() *http.Transport) { if c.endpointURL.Scheme != namedPipeProtocol { return } namedPipePath := c.endpointURL.Path dialFunc := func(network, addr string) (net.Conn, error) { timeout := namedPipeConnectTimeout return winio.DialPipe(namedPipePath, &timeout) } tr := trFunc() tr.Dial = dialFunc tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return dialFunc(network, addr) } c.Dialer = &pipeDialer{dialFunc} c.HTTPClient.Transport = tr }
[ "func", "(", "c", "*", "Client", ")", "initializeNativeClient", "(", "trFunc", "func", "(", ")", "*", "http", ".", "Transport", ")", "{", "if", "c", ".", "endpointURL", ".", "Scheme", "!=", "namedPipeProtocol", "{", "return", "\n", "}", "\n", "namedPipePath", ":=", "c", ".", "endpointURL", ".", "Path", "\n", "dialFunc", ":=", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "timeout", ":=", "namedPipeConnectTimeout", "\n", "return", "winio", ".", "DialPipe", "(", "namedPipePath", ",", "&", "timeout", ")", "\n", "}", "\n", "tr", ":=", "trFunc", "(", ")", "\n", "tr", ".", "Dial", "=", "dialFunc", "\n", "tr", ".", "DialContext", "=", "func", "(", "ctx", "context", ".", "Context", ",", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "dialFunc", "(", "network", ",", "addr", ")", "\n", "}", "\n", "c", ".", "Dialer", "=", "&", "pipeDialer", "{", "dialFunc", "}", "\n", "c", ".", "HTTPClient", ".", "Transport", "=", "tr", "\n", "}" ]
// initializeNativeClient initializes the native Named Pipe client for Windows
[ "initializeNativeClient", "initializes", "the", "native", "Named", "Pipe", "client", "for", "Windows" ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/client_windows.go#L29-L45
149,833
ory/dockertest
docker/auth.go
NewAuthConfigurationsFromFile
func NewAuthConfigurationsFromFile(path string) (*AuthConfigurations, error) { r, err := os.Open(path) if err != nil { return nil, err } return NewAuthConfigurations(r) }
go
func NewAuthConfigurationsFromFile(path string) (*AuthConfigurations, error) { r, err := os.Open(path) if err != nil { return nil, err } return NewAuthConfigurations(r) }
[ "func", "NewAuthConfigurationsFromFile", "(", "path", "string", ")", "(", "*", "AuthConfigurations", ",", "error", ")", "{", "r", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "NewAuthConfigurations", "(", "r", ")", "\n", "}" ]
// NewAuthConfigurationsFromFile returns AuthConfigurations from a path containing JSON // in the same format as the .dockercfg file.
[ "NewAuthConfigurationsFromFile", "returns", "AuthConfigurations", "from", "a", "path", "containing", "JSON", "in", "the", "same", "format", "as", "the", ".", "dockercfg", "file", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/auth.go#L51-L57
149,834
ory/dockertest
docker/auth.go
authConfigs
func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) { c := &AuthConfigurations{ Configs: make(map[string]AuthConfiguration), } for reg, conf := range confs { if conf.Auth == "" { continue } data, err := base64.StdEncoding.DecodeString(conf.Auth) if err != nil { return nil, err } userpass := strings.SplitN(string(data), ":", 2) if len(userpass) != 2 { return nil, ErrCannotParseDockercfg } c.Configs[reg] = AuthConfiguration{ Email: conf.Email, Username: userpass[0], Password: userpass[1], ServerAddress: reg, } } return c, nil }
go
func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) { c := &AuthConfigurations{ Configs: make(map[string]AuthConfiguration), } for reg, conf := range confs { if conf.Auth == "" { continue } data, err := base64.StdEncoding.DecodeString(conf.Auth) if err != nil { return nil, err } userpass := strings.SplitN(string(data), ":", 2) if len(userpass) != 2 { return nil, ErrCannotParseDockercfg } c.Configs[reg] = AuthConfiguration{ Email: conf.Email, Username: userpass[0], Password: userpass[1], ServerAddress: reg, } } return c, nil }
[ "func", "authConfigs", "(", "confs", "map", "[", "string", "]", "dockerConfig", ")", "(", "*", "AuthConfigurations", ",", "error", ")", "{", "c", ":=", "&", "AuthConfigurations", "{", "Configs", ":", "make", "(", "map", "[", "string", "]", "AuthConfiguration", ")", ",", "}", "\n", "for", "reg", ",", "conf", ":=", "range", "confs", "{", "if", "conf", ".", "Auth", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "data", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "conf", ".", "Auth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "userpass", ":=", "strings", ".", "SplitN", "(", "string", "(", "data", ")", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "userpass", ")", "!=", "2", "{", "return", "nil", ",", "ErrCannotParseDockercfg", "\n", "}", "\n", "c", ".", "Configs", "[", "reg", "]", "=", "AuthConfiguration", "{", "Email", ":", "conf", ".", "Email", ",", "Username", ":", "userpass", "[", "0", "]", ",", "Password", ":", "userpass", "[", "1", "]", ",", "ServerAddress", ":", "reg", ",", "}", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// authConfigs converts a dockerConfigs map to a AuthConfigurations object.
[ "authConfigs", "converts", "a", "dockerConfigs", "map", "to", "a", "AuthConfigurations", "object", "." ]
56b367fe94ad17019ab80b91fe686218e65ce9fa
https://github.com/ory/dockertest/blob/56b367fe94ad17019ab80b91fe686218e65ce9fa/docker/auth.go#L127-L151
149,835
hyperhq/hyperd
server/server_unix.go
newServer
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) { var ( err error ls []net.Listener ) switch proto { case "fd": ls, err = listenFD(addr, s.cfg.TLSConfig) if err != nil { return nil, err } case "tcp": l, err := s.initTCPSocket(addr) if err != nil { return nil, err } ls = append(ls, l) case "unix": l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup) if err != nil { return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err) } ls = append(ls, l) default: return nil, fmt.Errorf("Invalid protocol format: %q", proto) } var res []*HTTPServer for _, l := range ls { res = append(res, &HTTPServer{ &http.Server{ Addr: addr, }, l, }) } return res, nil }
go
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) { var ( err error ls []net.Listener ) switch proto { case "fd": ls, err = listenFD(addr, s.cfg.TLSConfig) if err != nil { return nil, err } case "tcp": l, err := s.initTCPSocket(addr) if err != nil { return nil, err } ls = append(ls, l) case "unix": l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup) if err != nil { return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err) } ls = append(ls, l) default: return nil, fmt.Errorf("Invalid protocol format: %q", proto) } var res []*HTTPServer for _, l := range ls { res = append(res, &HTTPServer{ &http.Server{ Addr: addr, }, l, }) } return res, nil }
[ "func", "(", "s", "*", "Server", ")", "newServer", "(", "proto", ",", "addr", "string", ")", "(", "[", "]", "*", "HTTPServer", ",", "error", ")", "{", "var", "(", "err", "error", "\n", "ls", "[", "]", "net", ".", "Listener", "\n", ")", "\n", "switch", "proto", "{", "case", "\"", "\"", ":", "ls", ",", "err", "=", "listenFD", "(", "addr", ",", "s", ".", "cfg", ".", "TLSConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "case", "\"", "\"", ":", "l", ",", "err", ":=", "s", ".", "initTCPSocket", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ls", "=", "append", "(", "ls", ",", "l", ")", "\n", "case", "\"", "\"", ":", "l", ",", "err", ":=", "sockets", ".", "NewUnixSocket", "(", "addr", ",", "s", ".", "cfg", ".", "SocketGroup", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "addr", ",", "err", ")", "\n", "}", "\n", "ls", "=", "append", "(", "ls", ",", "l", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "proto", ")", "\n", "}", "\n", "var", "res", "[", "]", "*", "HTTPServer", "\n", "for", "_", ",", "l", ":=", "range", "ls", "{", "res", "=", "append", "(", "res", ",", "&", "HTTPServer", "{", "&", "http", ".", "Server", "{", "Addr", ":", "addr", ",", "}", ",", "l", ",", "}", ")", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// newServer sets up the required HTTPServers and does protocol specific checking. // newServer does not set any muxers, you should set it later to Handler field
[ "newServer", "sets", "up", "the", "required", "HTTPServers", "and", "does", "protocol", "specific", "checking", ".", "newServer", "does", "not", "set", "any", "muxers", "you", "should", "set", "it", "later", "to", "Handler", "field" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server_unix.go#L20-L56
149,836
hyperhq/hyperd
daemon/pod/servicediscovery.go
add
func (s *Services) add(newServs []*apitypes.UserService) error { var err error // check if adding service conflict with existing ones exist := make(map[serviceKey]bool, s.size()) for _, srv := range s.spec { exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] = true } for _, srv := range newServs { if exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] { err = fmt.Errorf("service %v conflicts with existing ones", newServs) s.Log(ERROR, err) return err } exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] = true } // if pod is running, convert service to patch and send to vm if s.p.IsRunning() { if err = s.commit(newServs, "add"); err != nil { return err } } s.spec = append(s.spec, newServs...) return nil }
go
func (s *Services) add(newServs []*apitypes.UserService) error { var err error // check if adding service conflict with existing ones exist := make(map[serviceKey]bool, s.size()) for _, srv := range s.spec { exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] = true } for _, srv := range newServs { if exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] { err = fmt.Errorf("service %v conflicts with existing ones", newServs) s.Log(ERROR, err) return err } exist[serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol}] = true } // if pod is running, convert service to patch and send to vm if s.p.IsRunning() { if err = s.commit(newServs, "add"); err != nil { return err } } s.spec = append(s.spec, newServs...) return nil }
[ "func", "(", "s", "*", "Services", ")", "add", "(", "newServs", "[", "]", "*", "apitypes", ".", "UserService", ")", "error", "{", "var", "err", "error", "\n", "// check if adding service conflict with existing ones", "exist", ":=", "make", "(", "map", "[", "serviceKey", "]", "bool", ",", "s", ".", "size", "(", ")", ")", "\n", "for", "_", ",", "srv", ":=", "range", "s", ".", "spec", "{", "exist", "[", "serviceKey", "{", "srv", ".", "ServiceIP", ",", "srv", ".", "ServicePort", ",", "srv", ".", "Protocol", "}", "]", "=", "true", "\n", "}", "\n", "for", "_", ",", "srv", ":=", "range", "newServs", "{", "if", "exist", "[", "serviceKey", "{", "srv", ".", "ServiceIP", ",", "srv", ".", "ServicePort", ",", "srv", ".", "Protocol", "}", "]", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "newServs", ")", "\n", "s", ".", "Log", "(", "ERROR", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "exist", "[", "serviceKey", "{", "srv", ".", "ServiceIP", ",", "srv", ".", "ServicePort", ",", "srv", ".", "Protocol", "}", "]", "=", "true", "\n", "}", "\n\n", "// if pod is running, convert service to patch and send to vm", "if", "s", ".", "p", ".", "IsRunning", "(", ")", "{", "if", "err", "=", "s", ".", "commit", "(", "newServs", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "s", ".", "spec", "=", "append", "(", "s", ".", "spec", ",", "newServs", "...", ")", "\n\n", "return", "nil", "\n", "}" ]
// add will only add services in list that don't exist, else failed
[ "add", "will", "only", "add", "services", "in", "list", "that", "don", "t", "exist", "else", "failed" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/servicediscovery.go#L88-L113
149,837
hyperhq/hyperd
daemon/pod/servicediscovery.go
update
func (s *Services) update(srvs []*apitypes.UserService) error { var err error // check if update service list conflicts tbd := make(map[serviceKey]bool, len(srvs)) for _, srv := range srvs { key := serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol} if tbd[key] { err = fmt.Errorf("given service list conflict: %v", srv) s.Log(ERROR, err) return err } tbd[key] = true } if s.p.IsRunning() { if err = s.commit(srvs, "update"); err != nil { return err } } s.spec = srvs return nil }
go
func (s *Services) update(srvs []*apitypes.UserService) error { var err error // check if update service list conflicts tbd := make(map[serviceKey]bool, len(srvs)) for _, srv := range srvs { key := serviceKey{srv.ServiceIP, srv.ServicePort, srv.Protocol} if tbd[key] { err = fmt.Errorf("given service list conflict: %v", srv) s.Log(ERROR, err) return err } tbd[key] = true } if s.p.IsRunning() { if err = s.commit(srvs, "update"); err != nil { return err } } s.spec = srvs return nil }
[ "func", "(", "s", "*", "Services", ")", "update", "(", "srvs", "[", "]", "*", "apitypes", ".", "UserService", ")", "error", "{", "var", "err", "error", "\n", "// check if update service list conflicts", "tbd", ":=", "make", "(", "map", "[", "serviceKey", "]", "bool", ",", "len", "(", "srvs", ")", ")", "\n", "for", "_", ",", "srv", ":=", "range", "srvs", "{", "key", ":=", "serviceKey", "{", "srv", ".", "ServiceIP", ",", "srv", ".", "ServicePort", ",", "srv", ".", "Protocol", "}", "\n", "if", "tbd", "[", "key", "]", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "srv", ")", "\n", "s", ".", "Log", "(", "ERROR", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "tbd", "[", "key", "]", "=", "true", "\n", "}", "\n\n", "if", "s", ".", "p", ".", "IsRunning", "(", ")", "{", "if", "err", "=", "s", ".", "commit", "(", "srvs", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "s", ".", "spec", "=", "srvs", "\n\n", "return", "nil", "\n", "}" ]
// update removes services in list that already exist, and add with new ones // or just add new ones if they are not exist already
[ "update", "removes", "services", "in", "list", "that", "already", "exist", "and", "add", "with", "new", "ones", "or", "just", "add", "new", "ones", "if", "they", "are", "not", "exist", "already" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/servicediscovery.go#L144-L166
149,838
hyperhq/hyperd
daemon/server.go
CmdListPortMappings
func (daemon *Daemon) CmdListPortMappings(podId string) (*engine.Env, error) { p, ok := daemon.PodList.Get(podId) if !ok { return nil, errors.ErrPodNotFound.WithArgs(podId) } pms := p.ListPortMappings() v := &engine.Env{} v.SetJson("portMappings", pms) return v, nil }
go
func (daemon *Daemon) CmdListPortMappings(podId string) (*engine.Env, error) { p, ok := daemon.PodList.Get(podId) if !ok { return nil, errors.ErrPodNotFound.WithArgs(podId) } pms := p.ListPortMappings() v := &engine.Env{} v.SetJson("portMappings", pms) return v, nil }
[ "func", "(", "daemon", "*", "Daemon", ")", "CmdListPortMappings", "(", "podId", "string", ")", "(", "*", "engine", ".", "Env", ",", "error", ")", "{", "p", ",", "ok", ":=", "daemon", ".", "PodList", ".", "Get", "(", "podId", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "ErrPodNotFound", ".", "WithArgs", "(", "podId", ")", "\n", "}", "\n\n", "pms", ":=", "p", ".", "ListPortMappings", "(", ")", "\n", "v", ":=", "&", "engine", ".", "Env", "{", "}", "\n", "v", ".", "SetJson", "(", "\"", "\"", ",", "pms", ")", "\n\n", "return", "v", ",", "nil", "\n", "}" ]
// pod level port mappings API
[ "pod", "level", "port", "mappings", "API" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/server.go#L306-L317
149,839
hyperhq/hyperd
serverrpc/exec.go
ExecSignal
func (s *ServerRPC) ExecSignal(ctx context.Context, req *types.ExecSignalRequest) (*types.ExecSignalResponse, error) { err := s.daemon.KillExec(req.ContainerID, req.ExecID, req.Signal) if err != nil { return nil, err } return &types.ExecSignalResponse{}, nil }
go
func (s *ServerRPC) ExecSignal(ctx context.Context, req *types.ExecSignalRequest) (*types.ExecSignalResponse, error) { err := s.daemon.KillExec(req.ContainerID, req.ExecID, req.Signal) if err != nil { return nil, err } return &types.ExecSignalResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ExecSignal", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ExecSignalRequest", ")", "(", "*", "types", ".", "ExecSignalResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "KillExec", "(", "req", ".", "ContainerID", ",", "req", ".", "ExecID", ",", "req", ".", "Signal", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ExecSignalResponse", "{", "}", ",", "nil", "\n", "}" ]
// ExecSignal sends a singal to specified exec of specified container
[ "ExecSignal", "sends", "a", "singal", "to", "specified", "exec", "of", "specified", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/exec.go#L104-L111
149,840
hyperhq/hyperd
client/build.go
ValidateContextDirectory
func ValidateContextDirectory(srcPath string, excludes []string) error { contextRoot := filepath.Join(srcPath, ".") return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { // skip this directory/file if it's not in the path, it won't get added to the context if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil { return err } else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil { return err } else if skip { if f.IsDir() { return filepath.SkipDir } return nil } if err != nil { if os.IsPermission(err) { return fmt.Errorf("can't stat '%s'", filePath) } if os.IsNotExist(err) { return nil } return err } // skip checking if symlinks point to non-existing files, such symlinks can be useful // also skip named pipes, because they hanging on open if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 { return nil } if !f.IsDir() { currentFile, err := os.Open(filePath) if err != nil && os.IsPermission(err) { return fmt.Errorf("no permission to read from '%s'", filePath) } currentFile.Close() } return nil }) }
go
func ValidateContextDirectory(srcPath string, excludes []string) error { contextRoot := filepath.Join(srcPath, ".") return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { // skip this directory/file if it's not in the path, it won't get added to the context if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil { return err } else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil { return err } else if skip { if f.IsDir() { return filepath.SkipDir } return nil } if err != nil { if os.IsPermission(err) { return fmt.Errorf("can't stat '%s'", filePath) } if os.IsNotExist(err) { return nil } return err } // skip checking if symlinks point to non-existing files, such symlinks can be useful // also skip named pipes, because they hanging on open if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 { return nil } if !f.IsDir() { currentFile, err := os.Open(filePath) if err != nil && os.IsPermission(err) { return fmt.Errorf("no permission to read from '%s'", filePath) } currentFile.Close() } return nil }) }
[ "func", "ValidateContextDirectory", "(", "srcPath", "string", ",", "excludes", "[", "]", "string", ")", "error", "{", "contextRoot", ":=", "filepath", ".", "Join", "(", "srcPath", ",", "\"", "\"", ")", "\n\n", "return", "filepath", ".", "Walk", "(", "contextRoot", ",", "func", "(", "filePath", "string", ",", "f", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "// skip this directory/file if it's not in the path, it won't get added to the context", "if", "relFilePath", ",", "err", ":=", "filepath", ".", "Rel", "(", "contextRoot", ",", "filePath", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "if", "skip", ",", "err", ":=", "fileutils", ".", "Matches", "(", "relFilePath", ",", "excludes", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "if", "skip", "{", "if", "f", ".", "IsDir", "(", ")", "{", "return", "filepath", ".", "SkipDir", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "if", "os", ".", "IsPermission", "(", "err", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "filePath", ")", "\n", "}", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "// skip checking if symlinks point to non-existing files, such symlinks can be useful", "// also skip named pipes, because they hanging on open", "if", "f", ".", "Mode", "(", ")", "&", "(", "os", ".", "ModeSymlink", "|", "os", ".", "ModeNamedPipe", ")", "!=", "0", "{", "return", "nil", "\n", "}", "\n\n", "if", "!", "f", ".", "IsDir", "(", ")", "{", "currentFile", ",", "err", ":=", "os", ".", "Open", "(", "filePath", ")", "\n", "if", "err", "!=", "nil", "&&", "os", ".", "IsPermission", "(", "err", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "filePath", ")", "\n", "}", "\n", "currentFile", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// validateContextDirectory checks if all the contents of the directory // can be read and returns an error if some files can't be read // symlinks which point to non-existing files don't trigger an error
[ "validateContextDirectory", "checks", "if", "all", "the", "contents", "of", "the", "directory", "can", "be", "read", "and", "returns", "an", "error", "if", "some", "files", "can", "t", "be", "read", "symlinks", "which", "point", "to", "non", "-", "existing", "files", "don", "t", "trigger", "an", "error" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/client/build.go#L177-L218
149,841
hyperhq/hyperd
server/server.go
InitRouters
func (s *Server) InitRouters(d *daemon.Daemon) { s.addRouter(container.NewRouter(d)) s.addRouter(pod.NewRouter(d)) s.addRouter(service.NewRouter(d)) s.addRouter(local.NewRouter(d)) s.addRouter(system.NewRouter(d)) s.addRouter(build.NewRouter(d)) }
go
func (s *Server) InitRouters(d *daemon.Daemon) { s.addRouter(container.NewRouter(d)) s.addRouter(pod.NewRouter(d)) s.addRouter(service.NewRouter(d)) s.addRouter(local.NewRouter(d)) s.addRouter(system.NewRouter(d)) s.addRouter(build.NewRouter(d)) }
[ "func", "(", "s", "*", "Server", ")", "InitRouters", "(", "d", "*", "daemon", ".", "Daemon", ")", "{", "s", ".", "addRouter", "(", "container", ".", "NewRouter", "(", "d", ")", ")", "\n", "s", ".", "addRouter", "(", "pod", ".", "NewRouter", "(", "d", ")", ")", "\n", "s", ".", "addRouter", "(", "service", ".", "NewRouter", "(", "d", ")", ")", "\n", "s", ".", "addRouter", "(", "local", ".", "NewRouter", "(", "d", ")", ")", "\n", "s", ".", "addRouter", "(", "system", ".", "NewRouter", "(", "d", ")", ")", "\n", "s", ".", "addRouter", "(", "build", ".", "NewRouter", "(", "d", ")", ")", "\n", "}" ]
// InitRouters initializes a list of routers for the server.
[ "InitRouters", "initializes", "a", "list", "of", "routers", "for", "the", "server", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server.go#L177-L184
149,842
hyperhq/hyperd
server/server.go
addRouter
func (s *Server) addRouter(r router.Router) { s.routers = append(s.routers, r) }
go
func (s *Server) addRouter(r router.Router) { s.routers = append(s.routers, r) }
[ "func", "(", "s", "*", "Server", ")", "addRouter", "(", "r", "router", ".", "Router", ")", "{", "s", ".", "routers", "=", "append", "(", "s", ".", "routers", ",", "r", ")", "\n", "}" ]
// addRouter adds a new router to the server.
[ "addRouter", "adds", "a", "new", "router", "to", "the", "server", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server.go#L187-L189
149,843
hyperhq/hyperd
server/server.go
createMux
func (s *Server) createMux() *mux.Router { m := mux.NewRouter() if utils.IsDebugEnabled() { profilerSetup(m, "/debug/") } glog.V(3).Infof("Registering routers") for _, apiRouter := range s.routers { for _, r := range apiRouter.Routes() { f := s.makeHTTPHandler(r.Handler()) glog.V(3).Infof("Registering %s, %s", r.Method(), r.Path()) m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f) m.Path(r.Path()).Methods(r.Method()).Handler(f) } } return m }
go
func (s *Server) createMux() *mux.Router { m := mux.NewRouter() if utils.IsDebugEnabled() { profilerSetup(m, "/debug/") } glog.V(3).Infof("Registering routers") for _, apiRouter := range s.routers { for _, r := range apiRouter.Routes() { f := s.makeHTTPHandler(r.Handler()) glog.V(3).Infof("Registering %s, %s", r.Method(), r.Path()) m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f) m.Path(r.Path()).Methods(r.Method()).Handler(f) } } return m }
[ "func", "(", "s", "*", "Server", ")", "createMux", "(", ")", "*", "mux", ".", "Router", "{", "m", ":=", "mux", ".", "NewRouter", "(", ")", "\n", "if", "utils", ".", "IsDebugEnabled", "(", ")", "{", "profilerSetup", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n\n", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ")", "\n", "for", "_", ",", "apiRouter", ":=", "range", "s", ".", "routers", "{", "for", "_", ",", "r", ":=", "range", "apiRouter", ".", "Routes", "(", ")", "{", "f", ":=", "s", ".", "makeHTTPHandler", "(", "r", ".", "Handler", "(", ")", ")", "\n\n", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "r", ".", "Method", "(", ")", ",", "r", ".", "Path", "(", ")", ")", "\n", "m", ".", "Path", "(", "versionMatcher", "+", "r", ".", "Path", "(", ")", ")", ".", "Methods", "(", "r", ".", "Method", "(", ")", ")", ".", "Handler", "(", "f", ")", "\n", "m", ".", "Path", "(", "r", ".", "Path", "(", ")", ")", ".", "Methods", "(", "r", ".", "Method", "(", ")", ")", ".", "Handler", "(", "f", ")", "\n", "}", "\n", "}", "\n\n", "return", "m", "\n", "}" ]
// createMux initializes the main router the server uses. // we keep enableCors just for legacy usage, need to be removed in the future
[ "createMux", "initializes", "the", "main", "router", "the", "server", "uses", ".", "we", "keep", "enableCors", "just", "for", "legacy", "usage", "need", "to", "be", "removed", "in", "the", "future" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server.go#L193-L211
149,844
hyperhq/hyperd
server/server.go
Wait
func (s *Server) Wait(waitChan chan error) { if err := s.serveAPI(); err != nil { glog.Errorf("ServeAPI error: %v", err) waitChan <- err return } waitChan <- nil }
go
func (s *Server) Wait(waitChan chan error) { if err := s.serveAPI(); err != nil { glog.Errorf("ServeAPI error: %v", err) waitChan <- err return } waitChan <- nil }
[ "func", "(", "s", "*", "Server", ")", "Wait", "(", "waitChan", "chan", "error", ")", "{", "if", "err", ":=", "s", ".", "serveAPI", "(", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "waitChan", "<-", "err", "\n", "return", "\n", "}", "\n", "waitChan", "<-", "nil", "\n", "}" ]
// Wait blocks the server goroutine until it exits. // It sends an error message if there is any error during // the API execution.
[ "Wait", "blocks", "the", "server", "goroutine", "until", "it", "exits", ".", "It", "sends", "an", "error", "message", "if", "there", "is", "any", "error", "during", "the", "API", "execution", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server.go#L216-L223
149,845
hyperhq/hyperd
daemon/pod/etchosts.go
prepareHosts
func prepareHosts(podID string) (string, error) { var err error hostsDir, hostsPath := HostsPath(podID) if err = os.MkdirAll(hostsDir, 0755); err != nil { return "", err } if _, err = os.Stat(hostsPath); err != nil && os.IsNotExist(err) { // mount tmpfs on hostsDir if err := syscall.Mount(podID+"-hosts", hostsDir, "tmpfs", 0, "size=1024K"); err != nil { return "", err } hostsContent, err := generateDefaultHosts() if err != nil { return "", err } return hostsPath, ioutil.WriteFile(hostsPath, hostsContent, 0644) } return hostsPath, nil }
go
func prepareHosts(podID string) (string, error) { var err error hostsDir, hostsPath := HostsPath(podID) if err = os.MkdirAll(hostsDir, 0755); err != nil { return "", err } if _, err = os.Stat(hostsPath); err != nil && os.IsNotExist(err) { // mount tmpfs on hostsDir if err := syscall.Mount(podID+"-hosts", hostsDir, "tmpfs", 0, "size=1024K"); err != nil { return "", err } hostsContent, err := generateDefaultHosts() if err != nil { return "", err } return hostsPath, ioutil.WriteFile(hostsPath, hostsContent, 0644) } return hostsPath, nil }
[ "func", "prepareHosts", "(", "podID", "string", ")", "(", "string", ",", "error", ")", "{", "var", "err", "error", "\n\n", "hostsDir", ",", "hostsPath", ":=", "HostsPath", "(", "podID", ")", "\n\n", "if", "err", "=", "os", ".", "MkdirAll", "(", "hostsDir", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "os", ".", "Stat", "(", "hostsPath", ")", ";", "err", "!=", "nil", "&&", "os", ".", "IsNotExist", "(", "err", ")", "{", "// mount tmpfs on hostsDir", "if", "err", ":=", "syscall", ".", "Mount", "(", "podID", "+", "\"", "\"", ",", "hostsDir", ",", "\"", "\"", ",", "0", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "hostsContent", ",", "err", ":=", "generateDefaultHosts", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "hostsPath", ",", "ioutil", ".", "WriteFile", "(", "hostsPath", ",", "hostsContent", ",", "0644", ")", "\n", "}", "\n\n", "return", "hostsPath", ",", "nil", "\n", "}" ]
// prepareHosts creates hosts file for given pod
[ "prepareHosts", "creates", "hosts", "file", "for", "given", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/etchosts.go#L68-L91
149,846
hyperhq/hyperd
networking/portmapping/host_portmapping_linux.go
NewPortRange
func NewPortRange(r string) (*PortRange, error) { segs := strings.SplitN(r, "-", 2) b, err := strconv.ParseUint(segs[0], 10, 16) if err != nil { return nil, err } e := b if len(segs) > 1 { e, err = strconv.ParseUint(segs[1], 10, 16) if err != nil { return nil, err } } return &PortRange{ Begin: int(b), End: int(e), }, nil }
go
func NewPortRange(r string) (*PortRange, error) { segs := strings.SplitN(r, "-", 2) b, err := strconv.ParseUint(segs[0], 10, 16) if err != nil { return nil, err } e := b if len(segs) > 1 { e, err = strconv.ParseUint(segs[1], 10, 16) if err != nil { return nil, err } } return &PortRange{ Begin: int(b), End: int(e), }, nil }
[ "func", "NewPortRange", "(", "r", "string", ")", "(", "*", "PortRange", ",", "error", ")", "{", "segs", ":=", "strings", ".", "SplitN", "(", "r", ",", "\"", "\"", ",", "2", ")", "\n", "b", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "segs", "[", "0", "]", ",", "10", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "e", ":=", "b", "\n", "if", "len", "(", "segs", ")", ">", "1", "{", "e", ",", "err", "=", "strconv", ".", "ParseUint", "(", "segs", "[", "1", "]", ",", "10", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "PortRange", "{", "Begin", ":", "int", "(", "b", ")", ",", "End", ":", "int", "(", "e", ")", ",", "}", ",", "nil", "\n", "}" ]
// NewPortRange generate a port range from string r. the r should be a decimal number or // in format begin-end, where begin and end are both decimal number. And the port range should // be 0-65535, i.e. 16-bit unsigned int // It returns PortRange pointer for valid input, otherwise return error
[ "NewPortRange", "generate", "a", "port", "range", "from", "string", "r", ".", "the", "r", "should", "be", "a", "decimal", "number", "or", "in", "format", "begin", "-", "end", "where", "begin", "and", "end", "are", "both", "decimal", "number", ".", "And", "the", "port", "range", "should", "be", "0", "-", "65535", "i", ".", "e", ".", "16", "-", "bit", "unsigned", "int", "It", "returns", "PortRange", "pointer", "for", "valid", "input", "otherwise", "return", "error" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/networking/portmapping/host_portmapping_linux.go#L33-L50
149,847
hyperhq/hyperd
networking/portmapping/setup_linux.go
Setup
func Setup(bIface, addr string, disable bool) error { var err error disableIptables = disable bridgeIface = bIface if disableIptables { hlog.Log(hlog.DEBUG, "Iptables is disabled") return nil } hlog.Log(hlog.TRACE, "setting up iptables") err = setupIPTables(addr) if err != nil { hlog.Log(hlog.ERROR, "failed to setup iptables: %v", err) return err } return nil }
go
func Setup(bIface, addr string, disable bool) error { var err error disableIptables = disable bridgeIface = bIface if disableIptables { hlog.Log(hlog.DEBUG, "Iptables is disabled") return nil } hlog.Log(hlog.TRACE, "setting up iptables") err = setupIPTables(addr) if err != nil { hlog.Log(hlog.ERROR, "failed to setup iptables: %v", err) return err } return nil }
[ "func", "Setup", "(", "bIface", ",", "addr", "string", ",", "disable", "bool", ")", "error", "{", "var", "err", "error", "\n\n", "disableIptables", "=", "disable", "\n", "bridgeIface", "=", "bIface", "\n\n", "if", "disableIptables", "{", "hlog", ".", "Log", "(", "hlog", ".", "DEBUG", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "hlog", ".", "Log", "(", "hlog", ".", "TRACE", ",", "\"", "\"", ")", "\n", "err", "=", "setupIPTables", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "hlog", ".", "Log", "(", "hlog", ".", "ERROR", ",", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
//setup environment for iptables and IP forwarding
[ "setup", "environment", "for", "iptables", "and", "IP", "forwarding" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/networking/portmapping/setup_linux.go#L18-L37
149,848
hyperhq/hyperd
networking/portmapping/iptables/iptables_linux.go
OperatePortMap
func OperatePortMap(action Action, chain string, rule []string) error { if output, err := Raw(append([]string{ "-t", string(Nat), string(action), chain}, rule...)...); err != nil { return fmt.Errorf("Unable to setup network port map: %s", err) } else if len(output) != 0 { return &ChainError{Chain: chain, Output: output} } return nil }
go
func OperatePortMap(action Action, chain string, rule []string) error { if output, err := Raw(append([]string{ "-t", string(Nat), string(action), chain}, rule...)...); err != nil { return fmt.Errorf("Unable to setup network port map: %s", err) } else if len(output) != 0 { return &ChainError{Chain: chain, Output: output} } return nil }
[ "func", "OperatePortMap", "(", "action", "Action", ",", "chain", "string", ",", "rule", "[", "]", "string", ")", "error", "{", "if", "output", ",", "err", ":=", "Raw", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "string", "(", "Nat", ")", ",", "string", "(", "action", ")", ",", "chain", "}", ",", "rule", "...", ")", "...", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "else", "if", "len", "(", "output", ")", "!=", "0", "{", "return", "&", "ChainError", "{", "Chain", ":", "chain", ",", "Output", ":", "output", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Check if a dnat rule exists
[ "Check", "if", "a", "dnat", "rule", "exists" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/networking/portmapping/iptables/iptables_linux.go#L62-L71
149,849
hyperhq/hyperd
networking/portmapping/iptables/iptables_linux.go
Exists
func Exists(table Table, chain string, rule ...string) bool { if string(table) == "" { table = Filter } // iptables -C, --check option was added in v.1.4.11 // http://ftp.netfilter.org/pub/iptables/changes-iptables-1.4.11.txt // try -C // if exit status is 0 then return true, the rule exists if _, err := Raw(append([]string{ "-t", string(table), "-C", chain}, rule...)...); err == nil { return true } // parse "iptables -S" for the rule (this checks rules in a specific chain // in a specific table) ruleString := strings.Join(rule, " ") existingRules, _ := exec.Command("iptables", "-t", string(table), "-S", chain).Output() // regex to replace ips in rule // because MASQUERADE rule will not be exactly what was passed re := regexp.MustCompile(`[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}`) return strings.Contains( re.ReplaceAllString(string(existingRules), "?"), re.ReplaceAllString(ruleString, "?"), ) }
go
func Exists(table Table, chain string, rule ...string) bool { if string(table) == "" { table = Filter } // iptables -C, --check option was added in v.1.4.11 // http://ftp.netfilter.org/pub/iptables/changes-iptables-1.4.11.txt // try -C // if exit status is 0 then return true, the rule exists if _, err := Raw(append([]string{ "-t", string(table), "-C", chain}, rule...)...); err == nil { return true } // parse "iptables -S" for the rule (this checks rules in a specific chain // in a specific table) ruleString := strings.Join(rule, " ") existingRules, _ := exec.Command("iptables", "-t", string(table), "-S", chain).Output() // regex to replace ips in rule // because MASQUERADE rule will not be exactly what was passed re := regexp.MustCompile(`[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}`) return strings.Contains( re.ReplaceAllString(string(existingRules), "?"), re.ReplaceAllString(ruleString, "?"), ) }
[ "func", "Exists", "(", "table", "Table", ",", "chain", "string", ",", "rule", "...", "string", ")", "bool", "{", "if", "string", "(", "table", ")", "==", "\"", "\"", "{", "table", "=", "Filter", "\n", "}", "\n\n", "// iptables -C, --check option was added in v.1.4.11", "// http://ftp.netfilter.org/pub/iptables/changes-iptables-1.4.11.txt", "// try -C", "// if exit status is 0 then return true, the rule exists", "if", "_", ",", "err", ":=", "Raw", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "string", "(", "table", ")", ",", "\"", "\"", ",", "chain", "}", ",", "rule", "...", ")", "...", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n\n", "// parse \"iptables -S\" for the rule (this checks rules in a specific chain", "// in a specific table)", "ruleString", ":=", "strings", ".", "Join", "(", "rule", ",", "\"", "\"", ")", "\n", "existingRules", ",", "_", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "string", "(", "table", ")", ",", "\"", "\"", ",", "chain", ")", ".", "Output", "(", ")", "\n\n", "// regex to replace ips in rule", "// because MASQUERADE rule will not be exactly what was passed", "re", ":=", "regexp", ".", "MustCompile", "(", "`[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\/[0-9]{1,2}`", ")", "\n\n", "return", "strings", ".", "Contains", "(", "re", ".", "ReplaceAllString", "(", "string", "(", "existingRules", ")", ",", "\"", "\"", ")", ",", "re", ".", "ReplaceAllString", "(", "ruleString", ",", "\"", "\"", ")", ",", ")", "\n", "}" ]
// Check if a rule exists
[ "Check", "if", "a", "rule", "exists" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/networking/portmapping/iptables/iptables_linux.go#L142-L170
149,850
hyperhq/hyperd
networking/portmapping/iptables/iptables_linux.go
Raw
func Raw(args ...string) ([]byte, error) { if err := initCheck(); err != nil { return nil, err } if supportsXlock { args = append([]string{"--wait"}, args...) } hlog.Log(hlog.TRACE, "%s, %v", iptablesPath, args) output, err := exec.Command(iptablesPath, args...).CombinedOutput() if err != nil { return nil, fmt.Errorf("iptables failed: iptables %v: %s (%s)", strings.Join(args, " "), output, err) } // ignore iptables' message about xtables lock if strings.Contains(string(output), "waiting for it to exit") { output = []byte("") } return output, err }
go
func Raw(args ...string) ([]byte, error) { if err := initCheck(); err != nil { return nil, err } if supportsXlock { args = append([]string{"--wait"}, args...) } hlog.Log(hlog.TRACE, "%s, %v", iptablesPath, args) output, err := exec.Command(iptablesPath, args...).CombinedOutput() if err != nil { return nil, fmt.Errorf("iptables failed: iptables %v: %s (%s)", strings.Join(args, " "), output, err) } // ignore iptables' message about xtables lock if strings.Contains(string(output), "waiting for it to exit") { output = []byte("") } return output, err }
[ "func", "Raw", "(", "args", "...", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "err", ":=", "initCheck", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "supportsXlock", "{", "args", "=", "append", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "args", "...", ")", "\n", "}", "\n\n", "hlog", ".", "Log", "(", "hlog", ".", "TRACE", ",", "\"", "\"", ",", "iptablesPath", ",", "args", ")", "\n\n", "output", ",", "err", ":=", "exec", ".", "Command", "(", "iptablesPath", ",", "args", "...", ")", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ",", "output", ",", "err", ")", "\n", "}", "\n\n", "// ignore iptables' message about xtables lock", "if", "strings", ".", "Contains", "(", "string", "(", "output", ")", ",", "\"", "\"", ")", "{", "output", "=", "[", "]", "byte", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "output", ",", "err", "\n", "}" ]
// Call 'iptables' system command, passing supplied arguments
[ "Call", "iptables", "system", "command", "passing", "supplied", "arguments" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/networking/portmapping/iptables/iptables_linux.go#L173-L194
149,851
hyperhq/hyperd
daemon/daemondb/daemondb.go
LagecyGetPod
func (d *DaemonDB) LagecyGetPod(id string) ([]byte, error) { return d.Get(keyPod(id)) }
go
func (d *DaemonDB) LagecyGetPod(id string) ([]byte, error) { return d.Get(keyPod(id)) }
[ "func", "(", "d", "*", "DaemonDB", ")", "LagecyGetPod", "(", "id", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "d", ".", "Get", "(", "keyPod", "(", "id", ")", ")", "\n", "}" ]
// Pods podId and args
[ "Pods", "podId", "and", "args" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemondb/daemondb.go#L43-L45
149,852
hyperhq/hyperd
engine/env.go
Get
func (env *Env) Get(key string) (value string) { // not using Map() because of the extra allocations https://github.com/docker/docker/pull/7488#issuecomment-51638315 for _, kv := range *env { if strings.Index(kv, "=") == -1 { continue } parts := strings.SplitN(kv, "=", 2) if parts[0] != key { continue } if len(parts) < 2 { value = "" } else { value = parts[1] } } return }
go
func (env *Env) Get(key string) (value string) { // not using Map() because of the extra allocations https://github.com/docker/docker/pull/7488#issuecomment-51638315 for _, kv := range *env { if strings.Index(kv, "=") == -1 { continue } parts := strings.SplitN(kv, "=", 2) if parts[0] != key { continue } if len(parts) < 2 { value = "" } else { value = parts[1] } } return }
[ "func", "(", "env", "*", "Env", ")", "Get", "(", "key", "string", ")", "(", "value", "string", ")", "{", "// not using Map() because of the extra allocations https://github.com/docker/docker/pull/7488#issuecomment-51638315", "for", "_", ",", "kv", ":=", "range", "*", "env", "{", "if", "strings", ".", "Index", "(", "kv", ",", "\"", "\"", ")", "==", "-", "1", "{", "continue", "\n", "}", "\n", "parts", ":=", "strings", ".", "SplitN", "(", "kv", ",", "\"", "\"", ",", "2", ")", "\n", "if", "parts", "[", "0", "]", "!=", "key", "{", "continue", "\n", "}", "\n", "if", "len", "(", "parts", ")", "<", "2", "{", "value", "=", "\"", "\"", "\n", "}", "else", "{", "value", "=", "parts", "[", "1", "]", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Get returns the last value associated with the given key. If there are no // values associated with the key, Get returns the empty string.
[ "Get", "returns", "the", "last", "value", "associated", "with", "the", "given", "key", ".", "If", "there", "are", "no", "values", "associated", "with", "the", "key", "Get", "returns", "the", "empty", "string", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/env.go#L18-L35
149,853
hyperhq/hyperd
engine/env.go
Decode
func (env *Env) Decode(src io.Reader) error { m := make(map[string]interface{}) d := json.NewDecoder(src) // We need this or we'll lose data when we decode int64 in json d.UseNumber() if err := d.Decode(&m); err != nil { return err } for k, v := range m { env.SetAuto(k, v) } return nil }
go
func (env *Env) Decode(src io.Reader) error { m := make(map[string]interface{}) d := json.NewDecoder(src) // We need this or we'll lose data when we decode int64 in json d.UseNumber() if err := d.Decode(&m); err != nil { return err } for k, v := range m { env.SetAuto(k, v) } return nil }
[ "func", "(", "env", "*", "Env", ")", "Decode", "(", "src", "io", ".", "Reader", ")", "error", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "d", ":=", "json", ".", "NewDecoder", "(", "src", ")", "\n", "// We need this or we'll lose data when we decode int64 in json", "d", ".", "UseNumber", "(", ")", "\n", "if", "err", ":=", "d", ".", "Decode", "(", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "env", ".", "SetAuto", "(", "k", ",", "v", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DecodeEnv decodes `src` as a json dictionary, and adds // each decoded key-value pair to the environment. // // If `src` cannot be decoded as a json dictionary, an error // is returned.
[ "DecodeEnv", "decodes", "src", "as", "a", "json", "dictionary", "and", "adds", "each", "decoded", "key", "-", "value", "pair", "to", "the", "environment", ".", "If", "src", "cannot", "be", "decoded", "as", "a", "json", "dictionary", "an", "error", "is", "returned", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/env.go#L189-L201
149,854
hyperhq/hyperd
engine/env.go
MultiMap
func (env *Env) MultiMap() map[string][]string { m := make(map[string][]string) for _, kv := range *env { parts := strings.SplitN(kv, "=", 2) m[parts[0]] = append(m[parts[0]], parts[1]) } return m }
go
func (env *Env) MultiMap() map[string][]string { m := make(map[string][]string) for _, kv := range *env { parts := strings.SplitN(kv, "=", 2) m[parts[0]] = append(m[parts[0]], parts[1]) } return m }
[ "func", "(", "env", "*", "Env", ")", "MultiMap", "(", ")", "map", "[", "string", "]", "[", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "for", "_", ",", "kv", ":=", "range", "*", "env", "{", "parts", ":=", "strings", ".", "SplitN", "(", "kv", ",", "\"", "\"", ",", "2", ")", "\n", "m", "[", "parts", "[", "0", "]", "]", "=", "append", "(", "m", "[", "parts", "[", "0", "]", "]", ",", "parts", "[", "1", "]", ")", "\n", "}", "\n", "return", "m", "\n", "}" ]
// MultiMap returns a representation of env as a // map of string arrays, keyed by string. // This is the same structure as http headers for example, // which allow each key to have multiple values.
[ "MultiMap", "returns", "a", "representation", "of", "env", "as", "a", "map", "of", "string", "arrays", "keyed", "by", "string", ".", "This", "is", "the", "same", "structure", "as", "http", "headers", "for", "example", "which", "allow", "each", "key", "to", "have", "multiple", "values", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/env.go#L294-L301
149,855
hyperhq/hyperd
engine/env.go
InitMultiMap
func (env *Env) InitMultiMap(m map[string][]string) { (*env) = make([]string, 0, len(m)) for k, vals := range m { for _, v := range vals { env.Set(k, v) } } }
go
func (env *Env) InitMultiMap(m map[string][]string) { (*env) = make([]string, 0, len(m)) for k, vals := range m { for _, v := range vals { env.Set(k, v) } } }
[ "func", "(", "env", "*", "Env", ")", "InitMultiMap", "(", "m", "map", "[", "string", "]", "[", "]", "string", ")", "{", "(", "*", "env", ")", "=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "vals", ":=", "range", "m", "{", "for", "_", ",", "v", ":=", "range", "vals", "{", "env", ".", "Set", "(", "k", ",", "v", ")", "\n", "}", "\n", "}", "\n", "}" ]
// InitMultiMap removes all values in env, then initializes // new values from the contents of m.
[ "InitMultiMap", "removes", "all", "values", "in", "env", "then", "initializes", "new", "values", "from", "the", "contents", "of", "m", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/env.go#L305-L312
149,856
hyperhq/hyperd
lib/goconfig/conf.go
SetValue
func (c *ConfigFile) SetValue(section, key, value string) bool { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } if len(key) == 0 { return false } if c.BlockMode { c.lock.Lock() defer c.lock.Unlock() } // Check if section exists. if _, ok := c.data[section]; !ok { // Execute add operation. c.data[section] = make(map[string]string) // Append section to list. c.sectionList = append(c.sectionList, section) } // Check if key exists. _, ok := c.data[section][key] c.data[section][key] = value if !ok { // If not exists, append to key list. c.keyList[section] = append(c.keyList[section], key) } return !ok }
go
func (c *ConfigFile) SetValue(section, key, value string) bool { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } if len(key) == 0 { return false } if c.BlockMode { c.lock.Lock() defer c.lock.Unlock() } // Check if section exists. if _, ok := c.data[section]; !ok { // Execute add operation. c.data[section] = make(map[string]string) // Append section to list. c.sectionList = append(c.sectionList, section) } // Check if key exists. _, ok := c.data[section][key] c.data[section][key] = value if !ok { // If not exists, append to key list. c.keyList[section] = append(c.keyList[section], key) } return !ok }
[ "func", "(", "c", "*", "ConfigFile", ")", "SetValue", "(", "section", ",", "key", ",", "value", "string", ")", "bool", "{", "// Blank section name represents DEFAULT section.", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n", "if", "len", "(", "key", ")", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "if", "c", ".", "BlockMode", "{", "c", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "lock", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "// Check if section exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", ";", "!", "ok", "{", "// Execute add operation.", "c", ".", "data", "[", "section", "]", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "// Append section to list.", "c", ".", "sectionList", "=", "append", "(", "c", ".", "sectionList", ",", "section", ")", "\n", "}", "\n\n", "// Check if key exists.", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", "[", "key", "]", "\n", "c", ".", "data", "[", "section", "]", "[", "key", "]", "=", "value", "\n", "if", "!", "ok", "{", "// If not exists, append to key list.", "c", ".", "keyList", "[", "section", "]", "=", "append", "(", "c", ".", "keyList", "[", "section", "]", ",", "key", ")", "\n", "}", "\n", "return", "!", "ok", "\n", "}" ]
// SetValue adds a new section-key-value to the configuration. // It returns true if the key and value were inserted, // or returns false if the value was overwritten. // If the section does not exist in advance, it will be created.
[ "SetValue", "adds", "a", "new", "section", "-", "key", "-", "value", "to", "the", "configuration", ".", "It", "returns", "true", "if", "the", "key", "and", "value", "were", "inserted", "or", "returns", "false", "if", "the", "value", "was", "overwritten", ".", "If", "the", "section", "does", "not", "exist", "in", "advance", "it", "will", "be", "created", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/lib/goconfig/conf.go#L85-L115
149,857
hyperhq/hyperd
daemon/pod/streams.go
NewStreamConfig
func NewStreamConfig() *StreamConfig { return &StreamConfig{ stderr: new(broadcaster.Unbuffered), stdout: new(broadcaster.Unbuffered), } }
go
func NewStreamConfig() *StreamConfig { return &StreamConfig{ stderr: new(broadcaster.Unbuffered), stdout: new(broadcaster.Unbuffered), } }
[ "func", "NewStreamConfig", "(", ")", "*", "StreamConfig", "{", "return", "&", "StreamConfig", "{", "stderr", ":", "new", "(", "broadcaster", ".", "Unbuffered", ")", ",", "stdout", ":", "new", "(", "broadcaster", ".", "Unbuffered", ")", ",", "}", "\n", "}" ]
// NewStreamConfig creates a stream config and initializes // the standard err and standard out to new unbuffered broadcasters.
[ "NewStreamConfig", "creates", "a", "stream", "config", "and", "initializes", "the", "standard", "err", "and", "standard", "out", "to", "new", "unbuffered", "broadcasters", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/streams.go#L39-L44
149,858
hyperhq/hyperd
daemon/pod/streams.go
StdoutPipe
func (streamConfig *StreamConfig) StdoutPipe() io.ReadCloser { bytesPipe := ioutils.NewBytesPipe(nil) streamConfig.stdout.Add(bytesPipe) return bytesPipe }
go
func (streamConfig *StreamConfig) StdoutPipe() io.ReadCloser { bytesPipe := ioutils.NewBytesPipe(nil) streamConfig.stdout.Add(bytesPipe) return bytesPipe }
[ "func", "(", "streamConfig", "*", "StreamConfig", ")", "StdoutPipe", "(", ")", "io", ".", "ReadCloser", "{", "bytesPipe", ":=", "ioutils", ".", "NewBytesPipe", "(", "nil", ")", "\n", "streamConfig", ".", "stdout", ".", "Add", "(", "bytesPipe", ")", "\n", "return", "bytesPipe", "\n", "}" ]
// StdoutPipe creates a new io.ReadCloser with an empty bytes pipe. // It adds this new out pipe to the Stdout broadcaster.
[ "StdoutPipe", "creates", "a", "new", "io", ".", "ReadCloser", "with", "an", "empty", "bytes", "pipe", ".", "It", "adds", "this", "new", "out", "pipe", "to", "the", "Stdout", "broadcaster", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/streams.go#L68-L72
149,859
hyperhq/hyperd
daemon/pod/streams.go
StderrPipe
func (streamConfig *StreamConfig) StderrPipe() io.ReadCloser { bytesPipe := ioutils.NewBytesPipe(nil) streamConfig.stderr.Add(bytesPipe) return bytesPipe }
go
func (streamConfig *StreamConfig) StderrPipe() io.ReadCloser { bytesPipe := ioutils.NewBytesPipe(nil) streamConfig.stderr.Add(bytesPipe) return bytesPipe }
[ "func", "(", "streamConfig", "*", "StreamConfig", ")", "StderrPipe", "(", ")", "io", ".", "ReadCloser", "{", "bytesPipe", ":=", "ioutils", ".", "NewBytesPipe", "(", "nil", ")", "\n", "streamConfig", ".", "stderr", ".", "Add", "(", "bytesPipe", ")", "\n", "return", "bytesPipe", "\n", "}" ]
// StderrPipe creates a new io.ReadCloser with an empty bytes pipe. // It adds this new err pipe to the Stderr broadcaster.
[ "StderrPipe", "creates", "a", "new", "io", ".", "ReadCloser", "with", "an", "empty", "bytes", "pipe", ".", "It", "adds", "this", "new", "err", "pipe", "to", "the", "Stderr", "broadcaster", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/streams.go#L76-L80
149,860
hyperhq/hyperd
daemon/daemonbuilder/pod.go
ContainerAttach
func (d Docker) ContainerAttach(cId string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error { <-d.hyper.Ready err := d.Daemon.Attach(stdin, ioutils.NopWriteCloser(stdout), cId) if err != nil { return err } code, err := d.Daemon.ExitCode(cId, "") if err != nil { return err } if code == 0 { return nil } return &jsonmessage.JSONError{ Message: fmt.Sprintf("The container '%s' returned a non-zero code: %d", cId, code), Code: code, } }
go
func (d Docker) ContainerAttach(cId string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error { <-d.hyper.Ready err := d.Daemon.Attach(stdin, ioutils.NopWriteCloser(stdout), cId) if err != nil { return err } code, err := d.Daemon.ExitCode(cId, "") if err != nil { return err } if code == 0 { return nil } return &jsonmessage.JSONError{ Message: fmt.Sprintf("The container '%s' returned a non-zero code: %d", cId, code), Code: code, } }
[ "func", "(", "d", "Docker", ")", "ContainerAttach", "(", "cId", "string", ",", "stdin", "io", ".", "ReadCloser", ",", "stdout", ",", "stderr", "io", ".", "Writer", ",", "stream", "bool", ")", "error", "{", "<-", "d", ".", "hyper", ".", "Ready", "\n\n", "err", ":=", "d", ".", "Daemon", ".", "Attach", "(", "stdin", ",", "ioutils", ".", "NopWriteCloser", "(", "stdout", ")", ",", "cId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "code", ",", "err", ":=", "d", ".", "Daemon", ".", "ExitCode", "(", "cId", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "code", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "jsonmessage", ".", "JSONError", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "cId", ",", "code", ")", ",", "Code", ":", "code", ",", "}", "\n", "}" ]
// ContainerAttach attaches streams to the container cID. If stream is true, it streams the output.
[ "ContainerAttach", "attaches", "streams", "to", "the", "container", "cID", ".", "If", "stream", "is", "true", "it", "streams", "the", "output", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/pod.go#L26-L47
149,861
hyperhq/hyperd
daemon/daemonbuilder/pod.go
ContainerCreate
func (d Docker) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) { var spec *apitypes.UserPod var err error if params.Config == nil { return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig } podId := fmt.Sprintf("buildpod-%s", utils.RandStr(10, "alpha")) // Hack here, container created by ADD/COPY only has Config if params.HostConfig != nil { spec, err = MakeBasicPod(podId, params.Config, params.HostConfig) } else { spec, err = MakeCopyPod(podId, params.Config) } if err != nil { return types.ContainerCreateResponse{}, err } p, err := d.Daemon.CreatePod(podId, spec) if err != nil { return types.ContainerCreateResponse{}, err } containers := p.ContainerIds() if len(containers) != 1 { return types.ContainerCreateResponse{}, fmt.Errorf("container count in pod is incorrect") } cId := containers[0] if params.HostConfig != nil { d.hyper.BasicPods[cId] = podId glog.Infof("basic containerId %s, podId %s", cId, podId) } else { d.hyper.CopyPods[cId] = podId glog.Infof("copy containerId %s, podId %s", cId, podId) } return types.ContainerCreateResponse{ID: cId}, nil }
go
func (d Docker) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) { var spec *apitypes.UserPod var err error if params.Config == nil { return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig } podId := fmt.Sprintf("buildpod-%s", utils.RandStr(10, "alpha")) // Hack here, container created by ADD/COPY only has Config if params.HostConfig != nil { spec, err = MakeBasicPod(podId, params.Config, params.HostConfig) } else { spec, err = MakeCopyPod(podId, params.Config) } if err != nil { return types.ContainerCreateResponse{}, err } p, err := d.Daemon.CreatePod(podId, spec) if err != nil { return types.ContainerCreateResponse{}, err } containers := p.ContainerIds() if len(containers) != 1 { return types.ContainerCreateResponse{}, fmt.Errorf("container count in pod is incorrect") } cId := containers[0] if params.HostConfig != nil { d.hyper.BasicPods[cId] = podId glog.Infof("basic containerId %s, podId %s", cId, podId) } else { d.hyper.CopyPods[cId] = podId glog.Infof("copy containerId %s, podId %s", cId, podId) } return types.ContainerCreateResponse{ID: cId}, nil }
[ "func", "(", "d", "Docker", ")", "ContainerCreate", "(", "params", "types", ".", "ContainerCreateConfig", ")", "(", "types", ".", "ContainerCreateResponse", ",", "error", ")", "{", "var", "spec", "*", "apitypes", ".", "UserPod", "\n", "var", "err", "error", "\n\n", "if", "params", ".", "Config", "==", "nil", "{", "return", "types", ".", "ContainerCreateResponse", "{", "}", ",", "derr", ".", "ErrorCodeEmptyConfig", "\n", "}", "\n\n", "podId", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "utils", ".", "RandStr", "(", "10", ",", "\"", "\"", ")", ")", "\n", "// Hack here, container created by ADD/COPY only has Config", "if", "params", ".", "HostConfig", "!=", "nil", "{", "spec", ",", "err", "=", "MakeBasicPod", "(", "podId", ",", "params", ".", "Config", ",", "params", ".", "HostConfig", ")", "\n", "}", "else", "{", "spec", ",", "err", "=", "MakeCopyPod", "(", "podId", ",", "params", ".", "Config", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "types", ".", "ContainerCreateResponse", "{", "}", ",", "err", "\n", "}", "\n\n", "p", ",", "err", ":=", "d", ".", "Daemon", ".", "CreatePod", "(", "podId", ",", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "types", ".", "ContainerCreateResponse", "{", "}", ",", "err", "\n", "}", "\n\n", "containers", ":=", "p", ".", "ContainerIds", "(", ")", "\n\n", "if", "len", "(", "containers", ")", "!=", "1", "{", "return", "types", ".", "ContainerCreateResponse", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "cId", ":=", "containers", "[", "0", "]", "\n", "if", "params", ".", "HostConfig", "!=", "nil", "{", "d", ".", "hyper", ".", "BasicPods", "[", "cId", "]", "=", "podId", "\n", "glog", ".", "Infof", "(", "\"", "\"", ",", "cId", ",", "podId", ")", "\n", "}", "else", "{", "d", ".", "hyper", ".", "CopyPods", "[", "cId", "]", "=", "podId", "\n", "glog", ".", "Infof", "(", "\"", "\"", ",", "cId", ",", "podId", ")", "\n", "}", "\n\n", "return", "types", ".", "ContainerCreateResponse", "{", "ID", ":", "cId", "}", ",", "nil", "\n", "}" ]
// Override the Docker ContainerCreate interface, create pod to run command
[ "Override", "the", "Docker", "ContainerCreate", "interface", "create", "pod", "to", "run", "command" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/pod.go#L210-L250
149,862
hyperhq/hyperd
server/server_windows.go
newServer
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) { var ( ls []net.Listener ) switch proto { case "tcp": l, err := s.initTCPSocket(addr) if err != nil { return nil, err } ls = append(ls, l) default: return nil, errors.New("Invalid protocol format. Windows only supports tcp.") } var res []*HTTPServer for _, l := range ls { res = append(res, &HTTPServer{ &http.Server{ Addr: addr, }, l, }) } return res, nil }
go
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) { var ( ls []net.Listener ) switch proto { case "tcp": l, err := s.initTCPSocket(addr) if err != nil { return nil, err } ls = append(ls, l) default: return nil, errors.New("Invalid protocol format. Windows only supports tcp.") } var res []*HTTPServer for _, l := range ls { res = append(res, &HTTPServer{ &http.Server{ Addr: addr, }, l, }) } return res, nil }
[ "func", "(", "s", "*", "Server", ")", "newServer", "(", "proto", ",", "addr", "string", ")", "(", "[", "]", "*", "HTTPServer", ",", "error", ")", "{", "var", "(", "ls", "[", "]", "net", ".", "Listener", "\n", ")", "\n", "switch", "proto", "{", "case", "\"", "\"", ":", "l", ",", "err", ":=", "s", ".", "initTCPSocket", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ls", "=", "append", "(", "ls", ",", "l", ")", "\n\n", "default", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "res", "[", "]", "*", "HTTPServer", "\n", "for", "_", ",", "l", ":=", "range", "ls", "{", "res", "=", "append", "(", "res", ",", "&", "HTTPServer", "{", "&", "http", ".", "Server", "{", "Addr", ":", "addr", ",", "}", ",", "l", ",", "}", ")", "\n", "}", "\n", "return", "res", ",", "nil", "\n\n", "}" ]
// NewServer sets up the required Server and does protocol specific checking.
[ "NewServer", "sets", "up", "the", "required", "Server", "and", "does", "protocol", "specific", "checking", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/server_windows.go#L12-L39
149,863
hyperhq/hyperd
server/router/local/local.go
NewRoute
func NewRoute(method, path string, handler httputils.APIFunc) dkrouter.Route { return localRoute{method, path, handler} }
go
func NewRoute(method, path string, handler httputils.APIFunc) dkrouter.Route { return localRoute{method, path, handler} }
[ "func", "NewRoute", "(", "method", ",", "path", "string", ",", "handler", "httputils", ".", "APIFunc", ")", "dkrouter", ".", "Route", "{", "return", "localRoute", "{", "method", ",", "path", ",", "handler", "}", "\n", "}" ]
// NewRoute initializes a new local router for the reouter
[ "NewRoute", "initializes", "a", "new", "local", "router", "for", "the", "reouter" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/router/local/local.go#L39-L41
149,864
hyperhq/hyperd
server/router/local/local.go
NewRouter
func NewRouter(daemon *daemon.Daemon) dkrouter.Router { r := &router{ daemon: daemon, } r.initRoutes() return r }
go
func NewRouter(daemon *daemon.Daemon) dkrouter.Router { r := &router{ daemon: daemon, } r.initRoutes() return r }
[ "func", "NewRouter", "(", "daemon", "*", "daemon", ".", "Daemon", ")", "dkrouter", ".", "Router", "{", "r", ":=", "&", "router", "{", "daemon", ":", "daemon", ",", "}", "\n", "r", ".", "initRoutes", "(", ")", "\n", "return", "r", "\n", "}" ]
// NewRouter initializes a local router with a new daemon.
[ "NewRouter", "initializes", "a", "local", "router", "with", "a", "new", "daemon", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/router/local/local.go#L74-L80
149,865
hyperhq/hyperd
server/router/local/local.go
initRoutes
func (r *router) initRoutes() { r.routes = []dkrouter.Route{ // OPTIONS // GET // /images/json in docker NewGetRoute("/images/get", r.getImagesJSON), // /images/get in docker NewGetRoute("/images/save", r.getImagesSave), // POST NewPostRoute("/image/create", r.postImagesCreate), NewPostRoute("/image/load", r.postImagesLoad), NewPostRoute("/image/push", r.postImagesPush), // DELETE NewDeleteRoute("/image", r.deleteImages), } }
go
func (r *router) initRoutes() { r.routes = []dkrouter.Route{ // OPTIONS // GET // /images/json in docker NewGetRoute("/images/get", r.getImagesJSON), // /images/get in docker NewGetRoute("/images/save", r.getImagesSave), // POST NewPostRoute("/image/create", r.postImagesCreate), NewPostRoute("/image/load", r.postImagesLoad), NewPostRoute("/image/push", r.postImagesPush), // DELETE NewDeleteRoute("/image", r.deleteImages), } }
[ "func", "(", "r", "*", "router", ")", "initRoutes", "(", ")", "{", "r", ".", "routes", "=", "[", "]", "dkrouter", ".", "Route", "{", "// OPTIONS", "// GET", "// /images/json in docker", "NewGetRoute", "(", "\"", "\"", ",", "r", ".", "getImagesJSON", ")", ",", "// /images/get in docker", "NewGetRoute", "(", "\"", "\"", ",", "r", ".", "getImagesSave", ")", ",", "// POST", "NewPostRoute", "(", "\"", "\"", ",", "r", ".", "postImagesCreate", ")", ",", "NewPostRoute", "(", "\"", "\"", ",", "r", ".", "postImagesLoad", ")", ",", "NewPostRoute", "(", "\"", "\"", ",", "r", ".", "postImagesPush", ")", ",", "// DELETE", "NewDeleteRoute", "(", "\"", "\"", ",", "r", ".", "deleteImages", ")", ",", "}", "\n", "}" ]
// initRoutes initializes the routes in this router
[ "initRoutes", "initializes", "the", "routes", "in", "this", "router" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/router/local/local.go#L88-L103
149,866
hyperhq/hyperd
daemon/pod/container.go
initStreams
func (c *Container) initStreams() error { if c.streams != nil { return nil } if !c.p.IsAlive() { c.Log(ERROR, "can not init stream to a non-existing sandbox") return errors.ErrPodNotAlive.WithArgs(c.p.Id()) } c.Log(TRACE, "init io streams") c.streams = NewStreamConfig() c.streams.NewInputPipes() tty := &hypervisor.TtyIO{ Stdin: c.streams.Stdin(), Stdout: c.streams.Stdout(), Stderr: c.streams.Stderr(), } if err := c.p.sandbox.Attach(tty, c.Id()); err != nil { c.Log(ERROR, err) return err } return nil }
go
func (c *Container) initStreams() error { if c.streams != nil { return nil } if !c.p.IsAlive() { c.Log(ERROR, "can not init stream to a non-existing sandbox") return errors.ErrPodNotAlive.WithArgs(c.p.Id()) } c.Log(TRACE, "init io streams") c.streams = NewStreamConfig() c.streams.NewInputPipes() tty := &hypervisor.TtyIO{ Stdin: c.streams.Stdin(), Stdout: c.streams.Stdout(), Stderr: c.streams.Stderr(), } if err := c.p.sandbox.Attach(tty, c.Id()); err != nil { c.Log(ERROR, err) return err } return nil }
[ "func", "(", "c", "*", "Container", ")", "initStreams", "(", ")", "error", "{", "if", "c", ".", "streams", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "!", "c", ".", "p", ".", "IsAlive", "(", ")", "{", "c", ".", "Log", "(", "ERROR", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "ErrPodNotAlive", ".", "WithArgs", "(", "c", ".", "p", ".", "Id", "(", ")", ")", "\n", "}", "\n", "c", ".", "Log", "(", "TRACE", ",", "\"", "\"", ")", "\n", "c", ".", "streams", "=", "NewStreamConfig", "(", ")", "\n", "c", ".", "streams", ".", "NewInputPipes", "(", ")", "\n", "tty", ":=", "&", "hypervisor", ".", "TtyIO", "{", "Stdin", ":", "c", ".", "streams", ".", "Stdin", "(", ")", ",", "Stdout", ":", "c", ".", "streams", ".", "Stdout", "(", ")", ",", "Stderr", ":", "c", ".", "streams", ".", "Stderr", "(", ")", ",", "}", "\n", "if", "err", ":=", "c", ".", "p", ".", "sandbox", ".", "Attach", "(", "tty", ",", "c", ".", "Id", "(", ")", ")", ";", "err", "!=", "nil", "{", "c", ".", "Log", "(", "ERROR", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// This method should be called when initialzing container or put into resource lock.
[ "This", "method", "should", "be", "called", "when", "initialzing", "container", "or", "put", "into", "resource", "lock", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/container.go#L945-L966
149,867
hyperhq/hyperd
daemon/pod/container.go
Create
func (cs *ContainerStatus) Create() error { cs.Lock() defer cs.Unlock() if cs.State != S_CONTAINER_NONE { err := fmt.Errorf("only NONE container could be create, current: %d", cs.State) return err } cs.State = S_CONTAINER_CREATING cs.stateChanged.Broadcast() return nil }
go
func (cs *ContainerStatus) Create() error { cs.Lock() defer cs.Unlock() if cs.State != S_CONTAINER_NONE { err := fmt.Errorf("only NONE container could be create, current: %d", cs.State) return err } cs.State = S_CONTAINER_CREATING cs.stateChanged.Broadcast() return nil }
[ "func", "(", "cs", "*", "ContainerStatus", ")", "Create", "(", ")", "error", "{", "cs", ".", "Lock", "(", ")", "\n", "defer", "cs", ".", "Unlock", "(", ")", "\n\n", "if", "cs", ".", "State", "!=", "S_CONTAINER_NONE", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "cs", ".", "State", ")", "\n", "return", "err", "\n", "}", "\n\n", "cs", ".", "State", "=", "S_CONTAINER_CREATING", "\n", "cs", ".", "stateChanged", ".", "Broadcast", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// container status transition
[ "container", "status", "transition" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/container.go#L1196-L1209
149,868
hyperhq/hyperd
storage/devicemapper/dm.go
DMCleanup
func DMCleanup(dm *DeviceMapper) error { var parms string // Delete the thin pool for test parms = fmt.Sprintf("dmsetup remove \"/dev/mapper/%s\"", dm.PoolName) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } // Delete the loop device parms = fmt.Sprintf("losetup -d %s", dm.MetadataLoopFile) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } parms = fmt.Sprintf("losetup -d %s", dm.DataLoopFile) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } return nil }
go
func DMCleanup(dm *DeviceMapper) error { var parms string // Delete the thin pool for test parms = fmt.Sprintf("dmsetup remove \"/dev/mapper/%s\"", dm.PoolName) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } // Delete the loop device parms = fmt.Sprintf("losetup -d %s", dm.MetadataLoopFile) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } parms = fmt.Sprintf("losetup -d %s", dm.DataLoopFile) if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil { glog.Error(string(res)) return fmt.Errorf(string(res)) } return nil }
[ "func", "DMCleanup", "(", "dm", "*", "DeviceMapper", ")", "error", "{", "var", "parms", "string", "\n", "// Delete the thin pool for test", "parms", "=", "fmt", ".", "Sprintf", "(", "\"", "\\\"", "\\\"", "\"", ",", "dm", ".", "PoolName", ")", "\n", "if", "res", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "parms", ")", ".", "CombinedOutput", "(", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Error", "(", "string", "(", "res", ")", ")", "\n", "return", "fmt", ".", "Errorf", "(", "string", "(", "res", ")", ")", "\n", "}", "\n", "// Delete the loop device", "parms", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dm", ".", "MetadataLoopFile", ")", "\n", "if", "res", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "parms", ")", ".", "CombinedOutput", "(", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Error", "(", "string", "(", "res", ")", ")", "\n", "return", "fmt", ".", "Errorf", "(", "string", "(", "res", ")", ")", "\n", "}", "\n", "parms", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dm", ".", "DataLoopFile", ")", "\n", "if", "res", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "parms", ")", ".", "CombinedOutput", "(", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Error", "(", "string", "(", "res", ")", ")", "\n", "return", "fmt", ".", "Errorf", "(", "string", "(", "res", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete the pool which is created in 'Init' function
[ "Delete", "the", "pool", "which", "is", "created", "in", "Init", "function" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/devicemapper/dm.go#L295-L315
149,869
hyperhq/hyperd
server/httputils/httputils.go
ParseMultipartForm
func ParseMultipartForm(r *http.Request) error { if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") { return err } return nil }
go
func ParseMultipartForm(r *http.Request) error { if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") { return err } return nil }
[ "func", "ParseMultipartForm", "(", "r", "*", "http", ".", "Request", ")", "error", "{", "if", "err", ":=", "r", ".", "ParseMultipartForm", "(", "4096", ")", ";", "err", "!=", "nil", "&&", "!", "strings", ".", "HasPrefix", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ParseMultipartForm ensure the request form is parsed, even with invalid content types.
[ "ParseMultipartForm", "ensure", "the", "request", "form", "is", "parsed", "even", "with", "invalid", "content", "types", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/httputils/httputils.go#L81-L86
149,870
hyperhq/hyperd
server/httputils/httputils.go
WriteError
func WriteError(w http.ResponseWriter, err error) { if err == nil || w == nil { glog.Errorf("unexpected HTTP error handling, error %v, writer %v", err, w) return } statusCode := http.StatusInternalServerError errMsg := err.Error() // Based on the type of error we get we need to process things // slightly differently to extract the error message. // In the 'errcode.*' cases there are two different type of // error that could be returned. errocode.ErrorCode is the base // type of error object - it is just an 'int' that can then be // used as the look-up key to find the message. errorcode.Error // extends errorcode.Error by adding error-instance specific // data, like 'details' or variable strings to be inserted into // the message. // // Ideally, we should just be able to call err.Error() for all // cases but the errcode package doesn't support that yet. // // Additionally, in both errcode cases, there might be an http // status code associated with it, and if so use it. switch err.(type) { case errcode.ErrorCode: daError, _ := err.(errcode.ErrorCode) statusCode = daError.Descriptor().HTTPStatusCode errMsg = daError.Message() case errcode.Error: // For reference, if you're looking for a particular error // then you can do something like : // import ( derr "github.com/docker/docker/errors" ) // if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... } daError, _ := err.(errcode.Error) statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode errMsg = daError.Message default: // This part of will be removed once we've // converted everything over to use the errcode package // FIXME: this is brittle and should not be necessary. // If we need to differentiate between different possible error types, // we should create appropriate error types with clearly defined meaning errStr := strings.ToLower(err.Error()) for keyword, status := range map[string]int{ "not found": http.StatusNotFound, "no such": http.StatusNotFound, "bad parameter": http.StatusBadRequest, "conflict": http.StatusConflict, "impossible": http.StatusNotAcceptable, "wrong login/password": http.StatusUnauthorized, "hasn't been activated": http.StatusForbidden, } { if strings.Contains(errStr, keyword) { statusCode = status break } } } if statusCode == 0 { statusCode = http.StatusInternalServerError } http.Error(w, errMsg, statusCode) }
go
func WriteError(w http.ResponseWriter, err error) { if err == nil || w == nil { glog.Errorf("unexpected HTTP error handling, error %v, writer %v", err, w) return } statusCode := http.StatusInternalServerError errMsg := err.Error() // Based on the type of error we get we need to process things // slightly differently to extract the error message. // In the 'errcode.*' cases there are two different type of // error that could be returned. errocode.ErrorCode is the base // type of error object - it is just an 'int' that can then be // used as the look-up key to find the message. errorcode.Error // extends errorcode.Error by adding error-instance specific // data, like 'details' or variable strings to be inserted into // the message. // // Ideally, we should just be able to call err.Error() for all // cases but the errcode package doesn't support that yet. // // Additionally, in both errcode cases, there might be an http // status code associated with it, and if so use it. switch err.(type) { case errcode.ErrorCode: daError, _ := err.(errcode.ErrorCode) statusCode = daError.Descriptor().HTTPStatusCode errMsg = daError.Message() case errcode.Error: // For reference, if you're looking for a particular error // then you can do something like : // import ( derr "github.com/docker/docker/errors" ) // if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... } daError, _ := err.(errcode.Error) statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode errMsg = daError.Message default: // This part of will be removed once we've // converted everything over to use the errcode package // FIXME: this is brittle and should not be necessary. // If we need to differentiate between different possible error types, // we should create appropriate error types with clearly defined meaning errStr := strings.ToLower(err.Error()) for keyword, status := range map[string]int{ "not found": http.StatusNotFound, "no such": http.StatusNotFound, "bad parameter": http.StatusBadRequest, "conflict": http.StatusConflict, "impossible": http.StatusNotAcceptable, "wrong login/password": http.StatusUnauthorized, "hasn't been activated": http.StatusForbidden, } { if strings.Contains(errStr, keyword) { statusCode = status break } } } if statusCode == 0 { statusCode = http.StatusInternalServerError } http.Error(w, errMsg, statusCode) }
[ "func", "WriteError", "(", "w", "http", ".", "ResponseWriter", ",", "err", "error", ")", "{", "if", "err", "==", "nil", "||", "w", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "w", ")", "\n", "return", "\n", "}", "\n\n", "statusCode", ":=", "http", ".", "StatusInternalServerError", "\n", "errMsg", ":=", "err", ".", "Error", "(", ")", "\n\n", "// Based on the type of error we get we need to process things", "// slightly differently to extract the error message.", "// In the 'errcode.*' cases there are two different type of", "// error that could be returned. errocode.ErrorCode is the base", "// type of error object - it is just an 'int' that can then be", "// used as the look-up key to find the message. errorcode.Error", "// extends errorcode.Error by adding error-instance specific", "// data, like 'details' or variable strings to be inserted into", "// the message.", "//", "// Ideally, we should just be able to call err.Error() for all", "// cases but the errcode package doesn't support that yet.", "//", "// Additionally, in both errcode cases, there might be an http", "// status code associated with it, and if so use it.", "switch", "err", ".", "(", "type", ")", "{", "case", "errcode", ".", "ErrorCode", ":", "daError", ",", "_", ":=", "err", ".", "(", "errcode", ".", "ErrorCode", ")", "\n", "statusCode", "=", "daError", ".", "Descriptor", "(", ")", ".", "HTTPStatusCode", "\n", "errMsg", "=", "daError", ".", "Message", "(", ")", "\n\n", "case", "errcode", ".", "Error", ":", "// For reference, if you're looking for a particular error", "// then you can do something like :", "// import ( derr \"github.com/docker/docker/errors\" )", "// if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... }", "daError", ",", "_", ":=", "err", ".", "(", "errcode", ".", "Error", ")", "\n", "statusCode", "=", "daError", ".", "ErrorCode", "(", ")", ".", "Descriptor", "(", ")", ".", "HTTPStatusCode", "\n", "errMsg", "=", "daError", ".", "Message", "\n\n", "default", ":", "// This part of will be removed once we've", "// converted everything over to use the errcode package", "// FIXME: this is brittle and should not be necessary.", "// If we need to differentiate between different possible error types,", "// we should create appropriate error types with clearly defined meaning", "errStr", ":=", "strings", ".", "ToLower", "(", "err", ".", "Error", "(", ")", ")", "\n", "for", "keyword", ",", "status", ":=", "range", "map", "[", "string", "]", "int", "{", "\"", "\"", ":", "http", ".", "StatusNotFound", ",", "\"", "\"", ":", "http", ".", "StatusNotFound", ",", "\"", "\"", ":", "http", ".", "StatusBadRequest", ",", "\"", "\"", ":", "http", ".", "StatusConflict", ",", "\"", "\"", ":", "http", ".", "StatusNotAcceptable", ",", "\"", "\"", ":", "http", ".", "StatusUnauthorized", ",", "\"", "\"", ":", "http", ".", "StatusForbidden", ",", "}", "{", "if", "strings", ".", "Contains", "(", "errStr", ",", "keyword", ")", "{", "statusCode", "=", "status", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "statusCode", "==", "0", "{", "statusCode", "=", "http", ".", "StatusInternalServerError", "\n", "}", "\n\n", "http", ".", "Error", "(", "w", ",", "errMsg", ",", "statusCode", ")", "\n", "}" ]
// WriteError decodes a specific docker error and sends it in the response.
[ "WriteError", "decodes", "a", "specific", "docker", "error", "and", "sends", "it", "in", "the", "response", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/httputils/httputils.go#L89-L158
149,871
hyperhq/hyperd
image/tarexport/tarexport.go
NewTarExporter
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store) hyperimage.Exporter { return &tarexporter{ is: is, ls: ls, rs: rs, } }
go
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store) hyperimage.Exporter { return &tarexporter{ is: is, ls: ls, rs: rs, } }
[ "func", "NewTarExporter", "(", "is", "image", ".", "Store", ",", "ls", "layer", ".", "Store", ",", "rs", "reference", ".", "Store", ")", "hyperimage", ".", "Exporter", "{", "return", "&", "tarexporter", "{", "is", ":", "is", ",", "ls", ":", "ls", ",", "rs", ":", "rs", ",", "}", "\n", "}" ]
// NewTarExporter returns new ImageExporter for tar packages
[ "NewTarExporter", "returns", "new", "ImageExporter", "for", "tar", "packages" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/image/tarexport/tarexport.go#L31-L37
149,872
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { backingFs := "<unknown>" blockFs := "xfs" // TODO: make it configurable cow := true supported := "supported" fsMagic, err := graphdriver.GetFSMagic(home) if err != nil { return nil, err } if fsName, ok := graphdriver.FsNames[fsMagic]; ok { backingFs = fsName } // check if they are running over btrfs or xfs switch fsMagic { case graphdriver.FsMagicBtrfs: // support case graphdriver.FsMagicXfs: // check support if testReflinkSupport(home) { break } fallthrough default: cow = false supported = "NOT supported" } glog.Infof("RawBlock: copy-on-write is %s", supported) rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) if err != nil { return nil, err } if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil { return nil, err } var blockSize = uint64(10 * 1024 * 1024 * 1024) for _, option := range options { key, val, err := parsers.ParseKeyValueOpt(option) if err != nil { return nil, err } key = strings.ToLower(key) switch key { case "rawblock.basesize": size, err := units.RAMInBytes(val) if err != nil { return nil, err } blockSize = uint64(size) default: return nil, fmt.Errorf("rawblock: Unknown option %s\n", key) } } d := &Driver{ home: home, backingFs: backingFs, cow: cow, blockFs: blockFs, blockSize: blockSize, uid: rootUID, gid: rootGID, active: map[string]int{}, } return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil }
go
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { backingFs := "<unknown>" blockFs := "xfs" // TODO: make it configurable cow := true supported := "supported" fsMagic, err := graphdriver.GetFSMagic(home) if err != nil { return nil, err } if fsName, ok := graphdriver.FsNames[fsMagic]; ok { backingFs = fsName } // check if they are running over btrfs or xfs switch fsMagic { case graphdriver.FsMagicBtrfs: // support case graphdriver.FsMagicXfs: // check support if testReflinkSupport(home) { break } fallthrough default: cow = false supported = "NOT supported" } glog.Infof("RawBlock: copy-on-write is %s", supported) rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) if err != nil { return nil, err } if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil { return nil, err } var blockSize = uint64(10 * 1024 * 1024 * 1024) for _, option := range options { key, val, err := parsers.ParseKeyValueOpt(option) if err != nil { return nil, err } key = strings.ToLower(key) switch key { case "rawblock.basesize": size, err := units.RAMInBytes(val) if err != nil { return nil, err } blockSize = uint64(size) default: return nil, fmt.Errorf("rawblock: Unknown option %s\n", key) } } d := &Driver{ home: home, backingFs: backingFs, cow: cow, blockFs: blockFs, blockSize: blockSize, uid: rootUID, gid: rootGID, active: map[string]int{}, } return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil }
[ "func", "Init", "(", "home", "string", ",", "options", "[", "]", "string", ",", "uidMaps", ",", "gidMaps", "[", "]", "idtools", ".", "IDMap", ")", "(", "graphdriver", ".", "Driver", ",", "error", ")", "{", "backingFs", ":=", "\"", "\"", "\n", "blockFs", ":=", "\"", "\"", "// TODO: make it configurable", "\n", "cow", ":=", "true", "\n", "supported", ":=", "\"", "\"", "\n\n", "fsMagic", ",", "err", ":=", "graphdriver", ".", "GetFSMagic", "(", "home", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "fsName", ",", "ok", ":=", "graphdriver", ".", "FsNames", "[", "fsMagic", "]", ";", "ok", "{", "backingFs", "=", "fsName", "\n", "}", "\n\n", "// check if they are running over btrfs or xfs", "switch", "fsMagic", "{", "case", "graphdriver", ".", "FsMagicBtrfs", ":", "// support", "case", "graphdriver", ".", "FsMagicXfs", ":", "// check support", "if", "testReflinkSupport", "(", "home", ")", "{", "break", "\n", "}", "\n", "fallthrough", "\n", "default", ":", "cow", "=", "false", "\n", "supported", "=", "\"", "\"", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"", "\"", ",", "supported", ")", "\n\n", "rootUID", ",", "rootGID", ",", "err", ":=", "idtools", ".", "GetRootUIDGID", "(", "uidMaps", ",", "gidMaps", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "idtools", ".", "MkdirAllAs", "(", "home", ",", "0700", ",", "rootUID", ",", "rootGID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "blockSize", "=", "uint64", "(", "10", "*", "1024", "*", "1024", "*", "1024", ")", "\n", "for", "_", ",", "option", ":=", "range", "options", "{", "key", ",", "val", ",", "err", ":=", "parsers", ".", "ParseKeyValueOpt", "(", "option", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "key", "=", "strings", ".", "ToLower", "(", "key", ")", "\n", "switch", "key", "{", "case", "\"", "\"", ":", "size", ",", "err", ":=", "units", ".", "RAMInBytes", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "blockSize", "=", "uint64", "(", "size", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "key", ")", "\n", "}", "\n", "}", "\n\n", "d", ":=", "&", "Driver", "{", "home", ":", "home", ",", "backingFs", ":", "backingFs", ",", "cow", ":", "cow", ",", "blockFs", ":", "blockFs", ",", "blockSize", ":", "blockSize", ",", "uid", ":", "rootUID", ",", "gid", ":", "rootGID", ",", "active", ":", "map", "[", "string", "]", "int", "{", "}", ",", "}", "\n", "return", "graphdriver", ".", "NewNaiveDiffDriver", "(", "d", ",", "uidMaps", ",", "gidMaps", ")", ",", "nil", "\n", "}" ]
// Init returns a new Raw Block driver. // This sets the home directory for the driver and returns NaiveDiffDriver.
[ "Init", "returns", "a", "new", "Raw", "Block", "driver", ".", "This", "sets", "the", "home", "directory", "for", "the", "driver", "and", "returns", "NaiveDiffDriver", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L58-L124
149,873
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Status
func (d *Driver) Status() [][2]string { return [][2]string{ {"Backing Filesystem", d.backingFs}, {"Support Copy-On-Write", fmt.Sprintf("%v", d.cow)}, {"Block Filesystem", d.blockFs}, {"Block Size", fmt.Sprintf("%s", units.HumanSize(float64(d.blockSize)))}, } }
go
func (d *Driver) Status() [][2]string { return [][2]string{ {"Backing Filesystem", d.backingFs}, {"Support Copy-On-Write", fmt.Sprintf("%v", d.cow)}, {"Block Filesystem", d.blockFs}, {"Block Size", fmt.Sprintf("%s", units.HumanSize(float64(d.blockSize)))}, } }
[ "func", "(", "d", "*", "Driver", ")", "Status", "(", ")", "[", "]", "[", "2", "]", "string", "{", "return", "[", "]", "[", "2", "]", "string", "{", "{", "\"", "\"", ",", "d", ".", "backingFs", "}", ",", "{", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "cow", ")", "}", ",", "{", "\"", "\"", ",", "d", ".", "blockFs", "}", ",", "{", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "units", ".", "HumanSize", "(", "float64", "(", "d", ".", "blockSize", ")", ")", ")", "}", ",", "}", "\n", "}" ]
// Status is used for implementing the graphdriver.ProtoDriver interface.
[ "Status", "is", "used", "for", "implementing", "the", "graphdriver", ".", "ProtoDriver", "interface", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L131-L138
149,874
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Create
func (d *Driver) Create(id, parent, mountLabel string) error { if err := idtools.MkdirAllAs(filepath.Dir(d.block(id)), 0700, d.uid, d.gid); err != nil { return err } if parent == "" { return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize) } if out, err := exec.Command("cp", "-a", "--reflink=auto", d.block(parent), d.block(id)).CombinedOutput(); err != nil { return fmt.Errorf("Failed to reflink:%v:%s", err, string(out)) } return nil }
go
func (d *Driver) Create(id, parent, mountLabel string) error { if err := idtools.MkdirAllAs(filepath.Dir(d.block(id)), 0700, d.uid, d.gid); err != nil { return err } if parent == "" { return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize) } if out, err := exec.Command("cp", "-a", "--reflink=auto", d.block(parent), d.block(id)).CombinedOutput(); err != nil { return fmt.Errorf("Failed to reflink:%v:%s", err, string(out)) } return nil }
[ "func", "(", "d", "*", "Driver", ")", "Create", "(", "id", ",", "parent", ",", "mountLabel", "string", ")", "error", "{", "if", "err", ":=", "idtools", ".", "MkdirAllAs", "(", "filepath", ".", "Dir", "(", "d", ".", "block", "(", "id", ")", ")", ",", "0700", ",", "d", ".", "uid", ",", "d", ".", "gid", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "parent", "==", "\"", "\"", "{", "return", "CreateBlock", "(", "d", ".", "block", "(", "id", ")", ",", "d", ".", "blockFs", ",", "mountLabel", ",", "d", ".", "blockSize", ")", "\n", "}", "\n", "if", "out", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "d", ".", "block", "(", "parent", ")", ",", "d", ".", "block", "(", "id", ")", ")", ".", "CombinedOutput", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "string", "(", "out", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Create prepares the filesystem for the rawblock driver and copies the block from the parent.
[ "Create", "prepares", "the", "filesystem", "for", "the", "rawblock", "driver", "and", "copies", "the", "block", "from", "the", "parent", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L151-L162
149,875
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Exists
func (d *Driver) Exists(id string) bool { _, err := os.Stat(d.block(id)) return err == nil }
go
func (d *Driver) Exists(id string) bool { _, err := os.Stat(d.block(id)) return err == nil }
[ "func", "(", "d", "*", "Driver", ")", "Exists", "(", "id", "string", ")", "bool", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "d", ".", "block", "(", "id", ")", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// Exists checks to see if the directory exists for the given id.
[ "Exists", "checks", "to", "see", "if", "the", "directory", "exists", "for", "the", "given", "id", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L210-L213
149,876
hyperhq/hyperd
engine/streams.go
Tail
func Tail(buffer *bytes.Buffer, n int) string { if n <= 0 { return "" } s := strings.TrimRightFunc(buffer.String(), unicode.IsSpace) i := len(s) - 1 for ; i >= 0 && n > 0; i-- { if s[i] == '\n' { n-- if n == 0 { break } } } // when i == -1, return the whole string which is s[0:] return s[i+1:] }
go
func Tail(buffer *bytes.Buffer, n int) string { if n <= 0 { return "" } s := strings.TrimRightFunc(buffer.String(), unicode.IsSpace) i := len(s) - 1 for ; i >= 0 && n > 0; i-- { if s[i] == '\n' { n-- if n == 0 { break } } } // when i == -1, return the whole string which is s[0:] return s[i+1:] }
[ "func", "Tail", "(", "buffer", "*", "bytes", ".", "Buffer", ",", "n", "int", ")", "string", "{", "if", "n", "<=", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "s", ":=", "strings", ".", "TrimRightFunc", "(", "buffer", ".", "String", "(", ")", ",", "unicode", ".", "IsSpace", ")", "\n", "i", ":=", "len", "(", "s", ")", "-", "1", "\n", "for", ";", "i", ">=", "0", "&&", "n", ">", "0", ";", "i", "--", "{", "if", "s", "[", "i", "]", "==", "'\\n'", "{", "n", "--", "\n", "if", "n", "==", "0", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "// when i == -1, return the whole string which is s[0:]", "return", "s", "[", "i", "+", "1", ":", "]", "\n", "}" ]
// Tail returns the n last lines of a buffer // stripped out of trailing white spaces, if any. // // if n <= 0, returns an empty string
[ "Tail", "returns", "the", "n", "last", "lines", "of", "a", "buffer", "stripped", "out", "of", "trailing", "white", "spaces", "if", "any", ".", "if", "n", "<", "=", "0", "returns", "an", "empty", "string" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L24-L40
149,877
hyperhq/hyperd
engine/streams.go
Used
func (o *Output) Used() bool { o.Lock() defer o.Unlock() return o.used }
go
func (o *Output) Used() bool { o.Lock() defer o.Unlock() return o.used }
[ "func", "(", "o", "*", "Output", ")", "Used", "(", ")", "bool", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "return", "o", ".", "used", "\n", "}" ]
// Return true if something was written on this output
[ "Return", "true", "if", "something", "was", "written", "on", "this", "output" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L49-L53
149,878
hyperhq/hyperd
engine/streams.go
Add
func (o *Output) Add(dst io.Writer) { o.Lock() defer o.Unlock() o.dests = append(o.dests, dst) }
go
func (o *Output) Add(dst io.Writer) { o.Lock() defer o.Unlock() o.dests = append(o.dests, dst) }
[ "func", "(", "o", "*", "Output", ")", "Add", "(", "dst", "io", ".", "Writer", ")", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "dests", "=", "append", "(", "o", ".", "dests", ",", "dst", ")", "\n", "}" ]
// Add attaches a new destination to the Output. Any data subsequently written // to the output will be written to the new destination in addition to all the others. // This method is thread-safe.
[ "Add", "attaches", "a", "new", "destination", "to", "the", "Output", ".", "Any", "data", "subsequently", "written", "to", "the", "output", "will", "be", "written", "to", "the", "new", "destination", "in", "addition", "to", "all", "the", "others", ".", "This", "method", "is", "thread", "-", "safe", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L58-L62
149,879
hyperhq/hyperd
engine/streams.go
Set
func (o *Output) Set(dst io.Writer) { o.Close() o.Lock() defer o.Unlock() o.dests = []io.Writer{dst} }
go
func (o *Output) Set(dst io.Writer) { o.Close() o.Lock() defer o.Unlock() o.dests = []io.Writer{dst} }
[ "func", "(", "o", "*", "Output", ")", "Set", "(", "dst", "io", ".", "Writer", ")", "{", "o", ".", "Close", "(", ")", "\n", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "dests", "=", "[", "]", "io", ".", "Writer", "{", "dst", "}", "\n", "}" ]
// Set closes and remove existing destination and then attaches a new destination to // the Output. Any data subsequently written to the output will be written to the new // destination in addition to all the others. This method is thread-safe.
[ "Set", "closes", "and", "remove", "existing", "destination", "and", "then", "attaches", "a", "new", "destination", "to", "the", "Output", ".", "Any", "data", "subsequently", "written", "to", "the", "output", "will", "be", "written", "to", "the", "new", "destination", "in", "addition", "to", "all", "the", "others", ".", "This", "method", "is", "thread", "-", "safe", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L67-L72
149,880
hyperhq/hyperd
engine/streams.go
Write
func (o *Output) Write(p []byte) (n int, err error) { o.Lock() defer o.Unlock() o.used = true var firstErr error for _, dst := range o.dests { _, err := dst.Write(p) if err != nil && firstErr == nil { firstErr = err } } return len(p), firstErr }
go
func (o *Output) Write(p []byte) (n int, err error) { o.Lock() defer o.Unlock() o.used = true var firstErr error for _, dst := range o.dests { _, err := dst.Write(p) if err != nil && firstErr == nil { firstErr = err } } return len(p), firstErr }
[ "func", "(", "o", "*", "Output", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "used", "=", "true", "\n", "var", "firstErr", "error", "\n", "for", "_", ",", "dst", ":=", "range", "o", ".", "dests", "{", "_", ",", "err", ":=", "dst", ".", "Write", "(", "p", ")", "\n", "if", "err", "!=", "nil", "&&", "firstErr", "==", "nil", "{", "firstErr", "=", "err", "\n", "}", "\n", "}", "\n", "return", "len", "(", "p", ")", ",", "firstErr", "\n", "}" ]
// Write writes the same data to all registered destinations. // This method is thread-safe.
[ "Write", "writes", "the", "same", "data", "to", "all", "registered", "destinations", ".", "This", "method", "is", "thread", "-", "safe", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L86-L98
149,881
hyperhq/hyperd
engine/streams.go
Close
func (o *Output) Close() error { o.Lock() defer o.Unlock() var firstErr error for _, dst := range o.dests { if closer, ok := dst.(io.Closer); ok { err := closer.Close() if err != nil && firstErr == nil { firstErr = err } } } o.tasks.Wait() o.dests = nil return firstErr }
go
func (o *Output) Close() error { o.Lock() defer o.Unlock() var firstErr error for _, dst := range o.dests { if closer, ok := dst.(io.Closer); ok { err := closer.Close() if err != nil && firstErr == nil { firstErr = err } } } o.tasks.Wait() o.dests = nil return firstErr }
[ "func", "(", "o", "*", "Output", ")", "Close", "(", ")", "error", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "var", "firstErr", "error", "\n", "for", "_", ",", "dst", ":=", "range", "o", ".", "dests", "{", "if", "closer", ",", "ok", ":=", "dst", ".", "(", "io", ".", "Closer", ")", ";", "ok", "{", "err", ":=", "closer", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "&&", "firstErr", "==", "nil", "{", "firstErr", "=", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "o", ".", "tasks", ".", "Wait", "(", ")", "\n", "o", ".", "dests", "=", "nil", "\n", "return", "firstErr", "\n", "}" ]
// Close unregisters all destinations and waits for all background // AddTail and AddString tasks to complete. // The Close method of each destination is called if it exists.
[ "Close", "unregisters", "all", "destinations", "and", "waits", "for", "all", "background", "AddTail", "and", "AddString", "tasks", "to", "complete", ".", "The", "Close", "method", "of", "each", "destination", "is", "called", "if", "it", "exists", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L103-L118
149,882
hyperhq/hyperd
engine/streams.go
Read
func (i *Input) Read(p []byte) (n int, err error) { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src == nil { return 0, io.EOF } return i.src.Read(p) }
go
func (i *Input) Read(p []byte) (n int, err error) { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src == nil { return 0, io.EOF } return i.src.Read(p) }
[ "func", "(", "i", "*", "Input", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "i", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "if", "i", ".", "src", "==", "nil", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "\n", "return", "i", ".", "src", ".", "Read", "(", "p", ")", "\n", "}" ]
// Read reads from the input in a thread-safe way.
[ "Read", "reads", "from", "the", "input", "in", "a", "thread", "-", "safe", "way", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L132-L139
149,883
hyperhq/hyperd
engine/streams.go
Close
func (i *Input) Close() error { if i.src != nil { if closer, ok := i.src.(io.Closer); ok { return closer.Close() } } return nil }
go
func (i *Input) Close() error { if i.src != nil { if closer, ok := i.src.(io.Closer); ok { return closer.Close() } } return nil }
[ "func", "(", "i", "*", "Input", ")", "Close", "(", ")", "error", "{", "if", "i", ".", "src", "!=", "nil", "{", "if", "closer", ",", "ok", ":=", "i", ".", "src", ".", "(", "io", ".", "Closer", ")", ";", "ok", "{", "return", "closer", ".", "Close", "(", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Closes the src // Not thread safe on purpose
[ "Closes", "the", "src", "Not", "thread", "safe", "on", "purpose" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L143-L150
149,884
hyperhq/hyperd
engine/streams.go
Add
func (i *Input) Add(src io.Reader) error { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src != nil { return fmt.Errorf("Maximum number of sources reached: 1") } i.src = src return nil }
go
func (i *Input) Add(src io.Reader) error { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src != nil { return fmt.Errorf("Maximum number of sources reached: 1") } i.src = src return nil }
[ "func", "(", "i", "*", "Input", ")", "Add", "(", "src", "io", ".", "Reader", ")", "error", "{", "i", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "if", "i", ".", "src", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "i", ".", "src", "=", "src", "\n", "return", "nil", "\n", "}" ]
// Add attaches a new source to the input. // Add can only be called once per input. Subsequent calls will // return an error.
[ "Add", "attaches", "a", "new", "source", "to", "the", "input", ".", "Add", "can", "only", "be", "called", "once", "per", "input", ".", "Subsequent", "calls", "will", "return", "an", "error", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L155-L163
149,885
hyperhq/hyperd
engine/streams.go
AddEnv
func (o *Output) AddEnv() (dst *Env, err error) { src, err := o.AddPipe() if err != nil { return nil, err } dst = &Env{} o.tasks.Add(1) go func() { defer o.tasks.Done() decoder := NewDecoder(src) for { env, err := decoder.Decode() if err != nil { return } *dst = *env } }() return dst, nil }
go
func (o *Output) AddEnv() (dst *Env, err error) { src, err := o.AddPipe() if err != nil { return nil, err } dst = &Env{} o.tasks.Add(1) go func() { defer o.tasks.Done() decoder := NewDecoder(src) for { env, err := decoder.Decode() if err != nil { return } *dst = *env } }() return dst, nil }
[ "func", "(", "o", "*", "Output", ")", "AddEnv", "(", ")", "(", "dst", "*", "Env", ",", "err", "error", ")", "{", "src", ",", "err", ":=", "o", ".", "AddPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "dst", "=", "&", "Env", "{", "}", "\n", "o", ".", "tasks", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "defer", "o", ".", "tasks", ".", "Done", "(", ")", "\n", "decoder", ":=", "NewDecoder", "(", "src", ")", "\n", "for", "{", "env", ",", "err", ":=", "decoder", ".", "Decode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "*", "dst", "=", "*", "env", "\n", "}", "\n", "}", "(", ")", "\n", "return", "dst", ",", "nil", "\n", "}" ]
// AddEnv starts a new goroutine which will decode all subsequent data // as a stream of json-encoded objects, and point `dst` to the last // decoded object. // The result `env` can be queried using the type-neutral Env interface. // It is not safe to query `env` until the Output is closed.
[ "AddEnv", "starts", "a", "new", "goroutine", "which", "will", "decode", "all", "subsequent", "data", "as", "a", "stream", "of", "json", "-", "encoded", "objects", "and", "point", "dst", "to", "the", "last", "decoded", "object", ".", "The", "result", "env", "can", "be", "queried", "using", "the", "type", "-", "neutral", "Env", "interface", ".", "It", "is", "not", "safe", "to", "query", "env", "until", "the", "Output", "is", "closed", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L170-L189
149,886
hyperhq/hyperd
serverrpc/server.go
NewServerRPC
func NewServerRPC(d *daemon.Daemon) *ServerRPC { s := &ServerRPC{ server: grpc.NewServer(grpc.UnaryInterceptor(unaryLoger), grpc.StreamInterceptor(streamLoger)), daemon: d, } s.registerServer() return s }
go
func NewServerRPC(d *daemon.Daemon) *ServerRPC { s := &ServerRPC{ server: grpc.NewServer(grpc.UnaryInterceptor(unaryLoger), grpc.StreamInterceptor(streamLoger)), daemon: d, } s.registerServer() return s }
[ "func", "NewServerRPC", "(", "d", "*", "daemon", ".", "Daemon", ")", "*", "ServerRPC", "{", "s", ":=", "&", "ServerRPC", "{", "server", ":", "grpc", ".", "NewServer", "(", "grpc", ".", "UnaryInterceptor", "(", "unaryLoger", ")", ",", "grpc", ".", "StreamInterceptor", "(", "streamLoger", ")", ")", ",", "daemon", ":", "d", ",", "}", "\n", "s", ".", "registerServer", "(", ")", "\n", "return", "s", "\n", "}" ]
// NewServerRPC creates a new ServerRPC
[ "NewServerRPC", "creates", "a", "new", "ServerRPC" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/server.go#L59-L66
149,887
hyperhq/hyperd
serverrpc/server.go
Serve
func (s *ServerRPC) Serve(addr string) error { s.Log(hlog.DEBUG, "start server at %s", addr) l, err := net.Listen("tcp", addr) if err != nil { s.Log(hlog.ERROR, "Failed to listen %s: %v", addr, err) return err } return s.server.Serve(l) }
go
func (s *ServerRPC) Serve(addr string) error { s.Log(hlog.DEBUG, "start server at %s", addr) l, err := net.Listen("tcp", addr) if err != nil { s.Log(hlog.ERROR, "Failed to listen %s: %v", addr, err) return err } return s.server.Serve(l) }
[ "func", "(", "s", "*", "ServerRPC", ")", "Serve", "(", "addr", "string", ")", "error", "{", "s", ".", "Log", "(", "hlog", ".", "DEBUG", ",", "\"", "\"", ",", "addr", ")", "\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "Log", "(", "hlog", ".", "ERROR", ",", "\"", "\"", ",", "addr", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "s", ".", "server", ".", "Serve", "(", "l", ")", "\n", "}" ]
// Serve serves gRPC request by goroutines
[ "Serve", "serves", "gRPC", "request", "by", "goroutines" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/server.go#L84-L93
149,888
hyperhq/hyperd
integration/client.go
GetPodInfo
func (c *HyperClient) GetPodInfo(podID string) (*types.PodInfo, error) { request := types.PodInfoRequest{ PodID: podID, } pod, err := c.client.PodInfo(c.ctx, &request) if err != nil { return nil, err } return pod.PodInfo, nil }
go
func (c *HyperClient) GetPodInfo(podID string) (*types.PodInfo, error) { request := types.PodInfoRequest{ PodID: podID, } pod, err := c.client.PodInfo(c.ctx, &request) if err != nil { return nil, err } return pod.PodInfo, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodInfo", "(", "podID", "string", ")", "(", "*", "types", ".", "PodInfo", ",", "error", ")", "{", "request", ":=", "types", ".", "PodInfoRequest", "{", "PodID", ":", "podID", ",", "}", "\n", "pod", ",", "err", ":=", "c", ".", "client", ".", "PodInfo", "(", "c", ".", "ctx", ",", "&", "request", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "pod", ".", "PodInfo", ",", "nil", "\n", "}" ]
// GetPodInfo gets pod info by podID
[ "GetPodInfo", "gets", "pod", "info", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L37-L47
149,889
hyperhq/hyperd
integration/client.go
GetPodList
func (c *HyperClient) GetPodList() ([]*types.PodListResult, error) { request := types.PodListRequest{} podList, err := c.client.PodList( c.ctx, &request, ) if err != nil { return nil, err } return podList.PodList, nil }
go
func (c *HyperClient) GetPodList() ([]*types.PodListResult, error) { request := types.PodListRequest{} podList, err := c.client.PodList( c.ctx, &request, ) if err != nil { return nil, err } return podList.PodList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodList", "(", ")", "(", "[", "]", "*", "types", ".", "PodListResult", ",", "error", ")", "{", "request", ":=", "types", ".", "PodListRequest", "{", "}", "\n", "podList", ",", "err", ":=", "c", ".", "client", ".", "PodList", "(", "c", ".", "ctx", ",", "&", "request", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "podList", ".", "PodList", ",", "nil", "\n", "}" ]
// GetPodList get a list of Pods
[ "GetPodList", "get", "a", "list", "of", "Pods" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L50-L61
149,890
hyperhq/hyperd
integration/client.go
GetVMList
func (c *HyperClient) GetVMList() ([]*types.VMListResult, error) { req := types.VMListRequest{} vmList, err := c.client.VMList( c.ctx, &req, ) if err != nil { return nil, err } return vmList.VmList, nil }
go
func (c *HyperClient) GetVMList() ([]*types.VMListResult, error) { req := types.VMListRequest{} vmList, err := c.client.VMList( c.ctx, &req, ) if err != nil { return nil, err } return vmList.VmList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetVMList", "(", ")", "(", "[", "]", "*", "types", ".", "VMListResult", ",", "error", ")", "{", "req", ":=", "types", ".", "VMListRequest", "{", "}", "\n", "vmList", ",", "err", ":=", "c", ".", "client", ".", "VMList", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "vmList", ".", "VmList", ",", "nil", "\n", "}" ]
// GetVMList gets a list of VMs
[ "GetVMList", "gets", "a", "list", "of", "VMs" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L64-L75
149,891
hyperhq/hyperd
integration/client.go
GetContainerList
func (c *HyperClient) GetContainerList() ([]*types.ContainerListResult, error) { req := types.ContainerListRequest{} containerList, err := c.client.ContainerList( c.ctx, &req, ) if err != nil { return nil, err } return containerList.ContainerList, nil }
go
func (c *HyperClient) GetContainerList() ([]*types.ContainerListResult, error) { req := types.ContainerListRequest{} containerList, err := c.client.ContainerList( c.ctx, &req, ) if err != nil { return nil, err } return containerList.ContainerList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerList", "(", ")", "(", "[", "]", "*", "types", ".", "ContainerListResult", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerListRequest", "{", "}", "\n", "containerList", ",", "err", ":=", "c", ".", "client", ".", "ContainerList", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "containerList", ".", "ContainerList", ",", "nil", "\n", "}" ]
// GetContainerList gets a list of containers
[ "GetContainerList", "gets", "a", "list", "of", "containers" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L78-L89
149,892
hyperhq/hyperd
integration/client.go
GetContainerInfo
func (c *HyperClient) GetContainerInfo(container string) (*types.ContainerInfo, error) { req := types.ContainerInfoRequest{ Container: container, } cinfo, err := c.client.ContainerInfo( c.ctx, &req, ) if err != nil { return nil, err } return cinfo.ContainerInfo, nil }
go
func (c *HyperClient) GetContainerInfo(container string) (*types.ContainerInfo, error) { req := types.ContainerInfoRequest{ Container: container, } cinfo, err := c.client.ContainerInfo( c.ctx, &req, ) if err != nil { return nil, err } return cinfo.ContainerInfo, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerInfo", "(", "container", "string", ")", "(", "*", "types", ".", "ContainerInfo", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerInfoRequest", "{", "Container", ":", "container", ",", "}", "\n", "cinfo", ",", "err", ":=", "c", ".", "client", ".", "ContainerInfo", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "cinfo", ".", "ContainerInfo", ",", "nil", "\n", "}" ]
// GetContainerInfo gets container info by container name or id
[ "GetContainerInfo", "gets", "container", "info", "by", "container", "name", "or", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L92-L105
149,893
hyperhq/hyperd
integration/client.go
GetContainerLogs
func (c *HyperClient) GetContainerLogs(container string) ([]byte, error) { req := types.ContainerLogsRequest{ Container: container, Follow: false, Timestamps: false, Tail: "", Since: "", Stdout: true, Stderr: true, } stream, err := c.client.ContainerLogs( c.ctx, &req, ) if err != nil { return nil, err } ret := []byte{} for { res, err := stream.Recv() if err == io.EOF { if req.Follow == true { continue } break } if err != nil { return nil, err } ret = append(ret, res.Log...) } return ret, nil }
go
func (c *HyperClient) GetContainerLogs(container string) ([]byte, error) { req := types.ContainerLogsRequest{ Container: container, Follow: false, Timestamps: false, Tail: "", Since: "", Stdout: true, Stderr: true, } stream, err := c.client.ContainerLogs( c.ctx, &req, ) if err != nil { return nil, err } ret := []byte{} for { res, err := stream.Recv() if err == io.EOF { if req.Follow == true { continue } break } if err != nil { return nil, err } ret = append(ret, res.Log...) } return ret, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerLogs", "(", "container", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerLogsRequest", "{", "Container", ":", "container", ",", "Follow", ":", "false", ",", "Timestamps", ":", "false", ",", "Tail", ":", "\"", "\"", ",", "Since", ":", "\"", "\"", ",", "Stdout", ":", "true", ",", "Stderr", ":", "true", ",", "}", "\n", "stream", ",", "err", ":=", "c", ".", "client", ".", "ContainerLogs", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "ret", ":=", "[", "]", "byte", "{", "}", "\n", "for", "{", "res", ",", "err", ":=", "stream", ".", "Recv", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "if", "req", ".", "Follow", "==", "true", "{", "continue", "\n", "}", "\n", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "res", ".", "Log", "...", ")", "\n", "}", "\n\n", "return", "ret", ",", "nil", "\n", "}" ]
// GetContainerLogs gets container log by container name or id
[ "GetContainerLogs", "gets", "container", "log", "by", "container", "name", "or", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L108-L142
149,894
hyperhq/hyperd
integration/client.go
PostAttach
func (c *HyperClient) PostAttach(id string, tty bool) error { stream, err := c.client.Attach(c.ctx) if err != nil { return err } extractor := NewExtractor(tty) req := types.AttachMessage{ ContainerID: id, } if err := stream.Send(&req); err != nil { return err } cmd := types.AttachMessage{ Data: []byte("echo Hello Hyper\n"), } if err := stream.Send(&cmd); err != nil { return err } res, err := stream.Recv() if err != nil { return err } out, _, err := extractor.Extract(res.Data) if err != nil { return err } if string(out) != "Hello Hyper\n" { return fmt.Errorf("post attach response error\n") } return nil }
go
func (c *HyperClient) PostAttach(id string, tty bool) error { stream, err := c.client.Attach(c.ctx) if err != nil { return err } extractor := NewExtractor(tty) req := types.AttachMessage{ ContainerID: id, } if err := stream.Send(&req); err != nil { return err } cmd := types.AttachMessage{ Data: []byte("echo Hello Hyper\n"), } if err := stream.Send(&cmd); err != nil { return err } res, err := stream.Recv() if err != nil { return err } out, _, err := extractor.Extract(res.Data) if err != nil { return err } if string(out) != "Hello Hyper\n" { return fmt.Errorf("post attach response error\n") } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PostAttach", "(", "id", "string", ",", "tty", "bool", ")", "error", "{", "stream", ",", "err", ":=", "c", ".", "client", ".", "Attach", "(", "c", ".", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "extractor", ":=", "NewExtractor", "(", "tty", ")", "\n\n", "req", ":=", "types", ".", "AttachMessage", "{", "ContainerID", ":", "id", ",", "}", "\n", "if", "err", ":=", "stream", ".", "Send", "(", "&", "req", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cmd", ":=", "types", ".", "AttachMessage", "{", "Data", ":", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ",", "}", "\n", "if", "err", ":=", "stream", ".", "Send", "(", "&", "cmd", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "res", ",", "err", ":=", "stream", ".", "Recv", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "out", ",", "_", ",", "err", ":=", "extractor", ".", "Extract", "(", "res", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "string", "(", "out", ")", "!=", "\"", "\\n", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PostAttach attach to a container or pod by id
[ "PostAttach", "attach", "to", "a", "container", "or", "pod", "by", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L242-L279
149,895
hyperhq/hyperd
integration/client.go
GetImageList
func (c *HyperClient) GetImageList() ([]*types.ImageInfo, error) { req := types.ImageListRequest{} imageList, err := c.client.ImageList( c.ctx, &req, ) if err != nil { return nil, err } return imageList.ImageList, nil }
go
func (c *HyperClient) GetImageList() ([]*types.ImageInfo, error) { req := types.ImageListRequest{} imageList, err := c.client.ImageList( c.ctx, &req, ) if err != nil { return nil, err } return imageList.ImageList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetImageList", "(", ")", "(", "[", "]", "*", "types", ".", "ImageInfo", ",", "error", ")", "{", "req", ":=", "types", ".", "ImageListRequest", "{", "}", "\n", "imageList", ",", "err", ":=", "c", ".", "client", ".", "ImageList", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "imageList", ".", "ImageList", ",", "nil", "\n", "}" ]
// GetImageList gets a list of images
[ "GetImageList", "gets", "a", "list", "of", "images" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L282-L293
149,896
hyperhq/hyperd
integration/client.go
CreatePod
func (c *HyperClient) CreatePod(spec *types.UserPod) (string, error) { req := types.PodCreateRequest{ PodSpec: spec, } resp, err := c.client.PodCreate( c.ctx, &req, ) if err != nil { return "", err } return resp.PodID, nil }
go
func (c *HyperClient) CreatePod(spec *types.UserPod) (string, error) { req := types.PodCreateRequest{ PodSpec: spec, } resp, err := c.client.PodCreate( c.ctx, &req, ) if err != nil { return "", err } return resp.PodID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "CreatePod", "(", "spec", "*", "types", ".", "UserPod", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "PodCreateRequest", "{", "PodSpec", ":", "spec", ",", "}", "\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "PodCreate", "(", "c", ".", "ctx", ",", "&", "req", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "resp", ".", "PodID", ",", "nil", "\n", "}" ]
// CreatePod creates a pod
[ "CreatePod", "creates", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L296-L309
149,897
hyperhq/hyperd
integration/client.go
CreateContainer
func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (string, error) { req := types.ContainerCreateRequest{ PodID: podID, ContainerSpec: spec, } resp, err := c.client.ContainerCreate(c.ctx, &req) if err != nil { return "", err } return resp.ContainerID, nil }
go
func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (string, error) { req := types.ContainerCreateRequest{ PodID: podID, ContainerSpec: spec, } resp, err := c.client.ContainerCreate(c.ctx, &req) if err != nil { return "", err } return resp.ContainerID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "CreateContainer", "(", "podID", "string", ",", "spec", "*", "types", ".", "UserContainer", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerCreateRequest", "{", "PodID", ":", "podID", ",", "ContainerSpec", ":", "spec", ",", "}", "\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "ContainerCreate", "(", "c", ".", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "resp", ".", "ContainerID", ",", "nil", "\n", "}" ]
// CreateContainer creates a container
[ "CreateContainer", "creates", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L312-L323
149,898
hyperhq/hyperd
integration/client.go
RenameContainer
func (c *HyperClient) RenameContainer(oldName string, newName string) error { req := types.ContainerRenameRequest{ OldContainerName: oldName, NewContainerName: newName, } _, err := c.client.ContainerRename(c.ctx, &req) if err != nil { return err } return nil }
go
func (c *HyperClient) RenameContainer(oldName string, newName string) error { req := types.ContainerRenameRequest{ OldContainerName: oldName, NewContainerName: newName, } _, err := c.client.ContainerRename(c.ctx, &req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "RenameContainer", "(", "oldName", "string", ",", "newName", "string", ")", "error", "{", "req", ":=", "types", ".", "ContainerRenameRequest", "{", "OldContainerName", ":", "oldName", ",", "NewContainerName", ":", "newName", ",", "}", "\n", "_", ",", "err", ":=", "c", ".", "client", ".", "ContainerRename", "(", "c", ".", "ctx", ",", "&", "req", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RenameContainer renames a container
[ "RenameContainer", "renames", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L326-L338
149,899
hyperhq/hyperd
integration/client.go
RemovePod
func (c *HyperClient) RemovePod(podID string) error { _, err := c.client.PodRemove( c.ctx, &types.PodRemoveRequest{PodID: podID}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) RemovePod(podID string) error { _, err := c.client.PodRemove( c.ctx, &types.PodRemoveRequest{PodID: podID}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "RemovePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodRemove", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodRemoveRequest", "{", "PodID", ":", "podID", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RemovePod removes a pod by podID
[ "RemovePod", "removes", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L341-L352