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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
22,400
docker/libnetwork
datastore/datastore.go
DefaultScopes
func DefaultScopes(dataDir string) map[string]*ScopeCfg { if dataDir != "" { defaultScopes[LocalScope].Client.Address = dataDir + "/network/files/local-kv.db" return defaultScopes } defaultScopes[LocalScope].Client.Address = defaultPrefix + "/local-kv.db" return defaultScopes }
go
func DefaultScopes(dataDir string) map[string]*ScopeCfg { if dataDir != "" { defaultScopes[LocalScope].Client.Address = dataDir + "/network/files/local-kv.db" return defaultScopes } defaultScopes[LocalScope].Client.Address = defaultPrefix + "/local-kv.db" return defaultScopes }
[ "func", "DefaultScopes", "(", "dataDir", "string", ")", "map", "[", "string", "]", "*", "ScopeCfg", "{", "if", "dataDir", "!=", "\"", "\"", "{", "defaultScopes", "[", "LocalScope", "]", ".", "Client", ".", "Address", "=", "dataDir", "+", "\"", "\"", "\n", "return", "defaultScopes", "\n", "}", "\n\n", "defaultScopes", "[", "LocalScope", "]", ".", "Client", ".", "Address", "=", "defaultPrefix", "+", "\"", "\"", "\n", "return", "defaultScopes", "\n", "}" ]
// DefaultScopes returns a map of default scopes and its config for clients to use.
[ "DefaultScopes", "returns", "a", "map", "of", "default", "scopes", "and", "its", "config", "for", "clients", "to", "use", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L156-L164
22,401
docker/libnetwork
datastore/datastore.go
IsValid
func (cfg *ScopeCfg) IsValid() bool { if cfg == nil || strings.TrimSpace(cfg.Client.Provider) == "" || strings.TrimSpace(cfg.Client.Address) == "" { return false } return true }
go
func (cfg *ScopeCfg) IsValid() bool { if cfg == nil || strings.TrimSpace(cfg.Client.Provider) == "" || strings.TrimSpace(cfg.Client.Address) == "" { return false } return true }
[ "func", "(", "cfg", "*", "ScopeCfg", ")", "IsValid", "(", ")", "bool", "{", "if", "cfg", "==", "nil", "||", "strings", ".", "TrimSpace", "(", "cfg", ".", "Client", ".", "Provider", ")", "==", "\"", "\"", "||", "strings", ".", "TrimSpace", "(", "cfg", ".", "Client", ".", "Address", ")", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// IsValid checks if the scope config has valid configuration.
[ "IsValid", "checks", "if", "the", "scope", "config", "has", "valid", "configuration", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L167-L175
22,402
docker/libnetwork
datastore/datastore.go
Key
func Key(key ...string) string { keychain := append(rootChain, key...) str := strings.Join(keychain, "/") return str + "/" }
go
func Key(key ...string) string { keychain := append(rootChain, key...) str := strings.Join(keychain, "/") return str + "/" }
[ "func", "Key", "(", "key", "...", "string", ")", "string", "{", "keychain", ":=", "append", "(", "rootChain", ",", "key", "...", ")", "\n", "str", ":=", "strings", ".", "Join", "(", "keychain", ",", "\"", "\"", ")", "\n", "return", "str", "+", "\"", "\"", "\n", "}" ]
//Key provides convenient method to create a Key
[ "Key", "provides", "convenient", "method", "to", "create", "a", "Key" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L178-L182
22,403
docker/libnetwork
datastore/datastore.go
ParseKey
func ParseKey(key string) ([]string, error) { chain := strings.Split(strings.Trim(key, "/"), "/") // The key must at least be equal to the rootChain in order to be considered as valid if len(chain) <= len(rootChain) || !reflect.DeepEqual(chain[0:len(rootChain)], rootChain) { return nil, types.BadRequestErrorf("invalid Key : %s", key) } return chain[len(rootChain):], nil }
go
func ParseKey(key string) ([]string, error) { chain := strings.Split(strings.Trim(key, "/"), "/") // The key must at least be equal to the rootChain in order to be considered as valid if len(chain) <= len(rootChain) || !reflect.DeepEqual(chain[0:len(rootChain)], rootChain) { return nil, types.BadRequestErrorf("invalid Key : %s", key) } return chain[len(rootChain):], nil }
[ "func", "ParseKey", "(", "key", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "chain", ":=", "strings", ".", "Split", "(", "strings", ".", "Trim", "(", "key", ",", "\"", "\"", ")", ",", "\"", "\"", ")", "\n\n", "// The key must at least be equal to the rootChain in order to be considered as valid", "if", "len", "(", "chain", ")", "<=", "len", "(", "rootChain", ")", "||", "!", "reflect", ".", "DeepEqual", "(", "chain", "[", "0", ":", "len", "(", "rootChain", ")", "]", ",", "rootChain", ")", "{", "return", "nil", ",", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "return", "chain", "[", "len", "(", "rootChain", ")", ":", "]", ",", "nil", "\n", "}" ]
//ParseKey provides convenient method to unpack the key to complement the Key function
[ "ParseKey", "provides", "convenient", "method", "to", "unpack", "the", "key", "to", "complement", "the", "Key", "function" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L185-L193
22,404
docker/libnetwork
datastore/datastore.go
newClient
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error) { if cached && scope != LocalScope { return nil, fmt.Errorf("caching supported only for scope %s", LocalScope) } sequential := false if scope == LocalScope { sequential = true } if config == nil { config = &store.Config{} } var addrs []string if kv == string(store.BOLTDB) { // Parse file path addrs = strings.Split(addr, ",") } else { // Parse URI parts := strings.SplitN(addr, "/", 2) addrs = strings.Split(parts[0], ",") // Add the custom prefix to the root chain if len(parts) == 2 { rootChain = append([]string{parts[1]}, defaultRootChain...) } } store, err := libkv.NewStore(store.Backend(kv), addrs, config) if err != nil { return nil, err } ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{}), sequential: sequential} if cached { ds.cache = newCache(ds) } return ds, nil }
go
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error) { if cached && scope != LocalScope { return nil, fmt.Errorf("caching supported only for scope %s", LocalScope) } sequential := false if scope == LocalScope { sequential = true } if config == nil { config = &store.Config{} } var addrs []string if kv == string(store.BOLTDB) { // Parse file path addrs = strings.Split(addr, ",") } else { // Parse URI parts := strings.SplitN(addr, "/", 2) addrs = strings.Split(parts[0], ",") // Add the custom prefix to the root chain if len(parts) == 2 { rootChain = append([]string{parts[1]}, defaultRootChain...) } } store, err := libkv.NewStore(store.Backend(kv), addrs, config) if err != nil { return nil, err } ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{}), sequential: sequential} if cached { ds.cache = newCache(ds) } return ds, nil }
[ "func", "newClient", "(", "scope", "string", ",", "kv", "string", ",", "addr", "string", ",", "config", "*", "store", ".", "Config", ",", "cached", "bool", ")", "(", "DataStore", ",", "error", ")", "{", "if", "cached", "&&", "scope", "!=", "LocalScope", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "LocalScope", ")", "\n", "}", "\n", "sequential", ":=", "false", "\n", "if", "scope", "==", "LocalScope", "{", "sequential", "=", "true", "\n", "}", "\n\n", "if", "config", "==", "nil", "{", "config", "=", "&", "store", ".", "Config", "{", "}", "\n", "}", "\n\n", "var", "addrs", "[", "]", "string", "\n\n", "if", "kv", "==", "string", "(", "store", ".", "BOLTDB", ")", "{", "// Parse file path", "addrs", "=", "strings", ".", "Split", "(", "addr", ",", "\"", "\"", ")", "\n", "}", "else", "{", "// Parse URI", "parts", ":=", "strings", ".", "SplitN", "(", "addr", ",", "\"", "\"", ",", "2", ")", "\n", "addrs", "=", "strings", ".", "Split", "(", "parts", "[", "0", "]", ",", "\"", "\"", ")", "\n\n", "// Add the custom prefix to the root chain", "if", "len", "(", "parts", ")", "==", "2", "{", "rootChain", "=", "append", "(", "[", "]", "string", "{", "parts", "[", "1", "]", "}", ",", "defaultRootChain", "...", ")", "\n", "}", "\n", "}", "\n\n", "store", ",", "err", ":=", "libkv", ".", "NewStore", "(", "store", ".", "Backend", "(", "kv", ")", ",", "addrs", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "ds", ":=", "&", "datastore", "{", "scope", ":", "scope", ",", "store", ":", "store", ",", "active", ":", "true", ",", "watchCh", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "sequential", ":", "sequential", "}", "\n", "if", "cached", "{", "ds", ".", "cache", "=", "newCache", "(", "ds", ")", "\n", "}", "\n\n", "return", "ds", ",", "nil", "\n", "}" ]
// newClient used to connect to KV Store
[ "newClient", "used", "to", "connect", "to", "KV", "Store" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L196-L237
22,405
docker/libnetwork
datastore/datastore.go
NewDataStore
func NewDataStore(scope string, cfg *ScopeCfg) (DataStore, error) { if cfg == nil || cfg.Client.Provider == "" || cfg.Client.Address == "" { c, ok := defaultScopes[scope] if !ok || c.Client.Provider == "" || c.Client.Address == "" { return nil, fmt.Errorf("unexpected scope %s without configuration passed", scope) } cfg = c } var cached bool if scope == LocalScope { cached = true } return newClient(scope, cfg.Client.Provider, cfg.Client.Address, cfg.Client.Config, cached) }
go
func NewDataStore(scope string, cfg *ScopeCfg) (DataStore, error) { if cfg == nil || cfg.Client.Provider == "" || cfg.Client.Address == "" { c, ok := defaultScopes[scope] if !ok || c.Client.Provider == "" || c.Client.Address == "" { return nil, fmt.Errorf("unexpected scope %s without configuration passed", scope) } cfg = c } var cached bool if scope == LocalScope { cached = true } return newClient(scope, cfg.Client.Provider, cfg.Client.Address, cfg.Client.Config, cached) }
[ "func", "NewDataStore", "(", "scope", "string", ",", "cfg", "*", "ScopeCfg", ")", "(", "DataStore", ",", "error", ")", "{", "if", "cfg", "==", "nil", "||", "cfg", ".", "Client", ".", "Provider", "==", "\"", "\"", "||", "cfg", ".", "Client", ".", "Address", "==", "\"", "\"", "{", "c", ",", "ok", ":=", "defaultScopes", "[", "scope", "]", "\n", "if", "!", "ok", "||", "c", ".", "Client", ".", "Provider", "==", "\"", "\"", "||", "c", ".", "Client", ".", "Address", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "scope", ")", "\n", "}", "\n\n", "cfg", "=", "c", "\n", "}", "\n\n", "var", "cached", "bool", "\n", "if", "scope", "==", "LocalScope", "{", "cached", "=", "true", "\n", "}", "\n\n", "return", "newClient", "(", "scope", ",", "cfg", ".", "Client", ".", "Provider", ",", "cfg", ".", "Client", ".", "Address", ",", "cfg", ".", "Client", ".", "Config", ",", "cached", ")", "\n", "}" ]
// NewDataStore creates a new instance of LibKV data store
[ "NewDataStore", "creates", "a", "new", "instance", "of", "LibKV", "data", "store" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L240-L256
22,406
docker/libnetwork
datastore/datastore.go
NewDataStoreFromConfig
func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, error) { var ( ok bool sCfgP *store.Config ) sCfgP, ok = dsc.Config.(*store.Config) if !ok && dsc.Config != nil { return nil, fmt.Errorf("cannot parse store configuration: %v", dsc.Config) } scopeCfg := &ScopeCfg{ Client: ScopeClientCfg{ Address: dsc.Address, Provider: dsc.Provider, Config: sCfgP, }, } ds, err := NewDataStore(dsc.Scope, scopeCfg) if err != nil { return nil, fmt.Errorf("failed to construct datastore client from datastore configuration %v: %v", dsc, err) } return ds, err }
go
func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, error) { var ( ok bool sCfgP *store.Config ) sCfgP, ok = dsc.Config.(*store.Config) if !ok && dsc.Config != nil { return nil, fmt.Errorf("cannot parse store configuration: %v", dsc.Config) } scopeCfg := &ScopeCfg{ Client: ScopeClientCfg{ Address: dsc.Address, Provider: dsc.Provider, Config: sCfgP, }, } ds, err := NewDataStore(dsc.Scope, scopeCfg) if err != nil { return nil, fmt.Errorf("failed to construct datastore client from datastore configuration %v: %v", dsc, err) } return ds, err }
[ "func", "NewDataStoreFromConfig", "(", "dsc", "discoverapi", ".", "DatastoreConfigData", ")", "(", "DataStore", ",", "error", ")", "{", "var", "(", "ok", "bool", "\n", "sCfgP", "*", "store", ".", "Config", "\n", ")", "\n\n", "sCfgP", ",", "ok", "=", "dsc", ".", "Config", ".", "(", "*", "store", ".", "Config", ")", "\n", "if", "!", "ok", "&&", "dsc", ".", "Config", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dsc", ".", "Config", ")", "\n", "}", "\n\n", "scopeCfg", ":=", "&", "ScopeCfg", "{", "Client", ":", "ScopeClientCfg", "{", "Address", ":", "dsc", ".", "Address", ",", "Provider", ":", "dsc", ".", "Provider", ",", "Config", ":", "sCfgP", ",", "}", ",", "}", "\n\n", "ds", ",", "err", ":=", "NewDataStore", "(", "dsc", ".", "Scope", ",", "scopeCfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dsc", ",", "err", ")", "\n", "}", "\n\n", "return", "ds", ",", "err", "\n", "}" ]
// NewDataStoreFromConfig creates a new instance of LibKV data store starting from the datastore config data
[ "NewDataStoreFromConfig", "creates", "a", "new", "instance", "of", "LibKV", "data", "store", "starting", "from", "the", "datastore", "config", "data" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L259-L284
22,407
docker/libnetwork
datastore/datastore.go
PutObjectAtomic
func (ds *datastore) PutObjectAtomic(kvObject KVObject) error { var ( previous *store.KVPair pair *store.KVPair err error ) if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } kvObjValue := kvObject.Value() if kvObjValue == nil { return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...)) } if kvObject.Skip() { goto add_cache } if kvObject.Exists() { previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} } else { previous = nil } _, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil) if err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } kvObject.SetIndex(pair.LastIndex) add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
go
func (ds *datastore) PutObjectAtomic(kvObject KVObject) error { var ( previous *store.KVPair pair *store.KVPair err error ) if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } kvObjValue := kvObject.Value() if kvObjValue == nil { return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...)) } if kvObject.Skip() { goto add_cache } if kvObject.Exists() { previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} } else { previous = nil } _, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil) if err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } kvObject.SetIndex(pair.LastIndex) add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
[ "func", "(", "ds", "*", "datastore", ")", "PutObjectAtomic", "(", "kvObject", "KVObject", ")", "error", "{", "var", "(", "previous", "*", "store", ".", "KVPair", "\n", "pair", "*", "store", ".", "KVPair", "\n", "err", "error", "\n", ")", "\n", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", "kvObject", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "kvObjValue", ":=", "kvObject", ".", "Value", "(", ")", "\n\n", "if", "kvObjValue", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ")", "\n", "}", "\n\n", "if", "kvObject", ".", "Skip", "(", ")", "{", "goto", "add_cache", "\n", "}", "\n\n", "if", "kvObject", ".", "Exists", "(", ")", "{", "previous", "=", "&", "store", ".", "KVPair", "{", "Key", ":", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ",", "LastIndex", ":", "kvObject", ".", "Index", "(", ")", "}", "\n", "}", "else", "{", "previous", "=", "nil", "\n", "}", "\n\n", "_", ",", "pair", ",", "err", "=", "ds", ".", "store", ".", "AtomicPut", "(", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ",", "kvObjValue", ",", "previous", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "store", ".", "ErrKeyExists", "{", "return", "ErrKeyModified", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "kvObject", ".", "SetIndex", "(", "pair", ".", "LastIndex", ")", "\n\n", "add_cache", ":", "if", "ds", ".", "cache", "!=", "nil", "{", "// If persistent store is skipped, sequencing needs to", "// happen in cache.", "return", "ds", ".", "cache", ".", "add", "(", "kvObject", ",", "kvObject", ".", "Skip", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PutObjectAtomic adds a new Record based on an object into the datastore
[ "PutObjectAtomic", "adds", "a", "new", "Record", "based", "on", "an", "object", "into", "the", "datastore" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L384-L433
22,408
docker/libnetwork
datastore/datastore.go
PutObject
func (ds *datastore) PutObject(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } if kvObject.Skip() { goto add_cache } if err := ds.putObjectWithKey(kvObject, kvObject.Key()...); err != nil { return err } add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
go
func (ds *datastore) PutObject(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } if kvObject.Skip() { goto add_cache } if err := ds.putObjectWithKey(kvObject, kvObject.Key()...); err != nil { return err } add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
[ "func", "(", "ds", "*", "datastore", ")", "PutObject", "(", "kvObject", "KVObject", ")", "error", "{", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", "kvObject", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "kvObject", ".", "Skip", "(", ")", "{", "goto", "add_cache", "\n", "}", "\n\n", "if", "err", ":=", "ds", ".", "putObjectWithKey", "(", "kvObject", ",", "kvObject", ".", "Key", "(", ")", "...", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "add_cache", ":", "if", "ds", ".", "cache", "!=", "nil", "{", "// If persistent store is skipped, sequencing needs to", "// happen in cache.", "return", "ds", ".", "cache", ".", "add", "(", "kvObject", ",", "kvObject", ".", "Skip", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PutObject adds a new Record based on an object into the datastore
[ "PutObject", "adds", "a", "new", "Record", "based", "on", "an", "object", "into", "the", "datastore" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L436-L462
22,409
docker/libnetwork
datastore/datastore.go
GetObject
func (ds *datastore) GetObject(key string, o KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if ds.cache != nil { return ds.cache.get(key, o) } kvPair, err := ds.store.Get(key) if err != nil { return err } if err := o.SetValue(kvPair.Value); err != nil { return err } // Make sure the object has a correct view of the DB index in // case we need to modify it and update the DB. o.SetIndex(kvPair.LastIndex) return nil }
go
func (ds *datastore) GetObject(key string, o KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if ds.cache != nil { return ds.cache.get(key, o) } kvPair, err := ds.store.Get(key) if err != nil { return err } if err := o.SetValue(kvPair.Value); err != nil { return err } // Make sure the object has a correct view of the DB index in // case we need to modify it and update the DB. o.SetIndex(kvPair.LastIndex) return nil }
[ "func", "(", "ds", "*", "datastore", ")", "GetObject", "(", "key", "string", ",", "o", "KVObject", ")", "error", "{", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", "ds", ".", "cache", "!=", "nil", "{", "return", "ds", ".", "cache", ".", "get", "(", "key", ",", "o", ")", "\n", "}", "\n\n", "kvPair", ",", "err", ":=", "ds", ".", "store", ".", "Get", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "o", ".", "SetValue", "(", "kvPair", ".", "Value", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Make sure the object has a correct view of the DB index in", "// case we need to modify it and update the DB.", "o", ".", "SetIndex", "(", "kvPair", ".", "LastIndex", ")", "\n", "return", "nil", "\n", "}" ]
// GetObject returns a record matching the key
[ "GetObject", "returns", "a", "record", "matching", "the", "key" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L474-L497
22,410
docker/libnetwork
datastore/datastore.go
DeleteObject
func (ds *datastore) DeleteObject(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.Delete(Key(kvObject.Key()...)) }
go
func (ds *datastore) DeleteObject(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.Delete(Key(kvObject.Key()...)) }
[ "func", "(", "ds", "*", "datastore", ")", "DeleteObject", "(", "kvObject", "KVObject", ")", "error", "{", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "// cleanup the cache first", "if", "ds", ".", "cache", "!=", "nil", "{", "// If persistent store is skipped, sequencing needs to", "// happen in cache.", "ds", ".", "cache", ".", "del", "(", "kvObject", ",", "kvObject", ".", "Skip", "(", ")", ")", "\n", "}", "\n\n", "if", "kvObject", ".", "Skip", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "ds", ".", "store", ".", "Delete", "(", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ")", "\n", "}" ]
// DeleteObject unconditionally deletes a record from the store
[ "DeleteObject", "unconditionally", "deletes", "a", "record", "from", "the", "store" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L586-L604
22,411
docker/libnetwork
datastore/datastore.go
DeleteObjectAtomic
func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} if kvObject.Skip() { goto del_cache } if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } del_cache: // cleanup the cache only if AtomicDelete went through successfully if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.del(kvObject, kvObject.Skip()) } return nil }
go
func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} if kvObject.Skip() { goto del_cache } if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } del_cache: // cleanup the cache only if AtomicDelete went through successfully if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.del(kvObject, kvObject.Skip()) } return nil }
[ "func", "(", "ds", "*", "datastore", ")", "DeleteObjectAtomic", "(", "kvObject", "KVObject", ")", "error", "{", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", "kvObject", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "previous", ":=", "&", "store", ".", "KVPair", "{", "Key", ":", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ",", "LastIndex", ":", "kvObject", ".", "Index", "(", ")", "}", "\n\n", "if", "kvObject", ".", "Skip", "(", ")", "{", "goto", "del_cache", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "ds", ".", "store", ".", "AtomicDelete", "(", "Key", "(", "kvObject", ".", "Key", "(", ")", "...", ")", ",", "previous", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "store", ".", "ErrKeyExists", "{", "return", "ErrKeyModified", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "del_cache", ":", "// cleanup the cache only if AtomicDelete went through successfully", "if", "ds", ".", "cache", "!=", "nil", "{", "// If persistent store is skipped, sequencing needs to", "// happen in cache.", "return", "ds", ".", "cache", ".", "del", "(", "kvObject", ",", "kvObject", ".", "Skip", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteObjectAtomic performs atomic delete on a record
[ "DeleteObjectAtomic", "performs", "atomic", "delete", "on", "a", "record" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L607-L639
22,412
docker/libnetwork
datastore/datastore.go
DeleteTree
func (ds *datastore) DeleteTree(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.DeleteTree(Key(kvObject.KeyPrefix()...)) }
go
func (ds *datastore) DeleteTree(kvObject KVObject) error { if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.DeleteTree(Key(kvObject.KeyPrefix()...)) }
[ "func", "(", "ds", "*", "datastore", ")", "DeleteTree", "(", "kvObject", "KVObject", ")", "error", "{", "if", "ds", ".", "sequential", "{", "ds", ".", "Lock", "(", ")", "\n", "defer", "ds", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "// cleanup the cache first", "if", "ds", ".", "cache", "!=", "nil", "{", "// If persistent store is skipped, sequencing needs to", "// happen in cache.", "ds", ".", "cache", ".", "del", "(", "kvObject", ",", "kvObject", ".", "Skip", "(", ")", ")", "\n", "}", "\n\n", "if", "kvObject", ".", "Skip", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "ds", ".", "store", ".", "DeleteTree", "(", "Key", "(", "kvObject", ".", "KeyPrefix", "(", ")", "...", ")", ")", "\n", "}" ]
// DeleteTree unconditionally deletes a record from the store
[ "DeleteTree", "unconditionally", "deletes", "a", "record", "from", "the", "store" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L642-L660
22,413
docker/libnetwork
drivers/remote/driver.go
Init
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { newPluginHandler := func(name string, client *plugins.Client) { // negotiate driver capability with client d := newDriver(name, client) c, err := d.(*driver).getCapabilities() if err != nil { logrus.Errorf("error getting capability for %s due to %v", name, err) return } if err = dc.RegisterDriver(name, d, *c); err != nil { logrus.Errorf("error registering driver for %s due to %v", name, err) } } // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. handleFunc := plugins.Handle if pg := dc.GetPluginGetter(); pg != nil { handleFunc = pg.Handle activePlugins := pg.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType) for _, ap := range activePlugins { client, err := getPluginClient(ap) if err != nil { return err } newPluginHandler(ap.Name(), client) } } handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler) return nil }
go
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { newPluginHandler := func(name string, client *plugins.Client) { // negotiate driver capability with client d := newDriver(name, client) c, err := d.(*driver).getCapabilities() if err != nil { logrus.Errorf("error getting capability for %s due to %v", name, err) return } if err = dc.RegisterDriver(name, d, *c); err != nil { logrus.Errorf("error registering driver for %s due to %v", name, err) } } // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. handleFunc := plugins.Handle if pg := dc.GetPluginGetter(); pg != nil { handleFunc = pg.Handle activePlugins := pg.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType) for _, ap := range activePlugins { client, err := getPluginClient(ap) if err != nil { return err } newPluginHandler(ap.Name(), client) } } handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler) return nil }
[ "func", "Init", "(", "dc", "driverapi", ".", "DriverCallback", ",", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "newPluginHandler", ":=", "func", "(", "name", "string", ",", "client", "*", "plugins", ".", "Client", ")", "{", "// negotiate driver capability with client", "d", ":=", "newDriver", "(", "name", ",", "client", ")", "\n", "c", ",", "err", ":=", "d", ".", "(", "*", "driver", ")", ".", "getCapabilities", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "err", ")", "\n", "return", "\n", "}", "\n", "if", "err", "=", "dc", ".", "RegisterDriver", "(", "name", ",", "d", ",", "*", "c", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.", "handleFunc", ":=", "plugins", ".", "Handle", "\n", "if", "pg", ":=", "dc", ".", "GetPluginGetter", "(", ")", ";", "pg", "!=", "nil", "{", "handleFunc", "=", "pg", ".", "Handle", "\n", "activePlugins", ":=", "pg", ".", "GetAllManagedPluginsByCap", "(", "driverapi", ".", "NetworkPluginEndpointType", ")", "\n", "for", "_", ",", "ap", ":=", "range", "activePlugins", "{", "client", ",", "err", ":=", "getPluginClient", "(", "ap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "newPluginHandler", "(", "ap", ".", "Name", "(", ")", ",", "client", ")", "\n", "}", "\n", "}", "\n", "handleFunc", "(", "driverapi", ".", "NetworkPluginEndpointType", ",", "newPluginHandler", ")", "\n\n", "return", "nil", "\n", "}" ]
// Init makes sure a remote driver is registered when a network driver // plugin is activated.
[ "Init", "makes", "sure", "a", "remote", "driver", "is", "registered", "when", "a", "network", "driver", "plugin", "is", "activated", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L33-L63
22,414
docker/libnetwork
drivers/remote/driver.go
getCapabilities
func (d *driver) getCapabilities() (*driverapi.Capability, error) { var capResp api.GetCapabilityResponse if err := d.call("GetCapabilities", nil, &capResp); err != nil { return nil, err } c := &driverapi.Capability{} switch capResp.Scope { case "global": c.DataScope = datastore.GlobalScope case "local": c.DataScope = datastore.LocalScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } switch capResp.ConnectivityScope { case "global": c.ConnectivityScope = datastore.GlobalScope case "local": c.ConnectivityScope = datastore.LocalScope case "": c.ConnectivityScope = c.DataScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } return c, nil }
go
func (d *driver) getCapabilities() (*driverapi.Capability, error) { var capResp api.GetCapabilityResponse if err := d.call("GetCapabilities", nil, &capResp); err != nil { return nil, err } c := &driverapi.Capability{} switch capResp.Scope { case "global": c.DataScope = datastore.GlobalScope case "local": c.DataScope = datastore.LocalScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } switch capResp.ConnectivityScope { case "global": c.ConnectivityScope = datastore.GlobalScope case "local": c.ConnectivityScope = datastore.LocalScope case "": c.ConnectivityScope = c.DataScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } return c, nil }
[ "func", "(", "d", "*", "driver", ")", "getCapabilities", "(", ")", "(", "*", "driverapi", ".", "Capability", ",", "error", ")", "{", "var", "capResp", "api", ".", "GetCapabilityResponse", "\n", "if", "err", ":=", "d", ".", "call", "(", "\"", "\"", ",", "nil", ",", "&", "capResp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "c", ":=", "&", "driverapi", ".", "Capability", "{", "}", "\n", "switch", "capResp", ".", "Scope", "{", "case", "\"", "\"", ":", "c", ".", "DataScope", "=", "datastore", ".", "GlobalScope", "\n", "case", "\"", "\"", ":", "c", ".", "DataScope", "=", "datastore", ".", "LocalScope", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "capResp", ".", "Scope", ")", "\n", "}", "\n\n", "switch", "capResp", ".", "ConnectivityScope", "{", "case", "\"", "\"", ":", "c", ".", "ConnectivityScope", "=", "datastore", ".", "GlobalScope", "\n", "case", "\"", "\"", ":", "c", ".", "ConnectivityScope", "=", "datastore", ".", "LocalScope", "\n", "case", "\"", "\"", ":", "c", ".", "ConnectivityScope", "=", "c", ".", "DataScope", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "capResp", ".", "Scope", ")", "\n", "}", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// Get capability from client
[ "Get", "capability", "from", "client" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L88-L116
22,415
docker/libnetwork
drivers/remote/driver.go
ProgramExternalConnectivity
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { data := &api.ProgramExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, Options: options, } err := d.call("ProgramExternalConnectivity", data, &api.ProgramExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
go
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { data := &api.ProgramExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, Options: options, } err := d.call("ProgramExternalConnectivity", data, &api.ProgramExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
[ "func", "(", "d", "*", "driver", ")", "ProgramExternalConnectivity", "(", "nid", ",", "eid", "string", ",", "options", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "data", ":=", "&", "api", ".", "ProgramExternalConnectivityRequest", "{", "NetworkID", ":", "nid", ",", "EndpointID", ":", "eid", ",", "Options", ":", "options", ",", "}", "\n", "err", ":=", "d", ".", "call", "(", "\"", "\"", ",", "data", ",", "&", "api", ".", "ProgramExternalConnectivityResponse", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "plugins", ".", "IsNotFound", "(", "err", ")", "{", "// It is not mandatory yet to support this method", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// ProgramExternalConnectivity is invoked to program the rules to allow external connectivity for the endpoint.
[ "ProgramExternalConnectivity", "is", "invoked", "to", "program", "the", "rules", "to", "allow", "external", "connectivity", "for", "the", "endpoint", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L326-L338
22,416
docker/libnetwork
drivers/remote/driver.go
RevokeExternalConnectivity
func (d *driver) RevokeExternalConnectivity(nid, eid string) error { data := &api.RevokeExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, } err := d.call("RevokeExternalConnectivity", data, &api.RevokeExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
go
func (d *driver) RevokeExternalConnectivity(nid, eid string) error { data := &api.RevokeExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, } err := d.call("RevokeExternalConnectivity", data, &api.RevokeExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
[ "func", "(", "d", "*", "driver", ")", "RevokeExternalConnectivity", "(", "nid", ",", "eid", "string", ")", "error", "{", "data", ":=", "&", "api", ".", "RevokeExternalConnectivityRequest", "{", "NetworkID", ":", "nid", ",", "EndpointID", ":", "eid", ",", "}", "\n", "err", ":=", "d", ".", "call", "(", "\"", "\"", ",", "data", ",", "&", "api", ".", "RevokeExternalConnectivityResponse", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "plugins", ".", "IsNotFound", "(", "err", ")", "{", "// It is not mandatory yet to support this method", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// RevokeExternalConnectivity method is invoked to remove any external connectivity programming related to the endpoint.
[ "RevokeExternalConnectivity", "method", "is", "invoked", "to", "remove", "any", "external", "connectivity", "programming", "related", "to", "the", "endpoint", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L341-L352
22,417
docker/libnetwork
drivers/remote/driver.go
parseInterface
func parseInterface(r api.CreateEndpointResponse) (*api.Interface, error) { var outIf *api.Interface inIf := r.Interface if inIf != nil { var err error outIf = &api.Interface{} if inIf.Address != "" { if outIf.Address, err = types.ParseCIDR(inIf.Address); err != nil { return nil, err } } if inIf.AddressIPv6 != "" { if outIf.AddressIPv6, err = types.ParseCIDR(inIf.AddressIPv6); err != nil { return nil, err } } if inIf.MacAddress != "" { if outIf.MacAddress, err = net.ParseMAC(inIf.MacAddress); err != nil { return nil, err } } } return outIf, nil }
go
func parseInterface(r api.CreateEndpointResponse) (*api.Interface, error) { var outIf *api.Interface inIf := r.Interface if inIf != nil { var err error outIf = &api.Interface{} if inIf.Address != "" { if outIf.Address, err = types.ParseCIDR(inIf.Address); err != nil { return nil, err } } if inIf.AddressIPv6 != "" { if outIf.AddressIPv6, err = types.ParseCIDR(inIf.AddressIPv6); err != nil { return nil, err } } if inIf.MacAddress != "" { if outIf.MacAddress, err = net.ParseMAC(inIf.MacAddress); err != nil { return nil, err } } } return outIf, nil }
[ "func", "parseInterface", "(", "r", "api", ".", "CreateEndpointResponse", ")", "(", "*", "api", ".", "Interface", ",", "error", ")", "{", "var", "outIf", "*", "api", ".", "Interface", "\n\n", "inIf", ":=", "r", ".", "Interface", "\n", "if", "inIf", "!=", "nil", "{", "var", "err", "error", "\n", "outIf", "=", "&", "api", ".", "Interface", "{", "}", "\n", "if", "inIf", ".", "Address", "!=", "\"", "\"", "{", "if", "outIf", ".", "Address", ",", "err", "=", "types", ".", "ParseCIDR", "(", "inIf", ".", "Address", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "inIf", ".", "AddressIPv6", "!=", "\"", "\"", "{", "if", "outIf", ".", "AddressIPv6", ",", "err", "=", "types", ".", "ParseCIDR", "(", "inIf", ".", "AddressIPv6", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "inIf", ".", "MacAddress", "!=", "\"", "\"", "{", "if", "outIf", ".", "MacAddress", ",", "err", "=", "net", ".", "ParseMAC", "(", "inIf", ".", "MacAddress", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "outIf", ",", "nil", "\n", "}" ]
// parseInterfaces validates all the parameters of an Interface and returns them.
[ "parseInterfaces", "validates", "all", "the", "parameters", "of", "an", "Interface", "and", "returns", "them", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L411-L436
22,418
docker/libnetwork
cmd/proxy/udp_proxy.go
Close
func (proxy *UDPProxy) Close() { proxy.listener.Close() proxy.connTrackLock.Lock() defer proxy.connTrackLock.Unlock() for _, conn := range proxy.connTrackTable { conn.Close() } }
go
func (proxy *UDPProxy) Close() { proxy.listener.Close() proxy.connTrackLock.Lock() defer proxy.connTrackLock.Unlock() for _, conn := range proxy.connTrackTable { conn.Close() } }
[ "func", "(", "proxy", "*", "UDPProxy", ")", "Close", "(", ")", "{", "proxy", ".", "listener", ".", "Close", "(", ")", "\n", "proxy", ".", "connTrackLock", ".", "Lock", "(", ")", "\n", "defer", "proxy", ".", "connTrackLock", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "conn", ":=", "range", "proxy", ".", "connTrackTable", "{", "conn", ".", "Close", "(", ")", "\n", "}", "\n", "}" ]
// Close stops forwarding the traffic.
[ "Close", "stops", "forwarding", "the", "traffic", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/udp_proxy.go#L145-L152
22,419
docker/libnetwork
agent.go
getKeys
func (c *controller) getKeys(subsys string) ([][]byte, []uint64) { c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := [][]byte{} tags := []uint64{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key.Key) tags = append(tags, key.LamportTime) } } keys[0], keys[1] = keys[1], keys[0] tags[0], tags[1] = tags[1], tags[0] return keys, tags }
go
func (c *controller) getKeys(subsys string) ([][]byte, []uint64) { c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := [][]byte{} tags := []uint64{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key.Key) tags = append(tags, key.LamportTime) } } keys[0], keys[1] = keys[1], keys[0] tags[0], tags[1] = tags[1], tags[0] return keys, tags }
[ "func", "(", "c", "*", "controller", ")", "getKeys", "(", "subsys", "string", ")", "(", "[", "]", "[", "]", "byte", ",", "[", "]", "uint64", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n\n", "sort", ".", "Sort", "(", "ByTime", "(", "c", ".", "keys", ")", ")", "\n\n", "keys", ":=", "[", "]", "[", "]", "byte", "{", "}", "\n", "tags", ":=", "[", "]", "uint64", "{", "}", "\n", "for", "_", ",", "key", ":=", "range", "c", ".", "keys", "{", "if", "key", ".", "Subsystem", "==", "subsys", "{", "keys", "=", "append", "(", "keys", ",", "key", ".", "Key", ")", "\n", "tags", "=", "append", "(", "tags", ",", "key", ".", "LamportTime", ")", "\n", "}", "\n", "}", "\n\n", "keys", "[", "0", "]", ",", "keys", "[", "1", "]", "=", "keys", "[", "1", "]", ",", "keys", "[", "0", "]", "\n", "tags", "[", "0", "]", ",", "tags", "[", "1", "]", "=", "tags", "[", "1", "]", ",", "tags", "[", "0", "]", "\n", "return", "keys", ",", "tags", "\n", "}" ]
// For a given subsystem getKeys sorts the keys by lamport time and returns // slice of keys and lamport time which can used as a unique tag for the keys
[ "For", "a", "given", "subsystem", "getKeys", "sorts", "the", "keys", "by", "lamport", "time", "and", "returns", "slice", "of", "keys", "and", "lamport", "time", "which", "can", "used", "as", "a", "unique", "tag", "for", "the", "keys" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/agent.go#L241-L259
22,420
docker/libnetwork
agent.go
getPrimaryKeyTag
func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) { c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := []*types.EncryptionKey{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key) } } return keys[1].Key, keys[1].LamportTime, nil }
go
func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) { c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := []*types.EncryptionKey{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key) } } return keys[1].Key, keys[1].LamportTime, nil }
[ "func", "(", "c", "*", "controller", ")", "getPrimaryKeyTag", "(", "subsys", "string", ")", "(", "[", "]", "byte", ",", "uint64", ",", "error", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "sort", ".", "Sort", "(", "ByTime", "(", "c", ".", "keys", ")", ")", "\n", "keys", ":=", "[", "]", "*", "types", ".", "EncryptionKey", "{", "}", "\n", "for", "_", ",", "key", ":=", "range", "c", ".", "keys", "{", "if", "key", ".", "Subsystem", "==", "subsys", "{", "keys", "=", "append", "(", "keys", ",", "key", ")", "\n", "}", "\n", "}", "\n", "return", "keys", "[", "1", "]", ".", "Key", ",", "keys", "[", "1", "]", ".", "LamportTime", ",", "nil", "\n", "}" ]
// getPrimaryKeyTag returns the primary key for a given subsystem from the // list of sorted key and the associated tag
[ "getPrimaryKeyTag", "returns", "the", "primary", "key", "for", "a", "given", "subsystem", "from", "the", "list", "of", "sorted", "key", "and", "the", "associated", "tag" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/agent.go#L263-L274
22,421
docker/libnetwork
drivers/ipvlan/ipvlan_joinleave.go
getSubnetforIPv4
func (n *network) getSubnetforIPv4(ip *net.IPNet) *ipv4Subnet { for _, s := range n.config.Ipv4Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
go
func (n *network) getSubnetforIPv4(ip *net.IPNet) *ipv4Subnet { for _, s := range n.config.Ipv4Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
[ "func", "(", "n", "*", "network", ")", "getSubnetforIPv4", "(", "ip", "*", "net", ".", "IPNet", ")", "*", "ipv4Subnet", "{", "for", "_", ",", "s", ":=", "range", "n", ".", "config", ".", "Ipv4Subnets", "{", "_", ",", "snet", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "s", ".", "SubnetIP", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "// first check if the mask lengths are the same", "i", ",", "_", ":=", "snet", ".", "Mask", ".", "Size", "(", ")", "\n", "j", ",", "_", ":=", "ip", ".", "Mask", ".", "Size", "(", ")", "\n", "if", "i", "!=", "j", "{", "continue", "\n", "}", "\n", "if", "snet", ".", "Contains", "(", "ip", ".", "IP", ")", "{", "return", "s", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// getSubnetforIPv4 returns the ipv4 subnet to which the given IP belongs
[ "getSubnetforIPv4", "returns", "the", "ipv4", "subnet", "to", "which", "the", "given", "IP", "belongs" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L160-L178
22,422
docker/libnetwork
drivers/ipvlan/ipvlan_joinleave.go
getSubnetforIPv6
func (n *network) getSubnetforIPv6(ip *net.IPNet) *ipv6Subnet { for _, s := range n.config.Ipv6Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
go
func (n *network) getSubnetforIPv6(ip *net.IPNet) *ipv6Subnet { for _, s := range n.config.Ipv6Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
[ "func", "(", "n", "*", "network", ")", "getSubnetforIPv6", "(", "ip", "*", "net", ".", "IPNet", ")", "*", "ipv6Subnet", "{", "for", "_", ",", "s", ":=", "range", "n", ".", "config", ".", "Ipv6Subnets", "{", "_", ",", "snet", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "s", ".", "SubnetIP", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "// first check if the mask lengths are the same", "i", ",", "_", ":=", "snet", ".", "Mask", ".", "Size", "(", ")", "\n", "j", ",", "_", ":=", "ip", ".", "Mask", ".", "Size", "(", ")", "\n", "if", "i", "!=", "j", "{", "continue", "\n", "}", "\n", "if", "snet", ".", "Contains", "(", "ip", ".", "IP", ")", "{", "return", "s", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// getSubnetforIPv6 returns the ipv6 subnet to which the given IP belongs
[ "getSubnetforIPv6", "returns", "the", "ipv6", "subnet", "to", "which", "the", "given", "IP", "belongs" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L181-L199
22,423
docker/libnetwork
client/mflag/flag.go
Out
func (fs *FlagSet) Out() io.Writer { if fs.output == nil { return os.Stderr } return fs.output }
go
func (fs *FlagSet) Out() io.Writer { if fs.output == nil { return os.Stderr } return fs.output }
[ "func", "(", "fs", "*", "FlagSet", ")", "Out", "(", ")", "io", ".", "Writer", "{", "if", "fs", ".", "output", "==", "nil", "{", "return", "os", ".", "Stderr", "\n", "}", "\n", "return", "fs", ".", "output", "\n", "}" ]
// Out returns the destination for usage and error messages.
[ "Out", "returns", "the", "destination", "for", "usage", "and", "error", "messages", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L384-L389
22,424
docker/libnetwork
client/mflag/flag.go
IsSet
func (fs *FlagSet) IsSet(name string) bool { return fs.actual[name] != nil }
go
func (fs *FlagSet) IsSet(name string) bool { return fs.actual[name] != nil }
[ "func", "(", "fs", "*", "FlagSet", ")", "IsSet", "(", "name", "string", ")", "bool", "{", "return", "fs", ".", "actual", "[", "name", "]", "!=", "nil", "\n", "}" ]
// IsSet indicates whether the specified flag is set in the given FlagSet
[ "IsSet", "indicates", "whether", "the", "specified", "flag", "is", "set", "in", "the", "given", "FlagSet" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L431-L433
22,425
docker/libnetwork
client/mflag/flag.go
Set
func (fs *FlagSet) Set(name, value string) error { flag, ok := fs.formal[name] if !ok { return fmt.Errorf("no such flag -%v", name) } if err := flag.Value.Set(value); err != nil { return err } if fs.actual == nil { fs.actual = make(map[string]*Flag) } fs.actual[name] = flag return nil }
go
func (fs *FlagSet) Set(name, value string) error { flag, ok := fs.formal[name] if !ok { return fmt.Errorf("no such flag -%v", name) } if err := flag.Value.Set(value); err != nil { return err } if fs.actual == nil { fs.actual = make(map[string]*Flag) } fs.actual[name] = flag return nil }
[ "func", "(", "fs", "*", "FlagSet", ")", "Set", "(", "name", ",", "value", "string", ")", "error", "{", "flag", ",", "ok", ":=", "fs", ".", "formal", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "if", "err", ":=", "flag", ".", "Value", ".", "Set", "(", "value", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "fs", ".", "actual", "==", "nil", "{", "fs", ".", "actual", "=", "make", "(", "map", "[", "string", "]", "*", "Flag", ")", "\n", "}", "\n", "fs", ".", "actual", "[", "name", "]", "=", "flag", "\n", "return", "nil", "\n", "}" ]
// Set sets the value of the named flag.
[ "Set", "sets", "the", "value", "of", "the", "named", "flag", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L503-L516
22,426
docker/libnetwork
client/mflag/flag.go
PrintDefaults
func (fs *FlagSet) PrintDefaults() { writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0) home := homedir.Get() // Don't substitute when HOME is / if runtime.GOOS != "windows" && home == "/" { home = "" } // Add a blank line between cmd description and list of options if fs.FlagCount() > 0 { fmt.Fprintln(writer, "") } fs.VisitAll(func(flag *Flag) { names := []string{} for _, name := range flag.Names { if name[0] != '#' { names = append(names, name) } } if len(names) > 0 && len(flag.Usage) > 0 { val := flag.DefValue if home != "" && strings.HasPrefix(val, home) { val = homedir.GetShortcutString() + val[len(home):] } if isZeroValue(val) { format := " -%s" fmt.Fprintf(writer, format, strings.Join(names, ", -")) } else { format := " -%s=%s" fmt.Fprintf(writer, format, strings.Join(names, ", -"), val) } for _, line := range strings.Split(flag.Usage, "\n") { fmt.Fprintln(writer, "\t", line) } } }) writer.Flush() }
go
func (fs *FlagSet) PrintDefaults() { writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0) home := homedir.Get() // Don't substitute when HOME is / if runtime.GOOS != "windows" && home == "/" { home = "" } // Add a blank line between cmd description and list of options if fs.FlagCount() > 0 { fmt.Fprintln(writer, "") } fs.VisitAll(func(flag *Flag) { names := []string{} for _, name := range flag.Names { if name[0] != '#' { names = append(names, name) } } if len(names) > 0 && len(flag.Usage) > 0 { val := flag.DefValue if home != "" && strings.HasPrefix(val, home) { val = homedir.GetShortcutString() + val[len(home):] } if isZeroValue(val) { format := " -%s" fmt.Fprintf(writer, format, strings.Join(names, ", -")) } else { format := " -%s=%s" fmt.Fprintf(writer, format, strings.Join(names, ", -"), val) } for _, line := range strings.Split(flag.Usage, "\n") { fmt.Fprintln(writer, "\t", line) } } }) writer.Flush() }
[ "func", "(", "fs", "*", "FlagSet", ")", "PrintDefaults", "(", ")", "{", "writer", ":=", "tabwriter", ".", "NewWriter", "(", "fs", ".", "Out", "(", ")", ",", "20", ",", "1", ",", "3", ",", "' '", ",", "0", ")", "\n", "home", ":=", "homedir", ".", "Get", "(", ")", "\n\n", "// Don't substitute when HOME is /", "if", "runtime", ".", "GOOS", "!=", "\"", "\"", "&&", "home", "==", "\"", "\"", "{", "home", "=", "\"", "\"", "\n", "}", "\n\n", "// Add a blank line between cmd description and list of options", "if", "fs", ".", "FlagCount", "(", ")", ">", "0", "{", "fmt", ".", "Fprintln", "(", "writer", ",", "\"", "\"", ")", "\n", "}", "\n\n", "fs", ".", "VisitAll", "(", "func", "(", "flag", "*", "Flag", ")", "{", "names", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "name", ":=", "range", "flag", ".", "Names", "{", "if", "name", "[", "0", "]", "!=", "'#'", "{", "names", "=", "append", "(", "names", ",", "name", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "names", ")", ">", "0", "&&", "len", "(", "flag", ".", "Usage", ")", ">", "0", "{", "val", ":=", "flag", ".", "DefValue", "\n\n", "if", "home", "!=", "\"", "\"", "&&", "strings", ".", "HasPrefix", "(", "val", ",", "home", ")", "{", "val", "=", "homedir", ".", "GetShortcutString", "(", ")", "+", "val", "[", "len", "(", "home", ")", ":", "]", "\n", "}", "\n\n", "if", "isZeroValue", "(", "val", ")", "{", "format", ":=", "\"", "\"", "\n", "fmt", ".", "Fprintf", "(", "writer", ",", "format", ",", "strings", ".", "Join", "(", "names", ",", "\"", "\"", ")", ")", "\n", "}", "else", "{", "format", ":=", "\"", "\"", "\n", "fmt", ".", "Fprintf", "(", "writer", ",", "format", ",", "strings", ".", "Join", "(", "names", ",", "\"", "\"", ")", ",", "val", ")", "\n", "}", "\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "flag", ".", "Usage", ",", "\"", "\\n", "\"", ")", "{", "fmt", ".", "Fprintln", "(", "writer", ",", "\"", "\\t", "\"", ",", "line", ")", "\n", "}", "\n", "}", "\n", "}", ")", "\n", "writer", ".", "Flush", "(", ")", "\n", "}" ]
// PrintDefaults prints, to standard error unless configured // otherwise, the default values of all defined flags in the set.
[ "PrintDefaults", "prints", "to", "standard", "error", "unless", "configured", "otherwise", "the", "default", "values", "of", "all", "defined", "flags", "in", "the", "set", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L539-L580
22,427
docker/libnetwork
client/mflag/flag.go
FlagCountUndeprecated
func (fs *FlagSet) FlagCountUndeprecated() int { count := 0 for _, flag := range sortFlags(fs.formal) { for _, name := range flag.Names { if name[0] != '#' { count++ break } } } return count }
go
func (fs *FlagSet) FlagCountUndeprecated() int { count := 0 for _, flag := range sortFlags(fs.formal) { for _, name := range flag.Names { if name[0] != '#' { count++ break } } } return count }
[ "func", "(", "fs", "*", "FlagSet", ")", "FlagCountUndeprecated", "(", ")", "int", "{", "count", ":=", "0", "\n", "for", "_", ",", "flag", ":=", "range", "sortFlags", "(", "fs", ".", "formal", ")", "{", "for", "_", ",", "name", ":=", "range", "flag", ".", "Names", "{", "if", "name", "[", "0", "]", "!=", "'#'", "{", "count", "++", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "count", "\n", "}" ]
// FlagCountUndeprecated returns the number of undeprecated flags that have been defined.
[ "FlagCountUndeprecated", "returns", "the", "number", "of", "undeprecated", "flags", "that", "have", "been", "defined", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L618-L629
22,428
docker/libnetwork
client/mflag/flag.go
usage
func (fs *FlagSet) usage() { if fs == CommandLine { Usage() } else if fs.Usage == nil { defaultUsage(fs) } else { fs.Usage() } }
go
func (fs *FlagSet) usage() { if fs == CommandLine { Usage() } else if fs.Usage == nil { defaultUsage(fs) } else { fs.Usage() } }
[ "func", "(", "fs", "*", "FlagSet", ")", "usage", "(", ")", "{", "if", "fs", "==", "CommandLine", "{", "Usage", "(", ")", "\n", "}", "else", "if", "fs", ".", "Usage", "==", "nil", "{", "defaultUsage", "(", "fs", ")", "\n", "}", "else", "{", "fs", ".", "Usage", "(", ")", "\n", "}", "\n", "}" ]
// usage calls the Usage method for the flag set, or the usage function if // the flag set is CommandLine.
[ "usage", "calls", "the", "Usage", "method", "for", "the", "flag", "set", "or", "the", "usage", "function", "if", "the", "flag", "set", "is", "CommandLine", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L952-L960
22,429
docker/libnetwork
client/mflag/flag.go
ReportError
func (fs *FlagSet) ReportError(str string, withHelp bool) { if withHelp { if os.Args[0] == fs.Name() { str += ".\nSee '" + os.Args[0] + " --help'" } else { str += ".\nSee '" + os.Args[0] + " " + fs.Name() + " --help'" } } fmt.Fprintf(fs.Out(), "%s: %s.\n", os.Args[0], str) }
go
func (fs *FlagSet) ReportError(str string, withHelp bool) { if withHelp { if os.Args[0] == fs.Name() { str += ".\nSee '" + os.Args[0] + " --help'" } else { str += ".\nSee '" + os.Args[0] + " " + fs.Name() + " --help'" } } fmt.Fprintf(fs.Out(), "%s: %s.\n", os.Args[0], str) }
[ "func", "(", "fs", "*", "FlagSet", ")", "ReportError", "(", "str", "string", ",", "withHelp", "bool", ")", "{", "if", "withHelp", "{", "if", "os", ".", "Args", "[", "0", "]", "==", "fs", ".", "Name", "(", ")", "{", "str", "+=", "\"", "\\n", "\"", "+", "os", ".", "Args", "[", "0", "]", "+", "\"", "\"", "\n", "}", "else", "{", "str", "+=", "\"", "\\n", "\"", "+", "os", ".", "Args", "[", "0", "]", "+", "\"", "\"", "+", "fs", ".", "Name", "(", ")", "+", "\"", "\"", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "fs", ".", "Out", "(", ")", ",", "\"", "\\n", "\"", ",", "os", ".", "Args", "[", "0", "]", ",", "str", ")", "\n", "}" ]
// ReportError is a utility method that prints a user-friendly message // containing the error that occurred during parsing and a suggestion to get help
[ "ReportError", "is", "a", "utility", "method", "that", "prints", "a", "user", "-", "friendly", "message", "containing", "the", "error", "that", "occurred", "during", "parsing", "and", "a", "suggestion", "to", "get", "help" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1158-L1167
22,430
docker/libnetwork
client/mflag/flag.go
Name
func (v mergeVal) Name() string { type namedValue interface { Name() string } if nVal, ok := v.Value.(namedValue); ok { return nVal.Name() } return v.key }
go
func (v mergeVal) Name() string { type namedValue interface { Name() string } if nVal, ok := v.Value.(namedValue); ok { return nVal.Name() } return v.key }
[ "func", "(", "v", "mergeVal", ")", "Name", "(", ")", "string", "{", "type", "namedValue", "interface", "{", "Name", "(", ")", "string", "\n", "}", "\n", "if", "nVal", ",", "ok", ":=", "v", ".", "Value", ".", "(", "namedValue", ")", ";", "ok", "{", "return", "nVal", ".", "Name", "(", ")", "\n", "}", "\n", "return", "v", ".", "key", "\n", "}" ]
// Name returns the name of a mergeVal. // If the original value had a name, return the original name, // otherwise, return the key assigned to this mergeVal.
[ "Name", "returns", "the", "name", "of", "a", "mergeVal", ".", "If", "the", "original", "value", "had", "a", "name", "return", "the", "original", "name", "otherwise", "return", "the", "key", "assigned", "to", "this", "mergeVal", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1229-L1237
22,431
docker/libnetwork
client/mflag/flag.go
Merge
func Merge(dest *FlagSet, flagsets ...*FlagSet) error { for _, fset := range flagsets { if fset.formal == nil { continue } for k, f := range fset.formal { if _, ok := dest.formal[k]; ok { var err error if fset.name == "" { err = fmt.Errorf("flag redefined: %s", k) } else { err = fmt.Errorf("%s flag redefined: %s", fset.name, k) } fmt.Fprintln(fset.Out(), err.Error()) // Happens only if flags are declared with identical names switch dest.errorHandling { case ContinueOnError: return err case ExitOnError: os.Exit(2) case PanicOnError: panic(err) } } newF := *f newF.Value = mergeVal{f.Value, k, fset} if dest.formal == nil { dest.formal = make(map[string]*Flag) } dest.formal[k] = &newF } } return nil }
go
func Merge(dest *FlagSet, flagsets ...*FlagSet) error { for _, fset := range flagsets { if fset.formal == nil { continue } for k, f := range fset.formal { if _, ok := dest.formal[k]; ok { var err error if fset.name == "" { err = fmt.Errorf("flag redefined: %s", k) } else { err = fmt.Errorf("%s flag redefined: %s", fset.name, k) } fmt.Fprintln(fset.Out(), err.Error()) // Happens only if flags are declared with identical names switch dest.errorHandling { case ContinueOnError: return err case ExitOnError: os.Exit(2) case PanicOnError: panic(err) } } newF := *f newF.Value = mergeVal{f.Value, k, fset} if dest.formal == nil { dest.formal = make(map[string]*Flag) } dest.formal[k] = &newF } } return nil }
[ "func", "Merge", "(", "dest", "*", "FlagSet", ",", "flagsets", "...", "*", "FlagSet", ")", "error", "{", "for", "_", ",", "fset", ":=", "range", "flagsets", "{", "if", "fset", ".", "formal", "==", "nil", "{", "continue", "\n", "}", "\n", "for", "k", ",", "f", ":=", "range", "fset", ".", "formal", "{", "if", "_", ",", "ok", ":=", "dest", ".", "formal", "[", "k", "]", ";", "ok", "{", "var", "err", "error", "\n", "if", "fset", ".", "name", "==", "\"", "\"", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "k", ")", "\n", "}", "else", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "fset", ".", "name", ",", "k", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "fset", ".", "Out", "(", ")", ",", "err", ".", "Error", "(", ")", ")", "\n", "// Happens only if flags are declared with identical names", "switch", "dest", ".", "errorHandling", "{", "case", "ContinueOnError", ":", "return", "err", "\n", "case", "ExitOnError", ":", "os", ".", "Exit", "(", "2", ")", "\n", "case", "PanicOnError", ":", "panic", "(", "err", ")", "\n", "}", "\n", "}", "\n", "newF", ":=", "*", "f", "\n", "newF", ".", "Value", "=", "mergeVal", "{", "f", ".", "Value", ",", "k", ",", "fset", "}", "\n", "if", "dest", ".", "formal", "==", "nil", "{", "dest", ".", "formal", "=", "make", "(", "map", "[", "string", "]", "*", "Flag", ")", "\n", "}", "\n", "dest", ".", "formal", "[", "k", "]", "=", "&", "newF", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Merge is an helper function that merges n FlagSets into a single dest FlagSet // In case of name collision between the flagsets it will apply // the destination FlagSet's errorHandling behavior.
[ "Merge", "is", "an", "helper", "function", "that", "merges", "n", "FlagSets", "into", "a", "single", "dest", "FlagSet", "In", "case", "of", "name", "collision", "between", "the", "flagsets", "it", "will", "apply", "the", "destination", "FlagSet", "s", "errorHandling", "behavior", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1242-L1275
22,432
docker/libnetwork
sandbox_dns_unix.go
rebuildDNS
func (sb *sandbox) rebuildDNS() error { currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath) if err != nil { return err } if len(sb.extDNS) == 0 { sb.setExternalResolvers(currRC.Content, types.IPv4, false) } var ( dnsList = []string{sb.resolver.NameServer()} dnsOptionsList = resolvconf.GetOptions(currRC.Content) dnsSearchList = resolvconf.GetSearchDomains(currRC.Content) ) // external v6 DNS servers has to be listed in resolv.conf dnsList = append(dnsList, resolvconf.GetNameservers(currRC.Content, types.IPv6)...) // If the user config and embedded DNS server both have ndots option set, // remember the user's config so that unqualified names not in the docker // domain can be dropped. resOptions := sb.resolver.ResolverOptions() dnsOpt: for _, resOpt := range resOptions { if strings.Contains(resOpt, "ndots") { for _, option := range dnsOptionsList { if strings.Contains(option, "ndots") { parts := strings.Split(option, ":") if len(parts) != 2 { return fmt.Errorf("invalid ndots option %v", option) } if num, err := strconv.Atoi(parts[1]); err != nil { return fmt.Errorf("invalid number for ndots option: %v", parts[1]) } else if num >= 0 { // if the user sets ndots, use the user setting sb.ndotsSet = true break dnsOpt } else { return fmt.Errorf("invalid number for ndots option: %v", num) } } } } } if !sb.ndotsSet { // if the user did not set the ndots, set it to 0 to prioritize the service name resolution // Ref: https://linux.die.net/man/5/resolv.conf dnsOptionsList = append(dnsOptionsList, resOptions...) } _, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList) return err }
go
func (sb *sandbox) rebuildDNS() error { currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath) if err != nil { return err } if len(sb.extDNS) == 0 { sb.setExternalResolvers(currRC.Content, types.IPv4, false) } var ( dnsList = []string{sb.resolver.NameServer()} dnsOptionsList = resolvconf.GetOptions(currRC.Content) dnsSearchList = resolvconf.GetSearchDomains(currRC.Content) ) // external v6 DNS servers has to be listed in resolv.conf dnsList = append(dnsList, resolvconf.GetNameservers(currRC.Content, types.IPv6)...) // If the user config and embedded DNS server both have ndots option set, // remember the user's config so that unqualified names not in the docker // domain can be dropped. resOptions := sb.resolver.ResolverOptions() dnsOpt: for _, resOpt := range resOptions { if strings.Contains(resOpt, "ndots") { for _, option := range dnsOptionsList { if strings.Contains(option, "ndots") { parts := strings.Split(option, ":") if len(parts) != 2 { return fmt.Errorf("invalid ndots option %v", option) } if num, err := strconv.Atoi(parts[1]); err != nil { return fmt.Errorf("invalid number for ndots option: %v", parts[1]) } else if num >= 0 { // if the user sets ndots, use the user setting sb.ndotsSet = true break dnsOpt } else { return fmt.Errorf("invalid number for ndots option: %v", num) } } } } } if !sb.ndotsSet { // if the user did not set the ndots, set it to 0 to prioritize the service name resolution // Ref: https://linux.die.net/man/5/resolv.conf dnsOptionsList = append(dnsOptionsList, resOptions...) } _, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList) return err }
[ "func", "(", "sb", "*", "sandbox", ")", "rebuildDNS", "(", ")", "error", "{", "currRC", ",", "err", ":=", "resolvconf", ".", "GetSpecific", "(", "sb", ".", "config", ".", "resolvConfPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "sb", ".", "extDNS", ")", "==", "0", "{", "sb", ".", "setExternalResolvers", "(", "currRC", ".", "Content", ",", "types", ".", "IPv4", ",", "false", ")", "\n", "}", "\n", "var", "(", "dnsList", "=", "[", "]", "string", "{", "sb", ".", "resolver", ".", "NameServer", "(", ")", "}", "\n", "dnsOptionsList", "=", "resolvconf", ".", "GetOptions", "(", "currRC", ".", "Content", ")", "\n", "dnsSearchList", "=", "resolvconf", ".", "GetSearchDomains", "(", "currRC", ".", "Content", ")", "\n", ")", "\n\n", "// external v6 DNS servers has to be listed in resolv.conf", "dnsList", "=", "append", "(", "dnsList", ",", "resolvconf", ".", "GetNameservers", "(", "currRC", ".", "Content", ",", "types", ".", "IPv6", ")", "...", ")", "\n\n", "// If the user config and embedded DNS server both have ndots option set,", "// remember the user's config so that unqualified names not in the docker", "// domain can be dropped.", "resOptions", ":=", "sb", ".", "resolver", ".", "ResolverOptions", "(", ")", "\n\n", "dnsOpt", ":", "for", "_", ",", "resOpt", ":=", "range", "resOptions", "{", "if", "strings", ".", "Contains", "(", "resOpt", ",", "\"", "\"", ")", "{", "for", "_", ",", "option", ":=", "range", "dnsOptionsList", "{", "if", "strings", ".", "Contains", "(", "option", ",", "\"", "\"", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "option", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "option", ")", "\n", "}", "\n", "if", "num", ",", "err", ":=", "strconv", ".", "Atoi", "(", "parts", "[", "1", "]", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "parts", "[", "1", "]", ")", "\n", "}", "else", "if", "num", ">=", "0", "{", "// if the user sets ndots, use the user setting", "sb", ".", "ndotsSet", "=", "true", "\n", "break", "dnsOpt", "\n", "}", "else", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "num", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "!", "sb", ".", "ndotsSet", "{", "// if the user did not set the ndots, set it to 0 to prioritize the service name resolution", "// Ref: https://linux.die.net/man/5/resolv.conf", "dnsOptionsList", "=", "append", "(", "dnsOptionsList", ",", "resOptions", "...", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "resolvconf", ".", "Build", "(", "sb", ".", "config", ".", "resolvConfPath", ",", "dnsList", ",", "dnsSearchList", ",", "dnsOptionsList", ")", "\n", "return", "err", "\n", "}" ]
// Embedded DNS server has to be enabled for this sandbox. Rebuild the container's // resolv.conf by doing the following // - Add only the embedded server's IP to container's resolv.conf // - If the embedded server needs any resolv.conf options add it to the current list
[ "Embedded", "DNS", "server", "has", "to", "be", "enabled", "for", "this", "sandbox", ".", "Rebuild", "the", "container", "s", "resolv", ".", "conf", "by", "doing", "the", "following", "-", "Add", "only", "the", "embedded", "server", "s", "IP", "to", "container", "s", "resolv", ".", "conf", "-", "If", "the", "embedded", "server", "needs", "any", "resolv", ".", "conf", "options", "add", "it", "to", "the", "current", "list" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox_dns_unix.go#L351-L405
22,433
docker/libnetwork
client/client.go
NewNetworkCli
func NewNetworkCli(out, err io.Writer, call CallFunc) *NetworkCli { return &NetworkCli{ out: out, err: err, call: call, } }
go
func NewNetworkCli(out, err io.Writer, call CallFunc) *NetworkCli { return &NetworkCli{ out: out, err: err, call: call, } }
[ "func", "NewNetworkCli", "(", "out", ",", "err", "io", ".", "Writer", ",", "call", "CallFunc", ")", "*", "NetworkCli", "{", "return", "&", "NetworkCli", "{", "out", ":", "out", ",", "err", ":", "err", ",", "call", ":", "call", ",", "}", "\n", "}" ]
// NewNetworkCli is a convenient function to create a NetworkCli object
[ "NewNetworkCli", "is", "a", "convenient", "function", "to", "create", "a", "NetworkCli", "object" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L25-L31
22,434
docker/libnetwork
client/client.go
getMethod
func (cli *NetworkCli) getMethod(args ...string) (func(string, ...string) error, bool) { camelArgs := make([]string, len(args)) for i, s := range args { if len(s) == 0 { return nil, false } camelArgs[i] = strings.ToUpper(s[:1]) + strings.ToLower(s[1:]) } methodName := "Cmd" + strings.Join(camelArgs, "") method := reflect.ValueOf(cli).MethodByName(methodName) if !method.IsValid() { return nil, false } return method.Interface().(func(string, ...string) error), true }
go
func (cli *NetworkCli) getMethod(args ...string) (func(string, ...string) error, bool) { camelArgs := make([]string, len(args)) for i, s := range args { if len(s) == 0 { return nil, false } camelArgs[i] = strings.ToUpper(s[:1]) + strings.ToLower(s[1:]) } methodName := "Cmd" + strings.Join(camelArgs, "") method := reflect.ValueOf(cli).MethodByName(methodName) if !method.IsValid() { return nil, false } return method.Interface().(func(string, ...string) error), true }
[ "func", "(", "cli", "*", "NetworkCli", ")", "getMethod", "(", "args", "...", "string", ")", "(", "func", "(", "string", ",", "...", "string", ")", "error", ",", "bool", ")", "{", "camelArgs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "args", ")", ")", "\n", "for", "i", ",", "s", ":=", "range", "args", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "nil", ",", "false", "\n", "}", "\n", "camelArgs", "[", "i", "]", "=", "strings", ".", "ToUpper", "(", "s", "[", ":", "1", "]", ")", "+", "strings", ".", "ToLower", "(", "s", "[", "1", ":", "]", ")", "\n", "}", "\n", "methodName", ":=", "\"", "\"", "+", "strings", ".", "Join", "(", "camelArgs", ",", "\"", "\"", ")", "\n", "method", ":=", "reflect", ".", "ValueOf", "(", "cli", ")", ".", "MethodByName", "(", "methodName", ")", "\n", "if", "!", "method", ".", "IsValid", "(", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "return", "method", ".", "Interface", "(", ")", ".", "(", "func", "(", "string", ",", "...", "string", ")", "error", ")", ",", "true", "\n", "}" ]
// getMethod is Borrowed from Docker UI which uses reflection to identify the UI Handler
[ "getMethod", "is", "Borrowed", "from", "Docker", "UI", "which", "uses", "reflection", "to", "identify", "the", "UI", "Handler" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L34-L48
22,435
docker/libnetwork
client/client.go
Cmd
func (cli *NetworkCli) Cmd(chain string, args ...string) error { if len(args) > 2 { method, exists := cli.getMethod(args[:3]...) if exists { return method(chain+" "+args[0]+" "+args[1], args[3:]...) } } if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(chain+" "+args[0], args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { return fmt.Errorf("%s: '%s' is not a %s command. See '%s --help'", chain, args[0], chain, chain) } return method(chain, args[1:]...) } flag.Usage() return nil }
go
func (cli *NetworkCli) Cmd(chain string, args ...string) error { if len(args) > 2 { method, exists := cli.getMethod(args[:3]...) if exists { return method(chain+" "+args[0]+" "+args[1], args[3:]...) } } if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(chain+" "+args[0], args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { return fmt.Errorf("%s: '%s' is not a %s command. See '%s --help'", chain, args[0], chain, chain) } return method(chain, args[1:]...) } flag.Usage() return nil }
[ "func", "(", "cli", "*", "NetworkCli", ")", "Cmd", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "if", "len", "(", "args", ")", ">", "2", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", ":", "3", "]", "...", ")", "\n", "if", "exists", "{", "return", "method", "(", "chain", "+", "\"", "\"", "+", "args", "[", "0", "]", "+", "\"", "\"", "+", "args", "[", "1", "]", ",", "args", "[", "3", ":", "]", "...", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "args", ")", ">", "1", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", ":", "2", "]", "...", ")", "\n", "if", "exists", "{", "return", "method", "(", "chain", "+", "\"", "\"", "+", "args", "[", "0", "]", ",", "args", "[", "2", ":", "]", "...", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "args", ")", ">", "0", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", "0", "]", ")", "\n", "if", "!", "exists", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "chain", ",", "args", "[", "0", "]", ",", "chain", ",", "chain", ")", "\n", "}", "\n", "return", "method", "(", "chain", ",", "args", "[", "1", ":", "]", "...", ")", "\n", "}", "\n", "flag", ".", "Usage", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Cmd is borrowed from Docker UI and acts as the entry point for network UI commands. // network UI commands are designed to be invoked from multiple parent chains
[ "Cmd", "is", "borrowed", "from", "Docker", "UI", "and", "acts", "as", "the", "entry", "point", "for", "network", "UI", "commands", ".", "network", "UI", "commands", "are", "designed", "to", "be", "invoked", "from", "multiple", "parent", "chains" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L52-L74
22,436
docker/libnetwork
client/client.go
Subcmd
func (cli *NetworkCli) Subcmd(chain, name, signature, description string, exitOnError bool) *flag.FlagSet { var errorHandling flag.ErrorHandling if exitOnError { errorHandling = flag.ExitOnError } else { errorHandling = flag.ContinueOnError } flags := flag.NewFlagSet(name, errorHandling) flags.Usage = func() { flags.ShortUsage() flags.PrintDefaults() } flags.ShortUsage = func() { options := "" if signature != "" { signature = " " + signature } if flags.FlagCountUndeprecated() > 0 { options = " [OPTIONS]" } fmt.Fprintf(cli.out, "\nUsage: %s %s%s%s\n\n%s\n\n", chain, name, options, signature, description) flags.SetOutput(cli.out) } return flags }
go
func (cli *NetworkCli) Subcmd(chain, name, signature, description string, exitOnError bool) *flag.FlagSet { var errorHandling flag.ErrorHandling if exitOnError { errorHandling = flag.ExitOnError } else { errorHandling = flag.ContinueOnError } flags := flag.NewFlagSet(name, errorHandling) flags.Usage = func() { flags.ShortUsage() flags.PrintDefaults() } flags.ShortUsage = func() { options := "" if signature != "" { signature = " " + signature } if flags.FlagCountUndeprecated() > 0 { options = " [OPTIONS]" } fmt.Fprintf(cli.out, "\nUsage: %s %s%s%s\n\n%s\n\n", chain, name, options, signature, description) flags.SetOutput(cli.out) } return flags }
[ "func", "(", "cli", "*", "NetworkCli", ")", "Subcmd", "(", "chain", ",", "name", ",", "signature", ",", "description", "string", ",", "exitOnError", "bool", ")", "*", "flag", ".", "FlagSet", "{", "var", "errorHandling", "flag", ".", "ErrorHandling", "\n", "if", "exitOnError", "{", "errorHandling", "=", "flag", ".", "ExitOnError", "\n", "}", "else", "{", "errorHandling", "=", "flag", ".", "ContinueOnError", "\n", "}", "\n", "flags", ":=", "flag", ".", "NewFlagSet", "(", "name", ",", "errorHandling", ")", "\n", "flags", ".", "Usage", "=", "func", "(", ")", "{", "flags", ".", "ShortUsage", "(", ")", "\n", "flags", ".", "PrintDefaults", "(", ")", "\n", "}", "\n", "flags", ".", "ShortUsage", "=", "func", "(", ")", "{", "options", ":=", "\"", "\"", "\n", "if", "signature", "!=", "\"", "\"", "{", "signature", "=", "\"", "\"", "+", "signature", "\n", "}", "\n", "if", "flags", ".", "FlagCountUndeprecated", "(", ")", ">", "0", "{", "options", "=", "\"", "\"", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\\n", "\\n", "\\n", "\\n", "\"", ",", "chain", ",", "name", ",", "options", ",", "signature", ",", "description", ")", "\n", "flags", ".", "SetOutput", "(", "cli", ".", "out", ")", "\n", "}", "\n", "return", "flags", "\n", "}" ]
// Subcmd is borrowed from Docker UI and performs the same function of configuring the subCmds
[ "Subcmd", "is", "borrowed", "from", "Docker", "UI", "and", "performs", "the", "same", "function", "of", "configuring", "the", "subCmds" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L77-L101
22,437
docker/libnetwork
etchosts/etchosts.go
WriteTo
func (r Record) WriteTo(w io.Writer) (int64, error) { n, err := fmt.Fprintf(w, "%s\t%s\n", r.IP, r.Hosts) return int64(n), err }
go
func (r Record) WriteTo(w io.Writer) (int64, error) { n, err := fmt.Fprintf(w, "%s\t%s\n", r.IP, r.Hosts) return int64(n), err }
[ "func", "(", "r", "Record", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "n", ",", "err", ":=", "fmt", ".", "Fprintf", "(", "w", ",", "\"", "\\t", "\\n", "\"", ",", "r", ".", "IP", ",", "r", ".", "Hosts", ")", "\n", "return", "int64", "(", "n", ")", ",", "err", "\n", "}" ]
// WriteTo writes record to file and returns bytes written or error
[ "WriteTo", "writes", "record", "to", "file", "and", "returns", "bytes", "written", "or", "error" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L22-L25
22,438
docker/libnetwork
etchosts/etchosts.go
Drop
func Drop(path string) { pathMutex.Lock() defer pathMutex.Unlock() delete(pathMap, path) }
go
func Drop(path string) { pathMutex.Lock() defer pathMutex.Unlock() delete(pathMap, path) }
[ "func", "Drop", "(", "path", "string", ")", "{", "pathMutex", ".", "Lock", "(", ")", "\n", "defer", "pathMutex", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "pathMap", ",", "path", ")", "\n", "}" ]
// Drop drops the path string from the path cache
[ "Drop", "drops", "the", "path", "string", "from", "the", "path", "cache" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L63-L68
22,439
docker/libnetwork
etchosts/etchosts.go
Build
func Build(path, IP, hostname, domainname string, extraContent []Record) error { defer pathLock(path)() content := bytes.NewBuffer(nil) if IP != "" { //set main record var mainRec Record mainRec.IP = IP // User might have provided a FQDN in hostname or split it across hostname // and domainname. We want the FQDN and the bare hostname. fqdn := hostname if domainname != "" { fqdn = fmt.Sprintf("%s.%s", fqdn, domainname) } parts := strings.SplitN(fqdn, ".", 2) if len(parts) == 2 { mainRec.Hosts = fmt.Sprintf("%s %s", fqdn, parts[0]) } else { mainRec.Hosts = fqdn } if _, err := mainRec.WriteTo(content); err != nil { return err } } // Write defaultContent slice to buffer for _, r := range defaultContent { if _, err := r.WriteTo(content); err != nil { return err } } // Write extra content from function arguments for _, r := range extraContent { if _, err := r.WriteTo(content); err != nil { return err } } return ioutil.WriteFile(path, content.Bytes(), 0644) }
go
func Build(path, IP, hostname, domainname string, extraContent []Record) error { defer pathLock(path)() content := bytes.NewBuffer(nil) if IP != "" { //set main record var mainRec Record mainRec.IP = IP // User might have provided a FQDN in hostname or split it across hostname // and domainname. We want the FQDN and the bare hostname. fqdn := hostname if domainname != "" { fqdn = fmt.Sprintf("%s.%s", fqdn, domainname) } parts := strings.SplitN(fqdn, ".", 2) if len(parts) == 2 { mainRec.Hosts = fmt.Sprintf("%s %s", fqdn, parts[0]) } else { mainRec.Hosts = fqdn } if _, err := mainRec.WriteTo(content); err != nil { return err } } // Write defaultContent slice to buffer for _, r := range defaultContent { if _, err := r.WriteTo(content); err != nil { return err } } // Write extra content from function arguments for _, r := range extraContent { if _, err := r.WriteTo(content); err != nil { return err } } return ioutil.WriteFile(path, content.Bytes(), 0644) }
[ "func", "Build", "(", "path", ",", "IP", ",", "hostname", ",", "domainname", "string", ",", "extraContent", "[", "]", "Record", ")", "error", "{", "defer", "pathLock", "(", "path", ")", "(", ")", "\n\n", "content", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "if", "IP", "!=", "\"", "\"", "{", "//set main record", "var", "mainRec", "Record", "\n", "mainRec", ".", "IP", "=", "IP", "\n", "// User might have provided a FQDN in hostname or split it across hostname", "// and domainname. We want the FQDN and the bare hostname.", "fqdn", ":=", "hostname", "\n", "if", "domainname", "!=", "\"", "\"", "{", "fqdn", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fqdn", ",", "domainname", ")", "\n", "}", "\n", "parts", ":=", "strings", ".", "SplitN", "(", "fqdn", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "parts", ")", "==", "2", "{", "mainRec", ".", "Hosts", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fqdn", ",", "parts", "[", "0", "]", ")", "\n", "}", "else", "{", "mainRec", ".", "Hosts", "=", "fqdn", "\n", "}", "\n", "if", "_", ",", "err", ":=", "mainRec", ".", "WriteTo", "(", "content", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// Write defaultContent slice to buffer", "for", "_", ",", "r", ":=", "range", "defaultContent", "{", "if", "_", ",", "err", ":=", "r", ".", "WriteTo", "(", "content", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// Write extra content from function arguments", "for", "_", ",", "r", ":=", "range", "extraContent", "{", "if", "_", ",", "err", ":=", "r", ".", "WriteTo", "(", "content", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "ioutil", ".", "WriteFile", "(", "path", ",", "content", ".", "Bytes", "(", ")", ",", "0644", ")", "\n", "}" ]
// Build function // path is path to host file string required // IP, hostname, and domainname set main record leave empty for no master record // extraContent is an array of extra host records.
[ "Build", "function", "path", "is", "path", "to", "host", "file", "string", "required", "IP", "hostname", "and", "domainname", "set", "main", "record", "leave", "empty", "for", "no", "master", "record", "extraContent", "is", "an", "array", "of", "extra", "host", "records", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L74-L112
22,440
docker/libnetwork
etchosts/etchosts.go
Update
func Update(path, IP, hostname string) error { defer pathLock(path)() old, err := ioutil.ReadFile(path) if err != nil { return err } var re = regexp.MustCompile(fmt.Sprintf("(\\S*)(\\t%s)(\\s|\\.)", regexp.QuoteMeta(hostname))) return ioutil.WriteFile(path, re.ReplaceAll(old, []byte(IP+"$2"+"$3")), 0644) }
go
func Update(path, IP, hostname string) error { defer pathLock(path)() old, err := ioutil.ReadFile(path) if err != nil { return err } var re = regexp.MustCompile(fmt.Sprintf("(\\S*)(\\t%s)(\\s|\\.)", regexp.QuoteMeta(hostname))) return ioutil.WriteFile(path, re.ReplaceAll(old, []byte(IP+"$2"+"$3")), 0644) }
[ "func", "Update", "(", "path", ",", "IP", ",", "hostname", "string", ")", "error", "{", "defer", "pathLock", "(", "path", ")", "(", ")", "\n\n", "old", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "re", "=", "regexp", ".", "MustCompile", "(", "fmt", ".", "Sprintf", "(", "\"", "\\\\", "\\\\", "\\\\", "\\\\", "\"", ",", "regexp", ".", "QuoteMeta", "(", "hostname", ")", ")", ")", "\n", "return", "ioutil", ".", "WriteFile", "(", "path", ",", "re", ".", "ReplaceAll", "(", "old", ",", "[", "]", "byte", "(", "IP", "+", "\"", "\"", "+", "\"", "\"", ")", ")", ",", "0644", ")", "\n", "}" ]
// Update all IP addresses where hostname matches. // path is path to host file // IP is new IP address // hostname is hostname to search for to replace IP
[ "Update", "all", "IP", "addresses", "where", "hostname", "matches", ".", "path", "is", "path", "to", "host", "file", "IP", "is", "new", "IP", "address", "hostname", "is", "hostname", "to", "search", "for", "to", "replace", "IP" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L199-L208
22,441
docker/libnetwork
drivers/overlay/overlay.go
restoreEndpoints
func (d *driver) restoreEndpoints() error { if d.localStore == nil { logrus.Warn("Cannot restore overlay endpoints because local datastore is missing") return nil } kvol, err := d.localStore.List(datastore.Key(overlayEndpointPrefix), &endpoint{}) if err != nil && err != datastore.ErrKeyNotFound { return fmt.Errorf("failed to read overlay endpoint from store: %v", err) } if err == datastore.ErrKeyNotFound { return nil } for _, kvo := range kvol { ep := kvo.(*endpoint) n := d.network(ep.nid) if n == nil { logrus.Debugf("Network (%.7s) not found for restored endpoint (%.7s)", ep.nid, ep.id) logrus.Debugf("Deleting stale overlay endpoint (%.7s) from store", ep.id) if err := d.deleteEndpointFromStore(ep); err != nil { logrus.Debugf("Failed to delete stale overlay endpoint (%.7s) from store", ep.id) } continue } n.addEndpoint(ep) s := n.getSubnetforIP(ep.addr) if s == nil { return fmt.Errorf("could not find subnet for endpoint %s", ep.id) } if err := n.joinSandbox(s, true, true); err != nil { return fmt.Errorf("restore network sandbox failed: %v", err) } Ifaces := make(map[string][]osl.IfaceOption) vethIfaceOption := make([]osl.IfaceOption, 1) vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName)) Ifaces["veth+veth"] = vethIfaceOption err := n.sbox.Restore(Ifaces, nil, nil, nil) if err != nil { n.leaveSandbox() return fmt.Errorf("failed to restore overlay sandbox: %v", err) } d.peerAdd(ep.nid, ep.id, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), false, false, true) } return nil }
go
func (d *driver) restoreEndpoints() error { if d.localStore == nil { logrus.Warn("Cannot restore overlay endpoints because local datastore is missing") return nil } kvol, err := d.localStore.List(datastore.Key(overlayEndpointPrefix), &endpoint{}) if err != nil && err != datastore.ErrKeyNotFound { return fmt.Errorf("failed to read overlay endpoint from store: %v", err) } if err == datastore.ErrKeyNotFound { return nil } for _, kvo := range kvol { ep := kvo.(*endpoint) n := d.network(ep.nid) if n == nil { logrus.Debugf("Network (%.7s) not found for restored endpoint (%.7s)", ep.nid, ep.id) logrus.Debugf("Deleting stale overlay endpoint (%.7s) from store", ep.id) if err := d.deleteEndpointFromStore(ep); err != nil { logrus.Debugf("Failed to delete stale overlay endpoint (%.7s) from store", ep.id) } continue } n.addEndpoint(ep) s := n.getSubnetforIP(ep.addr) if s == nil { return fmt.Errorf("could not find subnet for endpoint %s", ep.id) } if err := n.joinSandbox(s, true, true); err != nil { return fmt.Errorf("restore network sandbox failed: %v", err) } Ifaces := make(map[string][]osl.IfaceOption) vethIfaceOption := make([]osl.IfaceOption, 1) vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName)) Ifaces["veth+veth"] = vethIfaceOption err := n.sbox.Restore(Ifaces, nil, nil, nil) if err != nil { n.leaveSandbox() return fmt.Errorf("failed to restore overlay sandbox: %v", err) } d.peerAdd(ep.nid, ep.id, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), false, false, true) } return nil }
[ "func", "(", "d", "*", "driver", ")", "restoreEndpoints", "(", ")", "error", "{", "if", "d", ".", "localStore", "==", "nil", "{", "logrus", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "kvol", ",", "err", ":=", "d", ".", "localStore", ".", "List", "(", "datastore", ".", "Key", "(", "overlayEndpointPrefix", ")", ",", "&", "endpoint", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "datastore", ".", "ErrKeyNotFound", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", "==", "datastore", ".", "ErrKeyNotFound", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "kvo", ":=", "range", "kvol", "{", "ep", ":=", "kvo", ".", "(", "*", "endpoint", ")", "\n", "n", ":=", "d", ".", "network", "(", "ep", ".", "nid", ")", "\n", "if", "n", "==", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "ep", ".", "nid", ",", "ep", ".", "id", ")", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "ep", ".", "id", ")", "\n", "if", "err", ":=", "d", ".", "deleteEndpointFromStore", "(", "ep", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "ep", ".", "id", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "n", ".", "addEndpoint", "(", "ep", ")", "\n\n", "s", ":=", "n", ".", "getSubnetforIP", "(", "ep", ".", "addr", ")", "\n", "if", "s", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ep", ".", "id", ")", "\n", "}", "\n\n", "if", "err", ":=", "n", ".", "joinSandbox", "(", "s", ",", "true", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "Ifaces", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "osl", ".", "IfaceOption", ")", "\n", "vethIfaceOption", ":=", "make", "(", "[", "]", "osl", ".", "IfaceOption", ",", "1", ")", "\n", "vethIfaceOption", "=", "append", "(", "vethIfaceOption", ",", "n", ".", "sbox", ".", "InterfaceOptions", "(", ")", ".", "Master", "(", "s", ".", "brName", ")", ")", "\n", "Ifaces", "[", "\"", "\"", "]", "=", "vethIfaceOption", "\n\n", "err", ":=", "n", ".", "sbox", ".", "Restore", "(", "Ifaces", ",", "nil", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "n", ".", "leaveSandbox", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "d", ".", "peerAdd", "(", "ep", ".", "nid", ",", "ep", ".", "id", ",", "ep", ".", "addr", ".", "IP", ",", "ep", ".", "addr", ".", "Mask", ",", "ep", ".", "mac", ",", "net", ".", "ParseIP", "(", "d", ".", "advertiseAddress", ")", ",", "false", ",", "false", ",", "true", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Endpoints are stored in the local store. Restore them and reconstruct the overlay sandbox
[ "Endpoints", "are", "stored", "in", "the", "local", "store", ".", "Restore", "them", "and", "reconstruct", "the", "overlay", "sandbox" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L111-L160
22,442
docker/libnetwork
drivers/overlay/overlay.go
Fini
func Fini(drv driverapi.Driver) { d := drv.(*driver) // Notify the peer go routine to return if d.peerOpCancel != nil { d.peerOpCancel() } if d.exitCh != nil { waitCh := make(chan struct{}) d.exitCh <- waitCh <-waitCh } }
go
func Fini(drv driverapi.Driver) { d := drv.(*driver) // Notify the peer go routine to return if d.peerOpCancel != nil { d.peerOpCancel() } if d.exitCh != nil { waitCh := make(chan struct{}) d.exitCh <- waitCh <-waitCh } }
[ "func", "Fini", "(", "drv", "driverapi", ".", "Driver", ")", "{", "d", ":=", "drv", ".", "(", "*", "driver", ")", "\n\n", "// Notify the peer go routine to return", "if", "d", ".", "peerOpCancel", "!=", "nil", "{", "d", ".", "peerOpCancel", "(", ")", "\n", "}", "\n\n", "if", "d", ".", "exitCh", "!=", "nil", "{", "waitCh", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n\n", "d", ".", "exitCh", "<-", "waitCh", "\n\n", "<-", "waitCh", "\n", "}", "\n", "}" ]
// Fini cleans up the driver resources
[ "Fini", "cleans", "up", "the", "driver", "resources" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L163-L178
22,443
docker/libnetwork
drivers/host/host.go
Init
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, &driver{}, c) }
go
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, &driver{}, c) }
[ "func", "Init", "(", "dc", "driverapi", ".", "DriverCallback", ",", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "c", ":=", "driverapi", ".", "Capability", "{", "DataScope", ":", "datastore", ".", "LocalScope", ",", "ConnectivityScope", ":", "datastore", ".", "LocalScope", ",", "}", "\n", "return", "dc", ".", "RegisterDriver", "(", "networkType", ",", "&", "driver", "{", "}", ",", "c", ")", "\n", "}" ]
// Init registers a new instance of host driver
[ "Init", "registers", "a", "new", "instance", "of", "host", "driver" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/host/host.go#L20-L26
22,444
docker/libnetwork
drivers/bridge/interface.go
newInterface
func newInterface(nlh *netlink.Handle, config *networkConfiguration) (*bridgeInterface, error) { var err error i := &bridgeInterface{nlh: nlh} // Initialize the bridge name to the default if unspecified. if config.BridgeName == "" { config.BridgeName = DefaultBridgeName } // Attempt to find an existing bridge named with the specified name. i.Link, err = nlh.LinkByName(config.BridgeName) if err != nil { logrus.Debugf("Did not find any interface with name %s: %v", config.BridgeName, err) } else if _, ok := i.Link.(*netlink.Bridge); !ok { return nil, fmt.Errorf("existing interface %s is not a bridge", i.Link.Attrs().Name) } return i, nil }
go
func newInterface(nlh *netlink.Handle, config *networkConfiguration) (*bridgeInterface, error) { var err error i := &bridgeInterface{nlh: nlh} // Initialize the bridge name to the default if unspecified. if config.BridgeName == "" { config.BridgeName = DefaultBridgeName } // Attempt to find an existing bridge named with the specified name. i.Link, err = nlh.LinkByName(config.BridgeName) if err != nil { logrus.Debugf("Did not find any interface with name %s: %v", config.BridgeName, err) } else if _, ok := i.Link.(*netlink.Bridge); !ok { return nil, fmt.Errorf("existing interface %s is not a bridge", i.Link.Attrs().Name) } return i, nil }
[ "func", "newInterface", "(", "nlh", "*", "netlink", ".", "Handle", ",", "config", "*", "networkConfiguration", ")", "(", "*", "bridgeInterface", ",", "error", ")", "{", "var", "err", "error", "\n", "i", ":=", "&", "bridgeInterface", "{", "nlh", ":", "nlh", "}", "\n\n", "// Initialize the bridge name to the default if unspecified.", "if", "config", ".", "BridgeName", "==", "\"", "\"", "{", "config", ".", "BridgeName", "=", "DefaultBridgeName", "\n", "}", "\n\n", "// Attempt to find an existing bridge named with the specified name.", "i", ".", "Link", ",", "err", "=", "nlh", ".", "LinkByName", "(", "config", ".", "BridgeName", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "config", ".", "BridgeName", ",", "err", ")", "\n", "}", "else", "if", "_", ",", "ok", ":=", "i", ".", "Link", ".", "(", "*", "netlink", ".", "Bridge", ")", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ".", "Link", ".", "Attrs", "(", ")", ".", "Name", ")", "\n", "}", "\n", "return", "i", ",", "nil", "\n", "}" ]
// newInterface creates a new bridge interface structure. It attempts to find // an already existing device identified by the configuration BridgeName field, // or the default bridge name when unspecified, but doesn't attempt to create // one when missing
[ "newInterface", "creates", "a", "new", "bridge", "interface", "structure", ".", "It", "attempts", "to", "find", "an", "already", "existing", "device", "identified", "by", "the", "configuration", "BridgeName", "field", "or", "the", "default", "bridge", "name", "when", "unspecified", "but", "doesn", "t", "attempt", "to", "create", "one", "when", "missing" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/interface.go#L31-L48
22,445
docker/libnetwork
drivers/bridge/interface.go
addresses
func (i *bridgeInterface) addresses() ([]netlink.Addr, []netlink.Addr, error) { v4addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V4) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V4 addresses: %v", err) } v6addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V6) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V6 addresses: %v", err) } if len(v4addr) == 0 { return nil, v6addr, nil } return v4addr, v6addr, nil }
go
func (i *bridgeInterface) addresses() ([]netlink.Addr, []netlink.Addr, error) { v4addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V4) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V4 addresses: %v", err) } v6addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V6) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V6 addresses: %v", err) } if len(v4addr) == 0 { return nil, v6addr, nil } return v4addr, v6addr, nil }
[ "func", "(", "i", "*", "bridgeInterface", ")", "addresses", "(", ")", "(", "[", "]", "netlink", ".", "Addr", ",", "[", "]", "netlink", ".", "Addr", ",", "error", ")", "{", "v4addr", ",", "err", ":=", "i", ".", "nlh", ".", "AddrList", "(", "i", ".", "Link", ",", "netlink", ".", "FAMILY_V4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "v6addr", ",", "err", ":=", "i", ".", "nlh", ".", "AddrList", "(", "i", ".", "Link", ",", "netlink", ".", "FAMILY_V6", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "len", "(", "v4addr", ")", "==", "0", "{", "return", "nil", ",", "v6addr", ",", "nil", "\n", "}", "\n", "return", "v4addr", ",", "v6addr", ",", "nil", "\n", "}" ]
// addresses returns all IPv4 addresses and all IPv6 addresses for the bridge interface.
[ "addresses", "returns", "all", "IPv4", "addresses", "and", "all", "IPv6", "addresses", "for", "the", "bridge", "interface", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/interface.go#L56-L71
22,446
docker/libnetwork
diagnostic/server.go
Init
func (s *Server) Init() { s.mux = http.NewServeMux() // Register local handlers s.RegisterHandler(s, diagPaths2Func) }
go
func (s *Server) Init() { s.mux = http.NewServeMux() // Register local handlers s.RegisterHandler(s, diagPaths2Func) }
[ "func", "(", "s", "*", "Server", ")", "Init", "(", ")", "{", "s", ".", "mux", "=", "http", ".", "NewServeMux", "(", ")", "\n\n", "// Register local handlers", "s", ".", "RegisterHandler", "(", "s", ",", "diagPaths2Func", ")", "\n", "}" ]
// Init initialize the mux for the http handling and register the base hooks
[ "Init", "initialize", "the", "mux", "for", "the", "http", "handling", "and", "register", "the", "base", "hooks" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L55-L60
22,447
docker/libnetwork
diagnostic/server.go
RegisterHandler
func (s *Server) RegisterHandler(ctx interface{}, hdlrs map[string]HTTPHandlerFunc) { s.Lock() defer s.Unlock() for path, fun := range hdlrs { if _, ok := s.registeredHanders[path]; ok { continue } s.mux.Handle(path, httpHandlerCustom{ctx, fun}) s.registeredHanders[path] = true } }
go
func (s *Server) RegisterHandler(ctx interface{}, hdlrs map[string]HTTPHandlerFunc) { s.Lock() defer s.Unlock() for path, fun := range hdlrs { if _, ok := s.registeredHanders[path]; ok { continue } s.mux.Handle(path, httpHandlerCustom{ctx, fun}) s.registeredHanders[path] = true } }
[ "func", "(", "s", "*", "Server", ")", "RegisterHandler", "(", "ctx", "interface", "{", "}", ",", "hdlrs", "map", "[", "string", "]", "HTTPHandlerFunc", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "for", "path", ",", "fun", ":=", "range", "hdlrs", "{", "if", "_", ",", "ok", ":=", "s", ".", "registeredHanders", "[", "path", "]", ";", "ok", "{", "continue", "\n", "}", "\n", "s", ".", "mux", ".", "Handle", "(", "path", ",", "httpHandlerCustom", "{", "ctx", ",", "fun", "}", ")", "\n", "s", ".", "registeredHanders", "[", "path", "]", "=", "true", "\n", "}", "\n", "}" ]
// RegisterHandler allows to register new handlers to the mux and to a specific path
[ "RegisterHandler", "allows", "to", "register", "new", "handlers", "to", "the", "mux", "and", "to", "a", "specific", "path" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L63-L73
22,448
docker/libnetwork
diagnostic/server.go
EnableDiagnostic
func (s *Server) EnableDiagnostic(ip string, port int) { s.Lock() defer s.Unlock() s.port = port if s.enable == 1 { logrus.Info("The server is already up and running") return } logrus.Infof("Starting the diagnostic server listening on %d for commands", port) srv := &http.Server{Addr: fmt.Sprintf("%s:%d", ip, port), Handler: s} s.srv = srv s.enable = 1 go func(n *Server) { // Ignore ErrServerClosed that is returned on the Shutdown call if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { logrus.Errorf("ListenAndServe error: %s", err) atomic.SwapInt32(&n.enable, 0) } }(s) }
go
func (s *Server) EnableDiagnostic(ip string, port int) { s.Lock() defer s.Unlock() s.port = port if s.enable == 1 { logrus.Info("The server is already up and running") return } logrus.Infof("Starting the diagnostic server listening on %d for commands", port) srv := &http.Server{Addr: fmt.Sprintf("%s:%d", ip, port), Handler: s} s.srv = srv s.enable = 1 go func(n *Server) { // Ignore ErrServerClosed that is returned on the Shutdown call if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { logrus.Errorf("ListenAndServe error: %s", err) atomic.SwapInt32(&n.enable, 0) } }(s) }
[ "func", "(", "s", "*", "Server", ")", "EnableDiagnostic", "(", "ip", "string", ",", "port", "int", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "port", "=", "port", "\n\n", "if", "s", ".", "enable", "==", "1", "{", "logrus", ".", "Info", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "port", ")", "\n", "srv", ":=", "&", "http", ".", "Server", "{", "Addr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ip", ",", "port", ")", ",", "Handler", ":", "s", "}", "\n", "s", ".", "srv", "=", "srv", "\n", "s", ".", "enable", "=", "1", "\n", "go", "func", "(", "n", "*", "Server", ")", "{", "// Ignore ErrServerClosed that is returned on the Shutdown call", "if", "err", ":=", "srv", ".", "ListenAndServe", "(", ")", ";", "err", "!=", "nil", "&&", "err", "!=", "http", ".", "ErrServerClosed", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "atomic", ".", "SwapInt32", "(", "&", "n", ".", "enable", ",", "0", ")", "\n", "}", "\n", "}", "(", "s", ")", "\n", "}" ]
// EnableDiagnostic opens a TCP socket to debug the passed network DB
[ "EnableDiagnostic", "opens", "a", "TCP", "socket", "to", "debug", "the", "passed", "network", "DB" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L82-L104
22,449
docker/libnetwork
diagnostic/server.go
DisableDiagnostic
func (s *Server) DisableDiagnostic() { s.Lock() defer s.Unlock() s.srv.Shutdown(context.Background()) s.srv = nil s.enable = 0 logrus.Info("Disabling the diagnostic server") }
go
func (s *Server) DisableDiagnostic() { s.Lock() defer s.Unlock() s.srv.Shutdown(context.Background()) s.srv = nil s.enable = 0 logrus.Info("Disabling the diagnostic server") }
[ "func", "(", "s", "*", "Server", ")", "DisableDiagnostic", "(", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "srv", ".", "Shutdown", "(", "context", ".", "Background", "(", ")", ")", "\n", "s", ".", "srv", "=", "nil", "\n", "s", ".", "enable", "=", "0", "\n", "logrus", ".", "Info", "(", "\"", "\"", ")", "\n", "}" ]
// DisableDiagnostic stop the dubug and closes the tcp socket
[ "DisableDiagnostic", "stop", "the", "dubug", "and", "closes", "the", "tcp", "socket" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L107-L115
22,450
docker/libnetwork
diagnostic/server.go
IsDiagnosticEnabled
func (s *Server) IsDiagnosticEnabled() bool { s.Lock() defer s.Unlock() return s.enable == 1 }
go
func (s *Server) IsDiagnosticEnabled() bool { s.Lock() defer s.Unlock() return s.enable == 1 }
[ "func", "(", "s", "*", "Server", ")", "IsDiagnosticEnabled", "(", ")", "bool", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "enable", "==", "1", "\n", "}" ]
// IsDiagnosticEnabled returns true when the debug is enabled
[ "IsDiagnosticEnabled", "returns", "true", "when", "the", "debug", "is", "enabled" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L118-L122
22,451
docker/libnetwork
diagnostic/server.go
DebugHTTPForm
func DebugHTTPForm(r *http.Request) { for k, v := range r.Form { logrus.Debugf("Form[%q] = %q\n", k, v) } }
go
func DebugHTTPForm(r *http.Request) { for k, v := range r.Form { logrus.Debugf("Form[%q] = %q\n", k, v) } }
[ "func", "DebugHTTPForm", "(", "r", "*", "http", ".", "Request", ")", "{", "for", "k", ",", "v", ":=", "range", "r", ".", "Form", "{", "logrus", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "k", ",", "v", ")", "\n", "}", "\n", "}" ]
// DebugHTTPForm helper to print the form url parameters
[ "DebugHTTPForm", "helper", "to", "print", "the", "form", "url", "parameters" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L183-L187
22,452
docker/libnetwork
diagnostic/server.go
ParseHTTPFormOptions
func ParseHTTPFormOptions(r *http.Request) (bool, *JSONOutput) { _, unsafe := r.Form["unsafe"] v, json := r.Form["json"] var pretty bool if len(v) > 0 { pretty = v[0] == "pretty" } return unsafe, &JSONOutput{enable: json, prettyPrint: pretty} }
go
func ParseHTTPFormOptions(r *http.Request) (bool, *JSONOutput) { _, unsafe := r.Form["unsafe"] v, json := r.Form["json"] var pretty bool if len(v) > 0 { pretty = v[0] == "pretty" } return unsafe, &JSONOutput{enable: json, prettyPrint: pretty} }
[ "func", "ParseHTTPFormOptions", "(", "r", "*", "http", ".", "Request", ")", "(", "bool", ",", "*", "JSONOutput", ")", "{", "_", ",", "unsafe", ":=", "r", ".", "Form", "[", "\"", "\"", "]", "\n", "v", ",", "json", ":=", "r", ".", "Form", "[", "\"", "\"", "]", "\n", "var", "pretty", "bool", "\n", "if", "len", "(", "v", ")", ">", "0", "{", "pretty", "=", "v", "[", "0", "]", "==", "\"", "\"", "\n", "}", "\n", "return", "unsafe", ",", "&", "JSONOutput", "{", "enable", ":", "json", ",", "prettyPrint", ":", "pretty", "}", "\n", "}" ]
// ParseHTTPFormOptions easily parse the JSON printing options
[ "ParseHTTPFormOptions", "easily", "parse", "the", "JSON", "printing", "options" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L196-L204
22,453
docker/libnetwork
diagnostic/server.go
HTTPReply
func HTTPReply(w http.ResponseWriter, r *HTTPResult, j *JSONOutput) (int, error) { var response []byte if j.enable { w.Header().Set("Content-Type", "application/json") var err error if j.prettyPrint { response, err = json.MarshalIndent(r, "", " ") if err != nil { response, _ = json.MarshalIndent(FailCommand(err), "", " ") } } else { response, err = json.Marshal(r) if err != nil { response, _ = json.Marshal(FailCommand(err)) } } } else { response = []byte(r.String()) } return fmt.Fprint(w, string(response)) }
go
func HTTPReply(w http.ResponseWriter, r *HTTPResult, j *JSONOutput) (int, error) { var response []byte if j.enable { w.Header().Set("Content-Type", "application/json") var err error if j.prettyPrint { response, err = json.MarshalIndent(r, "", " ") if err != nil { response, _ = json.MarshalIndent(FailCommand(err), "", " ") } } else { response, err = json.Marshal(r) if err != nil { response, _ = json.Marshal(FailCommand(err)) } } } else { response = []byte(r.String()) } return fmt.Fprint(w, string(response)) }
[ "func", "HTTPReply", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "HTTPResult", ",", "j", "*", "JSONOutput", ")", "(", "int", ",", "error", ")", "{", "var", "response", "[", "]", "byte", "\n", "if", "j", ".", "enable", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "var", "err", "error", "\n", "if", "j", ".", "prettyPrint", "{", "response", ",", "err", "=", "json", ".", "MarshalIndent", "(", "r", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "response", ",", "_", "=", "json", ".", "MarshalIndent", "(", "FailCommand", "(", "err", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "{", "response", ",", "err", "=", "json", ".", "Marshal", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "response", ",", "_", "=", "json", ".", "Marshal", "(", "FailCommand", "(", "err", ")", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "response", "=", "[", "]", "byte", "(", "r", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "fmt", ".", "Fprint", "(", "w", ",", "string", "(", "response", ")", ")", "\n", "}" ]
// HTTPReply helper function that takes care of sending the message out
[ "HTTPReply", "helper", "function", "that", "takes", "care", "of", "sending", "the", "message", "out" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L207-L227
22,454
docker/libnetwork
ipams/remote/remote.go
GetDefaultAddressSpaces
func (a *allocator) GetDefaultAddressSpaces() (string, string, error) { res := &api.GetAddressSpacesResponse{} if err := a.call("GetDefaultAddressSpaces", nil, res); err != nil { return "", "", err } return res.LocalDefaultAddressSpace, res.GlobalDefaultAddressSpace, nil }
go
func (a *allocator) GetDefaultAddressSpaces() (string, string, error) { res := &api.GetAddressSpacesResponse{} if err := a.call("GetDefaultAddressSpaces", nil, res); err != nil { return "", "", err } return res.LocalDefaultAddressSpace, res.GlobalDefaultAddressSpace, nil }
[ "func", "(", "a", "*", "allocator", ")", "GetDefaultAddressSpaces", "(", ")", "(", "string", ",", "string", ",", "error", ")", "{", "res", ":=", "&", "api", ".", "GetAddressSpacesResponse", "{", "}", "\n", "if", "err", ":=", "a", ".", "call", "(", "\"", "\"", ",", "nil", ",", "res", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "res", ".", "LocalDefaultAddressSpace", ",", "res", ".", "GlobalDefaultAddressSpace", ",", "nil", "\n", "}" ]
// GetDefaultAddressSpaces returns the local and global default address spaces
[ "GetDefaultAddressSpaces", "returns", "the", "local", "and", "global", "default", "address", "spaces" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L111-L117
22,455
docker/libnetwork
ipams/remote/remote.go
RequestPool
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { req := &api.RequestPoolRequest{AddressSpace: addressSpace, Pool: pool, SubPool: subPool, Options: options, V6: v6} res := &api.RequestPoolResponse{} if err := a.call("RequestPool", req, res); err != nil { return "", nil, nil, err } retPool, err := types.ParseCIDR(res.Pool) return res.PoolID, retPool, res.Data, err }
go
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { req := &api.RequestPoolRequest{AddressSpace: addressSpace, Pool: pool, SubPool: subPool, Options: options, V6: v6} res := &api.RequestPoolResponse{} if err := a.call("RequestPool", req, res); err != nil { return "", nil, nil, err } retPool, err := types.ParseCIDR(res.Pool) return res.PoolID, retPool, res.Data, err }
[ "func", "(", "a", "*", "allocator", ")", "RequestPool", "(", "addressSpace", ",", "pool", ",", "subPool", "string", ",", "options", "map", "[", "string", "]", "string", ",", "v6", "bool", ")", "(", "string", ",", "*", "net", ".", "IPNet", ",", "map", "[", "string", "]", "string", ",", "error", ")", "{", "req", ":=", "&", "api", ".", "RequestPoolRequest", "{", "AddressSpace", ":", "addressSpace", ",", "Pool", ":", "pool", ",", "SubPool", ":", "subPool", ",", "Options", ":", "options", ",", "V6", ":", "v6", "}", "\n", "res", ":=", "&", "api", ".", "RequestPoolResponse", "{", "}", "\n", "if", "err", ":=", "a", ".", "call", "(", "\"", "\"", ",", "req", ",", "res", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "retPool", ",", "err", ":=", "types", ".", "ParseCIDR", "(", "res", ".", "Pool", ")", "\n", "return", "res", ".", "PoolID", ",", "retPool", ",", "res", ".", "Data", ",", "err", "\n", "}" ]
// RequestPool requests an address pool in the specified address space
[ "RequestPool", "requests", "an", "address", "pool", "in", "the", "specified", "address", "space" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L120-L128
22,456
docker/libnetwork
ipams/remote/remote.go
ReleasePool
func (a *allocator) ReleasePool(poolID string) error { req := &api.ReleasePoolRequest{PoolID: poolID} res := &api.ReleasePoolResponse{} return a.call("ReleasePool", req, res) }
go
func (a *allocator) ReleasePool(poolID string) error { req := &api.ReleasePoolRequest{PoolID: poolID} res := &api.ReleasePoolResponse{} return a.call("ReleasePool", req, res) }
[ "func", "(", "a", "*", "allocator", ")", "ReleasePool", "(", "poolID", "string", ")", "error", "{", "req", ":=", "&", "api", ".", "ReleasePoolRequest", "{", "PoolID", ":", "poolID", "}", "\n", "res", ":=", "&", "api", ".", "ReleasePoolResponse", "{", "}", "\n", "return", "a", ".", "call", "(", "\"", "\"", ",", "req", ",", "res", ")", "\n", "}" ]
// ReleasePool removes an address pool from the specified address space
[ "ReleasePool", "removes", "an", "address", "pool", "from", "the", "specified", "address", "space" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L131-L135
22,457
docker/libnetwork
ipams/remote/remote.go
RequestAddress
func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error) { var ( prefAddress string retAddress *net.IPNet err error ) if address != nil { prefAddress = address.String() } req := &api.RequestAddressRequest{PoolID: poolID, Address: prefAddress, Options: options} res := &api.RequestAddressResponse{} if err := a.call("RequestAddress", req, res); err != nil { return nil, nil, err } if res.Address != "" { retAddress, err = types.ParseCIDR(res.Address) } else { return nil, nil, ipamapi.ErrNoIPReturned } return retAddress, res.Data, err }
go
func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error) { var ( prefAddress string retAddress *net.IPNet err error ) if address != nil { prefAddress = address.String() } req := &api.RequestAddressRequest{PoolID: poolID, Address: prefAddress, Options: options} res := &api.RequestAddressResponse{} if err := a.call("RequestAddress", req, res); err != nil { return nil, nil, err } if res.Address != "" { retAddress, err = types.ParseCIDR(res.Address) } else { return nil, nil, ipamapi.ErrNoIPReturned } return retAddress, res.Data, err }
[ "func", "(", "a", "*", "allocator", ")", "RequestAddress", "(", "poolID", "string", ",", "address", "net", ".", "IP", ",", "options", "map", "[", "string", "]", "string", ")", "(", "*", "net", ".", "IPNet", ",", "map", "[", "string", "]", "string", ",", "error", ")", "{", "var", "(", "prefAddress", "string", "\n", "retAddress", "*", "net", ".", "IPNet", "\n", "err", "error", "\n", ")", "\n", "if", "address", "!=", "nil", "{", "prefAddress", "=", "address", ".", "String", "(", ")", "\n", "}", "\n", "req", ":=", "&", "api", ".", "RequestAddressRequest", "{", "PoolID", ":", "poolID", ",", "Address", ":", "prefAddress", ",", "Options", ":", "options", "}", "\n", "res", ":=", "&", "api", ".", "RequestAddressResponse", "{", "}", "\n", "if", "err", ":=", "a", ".", "call", "(", "\"", "\"", ",", "req", ",", "res", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "if", "res", ".", "Address", "!=", "\"", "\"", "{", "retAddress", ",", "err", "=", "types", ".", "ParseCIDR", "(", "res", ".", "Address", ")", "\n", "}", "else", "{", "return", "nil", ",", "nil", ",", "ipamapi", ".", "ErrNoIPReturned", "\n", "}", "\n", "return", "retAddress", ",", "res", ".", "Data", ",", "err", "\n", "}" ]
// RequestAddress requests an address from the address pool
[ "RequestAddress", "requests", "an", "address", "from", "the", "address", "pool" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L138-L158
22,458
docker/libnetwork
ipams/remote/remote.go
ReleaseAddress
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error { var relAddress string if address != nil { relAddress = address.String() } req := &api.ReleaseAddressRequest{PoolID: poolID, Address: relAddress} res := &api.ReleaseAddressResponse{} return a.call("ReleaseAddress", req, res) }
go
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error { var relAddress string if address != nil { relAddress = address.String() } req := &api.ReleaseAddressRequest{PoolID: poolID, Address: relAddress} res := &api.ReleaseAddressResponse{} return a.call("ReleaseAddress", req, res) }
[ "func", "(", "a", "*", "allocator", ")", "ReleaseAddress", "(", "poolID", "string", ",", "address", "net", ".", "IP", ")", "error", "{", "var", "relAddress", "string", "\n", "if", "address", "!=", "nil", "{", "relAddress", "=", "address", ".", "String", "(", ")", "\n", "}", "\n", "req", ":=", "&", "api", ".", "ReleaseAddressRequest", "{", "PoolID", ":", "poolID", ",", "Address", ":", "relAddress", "}", "\n", "res", ":=", "&", "api", ".", "ReleaseAddressResponse", "{", "}", "\n", "return", "a", ".", "call", "(", "\"", "\"", ",", "req", ",", "res", ")", "\n", "}" ]
// ReleaseAddress releases the address from the specified address pool
[ "ReleaseAddress", "releases", "the", "address", "from", "the", "specified", "address", "pool" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L161-L169
22,459
docker/libnetwork
diagnostic/types.go
FailCommand
func FailCommand(err error) *HTTPResult { return &HTTPResult{ Message: "FAIL", Details: &ErrorCmd{Error: err.Error()}, } }
go
func FailCommand(err error) *HTTPResult { return &HTTPResult{ Message: "FAIL", Details: &ErrorCmd{Error: err.Error()}, } }
[ "func", "FailCommand", "(", "err", "error", ")", "*", "HTTPResult", "{", "return", "&", "HTTPResult", "{", "Message", ":", "\"", "\"", ",", "Details", ":", "&", "ErrorCmd", "{", "Error", ":", "err", ".", "Error", "(", ")", "}", ",", "}", "\n", "}" ]
// FailCommand creates a failure message with error
[ "FailCommand", "creates", "a", "failure", "message", "with", "error" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/types.go#L19-L24
22,460
docker/libnetwork
diagnostic/types.go
WrongCommand
func WrongCommand(message, usage string) *HTTPResult { return &HTTPResult{ Message: message, Details: &UsageCmd{Usage: usage}, } }
go
func WrongCommand(message, usage string) *HTTPResult { return &HTTPResult{ Message: message, Details: &UsageCmd{Usage: usage}, } }
[ "func", "WrongCommand", "(", "message", ",", "usage", "string", ")", "*", "HTTPResult", "{", "return", "&", "HTTPResult", "{", "Message", ":", "message", ",", "Details", ":", "&", "UsageCmd", "{", "Usage", ":", "usage", "}", ",", "}", "\n", "}" ]
// WrongCommand creates a wrong command response
[ "WrongCommand", "creates", "a", "wrong", "command", "response" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/types.go#L27-L32
22,461
docker/libnetwork
drivers/bridge/bridge.go
Init
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { d := newDriver() if err := d.configure(config); err != nil { return err } c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, d, c) }
go
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { d := newDriver() if err := d.configure(config); err != nil { return err } c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, d, c) }
[ "func", "Init", "(", "dc", "driverapi", ".", "DriverCallback", ",", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "d", ":=", "newDriver", "(", ")", "\n", "if", "err", ":=", "d", ".", "configure", "(", "config", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "c", ":=", "driverapi", ".", "Capability", "{", "DataScope", ":", "datastore", ".", "LocalScope", ",", "ConnectivityScope", ":", "datastore", ".", "LocalScope", ",", "}", "\n", "return", "dc", ".", "RegisterDriver", "(", "networkType", ",", "d", ",", "c", ")", "\n", "}" ]
// Init registers a new instance of bridge driver
[ "Init", "registers", "a", "new", "instance", "of", "bridge", "driver" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L159-L170
22,462
docker/libnetwork
drivers/bridge/bridge.go
Validate
func (c *networkConfiguration) Validate() error { if c.Mtu < 0 { return ErrInvalidMtu(c.Mtu) } // If bridge v4 subnet is specified if c.AddressIPv4 != nil { // If default gw is specified, it must be part of bridge subnet if c.DefaultGatewayIPv4 != nil { if !c.AddressIPv4.Contains(c.DefaultGatewayIPv4) { return &ErrInvalidGateway{} } } } // If default v6 gw is specified, AddressIPv6 must be specified and gw must belong to AddressIPv6 subnet if c.EnableIPv6 && c.DefaultGatewayIPv6 != nil { if c.AddressIPv6 == nil || !c.AddressIPv6.Contains(c.DefaultGatewayIPv6) { return &ErrInvalidGateway{} } } return nil }
go
func (c *networkConfiguration) Validate() error { if c.Mtu < 0 { return ErrInvalidMtu(c.Mtu) } // If bridge v4 subnet is specified if c.AddressIPv4 != nil { // If default gw is specified, it must be part of bridge subnet if c.DefaultGatewayIPv4 != nil { if !c.AddressIPv4.Contains(c.DefaultGatewayIPv4) { return &ErrInvalidGateway{} } } } // If default v6 gw is specified, AddressIPv6 must be specified and gw must belong to AddressIPv6 subnet if c.EnableIPv6 && c.DefaultGatewayIPv6 != nil { if c.AddressIPv6 == nil || !c.AddressIPv6.Contains(c.DefaultGatewayIPv6) { return &ErrInvalidGateway{} } } return nil }
[ "func", "(", "c", "*", "networkConfiguration", ")", "Validate", "(", ")", "error", "{", "if", "c", ".", "Mtu", "<", "0", "{", "return", "ErrInvalidMtu", "(", "c", ".", "Mtu", ")", "\n", "}", "\n\n", "// If bridge v4 subnet is specified", "if", "c", ".", "AddressIPv4", "!=", "nil", "{", "// If default gw is specified, it must be part of bridge subnet", "if", "c", ".", "DefaultGatewayIPv4", "!=", "nil", "{", "if", "!", "c", ".", "AddressIPv4", ".", "Contains", "(", "c", ".", "DefaultGatewayIPv4", ")", "{", "return", "&", "ErrInvalidGateway", "{", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// If default v6 gw is specified, AddressIPv6 must be specified and gw must belong to AddressIPv6 subnet", "if", "c", ".", "EnableIPv6", "&&", "c", ".", "DefaultGatewayIPv6", "!=", "nil", "{", "if", "c", ".", "AddressIPv6", "==", "nil", "||", "!", "c", ".", "AddressIPv6", ".", "Contains", "(", "c", ".", "DefaultGatewayIPv6", ")", "{", "return", "&", "ErrInvalidGateway", "{", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate performs a static validation on the network configuration parameters. // Whatever can be assessed a priori before attempting any programming.
[ "Validate", "performs", "a", "static", "validation", "on", "the", "network", "configuration", "parameters", ".", "Whatever", "can", "be", "assessed", "a", "priori", "before", "attempting", "any", "programming", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L174-L196
22,463
docker/libnetwork
drivers/bridge/bridge.go
Conflicts
func (c *networkConfiguration) Conflicts(o *networkConfiguration) error { if o == nil { return errors.New("same configuration") } // Also empty, because only one network with empty name is allowed if c.BridgeName == o.BridgeName { return errors.New("networks have same bridge name") } // They must be in different subnets if (c.AddressIPv4 != nil && o.AddressIPv4 != nil) && (c.AddressIPv4.Contains(o.AddressIPv4.IP) || o.AddressIPv4.Contains(c.AddressIPv4.IP)) { return errors.New("networks have overlapping IPv4") } // They must be in different v6 subnets if (c.AddressIPv6 != nil && o.AddressIPv6 != nil) && (c.AddressIPv6.Contains(o.AddressIPv6.IP) || o.AddressIPv6.Contains(c.AddressIPv6.IP)) { return errors.New("networks have overlapping IPv6") } return nil }
go
func (c *networkConfiguration) Conflicts(o *networkConfiguration) error { if o == nil { return errors.New("same configuration") } // Also empty, because only one network with empty name is allowed if c.BridgeName == o.BridgeName { return errors.New("networks have same bridge name") } // They must be in different subnets if (c.AddressIPv4 != nil && o.AddressIPv4 != nil) && (c.AddressIPv4.Contains(o.AddressIPv4.IP) || o.AddressIPv4.Contains(c.AddressIPv4.IP)) { return errors.New("networks have overlapping IPv4") } // They must be in different v6 subnets if (c.AddressIPv6 != nil && o.AddressIPv6 != nil) && (c.AddressIPv6.Contains(o.AddressIPv6.IP) || o.AddressIPv6.Contains(c.AddressIPv6.IP)) { return errors.New("networks have overlapping IPv6") } return nil }
[ "func", "(", "c", "*", "networkConfiguration", ")", "Conflicts", "(", "o", "*", "networkConfiguration", ")", "error", "{", "if", "o", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Also empty, because only one network with empty name is allowed", "if", "c", ".", "BridgeName", "==", "o", ".", "BridgeName", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// They must be in different subnets", "if", "(", "c", ".", "AddressIPv4", "!=", "nil", "&&", "o", ".", "AddressIPv4", "!=", "nil", ")", "&&", "(", "c", ".", "AddressIPv4", ".", "Contains", "(", "o", ".", "AddressIPv4", ".", "IP", ")", "||", "o", ".", "AddressIPv4", ".", "Contains", "(", "c", ".", "AddressIPv4", ".", "IP", ")", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// They must be in different v6 subnets", "if", "(", "c", ".", "AddressIPv6", "!=", "nil", "&&", "o", ".", "AddressIPv6", "!=", "nil", ")", "&&", "(", "c", ".", "AddressIPv6", ".", "Contains", "(", "o", ".", "AddressIPv6", ".", "IP", ")", "||", "o", ".", "AddressIPv6", ".", "Contains", "(", "c", ".", "AddressIPv6", ".", "IP", ")", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Conflicts check if two NetworkConfiguration objects overlap
[ "Conflicts", "check", "if", "two", "NetworkConfiguration", "objects", "overlap" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L199-L222
22,464
docker/libnetwork
drivers/bridge/bridge.go
getV6Network
func getV6Network(config *networkConfiguration, i *bridgeInterface) *net.IPNet { if config.AddressIPv6 != nil { return config.AddressIPv6 } if i.bridgeIPv6 != nil && i.bridgeIPv6.IP != nil && !i.bridgeIPv6.IP.IsLinkLocalUnicast() { return i.bridgeIPv6 } return nil }
go
func getV6Network(config *networkConfiguration, i *bridgeInterface) *net.IPNet { if config.AddressIPv6 != nil { return config.AddressIPv6 } if i.bridgeIPv6 != nil && i.bridgeIPv6.IP != nil && !i.bridgeIPv6.IP.IsLinkLocalUnicast() { return i.bridgeIPv6 } return nil }
[ "func", "getV6Network", "(", "config", "*", "networkConfiguration", ",", "i", "*", "bridgeInterface", ")", "*", "net", ".", "IPNet", "{", "if", "config", ".", "AddressIPv6", "!=", "nil", "{", "return", "config", ".", "AddressIPv6", "\n", "}", "\n", "if", "i", ".", "bridgeIPv6", "!=", "nil", "&&", "i", ".", "bridgeIPv6", ".", "IP", "!=", "nil", "&&", "!", "i", ".", "bridgeIPv6", ".", "IP", ".", "IsLinkLocalUnicast", "(", ")", "{", "return", "i", ".", "bridgeIPv6", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Returns the non link-local IPv6 subnet for the containers attached to this bridge if found, nil otherwise
[ "Returns", "the", "non", "link", "-", "local", "IPv6", "subnet", "for", "the", "containers", "attached", "to", "this", "bridge", "if", "found", "nil", "otherwise" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L509-L518
22,465
docker/libnetwork
drivers/bridge/bridge.go
CreateNetwork
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" { return types.BadRequestErrorf("ipv4 pool is empty") } // Sanity checks d.Lock() if _, ok := d.networks[id]; ok { d.Unlock() return types.ForbiddenErrorf("network %s exists", id) } d.Unlock() // Parse and validate the config. It should not be conflict with existing networks' config config, err := parseNetworkOptions(id, option) if err != nil { return err } if err = config.processIPAM(id, ipV4Data, ipV6Data); err != nil { return err } // start the critical section, from this point onward we are dealing with the list of networks // so to be consistent we cannot allow that the list changes d.configNetwork.Lock() defer d.configNetwork.Unlock() // check network conflicts if err = d.checkConflict(config); err != nil { nerr, ok := err.(defaultBridgeNetworkConflict) if !ok { return err } // Got a conflict with a stale default network, clean that up and continue logrus.Warn(nerr) d.deleteNetwork(nerr.ID) } // there is no conflict, now create the network if err = d.createNetwork(config); err != nil { return err } return d.storeUpdate(config) }
go
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" { return types.BadRequestErrorf("ipv4 pool is empty") } // Sanity checks d.Lock() if _, ok := d.networks[id]; ok { d.Unlock() return types.ForbiddenErrorf("network %s exists", id) } d.Unlock() // Parse and validate the config. It should not be conflict with existing networks' config config, err := parseNetworkOptions(id, option) if err != nil { return err } if err = config.processIPAM(id, ipV4Data, ipV6Data); err != nil { return err } // start the critical section, from this point onward we are dealing with the list of networks // so to be consistent we cannot allow that the list changes d.configNetwork.Lock() defer d.configNetwork.Unlock() // check network conflicts if err = d.checkConflict(config); err != nil { nerr, ok := err.(defaultBridgeNetworkConflict) if !ok { return err } // Got a conflict with a stale default network, clean that up and continue logrus.Warn(nerr) d.deleteNetwork(nerr.ID) } // there is no conflict, now create the network if err = d.createNetwork(config); err != nil { return err } return d.storeUpdate(config) }
[ "func", "(", "d", "*", "driver", ")", "CreateNetwork", "(", "id", "string", ",", "option", "map", "[", "string", "]", "interface", "{", "}", ",", "nInfo", "driverapi", ".", "NetworkInfo", ",", "ipV4Data", ",", "ipV6Data", "[", "]", "driverapi", ".", "IPAMData", ")", "error", "{", "if", "len", "(", "ipV4Data", ")", "==", "0", "||", "ipV4Data", "[", "0", "]", ".", "Pool", ".", "String", "(", ")", "==", "\"", "\"", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n", "// Sanity checks", "d", ".", "Lock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "d", ".", "networks", "[", "id", "]", ";", "ok", "{", "d", ".", "Unlock", "(", ")", "\n", "return", "types", ".", "ForbiddenErrorf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n", "d", ".", "Unlock", "(", ")", "\n\n", "// Parse and validate the config. It should not be conflict with existing networks' config", "config", ",", "err", ":=", "parseNetworkOptions", "(", "id", ",", "option", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", "=", "config", ".", "processIPAM", "(", "id", ",", "ipV4Data", ",", "ipV6Data", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// start the critical section, from this point onward we are dealing with the list of networks", "// so to be consistent we cannot allow that the list changes", "d", ".", "configNetwork", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "configNetwork", ".", "Unlock", "(", ")", "\n\n", "// check network conflicts", "if", "err", "=", "d", ".", "checkConflict", "(", "config", ")", ";", "err", "!=", "nil", "{", "nerr", ",", "ok", ":=", "err", ".", "(", "defaultBridgeNetworkConflict", ")", "\n", "if", "!", "ok", "{", "return", "err", "\n", "}", "\n", "// Got a conflict with a stale default network, clean that up and continue", "logrus", ".", "Warn", "(", "nerr", ")", "\n", "d", ".", "deleteNetwork", "(", "nerr", ".", "ID", ")", "\n", "}", "\n\n", "// there is no conflict, now create the network", "if", "err", "=", "d", ".", "createNetwork", "(", "config", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "d", ".", "storeUpdate", "(", "config", ")", "\n", "}" ]
// Create a new network using bridge plugin
[ "Create", "a", "new", "network", "using", "bridge", "plugin" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L548-L592
22,466
docker/libnetwork
service.go
assignIPToEndpoint
func (s *service) assignIPToEndpoint(ip, eID string) (bool, int) { return s.ipToEndpoint.Insert(ip, eID) }
go
func (s *service) assignIPToEndpoint(ip, eID string) (bool, int) { return s.ipToEndpoint.Insert(ip, eID) }
[ "func", "(", "s", "*", "service", ")", "assignIPToEndpoint", "(", "ip", ",", "eID", "string", ")", "(", "bool", ",", "int", ")", "{", "return", "s", ".", "ipToEndpoint", ".", "Insert", "(", "ip", ",", "eID", ")", "\n", "}" ]
// assignIPToEndpoint inserts the mapping between the IP and the endpoint identifier // returns true if the mapping was not present, false otherwise // returns also the number of endpoints associated to the IP
[ "assignIPToEndpoint", "inserts", "the", "mapping", "between", "the", "IP", "and", "the", "endpoint", "identifier", "returns", "true", "if", "the", "mapping", "was", "not", "present", "false", "otherwise", "returns", "also", "the", "number", "of", "endpoints", "associated", "to", "the", "IP" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service.go#L67-L69
22,467
docker/libnetwork
service.go
removeIPToEndpoint
func (s *service) removeIPToEndpoint(ip, eID string) (bool, int) { return s.ipToEndpoint.Remove(ip, eID) }
go
func (s *service) removeIPToEndpoint(ip, eID string) (bool, int) { return s.ipToEndpoint.Remove(ip, eID) }
[ "func", "(", "s", "*", "service", ")", "removeIPToEndpoint", "(", "ip", ",", "eID", "string", ")", "(", "bool", ",", "int", ")", "{", "return", "s", ".", "ipToEndpoint", ".", "Remove", "(", "ip", ",", "eID", ")", "\n", "}" ]
// removeIPToEndpoint removes the mapping between the IP and the endpoint identifier // returns true if the mapping was deleted, false otherwise // returns also the number of endpoints associated to the IP
[ "removeIPToEndpoint", "removes", "the", "mapping", "between", "the", "IP", "and", "the", "endpoint", "identifier", "returns", "true", "if", "the", "mapping", "was", "deleted", "false", "otherwise", "returns", "also", "the", "number", "of", "endpoints", "associated", "to", "the", "IP" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service.go#L74-L76
22,468
docker/libnetwork
controller.go
New
func New(cfgOptions ...config.Option) (NetworkController, error) { c := &controller{ id: stringid.GenerateRandomID(), cfg: config.ParseConfigOptions(cfgOptions...), sandboxes: sandboxTable{}, svcRecords: make(map[string]svcInfo), serviceBindings: make(map[serviceKey]*service), agentInitDone: make(chan struct{}), networkLocker: locker.New(), DiagnosticServer: diagnostic.New(), } c.DiagnosticServer.Init() if err := c.initStores(); err != nil { return nil, err } drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil, c.cfg.PluginGetter) if err != nil { return nil, err } for _, i := range getInitializers(c.cfg.Daemon.Experimental) { var dcfg map[string]interface{} // External plugins don't need config passed through daemon. They can // bootstrap themselves if i.ntype != "remote" { dcfg = c.makeDriverConfig(i.ntype) } if err := drvRegistry.AddDriver(i.ntype, i.fn, dcfg); err != nil { return nil, err } } if err = initIPAMDrivers(drvRegistry, nil, c.getStore(datastore.GlobalScope), c.cfg.Daemon.DefaultAddressPool); err != nil { return nil, err } c.drvRegistry = drvRegistry if c.cfg != nil && c.cfg.Cluster.Watcher != nil { if err := c.initDiscovery(c.cfg.Cluster.Watcher); err != nil { // Failing to initialize discovery is a bad situation to be in. // But it cannot fail creating the Controller logrus.Errorf("Failed to Initialize Discovery : %v", err) } } c.WalkNetworks(populateSpecial) // Reserve pools first before doing cleanup. Otherwise the // cleanups of endpoint/network and sandbox below will // generate many unnecessary warnings c.reservePools() // Cleanup resources c.sandboxCleanup(c.cfg.ActiveSandboxes) c.cleanupLocalEndpoints() c.networkCleanup() if err := c.startExternalKeyListener(); err != nil { return nil, err } return c, nil }
go
func New(cfgOptions ...config.Option) (NetworkController, error) { c := &controller{ id: stringid.GenerateRandomID(), cfg: config.ParseConfigOptions(cfgOptions...), sandboxes: sandboxTable{}, svcRecords: make(map[string]svcInfo), serviceBindings: make(map[serviceKey]*service), agentInitDone: make(chan struct{}), networkLocker: locker.New(), DiagnosticServer: diagnostic.New(), } c.DiagnosticServer.Init() if err := c.initStores(); err != nil { return nil, err } drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil, c.cfg.PluginGetter) if err != nil { return nil, err } for _, i := range getInitializers(c.cfg.Daemon.Experimental) { var dcfg map[string]interface{} // External plugins don't need config passed through daemon. They can // bootstrap themselves if i.ntype != "remote" { dcfg = c.makeDriverConfig(i.ntype) } if err := drvRegistry.AddDriver(i.ntype, i.fn, dcfg); err != nil { return nil, err } } if err = initIPAMDrivers(drvRegistry, nil, c.getStore(datastore.GlobalScope), c.cfg.Daemon.DefaultAddressPool); err != nil { return nil, err } c.drvRegistry = drvRegistry if c.cfg != nil && c.cfg.Cluster.Watcher != nil { if err := c.initDiscovery(c.cfg.Cluster.Watcher); err != nil { // Failing to initialize discovery is a bad situation to be in. // But it cannot fail creating the Controller logrus.Errorf("Failed to Initialize Discovery : %v", err) } } c.WalkNetworks(populateSpecial) // Reserve pools first before doing cleanup. Otherwise the // cleanups of endpoint/network and sandbox below will // generate many unnecessary warnings c.reservePools() // Cleanup resources c.sandboxCleanup(c.cfg.ActiveSandboxes) c.cleanupLocalEndpoints() c.networkCleanup() if err := c.startExternalKeyListener(); err != nil { return nil, err } return c, nil }
[ "func", "New", "(", "cfgOptions", "...", "config", ".", "Option", ")", "(", "NetworkController", ",", "error", ")", "{", "c", ":=", "&", "controller", "{", "id", ":", "stringid", ".", "GenerateRandomID", "(", ")", ",", "cfg", ":", "config", ".", "ParseConfigOptions", "(", "cfgOptions", "...", ")", ",", "sandboxes", ":", "sandboxTable", "{", "}", ",", "svcRecords", ":", "make", "(", "map", "[", "string", "]", "svcInfo", ")", ",", "serviceBindings", ":", "make", "(", "map", "[", "serviceKey", "]", "*", "service", ")", ",", "agentInitDone", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "networkLocker", ":", "locker", ".", "New", "(", ")", ",", "DiagnosticServer", ":", "diagnostic", ".", "New", "(", ")", ",", "}", "\n", "c", ".", "DiagnosticServer", ".", "Init", "(", ")", "\n\n", "if", "err", ":=", "c", ".", "initStores", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "drvRegistry", ",", "err", ":=", "drvregistry", ".", "New", "(", "c", ".", "getStore", "(", "datastore", ".", "LocalScope", ")", ",", "c", ".", "getStore", "(", "datastore", ".", "GlobalScope", ")", ",", "c", ".", "RegisterDriver", ",", "nil", ",", "c", ".", "cfg", ".", "PluginGetter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "i", ":=", "range", "getInitializers", "(", "c", ".", "cfg", ".", "Daemon", ".", "Experimental", ")", "{", "var", "dcfg", "map", "[", "string", "]", "interface", "{", "}", "\n\n", "// External plugins don't need config passed through daemon. They can", "// bootstrap themselves", "if", "i", ".", "ntype", "!=", "\"", "\"", "{", "dcfg", "=", "c", ".", "makeDriverConfig", "(", "i", ".", "ntype", ")", "\n", "}", "\n\n", "if", "err", ":=", "drvRegistry", ".", "AddDriver", "(", "i", ".", "ntype", ",", "i", ".", "fn", ",", "dcfg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "if", "err", "=", "initIPAMDrivers", "(", "drvRegistry", ",", "nil", ",", "c", ".", "getStore", "(", "datastore", ".", "GlobalScope", ")", ",", "c", ".", "cfg", ".", "Daemon", ".", "DefaultAddressPool", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "c", ".", "drvRegistry", "=", "drvRegistry", "\n\n", "if", "c", ".", "cfg", "!=", "nil", "&&", "c", ".", "cfg", ".", "Cluster", ".", "Watcher", "!=", "nil", "{", "if", "err", ":=", "c", ".", "initDiscovery", "(", "c", ".", "cfg", ".", "Cluster", ".", "Watcher", ")", ";", "err", "!=", "nil", "{", "// Failing to initialize discovery is a bad situation to be in.", "// But it cannot fail creating the Controller", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "c", ".", "WalkNetworks", "(", "populateSpecial", ")", "\n\n", "// Reserve pools first before doing cleanup. Otherwise the", "// cleanups of endpoint/network and sandbox below will", "// generate many unnecessary warnings", "c", ".", "reservePools", "(", ")", "\n\n", "// Cleanup resources", "c", ".", "sandboxCleanup", "(", "c", ".", "cfg", ".", "ActiveSandboxes", ")", "\n", "c", ".", "cleanupLocalEndpoints", "(", ")", "\n", "c", ".", "networkCleanup", "(", ")", "\n\n", "if", "err", ":=", "c", ".", "startExternalKeyListener", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// New creates a new instance of network controller.
[ "New", "creates", "a", "new", "instance", "of", "network", "controller", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L189-L256
22,469
docker/libnetwork
controller.go
SetKeys
func (c *controller) SetKeys(keys []*types.EncryptionKey) error { subsysKeys := make(map[string]int) for _, key := range keys { if key.Subsystem != subsysGossip && key.Subsystem != subsysIPSec { return fmt.Errorf("key received for unrecognized subsystem") } subsysKeys[key.Subsystem]++ } for s, count := range subsysKeys { if count != keyringSize { return fmt.Errorf("incorrect number of keys for subsystem %v", s) } } agent := c.getAgent() if agent == nil { c.Lock() c.keys = keys c.Unlock() return nil } return c.handleKeyChange(keys) }
go
func (c *controller) SetKeys(keys []*types.EncryptionKey) error { subsysKeys := make(map[string]int) for _, key := range keys { if key.Subsystem != subsysGossip && key.Subsystem != subsysIPSec { return fmt.Errorf("key received for unrecognized subsystem") } subsysKeys[key.Subsystem]++ } for s, count := range subsysKeys { if count != keyringSize { return fmt.Errorf("incorrect number of keys for subsystem %v", s) } } agent := c.getAgent() if agent == nil { c.Lock() c.keys = keys c.Unlock() return nil } return c.handleKeyChange(keys) }
[ "func", "(", "c", "*", "controller", ")", "SetKeys", "(", "keys", "[", "]", "*", "types", ".", "EncryptionKey", ")", "error", "{", "subsysKeys", ":=", "make", "(", "map", "[", "string", "]", "int", ")", "\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "if", "key", ".", "Subsystem", "!=", "subsysGossip", "&&", "key", ".", "Subsystem", "!=", "subsysIPSec", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "subsysKeys", "[", "key", ".", "Subsystem", "]", "++", "\n", "}", "\n", "for", "s", ",", "count", ":=", "range", "subsysKeys", "{", "if", "count", "!=", "keyringSize", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ")", "\n", "}", "\n", "}", "\n\n", "agent", ":=", "c", ".", "getAgent", "(", ")", "\n\n", "if", "agent", "==", "nil", "{", "c", ".", "Lock", "(", ")", "\n", "c", ".", "keys", "=", "keys", "\n", "c", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "c", ".", "handleKeyChange", "(", "keys", ")", "\n", "}" ]
// libnetwork side of agent depends on the keys. On the first receipt of // keys setup the agent. For subsequent key set handle the key change
[ "libnetwork", "side", "of", "agent", "depends", "on", "the", "keys", ".", "On", "the", "first", "receipt", "of", "keys", "setup", "the", "agent", ".", "For", "subsequent", "key", "set", "handle", "the", "key", "change" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L285-L309
22,470
docker/libnetwork
controller.go
AgentInitWait
func (c *controller) AgentInitWait() { c.Lock() agentInitDone := c.agentInitDone c.Unlock() if agentInitDone != nil { <-agentInitDone } }
go
func (c *controller) AgentInitWait() { c.Lock() agentInitDone := c.agentInitDone c.Unlock() if agentInitDone != nil { <-agentInitDone } }
[ "func", "(", "c", "*", "controller", ")", "AgentInitWait", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "agentInitDone", ":=", "c", ".", "agentInitDone", "\n", "c", ".", "Unlock", "(", ")", "\n\n", "if", "agentInitDone", "!=", "nil", "{", "<-", "agentInitDone", "\n", "}", "\n", "}" ]
// AgentInitWait waits for agent initialization to be completed in the controller.
[ "AgentInitWait", "waits", "for", "agent", "initialization", "to", "be", "completed", "in", "the", "controller", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L367-L375
22,471
docker/libnetwork
controller.go
AgentStopWait
func (c *controller) AgentStopWait() { c.Lock() agentStopDone := c.agentStopDone c.Unlock() if agentStopDone != nil { <-agentStopDone } }
go
func (c *controller) AgentStopWait() { c.Lock() agentStopDone := c.agentStopDone c.Unlock() if agentStopDone != nil { <-agentStopDone } }
[ "func", "(", "c", "*", "controller", ")", "AgentStopWait", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "agentStopDone", ":=", "c", ".", "agentStopDone", "\n", "c", ".", "Unlock", "(", ")", "\n", "if", "agentStopDone", "!=", "nil", "{", "<-", "agentStopDone", "\n", "}", "\n", "}" ]
// AgentStopWait waits for the Agent stop to be completed in the controller
[ "AgentStopWait", "waits", "for", "the", "Agent", "stop", "to", "be", "completed", "in", "the", "controller" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L378-L385
22,472
docker/libnetwork
controller.go
agentOperationStart
func (c *controller) agentOperationStart() { c.Lock() if c.agentInitDone == nil { c.agentInitDone = make(chan struct{}) } if c.agentStopDone == nil { c.agentStopDone = make(chan struct{}) } c.Unlock() }
go
func (c *controller) agentOperationStart() { c.Lock() if c.agentInitDone == nil { c.agentInitDone = make(chan struct{}) } if c.agentStopDone == nil { c.agentStopDone = make(chan struct{}) } c.Unlock() }
[ "func", "(", "c", "*", "controller", ")", "agentOperationStart", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "agentInitDone", "==", "nil", "{", "c", ".", "agentInitDone", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "}", "\n", "if", "c", ".", "agentStopDone", "==", "nil", "{", "c", ".", "agentStopDone", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n", "}" ]
// agentOperationStart marks the start of an Agent Init or Agent Stop
[ "agentOperationStart", "marks", "the", "start", "of", "an", "Agent", "Init", "or", "Agent", "Stop" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L388-L397
22,473
docker/libnetwork
controller.go
agentInitComplete
func (c *controller) agentInitComplete() { c.Lock() if c.agentInitDone != nil { close(c.agentInitDone) c.agentInitDone = nil } c.Unlock() }
go
func (c *controller) agentInitComplete() { c.Lock() if c.agentInitDone != nil { close(c.agentInitDone) c.agentInitDone = nil } c.Unlock() }
[ "func", "(", "c", "*", "controller", ")", "agentInitComplete", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "agentInitDone", "!=", "nil", "{", "close", "(", "c", ".", "agentInitDone", ")", "\n", "c", ".", "agentInitDone", "=", "nil", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n", "}" ]
// agentInitComplete notifies the successful completion of the Agent initialization
[ "agentInitComplete", "notifies", "the", "successful", "completion", "of", "the", "Agent", "initialization" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L400-L407
22,474
docker/libnetwork
controller.go
agentStopComplete
func (c *controller) agentStopComplete() { c.Lock() if c.agentStopDone != nil { close(c.agentStopDone) c.agentStopDone = nil } c.Unlock() }
go
func (c *controller) agentStopComplete() { c.Lock() if c.agentStopDone != nil { close(c.agentStopDone) c.agentStopDone = nil } c.Unlock() }
[ "func", "(", "c", "*", "controller", ")", "agentStopComplete", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "agentStopDone", "!=", "nil", "{", "close", "(", "c", ".", "agentStopDone", ")", "\n", "c", ".", "agentStopDone", "=", "nil", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n", "}" ]
// agentStopComplete notifies the successful completion of the Agent stop
[ "agentStopComplete", "notifies", "the", "successful", "completion", "of", "the", "Agent", "stop" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L410-L417
22,475
docker/libnetwork
controller.go
SandboxDestroy
func (c *controller) SandboxDestroy(id string) error { var sb *sandbox c.Lock() for _, s := range c.sandboxes { if s.containerID == id { sb = s break } } c.Unlock() // It is not an error if sandbox is not available if sb == nil { return nil } return sb.Delete() }
go
func (c *controller) SandboxDestroy(id string) error { var sb *sandbox c.Lock() for _, s := range c.sandboxes { if s.containerID == id { sb = s break } } c.Unlock() // It is not an error if sandbox is not available if sb == nil { return nil } return sb.Delete() }
[ "func", "(", "c", "*", "controller", ")", "SandboxDestroy", "(", "id", "string", ")", "error", "{", "var", "sb", "*", "sandbox", "\n", "c", ".", "Lock", "(", ")", "\n", "for", "_", ",", "s", ":=", "range", "c", ".", "sandboxes", "{", "if", "s", ".", "containerID", "==", "id", "{", "sb", "=", "s", "\n", "break", "\n", "}", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n\n", "// It is not an error if sandbox is not available", "if", "sb", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "sb", ".", "Delete", "(", ")", "\n", "}" ]
// SandboxDestroy destroys a sandbox given a container ID
[ "SandboxDestroy", "destroys", "a", "sandbox", "given", "a", "container", "ID" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1231-L1248
22,476
docker/libnetwork
controller.go
SandboxContainerWalker
func SandboxContainerWalker(out *Sandbox, containerID string) SandboxWalker { return func(sb Sandbox) bool { if sb.ContainerID() == containerID { *out = sb return true } return false } }
go
func SandboxContainerWalker(out *Sandbox, containerID string) SandboxWalker { return func(sb Sandbox) bool { if sb.ContainerID() == containerID { *out = sb return true } return false } }
[ "func", "SandboxContainerWalker", "(", "out", "*", "Sandbox", ",", "containerID", "string", ")", "SandboxWalker", "{", "return", "func", "(", "sb", "Sandbox", ")", "bool", "{", "if", "sb", ".", "ContainerID", "(", ")", "==", "containerID", "{", "*", "out", "=", "sb", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "}" ]
// SandboxContainerWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed containerID
[ "SandboxContainerWalker", "returns", "a", "Sandbox", "Walker", "function", "which", "looks", "for", "an", "existing", "Sandbox", "with", "the", "passed", "containerID" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1251-L1259
22,477
docker/libnetwork
controller.go
SandboxKeyWalker
func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker { return func(sb Sandbox) bool { if sb.Key() == key { *out = sb return true } return false } }
go
func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker { return func(sb Sandbox) bool { if sb.Key() == key { *out = sb return true } return false } }
[ "func", "SandboxKeyWalker", "(", "out", "*", "Sandbox", ",", "key", "string", ")", "SandboxWalker", "{", "return", "func", "(", "sb", "Sandbox", ")", "bool", "{", "if", "sb", ".", "Key", "(", ")", "==", "key", "{", "*", "out", "=", "sb", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "}" ]
// SandboxKeyWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed key
[ "SandboxKeyWalker", "returns", "a", "Sandbox", "Walker", "function", "which", "looks", "for", "an", "existing", "Sandbox", "with", "the", "passed", "key" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1262-L1270
22,478
docker/libnetwork
controller.go
StartDiagnostic
func (c *controller) StartDiagnostic(port int) { c.Lock() if !c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port) } c.Unlock() }
go
func (c *controller) StartDiagnostic(port int) { c.Lock() if !c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port) } c.Unlock() }
[ "func", "(", "c", "*", "controller", ")", "StartDiagnostic", "(", "port", "int", ")", "{", "c", ".", "Lock", "(", ")", "\n", "if", "!", "c", ".", "DiagnosticServer", ".", "IsDiagnosticEnabled", "(", ")", "{", "c", ".", "DiagnosticServer", ".", "EnableDiagnostic", "(", "\"", "\"", ",", "port", ")", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n", "}" ]
// StartDiagnostic start the network dias mode
[ "StartDiagnostic", "start", "the", "network", "dias", "mode" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1335-L1341
22,479
docker/libnetwork
controller.go
StopDiagnostic
func (c *controller) StopDiagnostic() { c.Lock() if c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.DisableDiagnostic() } c.Unlock() }
go
func (c *controller) StopDiagnostic() { c.Lock() if c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.DisableDiagnostic() } c.Unlock() }
[ "func", "(", "c", "*", "controller", ")", "StopDiagnostic", "(", ")", "{", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "DiagnosticServer", ".", "IsDiagnosticEnabled", "(", ")", "{", "c", ".", "DiagnosticServer", ".", "DisableDiagnostic", "(", ")", "\n", "}", "\n", "c", ".", "Unlock", "(", ")", "\n", "}" ]
// StopDiagnostic start the network dias mode
[ "StopDiagnostic", "start", "the", "network", "dias", "mode" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1344-L1350
22,480
docker/libnetwork
controller.go
IsDiagnosticEnabled
func (c *controller) IsDiagnosticEnabled() bool { c.Lock() defer c.Unlock() return c.DiagnosticServer.IsDiagnosticEnabled() }
go
func (c *controller) IsDiagnosticEnabled() bool { c.Lock() defer c.Unlock() return c.DiagnosticServer.IsDiagnosticEnabled() }
[ "func", "(", "c", "*", "controller", ")", "IsDiagnosticEnabled", "(", ")", "bool", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "DiagnosticServer", ".", "IsDiagnosticEnabled", "(", ")", "\n", "}" ]
// IsDiagnosticEnabled returns true if the dias is enabled
[ "IsDiagnosticEnabled", "returns", "true", "if", "the", "dias", "is", "enabled" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1353-L1357
22,481
docker/libnetwork
drivers/overlay/ov_network.go
destroySandbox
func (n *network) destroySandbox() { if n.sbox != nil { for _, iface := range n.sbox.Info().Interfaces() { if err := iface.Remove(); err != nil { logrus.Debugf("Remove interface %s failed: %v", iface.SrcName(), err) } } for _, s := range n.subnets { if hostMode { if err := removeFilters(n.id[:12], s.brName); err != nil { logrus.Warnf("Could not remove overlay filters: %v", err) } } if s.vxlanName != "" { err := deleteInterface(s.vxlanName) if err != nil { logrus.Warnf("could not cleanup sandbox properly: %v", err) } } } if hostMode { if err := removeNetworkChain(n.id[:12]); err != nil { logrus.Warnf("could not remove network chain: %v", err) } } // Close the netlink socket, this will also release the watchMiss goroutine that is using it if n.nlSocket != nil { n.nlSocket.Close() n.nlSocket = nil } n.sbox.Destroy() n.sbox = nil } }
go
func (n *network) destroySandbox() { if n.sbox != nil { for _, iface := range n.sbox.Info().Interfaces() { if err := iface.Remove(); err != nil { logrus.Debugf("Remove interface %s failed: %v", iface.SrcName(), err) } } for _, s := range n.subnets { if hostMode { if err := removeFilters(n.id[:12], s.brName); err != nil { logrus.Warnf("Could not remove overlay filters: %v", err) } } if s.vxlanName != "" { err := deleteInterface(s.vxlanName) if err != nil { logrus.Warnf("could not cleanup sandbox properly: %v", err) } } } if hostMode { if err := removeNetworkChain(n.id[:12]); err != nil { logrus.Warnf("could not remove network chain: %v", err) } } // Close the netlink socket, this will also release the watchMiss goroutine that is using it if n.nlSocket != nil { n.nlSocket.Close() n.nlSocket = nil } n.sbox.Destroy() n.sbox = nil } }
[ "func", "(", "n", "*", "network", ")", "destroySandbox", "(", ")", "{", "if", "n", ".", "sbox", "!=", "nil", "{", "for", "_", ",", "iface", ":=", "range", "n", ".", "sbox", ".", "Info", "(", ")", ".", "Interfaces", "(", ")", "{", "if", "err", ":=", "iface", ".", "Remove", "(", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "iface", ".", "SrcName", "(", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "s", ":=", "range", "n", ".", "subnets", "{", "if", "hostMode", "{", "if", "err", ":=", "removeFilters", "(", "n", ".", "id", "[", ":", "12", "]", ",", "s", ".", "brName", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "s", ".", "vxlanName", "!=", "\"", "\"", "{", "err", ":=", "deleteInterface", "(", "s", ".", "vxlanName", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "hostMode", "{", "if", "err", ":=", "removeNetworkChain", "(", "n", ".", "id", "[", ":", "12", "]", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Close the netlink socket, this will also release the watchMiss goroutine that is using it", "if", "n", ".", "nlSocket", "!=", "nil", "{", "n", ".", "nlSocket", ".", "Close", "(", ")", "\n", "n", ".", "nlSocket", "=", "nil", "\n", "}", "\n\n", "n", ".", "sbox", ".", "Destroy", "(", ")", "\n", "n", ".", "sbox", "=", "nil", "\n", "}", "\n", "}" ]
// to be called while holding network lock
[ "to", "be", "called", "while", "holding", "network", "lock" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L374-L412
22,482
docker/libnetwork
drivers/overlay/ov_network.go
initSubnetSandbox
func (n *network) initSubnetSandbox(s *subnet, restore bool) error { brName := n.generateBridgeName(s) vxlanName := n.generateVxlanName(s) if restore { if err := n.restoreSubnetSandbox(s, brName, vxlanName); err != nil { return err } } else { if err := n.setupSubnetSandbox(s, brName, vxlanName); err != nil { return err } } s.vxlanName = vxlanName s.brName = brName return nil }
go
func (n *network) initSubnetSandbox(s *subnet, restore bool) error { brName := n.generateBridgeName(s) vxlanName := n.generateVxlanName(s) if restore { if err := n.restoreSubnetSandbox(s, brName, vxlanName); err != nil { return err } } else { if err := n.setupSubnetSandbox(s, brName, vxlanName); err != nil { return err } } s.vxlanName = vxlanName s.brName = brName return nil }
[ "func", "(", "n", "*", "network", ")", "initSubnetSandbox", "(", "s", "*", "subnet", ",", "restore", "bool", ")", "error", "{", "brName", ":=", "n", ".", "generateBridgeName", "(", "s", ")", "\n", "vxlanName", ":=", "n", ".", "generateVxlanName", "(", "s", ")", "\n\n", "if", "restore", "{", "if", "err", ":=", "n", ".", "restoreSubnetSandbox", "(", "s", ",", "brName", ",", "vxlanName", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "if", "err", ":=", "n", ".", "setupSubnetSandbox", "(", "s", ",", "brName", ",", "vxlanName", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "s", ".", "vxlanName", "=", "vxlanName", "\n", "s", ".", "brName", "=", "brName", "\n\n", "return", "nil", "\n", "}" ]
// Must be called with the network lock
[ "Must", "be", "called", "with", "the", "network", "lock" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L662-L680
22,483
docker/libnetwork
drivers/overlay/ov_network.go
restoreNetworkFromStore
func (d *driver) restoreNetworkFromStore(nid string) *network { n := d.getNetworkFromStore(nid) if n != nil { n.driver = d n.endpoints = endpointTable{} d.networks[nid] = n } return n }
go
func (d *driver) restoreNetworkFromStore(nid string) *network { n := d.getNetworkFromStore(nid) if n != nil { n.driver = d n.endpoints = endpointTable{} d.networks[nid] = n } return n }
[ "func", "(", "d", "*", "driver", ")", "restoreNetworkFromStore", "(", "nid", "string", ")", "*", "network", "{", "n", ":=", "d", ".", "getNetworkFromStore", "(", "nid", ")", "\n", "if", "n", "!=", "nil", "{", "n", ".", "driver", "=", "d", "\n", "n", ".", "endpoints", "=", "endpointTable", "{", "}", "\n", "d", ".", "networks", "[", "nid", "]", "=", "n", "\n", "}", "\n", "return", "n", "\n", "}" ]
// Restore a network from the store to the driver if it is present. // Must be called with the driver locked!
[ "Restore", "a", "network", "from", "the", "store", "to", "the", "driver", "if", "it", "is", "present", ".", "Must", "be", "called", "with", "the", "driver", "locked!" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L863-L871
22,484
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
createNetwork
func (d *driver) createNetwork(config *configuration) error { networkList := d.getNetworks() for _, nw := range networkList { if config.Parent == nw.config.Parent { return fmt.Errorf("network %s is already using parent interface %s", getDummyName(stringid.TruncateID(nw.config.ID)), config.Parent) } } if !parentExists(config.Parent) { // if the --internal flag is set, create a dummy link if config.Internal { err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID))) if err != nil { return err } config.CreatedSlaveLink = true // notify the user in logs they have limited communications if config.Parent == getDummyName(stringid.TruncateID(config.ID)) { logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s", config.Parent) } } else { // if the subinterface parent_iface.vlan_id checks do not pass, return err. // a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10' err := createVlanLink(config.Parent) if err != nil { return err } // if driver created the networks slave link, record it for future deletion config.CreatedSlaveLink = true } } n := &network{ id: config.ID, driver: d, endpoints: endpointTable{}, config: config, } // add the *network d.addNetwork(n) return nil }
go
func (d *driver) createNetwork(config *configuration) error { networkList := d.getNetworks() for _, nw := range networkList { if config.Parent == nw.config.Parent { return fmt.Errorf("network %s is already using parent interface %s", getDummyName(stringid.TruncateID(nw.config.ID)), config.Parent) } } if !parentExists(config.Parent) { // if the --internal flag is set, create a dummy link if config.Internal { err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID))) if err != nil { return err } config.CreatedSlaveLink = true // notify the user in logs they have limited communications if config.Parent == getDummyName(stringid.TruncateID(config.ID)) { logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s", config.Parent) } } else { // if the subinterface parent_iface.vlan_id checks do not pass, return err. // a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10' err := createVlanLink(config.Parent) if err != nil { return err } // if driver created the networks slave link, record it for future deletion config.CreatedSlaveLink = true } } n := &network{ id: config.ID, driver: d, endpoints: endpointTable{}, config: config, } // add the *network d.addNetwork(n) return nil }
[ "func", "(", "d", "*", "driver", ")", "createNetwork", "(", "config", "*", "configuration", ")", "error", "{", "networkList", ":=", "d", ".", "getNetworks", "(", ")", "\n", "for", "_", ",", "nw", ":=", "range", "networkList", "{", "if", "config", ".", "Parent", "==", "nw", ".", "config", ".", "Parent", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "getDummyName", "(", "stringid", ".", "TruncateID", "(", "nw", ".", "config", ".", "ID", ")", ")", ",", "config", ".", "Parent", ")", "\n", "}", "\n", "}", "\n", "if", "!", "parentExists", "(", "config", ".", "Parent", ")", "{", "// if the --internal flag is set, create a dummy link", "if", "config", ".", "Internal", "{", "err", ":=", "createDummyLink", "(", "config", ".", "Parent", ",", "getDummyName", "(", "stringid", ".", "TruncateID", "(", "config", ".", "ID", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "config", ".", "CreatedSlaveLink", "=", "true", "\n", "// notify the user in logs they have limited communications", "if", "config", ".", "Parent", "==", "getDummyName", "(", "stringid", ".", "TruncateID", "(", "config", ".", "ID", ")", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "config", ".", "Parent", ")", "\n", "}", "\n", "}", "else", "{", "// if the subinterface parent_iface.vlan_id checks do not pass, return err.", "// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'", "err", ":=", "createVlanLink", "(", "config", ".", "Parent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// if driver created the networks slave link, record it for future deletion", "config", ".", "CreatedSlaveLink", "=", "true", "\n", "}", "\n", "}", "\n", "n", ":=", "&", "network", "{", "id", ":", "config", ".", "ID", ",", "driver", ":", "d", ",", "endpoints", ":", "endpointTable", "{", "}", ",", "config", ":", "config", ",", "}", "\n", "// add the *network", "d", ".", "addNetwork", "(", "n", ")", "\n\n", "return", "nil", "\n", "}" ]
// createNetwork is used by new network callbacks and persistent network cache
[ "createNetwork", "is", "used", "by", "new", "network", "callbacks", "and", "persistent", "network", "cache" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L79-L121
22,485
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
DeleteNetwork
func (d *driver) DeleteNetwork(nid string) error { defer osl.InitOSContext()() n := d.network(nid) if n == nil { return fmt.Errorf("network id %s not found", nid) } // if the driver created the slave interface, delete it, otherwise leave it if ok := n.config.CreatedSlaveLink; ok { // if the interface exists, only delete if it matches iface.vlan or dummy.net_id naming if ok := parentExists(n.config.Parent); ok { // only delete the link if it is named the net_id if n.config.Parent == getDummyName(stringid.TruncateID(nid)) { err := delDummyLink(n.config.Parent) if err != nil { logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v", n.config.Parent, err) } } else { // only delete the link if it matches iface.vlan naming err := delVlanLink(n.config.Parent) if err != nil { logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v", n.config.Parent, err) } } } } for _, ep := range n.endpoints { if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil { if err := ns.NlHandle().LinkDel(link); err != nil { logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id) } } if err := d.storeDelete(ep); err != nil { logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err) } } // delete the *network d.deleteNetwork(nid) // delete the network record from persistent cache err := d.storeDelete(n.config) if err != nil { return fmt.Errorf("error deleting deleting id %s from datastore: %v", nid, err) } return nil }
go
func (d *driver) DeleteNetwork(nid string) error { defer osl.InitOSContext()() n := d.network(nid) if n == nil { return fmt.Errorf("network id %s not found", nid) } // if the driver created the slave interface, delete it, otherwise leave it if ok := n.config.CreatedSlaveLink; ok { // if the interface exists, only delete if it matches iface.vlan or dummy.net_id naming if ok := parentExists(n.config.Parent); ok { // only delete the link if it is named the net_id if n.config.Parent == getDummyName(stringid.TruncateID(nid)) { err := delDummyLink(n.config.Parent) if err != nil { logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v", n.config.Parent, err) } } else { // only delete the link if it matches iface.vlan naming err := delVlanLink(n.config.Parent) if err != nil { logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v", n.config.Parent, err) } } } } for _, ep := range n.endpoints { if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil { if err := ns.NlHandle().LinkDel(link); err != nil { logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id) } } if err := d.storeDelete(ep); err != nil { logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err) } } // delete the *network d.deleteNetwork(nid) // delete the network record from persistent cache err := d.storeDelete(n.config) if err != nil { return fmt.Errorf("error deleting deleting id %s from datastore: %v", nid, err) } return nil }
[ "func", "(", "d", "*", "driver", ")", "DeleteNetwork", "(", "nid", "string", ")", "error", "{", "defer", "osl", ".", "InitOSContext", "(", ")", "(", ")", "\n", "n", ":=", "d", ".", "network", "(", "nid", ")", "\n", "if", "n", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ")", "\n", "}", "\n", "// if the driver created the slave interface, delete it, otherwise leave it", "if", "ok", ":=", "n", ".", "config", ".", "CreatedSlaveLink", ";", "ok", "{", "// if the interface exists, only delete if it matches iface.vlan or dummy.net_id naming", "if", "ok", ":=", "parentExists", "(", "n", ".", "config", ".", "Parent", ")", ";", "ok", "{", "// only delete the link if it is named the net_id", "if", "n", ".", "config", ".", "Parent", "==", "getDummyName", "(", "stringid", ".", "TruncateID", "(", "nid", ")", ")", "{", "err", ":=", "delDummyLink", "(", "n", ".", "config", ".", "Parent", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "n", ".", "config", ".", "Parent", ",", "err", ")", "\n", "}", "\n", "}", "else", "{", "// only delete the link if it matches iface.vlan naming", "err", ":=", "delVlanLink", "(", "n", ".", "config", ".", "Parent", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "n", ".", "config", ".", "Parent", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "_", ",", "ep", ":=", "range", "n", ".", "endpoints", "{", "if", "link", ",", "err", ":=", "ns", ".", "NlHandle", "(", ")", ".", "LinkByName", "(", "ep", ".", "srcName", ")", ";", "err", "==", "nil", "{", "if", "err", ":=", "ns", ".", "NlHandle", "(", ")", ".", "LinkDel", "(", "link", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Warnf", "(", "\"", "\"", ",", "ep", ".", "srcName", ",", "ep", ".", "id", ")", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "d", ".", "storeDelete", "(", "ep", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "ep", ".", "id", ",", "err", ")", "\n", "}", "\n", "}", "\n", "// delete the *network", "d", ".", "deleteNetwork", "(", "nid", ")", "\n", "// delete the network record from persistent cache", "err", ":=", "d", ".", "storeDelete", "(", "n", ".", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteNetwork the network for the specified driver type
[ "DeleteNetwork", "the", "network", "for", "the", "specified", "driver", "type" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L124-L170
22,486
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
parseNetworkOptions
func parseNetworkOptions(id string, option options.Generic) (*configuration, error) { var ( err error config = &configuration{} ) // parse generic labels first if genData, ok := option[netlabel.GenericData]; ok && genData != nil { if config, err = parseNetworkGenericOptions(genData); err != nil { return nil, err } } // setting the parent to "" will trigger an isolated network dummy parent link if _, ok := option[netlabel.Internal]; ok { config.Internal = true // empty --parent= and --internal are handled the same. config.Parent = "" } return config, nil }
go
func parseNetworkOptions(id string, option options.Generic) (*configuration, error) { var ( err error config = &configuration{} ) // parse generic labels first if genData, ok := option[netlabel.GenericData]; ok && genData != nil { if config, err = parseNetworkGenericOptions(genData); err != nil { return nil, err } } // setting the parent to "" will trigger an isolated network dummy parent link if _, ok := option[netlabel.Internal]; ok { config.Internal = true // empty --parent= and --internal are handled the same. config.Parent = "" } return config, nil }
[ "func", "parseNetworkOptions", "(", "id", "string", ",", "option", "options", ".", "Generic", ")", "(", "*", "configuration", ",", "error", ")", "{", "var", "(", "err", "error", "\n", "config", "=", "&", "configuration", "{", "}", "\n", ")", "\n", "// parse generic labels first", "if", "genData", ",", "ok", ":=", "option", "[", "netlabel", ".", "GenericData", "]", ";", "ok", "&&", "genData", "!=", "nil", "{", "if", "config", ",", "err", "=", "parseNetworkGenericOptions", "(", "genData", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "// setting the parent to \"\" will trigger an isolated network dummy parent link", "if", "_", ",", "ok", ":=", "option", "[", "netlabel", ".", "Internal", "]", ";", "ok", "{", "config", ".", "Internal", "=", "true", "\n", "// empty --parent= and --internal are handled the same.", "config", ".", "Parent", "=", "\"", "\"", "\n", "}", "\n", "return", "config", ",", "nil", "\n", "}" ]
// parseNetworkOptions parse docker network options
[ "parseNetworkOptions", "parse", "docker", "network", "options" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L173-L191
22,487
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
parseNetworkGenericOptions
func parseNetworkGenericOptions(data interface{}) (*configuration, error) { var ( err error config *configuration ) switch opt := data.(type) { case *configuration: config = opt case map[string]string: config = &configuration{} err = config.fromOptions(opt) case options.Generic: var opaqueConfig interface{} if opaqueConfig, err = options.GenerateFromModel(opt, config); err == nil { config = opaqueConfig.(*configuration) } default: err = types.BadRequestErrorf("unrecognized network configuration format: %v", opt) } return config, err }
go
func parseNetworkGenericOptions(data interface{}) (*configuration, error) { var ( err error config *configuration ) switch opt := data.(type) { case *configuration: config = opt case map[string]string: config = &configuration{} err = config.fromOptions(opt) case options.Generic: var opaqueConfig interface{} if opaqueConfig, err = options.GenerateFromModel(opt, config); err == nil { config = opaqueConfig.(*configuration) } default: err = types.BadRequestErrorf("unrecognized network configuration format: %v", opt) } return config, err }
[ "func", "parseNetworkGenericOptions", "(", "data", "interface", "{", "}", ")", "(", "*", "configuration", ",", "error", ")", "{", "var", "(", "err", "error", "\n", "config", "*", "configuration", "\n", ")", "\n", "switch", "opt", ":=", "data", ".", "(", "type", ")", "{", "case", "*", "configuration", ":", "config", "=", "opt", "\n", "case", "map", "[", "string", "]", "string", ":", "config", "=", "&", "configuration", "{", "}", "\n", "err", "=", "config", ".", "fromOptions", "(", "opt", ")", "\n", "case", "options", ".", "Generic", ":", "var", "opaqueConfig", "interface", "{", "}", "\n", "if", "opaqueConfig", ",", "err", "=", "options", ".", "GenerateFromModel", "(", "opt", ",", "config", ")", ";", "err", "==", "nil", "{", "config", "=", "opaqueConfig", ".", "(", "*", "configuration", ")", "\n", "}", "\n", "default", ":", "err", "=", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "opt", ")", "\n", "}", "\n", "return", "config", ",", "err", "\n", "}" ]
// parseNetworkGenericOptions parse generic driver docker network options
[ "parseNetworkGenericOptions", "parse", "generic", "driver", "docker", "network", "options" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L194-L214
22,488
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
fromOptions
func (config *configuration) fromOptions(labels map[string]string) error { for label, value := range labels { switch label { case parentOpt: // parse driver option '-o parent' config.Parent = value case driverModeOpt: // parse driver option '-o ipvlan_mode' config.IpvlanMode = value } } return nil }
go
func (config *configuration) fromOptions(labels map[string]string) error { for label, value := range labels { switch label { case parentOpt: // parse driver option '-o parent' config.Parent = value case driverModeOpt: // parse driver option '-o ipvlan_mode' config.IpvlanMode = value } } return nil }
[ "func", "(", "config", "*", "configuration", ")", "fromOptions", "(", "labels", "map", "[", "string", "]", "string", ")", "error", "{", "for", "label", ",", "value", ":=", "range", "labels", "{", "switch", "label", "{", "case", "parentOpt", ":", "// parse driver option '-o parent'", "config", ".", "Parent", "=", "value", "\n", "case", "driverModeOpt", ":", "// parse driver option '-o ipvlan_mode'", "config", ".", "IpvlanMode", "=", "value", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// fromOptions binds the generic options to networkConfiguration to cache
[ "fromOptions", "binds", "the", "generic", "options", "to", "networkConfiguration", "to", "cache" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L217-L229
22,489
docker/libnetwork
drivers/ipvlan/ipvlan_network.go
processIPAM
func (config *configuration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error { if len(ipamV4Data) > 0 { for _, ipd := range ipamV4Data { s := &ipv4Subnet{ SubnetIP: ipd.Pool.String(), GwIP: ipd.Gateway.String(), } config.Ipv4Subnets = append(config.Ipv4Subnets, s) } } if len(ipamV6Data) > 0 { for _, ipd := range ipamV6Data { s := &ipv6Subnet{ SubnetIP: ipd.Pool.String(), GwIP: ipd.Gateway.String(), } config.Ipv6Subnets = append(config.Ipv6Subnets, s) } } return nil }
go
func (config *configuration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error { if len(ipamV4Data) > 0 { for _, ipd := range ipamV4Data { s := &ipv4Subnet{ SubnetIP: ipd.Pool.String(), GwIP: ipd.Gateway.String(), } config.Ipv4Subnets = append(config.Ipv4Subnets, s) } } if len(ipamV6Data) > 0 { for _, ipd := range ipamV6Data { s := &ipv6Subnet{ SubnetIP: ipd.Pool.String(), GwIP: ipd.Gateway.String(), } config.Ipv6Subnets = append(config.Ipv6Subnets, s) } } return nil }
[ "func", "(", "config", "*", "configuration", ")", "processIPAM", "(", "id", "string", ",", "ipamV4Data", ",", "ipamV6Data", "[", "]", "driverapi", ".", "IPAMData", ")", "error", "{", "if", "len", "(", "ipamV4Data", ")", ">", "0", "{", "for", "_", ",", "ipd", ":=", "range", "ipamV4Data", "{", "s", ":=", "&", "ipv4Subnet", "{", "SubnetIP", ":", "ipd", ".", "Pool", ".", "String", "(", ")", ",", "GwIP", ":", "ipd", ".", "Gateway", ".", "String", "(", ")", ",", "}", "\n", "config", ".", "Ipv4Subnets", "=", "append", "(", "config", ".", "Ipv4Subnets", ",", "s", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "ipamV6Data", ")", ">", "0", "{", "for", "_", ",", "ipd", ":=", "range", "ipamV6Data", "{", "s", ":=", "&", "ipv6Subnet", "{", "SubnetIP", ":", "ipd", ".", "Pool", ".", "String", "(", ")", ",", "GwIP", ":", "ipd", ".", "Gateway", ".", "String", "(", ")", ",", "}", "\n", "config", ".", "Ipv6Subnets", "=", "append", "(", "config", ".", "Ipv6Subnets", ",", "s", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processIPAM parses v4 and v6 IP information and binds it to the network configuration
[ "processIPAM", "parses", "v4", "and", "v6", "IP", "information", "and", "binds", "it", "to", "the", "network", "configuration" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L232-L252
22,490
docker/libnetwork
hostdiscovery/hostdiscovery.go
NewHostDiscovery
func NewHostDiscovery(watcher discovery.Watcher) HostDiscovery { return &hostDiscovery{watcher: watcher, nodes: mapset.NewSet(), stopChan: make(chan struct{})} }
go
func NewHostDiscovery(watcher discovery.Watcher) HostDiscovery { return &hostDiscovery{watcher: watcher, nodes: mapset.NewSet(), stopChan: make(chan struct{})} }
[ "func", "NewHostDiscovery", "(", "watcher", "discovery", ".", "Watcher", ")", "HostDiscovery", "{", "return", "&", "hostDiscovery", "{", "watcher", ":", "watcher", ",", "nodes", ":", "mapset", ".", "NewSet", "(", ")", ",", "stopChan", ":", "make", "(", "chan", "struct", "{", "}", ")", "}", "\n", "}" ]
// NewHostDiscovery function creates a host discovery object
[ "NewHostDiscovery", "function", "creates", "a", "host", "discovery", "object" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/hostdiscovery/hostdiscovery.go#L33-L35
22,491
docker/libnetwork
driverapi/ipamdata.go
MarshalJSON
func (i *IPAMData) MarshalJSON() ([]byte, error) { m := map[string]interface{}{} m["AddressSpace"] = i.AddressSpace if i.Pool != nil { m["Pool"] = i.Pool.String() } if i.Gateway != nil { m["Gateway"] = i.Gateway.String() } if i.AuxAddresses != nil { am := make(map[string]string, len(i.AuxAddresses)) for k, v := range i.AuxAddresses { am[k] = v.String() } m["AuxAddresses"] = am } return json.Marshal(m) }
go
func (i *IPAMData) MarshalJSON() ([]byte, error) { m := map[string]interface{}{} m["AddressSpace"] = i.AddressSpace if i.Pool != nil { m["Pool"] = i.Pool.String() } if i.Gateway != nil { m["Gateway"] = i.Gateway.String() } if i.AuxAddresses != nil { am := make(map[string]string, len(i.AuxAddresses)) for k, v := range i.AuxAddresses { am[k] = v.String() } m["AuxAddresses"] = am } return json.Marshal(m) }
[ "func", "(", "i", "*", "IPAMData", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "m", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "m", "[", "\"", "\"", "]", "=", "i", ".", "AddressSpace", "\n", "if", "i", ".", "Pool", "!=", "nil", "{", "m", "[", "\"", "\"", "]", "=", "i", ".", "Pool", ".", "String", "(", ")", "\n", "}", "\n", "if", "i", ".", "Gateway", "!=", "nil", "{", "m", "[", "\"", "\"", "]", "=", "i", ".", "Gateway", ".", "String", "(", ")", "\n", "}", "\n", "if", "i", ".", "AuxAddresses", "!=", "nil", "{", "am", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "i", ".", "AuxAddresses", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "i", ".", "AuxAddresses", "{", "am", "[", "k", "]", "=", "v", ".", "String", "(", ")", "\n", "}", "\n", "m", "[", "\"", "\"", "]", "=", "am", "\n", "}", "\n", "return", "json", ".", "Marshal", "(", "m", ")", "\n", "}" ]
// MarshalJSON encodes IPAMData into json message
[ "MarshalJSON", "encodes", "IPAMData", "into", "json", "message" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L12-L29
22,492
docker/libnetwork
driverapi/ipamdata.go
UnmarshalJSON
func (i *IPAMData) UnmarshalJSON(data []byte) error { var ( m map[string]interface{} err error ) if err := json.Unmarshal(data, &m); err != nil { return err } i.AddressSpace = m["AddressSpace"].(string) if v, ok := m["Pool"]; ok { if i.Pool, err = types.ParseCIDR(v.(string)); err != nil { return err } } if v, ok := m["Gateway"]; ok { if i.Gateway, err = types.ParseCIDR(v.(string)); err != nil { return err } } if v, ok := m["AuxAddresses"]; ok { b, _ := json.Marshal(v) var am map[string]string if err = json.Unmarshal(b, &am); err != nil { return err } i.AuxAddresses = make(map[string]*net.IPNet, len(am)) for k, v := range am { if i.AuxAddresses[k], err = types.ParseCIDR(v); err != nil { return err } } } return nil }
go
func (i *IPAMData) UnmarshalJSON(data []byte) error { var ( m map[string]interface{} err error ) if err := json.Unmarshal(data, &m); err != nil { return err } i.AddressSpace = m["AddressSpace"].(string) if v, ok := m["Pool"]; ok { if i.Pool, err = types.ParseCIDR(v.(string)); err != nil { return err } } if v, ok := m["Gateway"]; ok { if i.Gateway, err = types.ParseCIDR(v.(string)); err != nil { return err } } if v, ok := m["AuxAddresses"]; ok { b, _ := json.Marshal(v) var am map[string]string if err = json.Unmarshal(b, &am); err != nil { return err } i.AuxAddresses = make(map[string]*net.IPNet, len(am)) for k, v := range am { if i.AuxAddresses[k], err = types.ParseCIDR(v); err != nil { return err } } } return nil }
[ "func", "(", "i", "*", "IPAMData", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "var", "(", "m", "map", "[", "string", "]", "interface", "{", "}", "\n", "err", "error", "\n", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "i", ".", "AddressSpace", "=", "m", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "v", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "if", "i", ".", "Pool", ",", "err", "=", "types", ".", "ParseCIDR", "(", "v", ".", "(", "string", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "if", "i", ".", "Gateway", ",", "err", "=", "types", ".", "ParseCIDR", "(", "v", ".", "(", "string", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "b", ",", "_", ":=", "json", ".", "Marshal", "(", "v", ")", "\n", "var", "am", "map", "[", "string", "]", "string", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "&", "am", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "i", ".", "AuxAddresses", "=", "make", "(", "map", "[", "string", "]", "*", "net", ".", "IPNet", ",", "len", "(", "am", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "am", "{", "if", "i", ".", "AuxAddresses", "[", "k", "]", ",", "err", "=", "types", ".", "ParseCIDR", "(", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON decodes a json message into IPAMData
[ "UnmarshalJSON", "decodes", "a", "json", "message", "into", "IPAMData" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L32-L65
22,493
docker/libnetwork
driverapi/ipamdata.go
Validate
func (i *IPAMData) Validate() error { var isV6 bool if i.Pool == nil { return types.BadRequestErrorf("invalid pool") } if i.Gateway == nil { return types.BadRequestErrorf("invalid gateway address") } isV6 = i.IsV6() if isV6 && i.Gateway.IP.To4() != nil || !isV6 && i.Gateway.IP.To4() == nil { return types.BadRequestErrorf("incongruent ip versions for pool and gateway") } for k, sip := range i.AuxAddresses { if isV6 && sip.IP.To4() != nil || !isV6 && sip.IP.To4() == nil { return types.BadRequestErrorf("incongruent ip versions for pool and secondary ip address %s", k) } } if !i.Pool.Contains(i.Gateway.IP) { return types.BadRequestErrorf("invalid gateway address (%s) does not belong to the pool (%s)", i.Gateway, i.Pool) } for k, sip := range i.AuxAddresses { if !i.Pool.Contains(sip.IP) { return types.BadRequestErrorf("invalid secondary address %s (%s) does not belong to the pool (%s)", k, i.Gateway, i.Pool) } } return nil }
go
func (i *IPAMData) Validate() error { var isV6 bool if i.Pool == nil { return types.BadRequestErrorf("invalid pool") } if i.Gateway == nil { return types.BadRequestErrorf("invalid gateway address") } isV6 = i.IsV6() if isV6 && i.Gateway.IP.To4() != nil || !isV6 && i.Gateway.IP.To4() == nil { return types.BadRequestErrorf("incongruent ip versions for pool and gateway") } for k, sip := range i.AuxAddresses { if isV6 && sip.IP.To4() != nil || !isV6 && sip.IP.To4() == nil { return types.BadRequestErrorf("incongruent ip versions for pool and secondary ip address %s", k) } } if !i.Pool.Contains(i.Gateway.IP) { return types.BadRequestErrorf("invalid gateway address (%s) does not belong to the pool (%s)", i.Gateway, i.Pool) } for k, sip := range i.AuxAddresses { if !i.Pool.Contains(sip.IP) { return types.BadRequestErrorf("invalid secondary address %s (%s) does not belong to the pool (%s)", k, i.Gateway, i.Pool) } } return nil }
[ "func", "(", "i", "*", "IPAMData", ")", "Validate", "(", ")", "error", "{", "var", "isV6", "bool", "\n", "if", "i", ".", "Pool", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "i", ".", "Gateway", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n", "isV6", "=", "i", ".", "IsV6", "(", ")", "\n", "if", "isV6", "&&", "i", ".", "Gateway", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "||", "!", "isV6", "&&", "i", ".", "Gateway", ".", "IP", ".", "To4", "(", ")", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "k", ",", "sip", ":=", "range", "i", ".", "AuxAddresses", "{", "if", "isV6", "&&", "sip", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "||", "!", "isV6", "&&", "sip", ".", "IP", ".", "To4", "(", ")", "==", "nil", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "k", ")", "\n", "}", "\n", "}", "\n", "if", "!", "i", ".", "Pool", ".", "Contains", "(", "i", ".", "Gateway", ".", "IP", ")", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "i", ".", "Gateway", ",", "i", ".", "Pool", ")", "\n", "}", "\n", "for", "k", ",", "sip", ":=", "range", "i", ".", "AuxAddresses", "{", "if", "!", "i", ".", "Pool", ".", "Contains", "(", "sip", ".", "IP", ")", "{", "return", "types", ".", "BadRequestErrorf", "(", "\"", "\"", ",", "k", ",", "i", ".", "Gateway", ",", "i", ".", "Pool", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate checks whether the IPAMData structure contains congruent data
[ "Validate", "checks", "whether", "the", "IPAMData", "structure", "contains", "congruent", "data" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L68-L94
22,494
docker/libnetwork
default_gateway.go
clearDefaultGW
func (sb *sandbox) clearDefaultGW() error { var ep *endpoint if ep = sb.getEndpointInGWNetwork(); ep == nil { return nil } if err := ep.sbLeave(sb, false); err != nil { return fmt.Errorf("container %s: endpoint leaving GW Network failed: %v", sb.containerID, err) } if err := ep.Delete(false); err != nil { return fmt.Errorf("container %s: deleting endpoint on GW Network failed: %v", sb.containerID, err) } return nil }
go
func (sb *sandbox) clearDefaultGW() error { var ep *endpoint if ep = sb.getEndpointInGWNetwork(); ep == nil { return nil } if err := ep.sbLeave(sb, false); err != nil { return fmt.Errorf("container %s: endpoint leaving GW Network failed: %v", sb.containerID, err) } if err := ep.Delete(false); err != nil { return fmt.Errorf("container %s: deleting endpoint on GW Network failed: %v", sb.containerID, err) } return nil }
[ "func", "(", "sb", "*", "sandbox", ")", "clearDefaultGW", "(", ")", "error", "{", "var", "ep", "*", "endpoint", "\n\n", "if", "ep", "=", "sb", ".", "getEndpointInGWNetwork", "(", ")", ";", "ep", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "ep", ".", "sbLeave", "(", "sb", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "containerID", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ep", ".", "Delete", "(", "false", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "containerID", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// If present, detach and remove the endpoint connecting the sandbox to the default gw network.
[ "If", "present", "detach", "and", "remove", "the", "endpoint", "connecting", "the", "sandbox", "to", "the", "default", "gw", "network", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/default_gateway.go#L98-L111
22,495
docker/libnetwork
default_gateway.go
needDefaultGW
func (sb *sandbox) needDefaultGW() bool { var needGW bool for _, ep := range sb.getConnectedEndpoints() { if ep.endpointInGWNetwork() { continue } if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { continue } if ep.getNetwork().Internal() { continue } // During stale sandbox cleanup, joinInfo may be nil if ep.joinInfo != nil && ep.joinInfo.disableGatewayService { continue } // TODO v6 needs to be handled. if len(ep.Gateway()) > 0 { return false } for _, r := range ep.StaticRoutes() { if r.Destination != nil && r.Destination.String() == "0.0.0.0/0" { return false } } needGW = true } return needGW }
go
func (sb *sandbox) needDefaultGW() bool { var needGW bool for _, ep := range sb.getConnectedEndpoints() { if ep.endpointInGWNetwork() { continue } if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { continue } if ep.getNetwork().Internal() { continue } // During stale sandbox cleanup, joinInfo may be nil if ep.joinInfo != nil && ep.joinInfo.disableGatewayService { continue } // TODO v6 needs to be handled. if len(ep.Gateway()) > 0 { return false } for _, r := range ep.StaticRoutes() { if r.Destination != nil && r.Destination.String() == "0.0.0.0/0" { return false } } needGW = true } return needGW }
[ "func", "(", "sb", "*", "sandbox", ")", "needDefaultGW", "(", ")", "bool", "{", "var", "needGW", "bool", "\n\n", "for", "_", ",", "ep", ":=", "range", "sb", ".", "getConnectedEndpoints", "(", ")", "{", "if", "ep", ".", "endpointInGWNetwork", "(", ")", "{", "continue", "\n", "}", "\n", "if", "ep", ".", "getNetwork", "(", ")", ".", "Type", "(", ")", "==", "\"", "\"", "||", "ep", ".", "getNetwork", "(", ")", ".", "Type", "(", ")", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "ep", ".", "getNetwork", "(", ")", ".", "Internal", "(", ")", "{", "continue", "\n", "}", "\n", "// During stale sandbox cleanup, joinInfo may be nil", "if", "ep", ".", "joinInfo", "!=", "nil", "&&", "ep", ".", "joinInfo", ".", "disableGatewayService", "{", "continue", "\n", "}", "\n", "// TODO v6 needs to be handled.", "if", "len", "(", "ep", ".", "Gateway", "(", ")", ")", ">", "0", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "ep", ".", "StaticRoutes", "(", ")", "{", "if", "r", ".", "Destination", "!=", "nil", "&&", "r", ".", "Destination", ".", "String", "(", ")", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "}", "\n", "needGW", "=", "true", "\n", "}", "\n\n", "return", "needGW", "\n", "}" ]
// Evaluate whether the sandbox requires a default gateway based // on the endpoints to which it is connected. It does not account // for the default gateway network endpoint.
[ "Evaluate", "whether", "the", "sandbox", "requires", "a", "default", "gateway", "based", "on", "the", "endpoints", "to", "which", "it", "is", "connected", ".", "It", "does", "not", "account", "for", "the", "default", "gateway", "network", "endpoint", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/default_gateway.go#L117-L147
22,496
docker/libnetwork
default_gateway.go
defaultGwNetwork
func (c *controller) defaultGwNetwork() (Network, error) { procGwNetwork <- true defer func() { <-procGwNetwork }() n, err := c.NetworkByName(libnGWNetwork) if _, ok := err.(types.NotFoundError); ok { n, err = c.createGWNetwork() } return n, err }
go
func (c *controller) defaultGwNetwork() (Network, error) { procGwNetwork <- true defer func() { <-procGwNetwork }() n, err := c.NetworkByName(libnGWNetwork) if _, ok := err.(types.NotFoundError); ok { n, err = c.createGWNetwork() } return n, err }
[ "func", "(", "c", "*", "controller", ")", "defaultGwNetwork", "(", ")", "(", "Network", ",", "error", ")", "{", "procGwNetwork", "<-", "true", "\n", "defer", "func", "(", ")", "{", "<-", "procGwNetwork", "}", "(", ")", "\n\n", "n", ",", "err", ":=", "c", ".", "NetworkByName", "(", "libnGWNetwork", ")", "\n", "if", "_", ",", "ok", ":=", "err", ".", "(", "types", ".", "NotFoundError", ")", ";", "ok", "{", "n", ",", "err", "=", "c", ".", "createGWNetwork", "(", ")", "\n", "}", "\n", "return", "n", ",", "err", "\n", "}" ]
// Looks for the default gw network and creates it if not there. // Parallel executions are serialized.
[ "Looks", "for", "the", "default", "gw", "network", "and", "creates", "it", "if", "not", "there", ".", "Parallel", "executions", "are", "serialized", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/default_gateway.go#L179-L188
22,497
docker/libnetwork
default_gateway.go
getGatewayEndpoint
func (sb *sandbox) getGatewayEndpoint() *endpoint { for _, ep := range sb.getConnectedEndpoints() { if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { continue } if len(ep.Gateway()) != 0 { return ep } } return nil }
go
func (sb *sandbox) getGatewayEndpoint() *endpoint { for _, ep := range sb.getConnectedEndpoints() { if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { continue } if len(ep.Gateway()) != 0 { return ep } } return nil }
[ "func", "(", "sb", "*", "sandbox", ")", "getGatewayEndpoint", "(", ")", "*", "endpoint", "{", "for", "_", ",", "ep", ":=", "range", "sb", ".", "getConnectedEndpoints", "(", ")", "{", "if", "ep", ".", "getNetwork", "(", ")", ".", "Type", "(", ")", "==", "\"", "\"", "||", "ep", ".", "getNetwork", "(", ")", ".", "Type", "(", ")", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "len", "(", "ep", ".", "Gateway", "(", ")", ")", "!=", "0", "{", "return", "ep", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Returns the endpoint which is providing external connectivity to the sandbox
[ "Returns", "the", "endpoint", "which", "is", "providing", "external", "connectivity", "to", "the", "sandbox" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/default_gateway.go#L191-L201
22,498
docker/libnetwork
netutils/utils.go
CheckNameserverOverlaps
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error { if len(nameservers) > 0 { for _, ns := range nameservers { _, nsNetwork, err := net.ParseCIDR(ns) if err != nil { return err } if NetworkOverlaps(toCheck, nsNetwork) { return ErrNetworkOverlapsWithNameservers } } } return nil }
go
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error { if len(nameservers) > 0 { for _, ns := range nameservers { _, nsNetwork, err := net.ParseCIDR(ns) if err != nil { return err } if NetworkOverlaps(toCheck, nsNetwork) { return ErrNetworkOverlapsWithNameservers } } } return nil }
[ "func", "CheckNameserverOverlaps", "(", "nameservers", "[", "]", "string", ",", "toCheck", "*", "net", ".", "IPNet", ")", "error", "{", "if", "len", "(", "nameservers", ")", ">", "0", "{", "for", "_", ",", "ns", ":=", "range", "nameservers", "{", "_", ",", "nsNetwork", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "ns", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "NetworkOverlaps", "(", "toCheck", ",", "nsNetwork", ")", "{", "return", "ErrNetworkOverlapsWithNameservers", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CheckNameserverOverlaps checks whether the passed network overlaps with any of the nameservers
[ "CheckNameserverOverlaps", "checks", "whether", "the", "passed", "network", "overlaps", "with", "any", "of", "the", "nameservers" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L27-L40
22,499
docker/libnetwork
netutils/utils.go
NetworkOverlaps
func NetworkOverlaps(netX *net.IPNet, netY *net.IPNet) bool { return netX.Contains(netY.IP) || netY.Contains(netX.IP) }
go
func NetworkOverlaps(netX *net.IPNet, netY *net.IPNet) bool { return netX.Contains(netY.IP) || netY.Contains(netX.IP) }
[ "func", "NetworkOverlaps", "(", "netX", "*", "net", ".", "IPNet", ",", "netY", "*", "net", ".", "IPNet", ")", "bool", "{", "return", "netX", ".", "Contains", "(", "netY", ".", "IP", ")", "||", "netY", ".", "Contains", "(", "netX", ".", "IP", ")", "\n", "}" ]
// NetworkOverlaps detects overlap between one IPNet and another
[ "NetworkOverlaps", "detects", "overlap", "between", "one", "IPNet", "and", "another" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L43-L45