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
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
docker/libnetwork
|
portmapper/mapper.go
|
ReMapAll
|
func (pm *PortMapper) ReMapAll() {
pm.lock.Lock()
defer pm.lock.Unlock()
logrus.Debugln("Re-applying all port mappings.")
for _, data := range pm.currentMappings {
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.AppendForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables add: %s", err)
}
}
}
|
go
|
func (pm *PortMapper) ReMapAll() {
pm.lock.Lock()
defer pm.lock.Unlock()
logrus.Debugln("Re-applying all port mappings.")
for _, data := range pm.currentMappings {
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.AppendForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables add: %s", err)
}
}
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"ReMapAll",
"(",
")",
"{",
"pm",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pm",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"logrus",
".",
"Debugln",
"(",
"\"Re-applying all port mappings.\"",
")",
"\n",
"for",
"_",
",",
"data",
":=",
"range",
"pm",
".",
"currentMappings",
"{",
"containerIP",
",",
"containerPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"container",
")",
"\n",
"hostIP",
",",
"hostPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"host",
")",
"\n",
"if",
"err",
":=",
"pm",
".",
"AppendForwardingTableEntry",
"(",
"data",
".",
"proto",
",",
"hostIP",
",",
"hostPort",
",",
"containerIP",
".",
"String",
"(",
")",
",",
"containerPort",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"Error on iptables add: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
//ReMapAll will re-apply all port mappings
|
[
"ReMapAll",
"will",
"re",
"-",
"apply",
"all",
"port",
"mappings"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L222-L233
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
Get
|
func (s *MockStore) Get(key string) (*store.KVPair, error) {
mData := s.db[key]
if mData == nil {
return nil, nil
}
return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
}
|
go
|
func (s *MockStore) Get(key string) (*store.KVPair, error) {
mData := s.db[key]
if mData == nil {
return nil, nil
}
return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"store",
".",
"KVPair",
"{",
"Value",
":",
"mData",
".",
"Data",
",",
"LastIndex",
":",
"mData",
".",
"Index",
"}",
",",
"nil",
"\n",
"}"
] |
// Get the value at "key", returns the last modified index
// to use in conjunction to CAS calls
|
[
"Get",
"the",
"value",
"at",
"key",
"returns",
"the",
"last",
"modified",
"index",
"to",
"use",
"in",
"conjunction",
"to",
"CAS",
"calls"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L34-L41
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
Put
|
func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
mData := s.db[key]
if mData == nil {
mData = &MockData{value, 0}
}
mData.Index = mData.Index + 1
s.db[key] = mData
return nil
}
|
go
|
func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
mData := s.db[key]
if mData == nil {
mData = &MockData{value, 0}
}
mData.Index = mData.Index + 1
s.db[key] = mData
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Put",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
",",
"options",
"*",
"store",
".",
"WriteOptions",
")",
"error",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"==",
"nil",
"{",
"mData",
"=",
"&",
"MockData",
"{",
"value",
",",
"0",
"}",
"\n",
"}",
"\n",
"mData",
".",
"Index",
"=",
"mData",
".",
"Index",
"+",
"1",
"\n",
"s",
".",
"db",
"[",
"key",
"]",
"=",
"mData",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Put a value at "key"
|
[
"Put",
"a",
"value",
"at",
"key"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L44-L52
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
Delete
|
func (s *MockStore) Delete(key string) error {
delete(s.db, key)
return nil
}
|
go
|
func (s *MockStore) Delete(key string) error {
delete(s.db, key)
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Delete",
"(",
"key",
"string",
")",
"error",
"{",
"delete",
"(",
"s",
".",
"db",
",",
"key",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Delete a value at "key"
|
[
"Delete",
"a",
"value",
"at",
"key"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L55-L58
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
Exists
|
func (s *MockStore) Exists(key string) (bool, error) {
_, ok := s.db[key]
return ok, nil
}
|
go
|
func (s *MockStore) Exists(key string) (bool, error) {
_, ok := s.db[key]
return ok, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Exists",
"(",
"key",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"ok",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"return",
"ok",
",",
"nil",
"\n",
"}"
] |
// Exists checks that the key exists inside the store
|
[
"Exists",
"checks",
"that",
"the",
"key",
"exists",
"inside",
"the",
"store"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L61-L64
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
List
|
func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"List",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// List gets a range of values at "directory"
|
[
"List",
"gets",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L67-L69
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
DeleteTree
|
func (s *MockStore) DeleteTree(prefix string) error {
delete(s.db, prefix)
return nil
}
|
go
|
func (s *MockStore) DeleteTree(prefix string) error {
delete(s.db, prefix)
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"DeleteTree",
"(",
"prefix",
"string",
")",
"error",
"{",
"delete",
"(",
"s",
".",
"db",
",",
"prefix",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteTree deletes a range of values at "directory"
|
[
"DeleteTree",
"deletes",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L72-L75
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
Watch
|
func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Watch",
"(",
"key",
"string",
",",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"(",
"<-",
"chan",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// Watch a single key for modifications
|
[
"Watch",
"a",
"single",
"key",
"for",
"modifications"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L78-L80
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
WatchTree
|
func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"WatchTree",
"(",
"prefix",
"string",
",",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"(",
"<-",
"chan",
"[",
"]",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// WatchTree triggers a watch on a range of values at "directory"
|
[
"WatchTree",
"triggers",
"a",
"watch",
"on",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L83-L85
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
AtomicPut
|
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
mData := s.db[key]
if previous == nil {
if mData != nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
} // Else OK.
} else {
if mData == nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
}
if mData != nil && mData.Index != previous.LastIndex {
return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
} // Else OK.
}
err := s.Put(key, newValue, nil)
if err != nil {
return false, nil, err
}
return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil
}
|
go
|
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
mData := s.db[key]
if previous == nil {
if mData != nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
} // Else OK.
} else {
if mData == nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
}
if mData != nil && mData.Index != previous.LastIndex {
return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
} // Else OK.
}
err := s.Put(key, newValue, nil)
if err != nil {
return false, nil, err
}
return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"AtomicPut",
"(",
"key",
"string",
",",
"newValue",
"[",
"]",
"byte",
",",
"previous",
"*",
"store",
".",
"KVPair",
",",
"options",
"*",
"store",
".",
"WriteOptions",
")",
"(",
"bool",
",",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"previous",
"==",
"nil",
"{",
"if",
"mData",
"!=",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"atomic put failed because key exists\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"mData",
"==",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"atomic put failed because key exists\"",
")",
"\n",
"}",
"\n",
"if",
"mData",
"!=",
"nil",
"&&",
"mData",
".",
"Index",
"!=",
"previous",
".",
"LastIndex",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"atomic put failed due to mismatched Index\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"s",
".",
"Put",
"(",
"key",
",",
"newValue",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"true",
",",
"&",
"store",
".",
"KVPair",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"newValue",
",",
"LastIndex",
":",
"s",
".",
"db",
"[",
"key",
"]",
".",
"Index",
"}",
",",
"nil",
"\n",
"}"
] |
// AtomicPut put a value at "key" if the key has not been
// modified in the meantime, throws an error if this is the case
|
[
"AtomicPut",
"put",
"a",
"value",
"at",
"key",
"if",
"the",
"key",
"has",
"not",
"been",
"modified",
"in",
"the",
"meantime",
"throws",
"an",
"error",
"if",
"this",
"is",
"the",
"case"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L94-L114
|
train
|
docker/libnetwork
|
datastore/mock_store.go
|
AtomicDelete
|
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
mData := s.db[key]
if mData != nil && mData.Index != previous.LastIndex {
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
}
return true, s.Delete(key)
}
|
go
|
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
mData := s.db[key]
if mData != nil && mData.Index != previous.LastIndex {
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
}
return true, s.Delete(key)
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"AtomicDelete",
"(",
"key",
"string",
",",
"previous",
"*",
"store",
".",
"KVPair",
")",
"(",
"bool",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"!=",
"nil",
"&&",
"mData",
".",
"Index",
"!=",
"previous",
".",
"LastIndex",
"{",
"return",
"false",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"atomic delete failed due to mismatched Index\"",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"s",
".",
"Delete",
"(",
"key",
")",
"\n",
"}"
] |
// AtomicDelete deletes a value at "key" if the key has not
// been modified in the meantime, throws an error if this is the case
|
[
"AtomicDelete",
"deletes",
"a",
"value",
"at",
"key",
"if",
"the",
"key",
"has",
"not",
"been",
"modified",
"in",
"the",
"meantime",
"throws",
"an",
"error",
"if",
"this",
"is",
"the",
"case"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L118-L124
|
train
|
docker/libnetwork
|
resolver.go
|
NewResolver
|
func NewResolver(address string, proxyDNS bool, resolverKey string, backend DNSBackend) Resolver {
return &resolver{
backend: backend,
proxyDNS: proxyDNS,
listenAddress: address,
resolverKey: resolverKey,
err: fmt.Errorf("setup not done yet"),
startCh: make(chan struct{}, 1),
}
}
|
go
|
func NewResolver(address string, proxyDNS bool, resolverKey string, backend DNSBackend) Resolver {
return &resolver{
backend: backend,
proxyDNS: proxyDNS,
listenAddress: address,
resolverKey: resolverKey,
err: fmt.Errorf("setup not done yet"),
startCh: make(chan struct{}, 1),
}
}
|
[
"func",
"NewResolver",
"(",
"address",
"string",
",",
"proxyDNS",
"bool",
",",
"resolverKey",
"string",
",",
"backend",
"DNSBackend",
")",
"Resolver",
"{",
"return",
"&",
"resolver",
"{",
"backend",
":",
"backend",
",",
"proxyDNS",
":",
"proxyDNS",
",",
"listenAddress",
":",
"address",
",",
"resolverKey",
":",
"resolverKey",
",",
"err",
":",
"fmt",
".",
"Errorf",
"(",
"\"setup not done yet\"",
")",
",",
"startCh",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
",",
"}",
"\n",
"}"
] |
// NewResolver creates a new instance of the Resolver
|
[
"NewResolver",
"creates",
"a",
"new",
"instance",
"of",
"the",
"Resolver"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolver.go#L102-L111
|
train
|
docker/libnetwork
|
ipam/utils.go
|
generateAddress
|
func generateAddress(ordinal uint64, network *net.IPNet) net.IP {
var address [16]byte
// Get network portion of IP
if getAddressVersion(network.IP) == v4 {
copy(address[:], network.IP.To4())
} else {
copy(address[:], network.IP)
}
end := len(network.Mask)
addIntToIP(address[:end], ordinal)
return net.IP(address[:end])
}
|
go
|
func generateAddress(ordinal uint64, network *net.IPNet) net.IP {
var address [16]byte
// Get network portion of IP
if getAddressVersion(network.IP) == v4 {
copy(address[:], network.IP.To4())
} else {
copy(address[:], network.IP)
}
end := len(network.Mask)
addIntToIP(address[:end], ordinal)
return net.IP(address[:end])
}
|
[
"func",
"generateAddress",
"(",
"ordinal",
"uint64",
",",
"network",
"*",
"net",
".",
"IPNet",
")",
"net",
".",
"IP",
"{",
"var",
"address",
"[",
"16",
"]",
"byte",
"\n",
"if",
"getAddressVersion",
"(",
"network",
".",
"IP",
")",
"==",
"v4",
"{",
"copy",
"(",
"address",
"[",
":",
"]",
",",
"network",
".",
"IP",
".",
"To4",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"copy",
"(",
"address",
"[",
":",
"]",
",",
"network",
".",
"IP",
")",
"\n",
"}",
"\n",
"end",
":=",
"len",
"(",
"network",
".",
"Mask",
")",
"\n",
"addIntToIP",
"(",
"address",
"[",
":",
"end",
"]",
",",
"ordinal",
")",
"\n",
"return",
"net",
".",
"IP",
"(",
"address",
"[",
":",
"end",
"]",
")",
"\n",
"}"
] |
// It generates the ip address in the passed subnet specified by
// the passed host address ordinal
|
[
"It",
"generates",
"the",
"ip",
"address",
"in",
"the",
"passed",
"subnet",
"specified",
"by",
"the",
"passed",
"host",
"address",
"ordinal"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L41-L55
|
train
|
docker/libnetwork
|
ipam/utils.go
|
addIntToIP
|
func addIntToIP(array []byte, ordinal uint64) {
for i := len(array) - 1; i >= 0; i-- {
array[i] |= (byte)(ordinal & 0xff)
ordinal >>= 8
}
}
|
go
|
func addIntToIP(array []byte, ordinal uint64) {
for i := len(array) - 1; i >= 0; i-- {
array[i] |= (byte)(ordinal & 0xff)
ordinal >>= 8
}
}
|
[
"func",
"addIntToIP",
"(",
"array",
"[",
"]",
"byte",
",",
"ordinal",
"uint64",
")",
"{",
"for",
"i",
":=",
"len",
"(",
"array",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"array",
"[",
"i",
"]",
"|=",
"(",
"byte",
")",
"(",
"ordinal",
"&",
"0xff",
")",
"\n",
"ordinal",
">>=",
"8",
"\n",
"}",
"\n",
"}"
] |
// Adds the ordinal IP to the current array
// 192.168.0.0 + 53 => 192.168.0.53
|
[
"Adds",
"the",
"ordinal",
"IP",
"to",
"the",
"current",
"array",
"192",
".",
"168",
".",
"0",
".",
"0",
"+",
"53",
"=",
">",
"192",
".",
"168",
".",
"0",
".",
"53"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L66-L71
|
train
|
docker/libnetwork
|
ipam/utils.go
|
ipToUint64
|
func ipToUint64(ip []byte) (value uint64) {
cip := types.GetMinimalIP(ip)
for i := 0; i < len(cip); i++ {
j := len(cip) - 1 - i
value += uint64(cip[i]) << uint(j*8)
}
return value
}
|
go
|
func ipToUint64(ip []byte) (value uint64) {
cip := types.GetMinimalIP(ip)
for i := 0; i < len(cip); i++ {
j := len(cip) - 1 - i
value += uint64(cip[i]) << uint(j*8)
}
return value
}
|
[
"func",
"ipToUint64",
"(",
"ip",
"[",
"]",
"byte",
")",
"(",
"value",
"uint64",
")",
"{",
"cip",
":=",
"types",
".",
"GetMinimalIP",
"(",
"ip",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"cip",
")",
";",
"i",
"++",
"{",
"j",
":=",
"len",
"(",
"cip",
")",
"-",
"1",
"-",
"i",
"\n",
"value",
"+=",
"uint64",
"(",
"cip",
"[",
"i",
"]",
")",
"<<",
"uint",
"(",
"j",
"*",
"8",
")",
"\n",
"}",
"\n",
"return",
"value",
"\n",
"}"
] |
// Convert an ordinal to the respective IP address
|
[
"Convert",
"an",
"ordinal",
"to",
"the",
"respective",
"IP",
"address"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L74-L81
|
train
|
docker/libnetwork
|
netlabel/labels.go
|
Key
|
func Key(label string) (key string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
}
return
}
|
go
|
func Key(label string) (key string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
}
return
}
|
[
"func",
"Key",
"(",
"label",
"string",
")",
"(",
"key",
"string",
")",
"{",
"if",
"kv",
":=",
"strings",
".",
"SplitN",
"(",
"label",
",",
"\"=\"",
",",
"2",
")",
";",
"len",
"(",
"kv",
")",
">",
"0",
"{",
"key",
"=",
"kv",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Key extracts the key portion of the label
|
[
"Key",
"extracts",
"the",
"key",
"portion",
"of",
"the",
"label"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netlabel/labels.go#L105-L110
|
train
|
docker/libnetwork
|
netlabel/labels.go
|
Value
|
func Value(label string) (value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
value = kv[1]
}
return
}
|
go
|
func Value(label string) (value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
value = kv[1]
}
return
}
|
[
"func",
"Value",
"(",
"label",
"string",
")",
"(",
"value",
"string",
")",
"{",
"if",
"kv",
":=",
"strings",
".",
"SplitN",
"(",
"label",
",",
"\"=\"",
",",
"2",
")",
";",
"len",
"(",
"kv",
")",
">",
"1",
"{",
"value",
"=",
"kv",
"[",
"1",
"]",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Value extracts the value portion of the label
|
[
"Value",
"extracts",
"the",
"value",
"portion",
"of",
"the",
"label"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netlabel/labels.go#L113-L118
|
train
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
GetInit
|
func GetInit(ipamName string) func(ic ipamapi.Callback, l, g interface{}) error {
return func(ic ipamapi.Callback, l, g interface{}) error {
return ic.RegisterIpamDriver(ipamName, &allocator{})
}
}
|
go
|
func GetInit(ipamName string) func(ic ipamapi.Callback, l, g interface{}) error {
return func(ic ipamapi.Callback, l, g interface{}) error {
return ic.RegisterIpamDriver(ipamName, &allocator{})
}
}
|
[
"func",
"GetInit",
"(",
"ipamName",
"string",
")",
"func",
"(",
"ic",
"ipamapi",
".",
"Callback",
",",
"l",
",",
"g",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"func",
"(",
"ic",
"ipamapi",
".",
"Callback",
",",
"l",
",",
"g",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ic",
".",
"RegisterIpamDriver",
"(",
"ipamName",
",",
"&",
"allocator",
"{",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// GetInit registers the built-in ipam service with libnetwork
|
[
"GetInit",
"registers",
"the",
"built",
"-",
"in",
"ipam",
"service",
"with",
"libnetwork"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L28-L32
|
train
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
RequestPool
|
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
if subPool != "" || v6 {
return "", nil, nil, types.InternalErrorf("This request is not supported by null ipam driver")
}
var ipNet *net.IPNet
var err error
if pool != "" {
_, ipNet, err = net.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
} else {
ipNet = defaultPool
}
return ipNet.String(), ipNet, nil, nil
}
|
go
|
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
if subPool != "" || v6 {
return "", nil, nil, types.InternalErrorf("This request is not supported by null ipam driver")
}
var ipNet *net.IPNet
var err error
if pool != "" {
_, ipNet, err = net.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
} else {
ipNet = defaultPool
}
return ipNet.String(), ipNet, nil, nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"RequestPool",
"(",
"addressSpace",
",",
"pool",
",",
"subPool",
"string",
",",
"options",
"map",
"[",
"string",
"]",
"string",
",",
"v6",
"bool",
")",
"(",
"string",
",",
"*",
"net",
".",
"IPNet",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"RequestPool(%s, %s, %s, %v, %t)\"",
",",
"addressSpace",
",",
"pool",
",",
"subPool",
",",
"options",
",",
"v6",
")",
"\n",
"if",
"subPool",
"!=",
"\"\"",
"||",
"v6",
"{",
"return",
"\"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"InternalErrorf",
"(",
"\"This request is not supported by null ipam driver\"",
")",
"\n",
"}",
"\n",
"var",
"ipNet",
"*",
"net",
".",
"IPNet",
"\n",
"var",
"err",
"error",
"\n",
"if",
"pool",
"!=",
"\"\"",
"{",
"_",
",",
"ipNet",
",",
"err",
"=",
"net",
".",
"ParseCIDR",
"(",
"pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"ipNet",
"=",
"defaultPool",
"\n",
"}",
"\n",
"return",
"ipNet",
".",
"String",
"(",
")",
",",
"ipNet",
",",
"nil",
",",
"nil",
"\n",
"}"
] |
// RequestPool returns an address pool along with its unique id. This is a null ipam driver. It allocates the
// subnet user asked and does not validate anything. Doesn't support subpool allocation
|
[
"RequestPool",
"returns",
"an",
"address",
"pool",
"along",
"with",
"its",
"unique",
"id",
".",
"This",
"is",
"a",
"null",
"ipam",
"driver",
".",
"It",
"allocates",
"the",
"subnet",
"user",
"asked",
"and",
"does",
"not",
"validate",
"anything",
".",
"Doesn",
"t",
"support",
"subpool",
"allocation"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L40-L59
|
train
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
ReleasePool
|
func (a *allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
return nil
}
|
go
|
func (a *allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
return nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"ReleasePool",
"(",
"poolID",
"string",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"ReleasePool(%s)\"",
",",
"poolID",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleasePool releases the address pool - always succeeds
|
[
"ReleasePool",
"releases",
"the",
"address",
"pool",
"-",
"always",
"succeeds"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L62-L65
|
train
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
ReleaseAddress
|
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
return nil
}
|
go
|
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
return nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"ReleaseAddress",
"(",
"poolID",
"string",
",",
"address",
"net",
".",
"IP",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"ReleaseAddress(%s, %v)\"",
",",
"poolID",
",",
"address",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleaseAddress releases the address - always succeeds
|
[
"ReleaseAddress",
"releases",
"the",
"address",
"-",
"always",
"succeeds"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L85-L88
|
train
|
docker/libnetwork
|
ipams/remote/api/api.go
|
ToCapability
|
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
return &ipamapi.Capability{
RequiresMACAddress: capRes.RequiresMACAddress,
RequiresRequestReplay: capRes.RequiresRequestReplay,
}
}
|
go
|
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
return &ipamapi.Capability{
RequiresMACAddress: capRes.RequiresMACAddress,
RequiresRequestReplay: capRes.RequiresRequestReplay,
}
}
|
[
"func",
"(",
"capRes",
"GetCapabilityResponse",
")",
"ToCapability",
"(",
")",
"*",
"ipamapi",
".",
"Capability",
"{",
"return",
"&",
"ipamapi",
".",
"Capability",
"{",
"RequiresMACAddress",
":",
"capRes",
".",
"RequiresMACAddress",
",",
"RequiresRequestReplay",
":",
"capRes",
".",
"RequiresRequestReplay",
",",
"}",
"\n",
"}"
] |
// ToCapability converts the capability response into the internal ipam driver capability structure
|
[
"ToCapability",
"converts",
"the",
"capability",
"response",
"into",
"the",
"internal",
"ipam",
"driver",
"capability",
"structure"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/api/api.go#L30-L35
|
train
|
docker/libnetwork
|
driverapi/driverapi.go
|
IsValidType
|
func IsValidType(objType ObjectType) bool {
switch objType {
case EndpointObject:
fallthrough
case NetworkObject:
fallthrough
case OpaqueObject:
return true
}
return false
}
|
go
|
func IsValidType(objType ObjectType) bool {
switch objType {
case EndpointObject:
fallthrough
case NetworkObject:
fallthrough
case OpaqueObject:
return true
}
return false
}
|
[
"func",
"IsValidType",
"(",
"objType",
"ObjectType",
")",
"bool",
"{",
"switch",
"objType",
"{",
"case",
"EndpointObject",
":",
"fallthrough",
"\n",
"case",
"NetworkObject",
":",
"fallthrough",
"\n",
"case",
"OpaqueObject",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsValidType validates the passed in type against the valid object types
|
[
"IsValidType",
"validates",
"the",
"passed",
"in",
"type",
"against",
"the",
"valid",
"object",
"types"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/driverapi.go#L203-L213
|
train
|
docker/libnetwork
|
network.go
|
Validate
|
func (c *IpamConf) Validate() error {
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
}
return nil
}
|
go
|
func (c *IpamConf) Validate() error {
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"IpamConf",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Gateway",
"!=",
"\"\"",
"&&",
"nil",
"==",
"net",
".",
"ParseIP",
"(",
"c",
".",
"Gateway",
")",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"invalid gateway address %s in Ipam configuration\"",
",",
"c",
".",
"Gateway",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate checks whether the configuration is valid
|
[
"Validate",
"checks",
"whether",
"the",
"configuration",
"is",
"valid"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L146-L151
|
train
|
docker/libnetwork
|
network.go
|
MarshalJSON
|
func (i *IpamInfo) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"PoolID": i.PoolID,
}
v, err := json.Marshal(&i.IPAMData)
if err != nil {
return nil, err
}
m["IPAMData"] = string(v)
if i.Meta != nil {
m["Meta"] = i.Meta
}
return json.Marshal(m)
}
|
go
|
func (i *IpamInfo) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"PoolID": i.PoolID,
}
v, err := json.Marshal(&i.IPAMData)
if err != nil {
return nil, err
}
m["IPAMData"] = string(v)
if i.Meta != nil {
m["Meta"] = i.Meta
}
return json.Marshal(m)
}
|
[
"func",
"(",
"i",
"*",
"IpamInfo",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"PoolID\"",
":",
"i",
".",
"PoolID",
",",
"}",
"\n",
"v",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"i",
".",
"IPAMData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"m",
"[",
"\"IPAMData\"",
"]",
"=",
"string",
"(",
"v",
")",
"\n",
"if",
"i",
".",
"Meta",
"!=",
"nil",
"{",
"m",
"[",
"\"Meta\"",
"]",
"=",
"i",
".",
"Meta",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"}"
] |
// MarshalJSON encodes IpamInfo into json message
|
[
"MarshalJSON",
"encodes",
"IpamInfo",
"into",
"json",
"message"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L161-L175
|
train
|
docker/libnetwork
|
network.go
|
UnmarshalJSON
|
func (i *IpamInfo) UnmarshalJSON(data []byte) error {
var (
m map[string]interface{}
err error
)
if err = json.Unmarshal(data, &m); err != nil {
return err
}
i.PoolID = m["PoolID"].(string)
if v, ok := m["Meta"]; ok {
b, _ := json.Marshal(v)
if err = json.Unmarshal(b, &i.Meta); err != nil {
return err
}
}
if v, ok := m["IPAMData"]; ok {
if err = json.Unmarshal([]byte(v.(string)), &i.IPAMData); err != nil {
return err
}
}
return nil
}
|
go
|
func (i *IpamInfo) UnmarshalJSON(data []byte) error {
var (
m map[string]interface{}
err error
)
if err = json.Unmarshal(data, &m); err != nil {
return err
}
i.PoolID = m["PoolID"].(string)
if v, ok := m["Meta"]; ok {
b, _ := json.Marshal(v)
if err = json.Unmarshal(b, &i.Meta); err != nil {
return err
}
}
if v, ok := m["IPAMData"]; ok {
if err = json.Unmarshal([]byte(v.(string)), &i.IPAMData); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"IpamInfo",
")",
"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",
".",
"PoolID",
"=",
"m",
"[",
"\"PoolID\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"m",
"[",
"\"Meta\"",
"]",
";",
"ok",
"{",
"b",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"v",
")",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"i",
".",
"Meta",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"m",
"[",
"\"IPAMData\"",
"]",
";",
"ok",
"{",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"v",
".",
"(",
"string",
")",
")",
",",
"&",
"i",
".",
"IPAMData",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes json message into PoolData
|
[
"UnmarshalJSON",
"decodes",
"json",
"message",
"into",
"PoolData"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L178-L199
|
train
|
docker/libnetwork
|
network.go
|
CopyTo
|
func (c *IpamConf) CopyTo(dstC *IpamConf) error {
dstC.PreferredPool = c.PreferredPool
dstC.SubPool = c.SubPool
dstC.Gateway = c.Gateway
if c.AuxAddresses != nil {
dstC.AuxAddresses = make(map[string]string, len(c.AuxAddresses))
for k, v := range c.AuxAddresses {
dstC.AuxAddresses[k] = v
}
}
return nil
}
|
go
|
func (c *IpamConf) CopyTo(dstC *IpamConf) error {
dstC.PreferredPool = c.PreferredPool
dstC.SubPool = c.SubPool
dstC.Gateway = c.Gateway
if c.AuxAddresses != nil {
dstC.AuxAddresses = make(map[string]string, len(c.AuxAddresses))
for k, v := range c.AuxAddresses {
dstC.AuxAddresses[k] = v
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"IpamConf",
")",
"CopyTo",
"(",
"dstC",
"*",
"IpamConf",
")",
"error",
"{",
"dstC",
".",
"PreferredPool",
"=",
"c",
".",
"PreferredPool",
"\n",
"dstC",
".",
"SubPool",
"=",
"c",
".",
"SubPool",
"\n",
"dstC",
".",
"Gateway",
"=",
"c",
".",
"Gateway",
"\n",
"if",
"c",
".",
"AuxAddresses",
"!=",
"nil",
"{",
"dstC",
".",
"AuxAddresses",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"c",
".",
"AuxAddresses",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"AuxAddresses",
"{",
"dstC",
".",
"AuxAddresses",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CopyTo deep copies to the destination IpamConfig
|
[
"CopyTo",
"deep",
"copies",
"to",
"the",
"destination",
"IpamConfig"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L335-L346
|
train
|
docker/libnetwork
|
network.go
|
CopyTo
|
func (i *IpamInfo) CopyTo(dstI *IpamInfo) error {
dstI.PoolID = i.PoolID
if i.Meta != nil {
dstI.Meta = make(map[string]string)
for k, v := range i.Meta {
dstI.Meta[k] = v
}
}
dstI.AddressSpace = i.AddressSpace
dstI.Pool = types.GetIPNetCopy(i.Pool)
dstI.Gateway = types.GetIPNetCopy(i.Gateway)
if i.AuxAddresses != nil {
dstI.AuxAddresses = make(map[string]*net.IPNet)
for k, v := range i.AuxAddresses {
dstI.AuxAddresses[k] = types.GetIPNetCopy(v)
}
}
return nil
}
|
go
|
func (i *IpamInfo) CopyTo(dstI *IpamInfo) error {
dstI.PoolID = i.PoolID
if i.Meta != nil {
dstI.Meta = make(map[string]string)
for k, v := range i.Meta {
dstI.Meta[k] = v
}
}
dstI.AddressSpace = i.AddressSpace
dstI.Pool = types.GetIPNetCopy(i.Pool)
dstI.Gateway = types.GetIPNetCopy(i.Gateway)
if i.AuxAddresses != nil {
dstI.AuxAddresses = make(map[string]*net.IPNet)
for k, v := range i.AuxAddresses {
dstI.AuxAddresses[k] = types.GetIPNetCopy(v)
}
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"IpamInfo",
")",
"CopyTo",
"(",
"dstI",
"*",
"IpamInfo",
")",
"error",
"{",
"dstI",
".",
"PoolID",
"=",
"i",
".",
"PoolID",
"\n",
"if",
"i",
".",
"Meta",
"!=",
"nil",
"{",
"dstI",
".",
"Meta",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"i",
".",
"Meta",
"{",
"dstI",
".",
"Meta",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"dstI",
".",
"AddressSpace",
"=",
"i",
".",
"AddressSpace",
"\n",
"dstI",
".",
"Pool",
"=",
"types",
".",
"GetIPNetCopy",
"(",
"i",
".",
"Pool",
")",
"\n",
"dstI",
".",
"Gateway",
"=",
"types",
".",
"GetIPNetCopy",
"(",
"i",
".",
"Gateway",
")",
"\n",
"if",
"i",
".",
"AuxAddresses",
"!=",
"nil",
"{",
"dstI",
".",
"AuxAddresses",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"net",
".",
"IPNet",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"i",
".",
"AuxAddresses",
"{",
"dstI",
".",
"AuxAddresses",
"[",
"k",
"]",
"=",
"types",
".",
"GetIPNetCopy",
"(",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CopyTo deep copies to the destination IpamInfo
|
[
"CopyTo",
"deep",
"copies",
"to",
"the",
"destination",
"IpamInfo"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L349-L370
|
train
|
docker/libnetwork
|
network.go
|
applyConfigurationTo
|
func (n *network) applyConfigurationTo(to *network) error {
to.enableIPv6 = n.enableIPv6
if len(n.labels) > 0 {
to.labels = make(map[string]string, len(n.labels))
for k, v := range n.labels {
if _, ok := to.labels[k]; !ok {
to.labels[k] = v
}
}
}
if len(n.ipamType) != 0 {
to.ipamType = n.ipamType
}
if len(n.ipamOptions) > 0 {
to.ipamOptions = make(map[string]string, len(n.ipamOptions))
for k, v := range n.ipamOptions {
if _, ok := to.ipamOptions[k]; !ok {
to.ipamOptions[k] = v
}
}
}
if len(n.ipamV4Config) > 0 {
to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config))
to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...)
}
if len(n.ipamV6Config) > 0 {
to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config))
to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...)
}
if len(n.generic) > 0 {
to.generic = options.Generic{}
for k, v := range n.generic {
to.generic[k] = v
}
}
return nil
}
|
go
|
func (n *network) applyConfigurationTo(to *network) error {
to.enableIPv6 = n.enableIPv6
if len(n.labels) > 0 {
to.labels = make(map[string]string, len(n.labels))
for k, v := range n.labels {
if _, ok := to.labels[k]; !ok {
to.labels[k] = v
}
}
}
if len(n.ipamType) != 0 {
to.ipamType = n.ipamType
}
if len(n.ipamOptions) > 0 {
to.ipamOptions = make(map[string]string, len(n.ipamOptions))
for k, v := range n.ipamOptions {
if _, ok := to.ipamOptions[k]; !ok {
to.ipamOptions[k] = v
}
}
}
if len(n.ipamV4Config) > 0 {
to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config))
to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...)
}
if len(n.ipamV6Config) > 0 {
to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config))
to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...)
}
if len(n.generic) > 0 {
to.generic = options.Generic{}
for k, v := range n.generic {
to.generic[k] = v
}
}
return nil
}
|
[
"func",
"(",
"n",
"*",
"network",
")",
"applyConfigurationTo",
"(",
"to",
"*",
"network",
")",
"error",
"{",
"to",
".",
"enableIPv6",
"=",
"n",
".",
"enableIPv6",
"\n",
"if",
"len",
"(",
"n",
".",
"labels",
")",
">",
"0",
"{",
"to",
".",
"labels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"n",
".",
"labels",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"n",
".",
"labels",
"{",
"if",
"_",
",",
"ok",
":=",
"to",
".",
"labels",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"to",
".",
"labels",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"ipamType",
")",
"!=",
"0",
"{",
"to",
".",
"ipamType",
"=",
"n",
".",
"ipamType",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"ipamOptions",
")",
">",
"0",
"{",
"to",
".",
"ipamOptions",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"n",
".",
"ipamOptions",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"n",
".",
"ipamOptions",
"{",
"if",
"_",
",",
"ok",
":=",
"to",
".",
"ipamOptions",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"to",
".",
"ipamOptions",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"ipamV4Config",
")",
">",
"0",
"{",
"to",
".",
"ipamV4Config",
"=",
"make",
"(",
"[",
"]",
"*",
"IpamConf",
",",
"0",
",",
"len",
"(",
"n",
".",
"ipamV4Config",
")",
")",
"\n",
"to",
".",
"ipamV4Config",
"=",
"append",
"(",
"to",
".",
"ipamV4Config",
",",
"n",
".",
"ipamV4Config",
"...",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"ipamV6Config",
")",
">",
"0",
"{",
"to",
".",
"ipamV6Config",
"=",
"make",
"(",
"[",
"]",
"*",
"IpamConf",
",",
"0",
",",
"len",
"(",
"n",
".",
"ipamV6Config",
")",
")",
"\n",
"to",
".",
"ipamV6Config",
"=",
"append",
"(",
"to",
".",
"ipamV6Config",
",",
"n",
".",
"ipamV6Config",
"...",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"generic",
")",
">",
"0",
"{",
"to",
".",
"generic",
"=",
"options",
".",
"Generic",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"n",
".",
"generic",
"{",
"to",
".",
"generic",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Applies network specific configurations
|
[
"Applies",
"network",
"specific",
"configurations"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L420-L456
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionGeneric
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
if val, ok := generic[netlabel.EnableIPv6]; ok {
n.enableIPv6 = val.(bool)
}
if val, ok := generic[netlabel.Internal]; ok {
n.internal = val.(bool)
}
for k, v := range generic {
n.generic[k] = v
}
}
}
|
go
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
if val, ok := generic[netlabel.EnableIPv6]; ok {
n.enableIPv6 = val.(bool)
}
if val, ok := generic[netlabel.Internal]; ok {
n.internal = val.(bool)
}
for k, v := range generic {
n.generic[k] = v
}
}
}
|
[
"func",
"NetworkOptionGeneric",
"(",
"generic",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"if",
"n",
".",
"generic",
"==",
"nil",
"{",
"n",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"if",
"val",
",",
"ok",
":=",
"generic",
"[",
"netlabel",
".",
"EnableIPv6",
"]",
";",
"ok",
"{",
"n",
".",
"enableIPv6",
"=",
"val",
".",
"(",
"bool",
")",
"\n",
"}",
"\n",
"if",
"val",
",",
"ok",
":=",
"generic",
"[",
"netlabel",
".",
"Internal",
"]",
";",
"ok",
"{",
"n",
".",
"internal",
"=",
"val",
".",
"(",
"bool",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"generic",
"{",
"n",
".",
"generic",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionGeneric function returns an option setter for a Generic option defined
// in a Dictionary of Key-Value pair
|
[
"NetworkOptionGeneric",
"function",
"returns",
"an",
"option",
"setter",
"for",
"a",
"Generic",
"option",
"defined",
"in",
"a",
"Dictionary",
"of",
"Key",
"-",
"Value",
"pair"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L733-L748
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionEnableIPv6
|
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
n.enableIPv6 = enableIPv6
n.generic[netlabel.EnableIPv6] = enableIPv6
}
}
|
go
|
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
n.enableIPv6 = enableIPv6
n.generic[netlabel.EnableIPv6] = enableIPv6
}
}
|
[
"func",
"NetworkOptionEnableIPv6",
"(",
"enableIPv6",
"bool",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"if",
"n",
".",
"generic",
"==",
"nil",
"{",
"n",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"n",
".",
"enableIPv6",
"=",
"enableIPv6",
"\n",
"n",
".",
"generic",
"[",
"netlabel",
".",
"EnableIPv6",
"]",
"=",
"enableIPv6",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6
|
[
"NetworkOptionEnableIPv6",
"returns",
"an",
"option",
"setter",
"to",
"explicitly",
"configure",
"IPv6"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L766-L774
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionInternalNetwork
|
func NetworkOptionInternalNetwork() NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
n.internal = true
n.generic[netlabel.Internal] = true
}
}
|
go
|
func NetworkOptionInternalNetwork() NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
n.internal = true
n.generic[netlabel.Internal] = true
}
}
|
[
"func",
"NetworkOptionInternalNetwork",
"(",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"if",
"n",
".",
"generic",
"==",
"nil",
"{",
"n",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"n",
".",
"internal",
"=",
"true",
"\n",
"n",
".",
"generic",
"[",
"netlabel",
".",
"Internal",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionInternalNetwork returns an option setter to config the network
// to be internal which disables default gateway service
|
[
"NetworkOptionInternalNetwork",
"returns",
"an",
"option",
"setter",
"to",
"config",
"the",
"network",
"to",
"be",
"internal",
"which",
"disables",
"default",
"gateway",
"service"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L778-L786
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionIpam
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
return func(n *network) {
if ipamDriver != "" {
n.ipamType = ipamDriver
if ipamDriver == ipamapi.DefaultIPAM {
n.ipamType = defaultIpamForNetworkType(n.Type())
}
}
n.ipamOptions = opts
n.addrSpace = addrSpace
n.ipamV4Config = ipV4
n.ipamV6Config = ipV6
}
}
|
go
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
return func(n *network) {
if ipamDriver != "" {
n.ipamType = ipamDriver
if ipamDriver == ipamapi.DefaultIPAM {
n.ipamType = defaultIpamForNetworkType(n.Type())
}
}
n.ipamOptions = opts
n.addrSpace = addrSpace
n.ipamV4Config = ipV4
n.ipamV6Config = ipV6
}
}
|
[
"func",
"NetworkOptionIpam",
"(",
"ipamDriver",
"string",
",",
"addrSpace",
"string",
",",
"ipV4",
"[",
"]",
"*",
"IpamConf",
",",
"ipV6",
"[",
"]",
"*",
"IpamConf",
",",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"if",
"ipamDriver",
"!=",
"\"\"",
"{",
"n",
".",
"ipamType",
"=",
"ipamDriver",
"\n",
"if",
"ipamDriver",
"==",
"ipamapi",
".",
"DefaultIPAM",
"{",
"n",
".",
"ipamType",
"=",
"defaultIpamForNetworkType",
"(",
"n",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"n",
".",
"ipamOptions",
"=",
"opts",
"\n",
"n",
".",
"addrSpace",
"=",
"addrSpace",
"\n",
"n",
".",
"ipamV4Config",
"=",
"ipV4",
"\n",
"n",
".",
"ipamV6Config",
"=",
"ipV6",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
[
"NetworkOptionIpam",
"function",
"returns",
"an",
"option",
"setter",
"for",
"the",
"ipam",
"configuration",
"for",
"this",
"network"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L804-L817
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionLBEndpoint
|
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption {
return func(n *network) {
n.loadBalancerIP = ip
}
}
|
go
|
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption {
return func(n *network) {
n.loadBalancerIP = ip
}
}
|
[
"func",
"NetworkOptionLBEndpoint",
"(",
"ip",
"net",
".",
"IP",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"n",
".",
"loadBalancerIP",
"=",
"ip",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionLBEndpoint function returns an option setter for the configuration of the load balancer endpoint for this network
|
[
"NetworkOptionLBEndpoint",
"function",
"returns",
"an",
"option",
"setter",
"for",
"the",
"configuration",
"of",
"the",
"load",
"balancer",
"endpoint",
"for",
"this",
"network"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L820-L824
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionDriverOpts
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
if opts == nil {
opts = make(map[string]string)
}
// Store the options
n.generic[netlabel.GenericData] = opts
}
}
|
go
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
return func(n *network) {
if n.generic == nil {
n.generic = make(map[string]interface{})
}
if opts == nil {
opts = make(map[string]string)
}
// Store the options
n.generic[netlabel.GenericData] = opts
}
}
|
[
"func",
"NetworkOptionDriverOpts",
"(",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"if",
"n",
".",
"generic",
"==",
"nil",
"{",
"n",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"n",
".",
"generic",
"[",
"netlabel",
".",
"GenericData",
"]",
"=",
"opts",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionDriverOpts function returns an option setter for any driver parameter described by a map
|
[
"NetworkOptionDriverOpts",
"function",
"returns",
"an",
"option",
"setter",
"for",
"any",
"driver",
"parameter",
"described",
"by",
"a",
"map"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L827-L838
|
train
|
docker/libnetwork
|
network.go
|
NetworkOptionLabels
|
func NetworkOptionLabels(labels map[string]string) NetworkOption {
return func(n *network) {
n.labels = labels
}
}
|
go
|
func NetworkOptionLabels(labels map[string]string) NetworkOption {
return func(n *network) {
n.labels = labels
}
}
|
[
"func",
"NetworkOptionLabels",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"NetworkOption",
"{",
"return",
"func",
"(",
"n",
"*",
"network",
")",
"{",
"n",
".",
"labels",
"=",
"labels",
"\n",
"}",
"\n",
"}"
] |
// NetworkOptionLabels function returns an option setter for labels specific to a network
|
[
"NetworkOptionLabels",
"function",
"returns",
"an",
"option",
"setter",
"for",
"labels",
"specific",
"to",
"a",
"network"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L841-L845
|
train
|
docker/libnetwork
|
network.go
|
getConfigNetwork
|
func (c *controller) getConfigNetwork(name string) (*network, error) {
var n Network
s := func(current Network) bool {
if current.Info().ConfigOnly() && current.Name() == name {
n = current
return true
}
return false
}
c.WalkNetworks(s)
if n == nil {
return nil, types.NotFoundErrorf("configuration network %q not found", name)
}
return n.(*network), nil
}
|
go
|
func (c *controller) getConfigNetwork(name string) (*network, error) {
var n Network
s := func(current Network) bool {
if current.Info().ConfigOnly() && current.Name() == name {
n = current
return true
}
return false
}
c.WalkNetworks(s)
if n == nil {
return nil, types.NotFoundErrorf("configuration network %q not found", name)
}
return n.(*network), nil
}
|
[
"func",
"(",
"c",
"*",
"controller",
")",
"getConfigNetwork",
"(",
"name",
"string",
")",
"(",
"*",
"network",
",",
"error",
")",
"{",
"var",
"n",
"Network",
"\n",
"s",
":=",
"func",
"(",
"current",
"Network",
")",
"bool",
"{",
"if",
"current",
".",
"Info",
"(",
")",
".",
"ConfigOnly",
"(",
")",
"&&",
"current",
".",
"Name",
"(",
")",
"==",
"name",
"{",
"n",
"=",
"current",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"c",
".",
"WalkNetworks",
"(",
"s",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
",",
"types",
".",
"NotFoundErrorf",
"(",
"\"configuration network %q not found\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"n",
".",
"(",
"*",
"network",
")",
",",
"nil",
"\n",
"}"
] |
// config-only network is looked up by name
|
[
"config",
"-",
"only",
"network",
"is",
"looked",
"up",
"by",
"name"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L2105-L2123
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
NewChain
|
func NewChain(name string, table Table, hairpinMode bool) (*ChainInfo, error) {
c := &ChainInfo{
Name: name,
Table: table,
HairpinMode: hairpinMode,
}
if string(c.Table) == "" {
c.Table = Filter
}
// Add chain if it doesn't exist
if _, err := Raw("-t", string(c.Table), "-n", "-L", c.Name); err != nil {
if output, err := Raw("-t", string(c.Table), "-N", c.Name); err != nil {
return nil, err
} else if len(output) != 0 {
return nil, fmt.Errorf("Could not create %s/%s chain: %s", c.Table, c.Name, output)
}
}
return c, nil
}
|
go
|
func NewChain(name string, table Table, hairpinMode bool) (*ChainInfo, error) {
c := &ChainInfo{
Name: name,
Table: table,
HairpinMode: hairpinMode,
}
if string(c.Table) == "" {
c.Table = Filter
}
// Add chain if it doesn't exist
if _, err := Raw("-t", string(c.Table), "-n", "-L", c.Name); err != nil {
if output, err := Raw("-t", string(c.Table), "-N", c.Name); err != nil {
return nil, err
} else if len(output) != 0 {
return nil, fmt.Errorf("Could not create %s/%s chain: %s", c.Table, c.Name, output)
}
}
return c, nil
}
|
[
"func",
"NewChain",
"(",
"name",
"string",
",",
"table",
"Table",
",",
"hairpinMode",
"bool",
")",
"(",
"*",
"ChainInfo",
",",
"error",
")",
"{",
"c",
":=",
"&",
"ChainInfo",
"{",
"Name",
":",
"name",
",",
"Table",
":",
"table",
",",
"HairpinMode",
":",
"hairpinMode",
",",
"}",
"\n",
"if",
"string",
"(",
"c",
".",
"Table",
")",
"==",
"\"\"",
"{",
"c",
".",
"Table",
"=",
"Filter",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"Raw",
"(",
"\"-t\"",
",",
"string",
"(",
"c",
".",
"Table",
")",
",",
"\"-n\"",
",",
"\"-L\"",
",",
"c",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"output",
",",
"err",
":=",
"Raw",
"(",
"\"-t\"",
",",
"string",
"(",
"c",
".",
"Table",
")",
",",
"\"-N\"",
",",
"c",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"len",
"(",
"output",
")",
"!=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Could not create %s/%s chain: %s\"",
",",
"c",
".",
"Table",
",",
"c",
".",
"Name",
",",
"output",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// NewChain adds a new chain to ip table.
|
[
"NewChain",
"adds",
"a",
"new",
"chain",
"to",
"ip",
"table",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L120-L139
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
RemoveExistingChain
|
func RemoveExistingChain(name string, table Table) error {
c := &ChainInfo{
Name: name,
Table: table,
}
if string(c.Table) == "" {
c.Table = Filter
}
return c.Remove()
}
|
go
|
func RemoveExistingChain(name string, table Table) error {
c := &ChainInfo{
Name: name,
Table: table,
}
if string(c.Table) == "" {
c.Table = Filter
}
return c.Remove()
}
|
[
"func",
"RemoveExistingChain",
"(",
"name",
"string",
",",
"table",
"Table",
")",
"error",
"{",
"c",
":=",
"&",
"ChainInfo",
"{",
"Name",
":",
"name",
",",
"Table",
":",
"table",
",",
"}",
"\n",
"if",
"string",
"(",
"c",
".",
"Table",
")",
"==",
"\"\"",
"{",
"c",
".",
"Table",
"=",
"Filter",
"\n",
"}",
"\n",
"return",
"c",
".",
"Remove",
"(",
")",
"\n",
"}"
] |
// RemoveExistingChain removes existing chain from the table.
|
[
"RemoveExistingChain",
"removes",
"existing",
"chain",
"from",
"the",
"table",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L227-L236
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
Forward
|
func (c *ChainInfo) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int, bridgeName string) error {
daddr := ip.String()
if ip.IsUnspecified() {
// iptables interprets "0.0.0.0" as "0.0.0.0/32", whereas we
// want "0.0.0.0/0". "0/0" is correctly interpreted as "any
// value" by both iptables and ip6tables.
daddr = "0/0"
}
args := []string{
"-p", proto,
"-d", daddr,
"--dport", strconv.Itoa(port),
"-j", "DNAT",
"--to-destination", net.JoinHostPort(destAddr, strconv.Itoa(destPort))}
if !c.HairpinMode {
args = append(args, "!", "-i", bridgeName)
}
if err := ProgramRule(Nat, c.Name, action, args); err != nil {
return err
}
args = []string{
"!", "-i", bridgeName,
"-o", bridgeName,
"-p", proto,
"-d", destAddr,
"--dport", strconv.Itoa(destPort),
"-j", "ACCEPT",
}
if err := ProgramRule(Filter, c.Name, action, args); err != nil {
return err
}
args = []string{
"-p", proto,
"-s", destAddr,
"-d", destAddr,
"--dport", strconv.Itoa(destPort),
"-j", "MASQUERADE",
}
if err := ProgramRule(Nat, "POSTROUTING", action, args); err != nil {
return err
}
if proto == "sctp" {
// Linux kernel v4.9 and below enables NETIF_F_SCTP_CRC for veth by
// the following commit.
// This introduces a problem when conbined with a physical NIC without
// NETIF_F_SCTP_CRC. As for a workaround, here we add an iptables entry
// to fill the checksum.
//
// https://github.com/torvalds/linux/commit/c80fafbbb59ef9924962f83aac85531039395b18
args = []string{
"-p", proto,
"--sport", strconv.Itoa(destPort),
"-j", "CHECKSUM",
"--checksum-fill",
}
if err := ProgramRule(Mangle, "POSTROUTING", action, args); err != nil {
return err
}
}
return nil
}
|
go
|
func (c *ChainInfo) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int, bridgeName string) error {
daddr := ip.String()
if ip.IsUnspecified() {
// iptables interprets "0.0.0.0" as "0.0.0.0/32", whereas we
// want "0.0.0.0/0". "0/0" is correctly interpreted as "any
// value" by both iptables and ip6tables.
daddr = "0/0"
}
args := []string{
"-p", proto,
"-d", daddr,
"--dport", strconv.Itoa(port),
"-j", "DNAT",
"--to-destination", net.JoinHostPort(destAddr, strconv.Itoa(destPort))}
if !c.HairpinMode {
args = append(args, "!", "-i", bridgeName)
}
if err := ProgramRule(Nat, c.Name, action, args); err != nil {
return err
}
args = []string{
"!", "-i", bridgeName,
"-o", bridgeName,
"-p", proto,
"-d", destAddr,
"--dport", strconv.Itoa(destPort),
"-j", "ACCEPT",
}
if err := ProgramRule(Filter, c.Name, action, args); err != nil {
return err
}
args = []string{
"-p", proto,
"-s", destAddr,
"-d", destAddr,
"--dport", strconv.Itoa(destPort),
"-j", "MASQUERADE",
}
if err := ProgramRule(Nat, "POSTROUTING", action, args); err != nil {
return err
}
if proto == "sctp" {
// Linux kernel v4.9 and below enables NETIF_F_SCTP_CRC for veth by
// the following commit.
// This introduces a problem when conbined with a physical NIC without
// NETIF_F_SCTP_CRC. As for a workaround, here we add an iptables entry
// to fill the checksum.
//
// https://github.com/torvalds/linux/commit/c80fafbbb59ef9924962f83aac85531039395b18
args = []string{
"-p", proto,
"--sport", strconv.Itoa(destPort),
"-j", "CHECKSUM",
"--checksum-fill",
}
if err := ProgramRule(Mangle, "POSTROUTING", action, args); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"ChainInfo",
")",
"Forward",
"(",
"action",
"Action",
",",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
",",
"proto",
",",
"destAddr",
"string",
",",
"destPort",
"int",
",",
"bridgeName",
"string",
")",
"error",
"{",
"daddr",
":=",
"ip",
".",
"String",
"(",
")",
"\n",
"if",
"ip",
".",
"IsUnspecified",
"(",
")",
"{",
"daddr",
"=",
"\"0/0\"",
"\n",
"}",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"-p\"",
",",
"proto",
",",
"\"-d\"",
",",
"daddr",
",",
"\"--dport\"",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
",",
"\"-j\"",
",",
"\"DNAT\"",
",",
"\"--to-destination\"",
",",
"net",
".",
"JoinHostPort",
"(",
"destAddr",
",",
"strconv",
".",
"Itoa",
"(",
"destPort",
")",
")",
"}",
"\n",
"if",
"!",
"c",
".",
"HairpinMode",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"!\"",
",",
"\"-i\"",
",",
"bridgeName",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ProgramRule",
"(",
"Nat",
",",
"c",
".",
"Name",
",",
"action",
",",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
"=",
"[",
"]",
"string",
"{",
"\"!\"",
",",
"\"-i\"",
",",
"bridgeName",
",",
"\"-o\"",
",",
"bridgeName",
",",
"\"-p\"",
",",
"proto",
",",
"\"-d\"",
",",
"destAddr",
",",
"\"--dport\"",
",",
"strconv",
".",
"Itoa",
"(",
"destPort",
")",
",",
"\"-j\"",
",",
"\"ACCEPT\"",
",",
"}",
"\n",
"if",
"err",
":=",
"ProgramRule",
"(",
"Filter",
",",
"c",
".",
"Name",
",",
"action",
",",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
"=",
"[",
"]",
"string",
"{",
"\"-p\"",
",",
"proto",
",",
"\"-s\"",
",",
"destAddr",
",",
"\"-d\"",
",",
"destAddr",
",",
"\"--dport\"",
",",
"strconv",
".",
"Itoa",
"(",
"destPort",
")",
",",
"\"-j\"",
",",
"\"MASQUERADE\"",
",",
"}",
"\n",
"if",
"err",
":=",
"ProgramRule",
"(",
"Nat",
",",
"\"POSTROUTING\"",
",",
"action",
",",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"proto",
"==",
"\"sctp\"",
"{",
"args",
"=",
"[",
"]",
"string",
"{",
"\"-p\"",
",",
"proto",
",",
"\"--sport\"",
",",
"strconv",
".",
"Itoa",
"(",
"destPort",
")",
",",
"\"-j\"",
",",
"\"CHECKSUM\"",
",",
"\"--checksum-fill\"",
",",
"}",
"\n",
"if",
"err",
":=",
"ProgramRule",
"(",
"Mangle",
",",
"\"POSTROUTING\"",
",",
"action",
",",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Forward adds forwarding rule to 'filter' table and corresponding nat rule to 'nat' table.
|
[
"Forward",
"adds",
"forwarding",
"rule",
"to",
"filter",
"table",
"and",
"corresponding",
"nat",
"rule",
"to",
"nat",
"table",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L239-L305
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
Link
|
func (c *ChainInfo) Link(action Action, ip1, ip2 net.IP, port int, proto string, bridgeName string) error {
// forward
args := []string{
"-i", bridgeName, "-o", bridgeName,
"-p", proto,
"-s", ip1.String(),
"-d", ip2.String(),
"--dport", strconv.Itoa(port),
"-j", "ACCEPT",
}
if err := ProgramRule(Filter, c.Name, action, args); err != nil {
return err
}
// reverse
args[7], args[9] = args[9], args[7]
args[10] = "--sport"
return ProgramRule(Filter, c.Name, action, args)
}
|
go
|
func (c *ChainInfo) Link(action Action, ip1, ip2 net.IP, port int, proto string, bridgeName string) error {
// forward
args := []string{
"-i", bridgeName, "-o", bridgeName,
"-p", proto,
"-s", ip1.String(),
"-d", ip2.String(),
"--dport", strconv.Itoa(port),
"-j", "ACCEPT",
}
if err := ProgramRule(Filter, c.Name, action, args); err != nil {
return err
}
// reverse
args[7], args[9] = args[9], args[7]
args[10] = "--sport"
return ProgramRule(Filter, c.Name, action, args)
}
|
[
"func",
"(",
"c",
"*",
"ChainInfo",
")",
"Link",
"(",
"action",
"Action",
",",
"ip1",
",",
"ip2",
"net",
".",
"IP",
",",
"port",
"int",
",",
"proto",
"string",
",",
"bridgeName",
"string",
")",
"error",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"-i\"",
",",
"bridgeName",
",",
"\"-o\"",
",",
"bridgeName",
",",
"\"-p\"",
",",
"proto",
",",
"\"-s\"",
",",
"ip1",
".",
"String",
"(",
")",
",",
"\"-d\"",
",",
"ip2",
".",
"String",
"(",
")",
",",
"\"--dport\"",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
",",
"\"-j\"",
",",
"\"ACCEPT\"",
",",
"}",
"\n",
"if",
"err",
":=",
"ProgramRule",
"(",
"Filter",
",",
"c",
".",
"Name",
",",
"action",
",",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
"[",
"7",
"]",
",",
"args",
"[",
"9",
"]",
"=",
"args",
"[",
"9",
"]",
",",
"args",
"[",
"7",
"]",
"\n",
"args",
"[",
"10",
"]",
"=",
"\"--sport\"",
"\n",
"return",
"ProgramRule",
"(",
"Filter",
",",
"c",
".",
"Name",
",",
"action",
",",
"args",
")",
"\n",
"}"
] |
// Link adds reciprocal ACCEPT rule for two supplied IP addresses.
// Traffic is allowed from ip1 to ip2 and vice-versa
|
[
"Link",
"adds",
"reciprocal",
"ACCEPT",
"rule",
"for",
"two",
"supplied",
"IP",
"addresses",
".",
"Traffic",
"is",
"allowed",
"from",
"ip1",
"to",
"ip2",
"and",
"vice",
"-",
"versa"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L309-L326
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
ProgramRule
|
func ProgramRule(table Table, chain string, action Action, args []string) error {
if Exists(table, chain, args...) != (action == Delete) {
return nil
}
return RawCombinedOutput(append([]string{"-t", string(table), string(action), chain}, args...)...)
}
|
go
|
func ProgramRule(table Table, chain string, action Action, args []string) error {
if Exists(table, chain, args...) != (action == Delete) {
return nil
}
return RawCombinedOutput(append([]string{"-t", string(table), string(action), chain}, args...)...)
}
|
[
"func",
"ProgramRule",
"(",
"table",
"Table",
",",
"chain",
"string",
",",
"action",
"Action",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"Exists",
"(",
"table",
",",
"chain",
",",
"args",
"...",
")",
"!=",
"(",
"action",
"==",
"Delete",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"RawCombinedOutput",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"\"-t\"",
",",
"string",
"(",
"table",
")",
",",
"string",
"(",
"action",
")",
",",
"chain",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"}"
] |
// ProgramRule adds the rule specified by args only if the
// rule is not already present in the chain. Reciprocally,
// it removes the rule only if present.
|
[
"ProgramRule",
"adds",
"the",
"rule",
"specified",
"by",
"args",
"only",
"if",
"the",
"rule",
"is",
"not",
"already",
"present",
"in",
"the",
"chain",
".",
"Reciprocally",
"it",
"removes",
"the",
"rule",
"only",
"if",
"present",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L331-L336
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
Remove
|
func (c *ChainInfo) Remove() error {
// Ignore errors - This could mean the chains were never set up
if c.Table == Nat {
c.Prerouting(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name)
c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "!", "--dst", "127.0.0.0/8", "-j", c.Name)
c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) // Created in versions <= 0.1.6
c.Prerouting(Delete)
c.Output(Delete)
}
Raw("-t", string(c.Table), "-F", c.Name)
Raw("-t", string(c.Table), "-X", c.Name)
return nil
}
|
go
|
func (c *ChainInfo) Remove() error {
// Ignore errors - This could mean the chains were never set up
if c.Table == Nat {
c.Prerouting(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name)
c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "!", "--dst", "127.0.0.0/8", "-j", c.Name)
c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) // Created in versions <= 0.1.6
c.Prerouting(Delete)
c.Output(Delete)
}
Raw("-t", string(c.Table), "-F", c.Name)
Raw("-t", string(c.Table), "-X", c.Name)
return nil
}
|
[
"func",
"(",
"c",
"*",
"ChainInfo",
")",
"Remove",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Table",
"==",
"Nat",
"{",
"c",
".",
"Prerouting",
"(",
"Delete",
",",
"\"-m\"",
",",
"\"addrtype\"",
",",
"\"--dst-type\"",
",",
"\"LOCAL\"",
",",
"\"-j\"",
",",
"c",
".",
"Name",
")",
"\n",
"c",
".",
"Output",
"(",
"Delete",
",",
"\"-m\"",
",",
"\"addrtype\"",
",",
"\"--dst-type\"",
",",
"\"LOCAL\"",
",",
"\"!\"",
",",
"\"--dst\"",
",",
"\"127.0.0.0/8\"",
",",
"\"-j\"",
",",
"c",
".",
"Name",
")",
"\n",
"c",
".",
"Output",
"(",
"Delete",
",",
"\"-m\"",
",",
"\"addrtype\"",
",",
"\"--dst-type\"",
",",
"\"LOCAL\"",
",",
"\"-j\"",
",",
"c",
".",
"Name",
")",
"\n",
"c",
".",
"Prerouting",
"(",
"Delete",
")",
"\n",
"c",
".",
"Output",
"(",
"Delete",
")",
"\n",
"}",
"\n",
"Raw",
"(",
"\"-t\"",
",",
"string",
"(",
"c",
".",
"Table",
")",
",",
"\"-F\"",
",",
"c",
".",
"Name",
")",
"\n",
"Raw",
"(",
"\"-t\"",
",",
"string",
"(",
"c",
".",
"Table",
")",
",",
"\"-X\"",
",",
"c",
".",
"Name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Remove removes the chain.
|
[
"Remove",
"removes",
"the",
"chain",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L367-L380
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
Exists
|
func Exists(table Table, chain string, rule ...string) bool {
return exists(false, table, chain, rule...)
}
|
go
|
func Exists(table Table, chain string, rule ...string) bool {
return exists(false, table, chain, rule...)
}
|
[
"func",
"Exists",
"(",
"table",
"Table",
",",
"chain",
"string",
",",
"rule",
"...",
"string",
")",
"bool",
"{",
"return",
"exists",
"(",
"false",
",",
"table",
",",
"chain",
",",
"rule",
"...",
")",
"\n",
"}"
] |
// Exists checks if a rule exists
|
[
"Exists",
"checks",
"if",
"a",
"rule",
"exists"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L383-L385
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
ExistsNative
|
func ExistsNative(table Table, chain string, rule ...string) bool {
return exists(true, table, chain, rule...)
}
|
go
|
func ExistsNative(table Table, chain string, rule ...string) bool {
return exists(true, table, chain, rule...)
}
|
[
"func",
"ExistsNative",
"(",
"table",
"Table",
",",
"chain",
"string",
",",
"rule",
"...",
"string",
")",
"bool",
"{",
"return",
"exists",
"(",
"true",
",",
"table",
",",
"chain",
",",
"rule",
"...",
")",
"\n",
"}"
] |
// ExistsNative behaves as Exists with the difference it
// will always invoke `iptables` binary.
|
[
"ExistsNative",
"behaves",
"as",
"Exists",
"with",
"the",
"difference",
"it",
"will",
"always",
"invoke",
"iptables",
"binary",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L389-L391
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
Raw
|
func Raw(args ...string) ([]byte, error) {
if firewalldRunning {
startTime := time.Now()
output, err := Passthrough(Iptables, args...)
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
return filterOutput(startTime, output, args...), err
}
}
return raw(args...)
}
|
go
|
func Raw(args ...string) ([]byte, error) {
if firewalldRunning {
startTime := time.Now()
output, err := Passthrough(Iptables, args...)
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
return filterOutput(startTime, output, args...), err
}
}
return raw(args...)
}
|
[
"func",
"Raw",
"(",
"args",
"...",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"firewalldRunning",
"{",
"startTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"output",
",",
"err",
":=",
"Passthrough",
"(",
"Iptables",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"==",
"nil",
"||",
"!",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"was not provided by any .service files\"",
")",
"{",
"return",
"filterOutput",
"(",
"startTime",
",",
"output",
",",
"args",
"...",
")",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"raw",
"(",
"args",
"...",
")",
"\n",
"}"
] |
// Raw calls 'iptables' system command, passing supplied arguments.
|
[
"Raw",
"calls",
"iptables",
"system",
"command",
"passing",
"supplied",
"arguments",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L447-L456
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
RawCombinedOutput
|
func RawCombinedOutput(args ...string) error {
if output, err := Raw(args...); err != nil || len(output) != 0 {
return fmt.Errorf("%s (%v)", string(output), err)
}
return nil
}
|
go
|
func RawCombinedOutput(args ...string) error {
if output, err := Raw(args...); err != nil || len(output) != 0 {
return fmt.Errorf("%s (%v)", string(output), err)
}
return nil
}
|
[
"func",
"RawCombinedOutput",
"(",
"args",
"...",
"string",
")",
"error",
"{",
"if",
"output",
",",
"err",
":=",
"Raw",
"(",
"args",
"...",
")",
";",
"err",
"!=",
"nil",
"||",
"len",
"(",
"output",
")",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"%s (%v)\"",
",",
"string",
"(",
"output",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RawCombinedOutput internally calls the Raw function and returns a non nil
// error if Raw returned a non nil error or a non empty output
|
[
"RawCombinedOutput",
"internally",
"calls",
"the",
"Raw",
"function",
"and",
"returns",
"a",
"non",
"nil",
"error",
"if",
"Raw",
"returned",
"a",
"non",
"nil",
"error",
"or",
"a",
"non",
"empty",
"output"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L482-L487
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
RawCombinedOutputNative
|
func RawCombinedOutputNative(args ...string) error {
if output, err := raw(args...); err != nil || len(output) != 0 {
return fmt.Errorf("%s (%v)", string(output), err)
}
return nil
}
|
go
|
func RawCombinedOutputNative(args ...string) error {
if output, err := raw(args...); err != nil || len(output) != 0 {
return fmt.Errorf("%s (%v)", string(output), err)
}
return nil
}
|
[
"func",
"RawCombinedOutputNative",
"(",
"args",
"...",
"string",
")",
"error",
"{",
"if",
"output",
",",
"err",
":=",
"raw",
"(",
"args",
"...",
")",
";",
"err",
"!=",
"nil",
"||",
"len",
"(",
"output",
")",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"%s (%v)\"",
",",
"string",
"(",
"output",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RawCombinedOutputNative behave as RawCombinedOutput with the difference it
// will always invoke `iptables` binary
|
[
"RawCombinedOutputNative",
"behave",
"as",
"RawCombinedOutput",
"with",
"the",
"difference",
"it",
"will",
"always",
"invoke",
"iptables",
"binary"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L491-L496
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
ExistChain
|
func ExistChain(chain string, table Table) bool {
if _, err := Raw("-t", string(table), "-nL", chain); err == nil {
return true
}
return false
}
|
go
|
func ExistChain(chain string, table Table) bool {
if _, err := Raw("-t", string(table), "-nL", chain); err == nil {
return true
}
return false
}
|
[
"func",
"ExistChain",
"(",
"chain",
"string",
",",
"table",
"Table",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"Raw",
"(",
"\"-t\"",
",",
"string",
"(",
"table",
")",
",",
"\"-nL\"",
",",
"chain",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// ExistChain checks if a chain exists
|
[
"ExistChain",
"checks",
"if",
"a",
"chain",
"exists"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L499-L504
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
GetVersion
|
func GetVersion() (major, minor, micro int, err error) {
out, err := exec.Command(iptablesPath, "--version").CombinedOutput()
if err == nil {
major, minor, micro = parseVersionNumbers(string(out))
}
return
}
|
go
|
func GetVersion() (major, minor, micro int, err error) {
out, err := exec.Command(iptablesPath, "--version").CombinedOutput()
if err == nil {
major, minor, micro = parseVersionNumbers(string(out))
}
return
}
|
[
"func",
"GetVersion",
"(",
")",
"(",
"major",
",",
"minor",
",",
"micro",
"int",
",",
"err",
"error",
")",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"iptablesPath",
",",
"\"--version\"",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"major",
",",
"minor",
",",
"micro",
"=",
"parseVersionNumbers",
"(",
"string",
"(",
"out",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// GetVersion reads the iptables version numbers during initialization
|
[
"GetVersion",
"reads",
"the",
"iptables",
"version",
"numbers",
"during",
"initialization"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L507-L513
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
AddReturnRule
|
func AddReturnRule(chain string) error {
var (
table = Filter
args = []string{"-j", "RETURN"}
)
if Exists(table, chain, args...) {
return nil
}
err := RawCombinedOutput(append([]string{"-A", chain}, args...)...)
if err != nil {
return fmt.Errorf("unable to add return rule in %s chain: %s", chain, err.Error())
}
return nil
}
|
go
|
func AddReturnRule(chain string) error {
var (
table = Filter
args = []string{"-j", "RETURN"}
)
if Exists(table, chain, args...) {
return nil
}
err := RawCombinedOutput(append([]string{"-A", chain}, args...)...)
if err != nil {
return fmt.Errorf("unable to add return rule in %s chain: %s", chain, err.Error())
}
return nil
}
|
[
"func",
"AddReturnRule",
"(",
"chain",
"string",
")",
"error",
"{",
"var",
"(",
"table",
"=",
"Filter",
"\n",
"args",
"=",
"[",
"]",
"string",
"{",
"\"-j\"",
",",
"\"RETURN\"",
"}",
"\n",
")",
"\n",
"if",
"Exists",
"(",
"table",
",",
"chain",
",",
"args",
"...",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"err",
":=",
"RawCombinedOutput",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"\"-A\"",
",",
"chain",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unable to add return rule in %s chain: %s\"",
",",
"chain",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddReturnRule adds a return rule for the chain in the filter table
|
[
"AddReturnRule",
"adds",
"a",
"return",
"rule",
"for",
"the",
"chain",
"in",
"the",
"filter",
"table"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L537-L553
|
train
|
docker/libnetwork
|
iptables/iptables.go
|
EnsureJumpRule
|
func EnsureJumpRule(fromChain, toChain string) error {
var (
table = Filter
args = []string{"-j", toChain}
)
if Exists(table, fromChain, args...) {
err := RawCombinedOutput(append([]string{"-D", fromChain}, args...)...)
if err != nil {
return fmt.Errorf("unable to remove jump to %s rule in %s chain: %s", toChain, fromChain, err.Error())
}
}
err := RawCombinedOutput(append([]string{"-I", fromChain}, args...)...)
if err != nil {
return fmt.Errorf("unable to insert jump to %s rule in %s chain: %s", toChain, fromChain, err.Error())
}
return nil
}
|
go
|
func EnsureJumpRule(fromChain, toChain string) error {
var (
table = Filter
args = []string{"-j", toChain}
)
if Exists(table, fromChain, args...) {
err := RawCombinedOutput(append([]string{"-D", fromChain}, args...)...)
if err != nil {
return fmt.Errorf("unable to remove jump to %s rule in %s chain: %s", toChain, fromChain, err.Error())
}
}
err := RawCombinedOutput(append([]string{"-I", fromChain}, args...)...)
if err != nil {
return fmt.Errorf("unable to insert jump to %s rule in %s chain: %s", toChain, fromChain, err.Error())
}
return nil
}
|
[
"func",
"EnsureJumpRule",
"(",
"fromChain",
",",
"toChain",
"string",
")",
"error",
"{",
"var",
"(",
"table",
"=",
"Filter",
"\n",
"args",
"=",
"[",
"]",
"string",
"{",
"\"-j\"",
",",
"toChain",
"}",
"\n",
")",
"\n",
"if",
"Exists",
"(",
"table",
",",
"fromChain",
",",
"args",
"...",
")",
"{",
"err",
":=",
"RawCombinedOutput",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"\"-D\"",
",",
"fromChain",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unable to remove jump to %s rule in %s chain: %s\"",
",",
"toChain",
",",
"fromChain",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"RawCombinedOutput",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"\"-I\"",
",",
"fromChain",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unable to insert jump to %s rule in %s chain: %s\"",
",",
"toChain",
",",
"fromChain",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// EnsureJumpRule ensures the jump rule is on top
|
[
"EnsureJumpRule",
"ensures",
"the",
"jump",
"rule",
"is",
"on",
"top"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L556-L575
|
train
|
docker/libnetwork
|
client/network.go
|
CmdNetwork
|
func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "network", "COMMAND [OPTIONS] [arg...]", networkUsage(chain), false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err == nil {
cmd.Usage()
return fmt.Errorf("invalid command : %v", args)
}
return err
}
|
go
|
func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "network", "COMMAND [OPTIONS] [arg...]", networkUsage(chain), false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err == nil {
cmd.Usage()
return fmt.Errorf("invalid command : %v", args)
}
return err
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdNetwork",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"network\"",
",",
"\"COMMAND [OPTIONS] [arg...]\"",
",",
"networkUsage",
"(",
"chain",
")",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid command : %v\"",
",",
"args",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// CmdNetwork handles the root Network UI
|
[
"CmdNetwork",
"handles",
"the",
"root",
"Network",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L31-L40
|
train
|
docker/libnetwork
|
client/network.go
|
CmdNetworkCreate
|
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
flID := cmd.String([]string{"-id"}, "", "Network ID string")
flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
flRange := cmd.String([]string{"-ip-range"}, "", "Range option")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
networkOpts := make(map[string]string)
if *flInternal {
networkOpts[netlabel.Internal] = "true"
}
if *flIPv6 {
networkOpts[netlabel.EnableIPv6] = "true"
}
driverOpts := make(map[string]string)
if *flOpts != "" {
opts := strings.Split(*flOpts, ",")
for _, opt := range opts {
driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
}
}
var icList []ipamConf
if *flSubnet != "" {
ic := ipamConf{
PreferredPool: *flSubnet,
}
if *flRange != "" {
ic.SubPool = *flRange
}
icList = append(icList, ic)
}
// Construct network create request body
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
if err != nil {
return err
}
var replyID string
err = json.Unmarshal(obj, &replyID)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s\n", replyID)
return nil
}
|
go
|
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
flID := cmd.String([]string{"-id"}, "", "Network ID string")
flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
flRange := cmd.String([]string{"-ip-range"}, "", "Range option")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
networkOpts := make(map[string]string)
if *flInternal {
networkOpts[netlabel.Internal] = "true"
}
if *flIPv6 {
networkOpts[netlabel.EnableIPv6] = "true"
}
driverOpts := make(map[string]string)
if *flOpts != "" {
opts := strings.Split(*flOpts, ",")
for _, opt := range opts {
driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
}
}
var icList []ipamConf
if *flSubnet != "" {
ic := ipamConf{
PreferredPool: *flSubnet,
}
if *flRange != "" {
ic.SubPool = *flRange
}
icList = append(icList, ic)
}
// Construct network create request body
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
if err != nil {
return err
}
var replyID string
err = json.Unmarshal(obj, &replyID)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s\n", replyID)
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdNetworkCreate",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"create\"",
",",
"\"NETWORK-NAME\"",
",",
"\"Creates a new network with a name specified by the user\"",
",",
"false",
")",
"\n",
"flDriver",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"d\"",
",",
"\"-driver\"",
"}",
",",
"\"\"",
",",
"\"Driver to manage the Network\"",
")",
"\n",
"flID",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"-id\"",
"}",
",",
"\"\"",
",",
"\"Network ID string\"",
")",
"\n",
"flOpts",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"o\"",
",",
"\"-opt\"",
"}",
",",
"\"\"",
",",
"\"Network options\"",
")",
"\n",
"flInternal",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"-internal\"",
"}",
",",
"false",
",",
"\"Config the network to be internal\"",
")",
"\n",
"flIPv6",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"-ipv6\"",
"}",
",",
"false",
",",
"\"Enable IPv6 on the network\"",
")",
"\n",
"flSubnet",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"-subnet\"",
"}",
",",
"\"\"",
",",
"\"Subnet option\"",
")",
"\n",
"flRange",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"-ip-range\"",
"}",
",",
"\"\"",
",",
"\"Range option\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"networkOpts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"*",
"flInternal",
"{",
"networkOpts",
"[",
"netlabel",
".",
"Internal",
"]",
"=",
"\"true\"",
"\n",
"}",
"\n",
"if",
"*",
"flIPv6",
"{",
"networkOpts",
"[",
"netlabel",
".",
"EnableIPv6",
"]",
"=",
"\"true\"",
"\n",
"}",
"\n",
"driverOpts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"*",
"flOpts",
"!=",
"\"\"",
"{",
"opts",
":=",
"strings",
".",
"Split",
"(",
"*",
"flOpts",
",",
"\",\"",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"driverOpts",
"[",
"netlabel",
".",
"Key",
"(",
"opt",
")",
"]",
"=",
"netlabel",
".",
"Value",
"(",
"opt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"icList",
"[",
"]",
"ipamConf",
"\n",
"if",
"*",
"flSubnet",
"!=",
"\"\"",
"{",
"ic",
":=",
"ipamConf",
"{",
"PreferredPool",
":",
"*",
"flSubnet",
",",
"}",
"\n",
"if",
"*",
"flRange",
"!=",
"\"\"",
"{",
"ic",
".",
"SubPool",
"=",
"*",
"flRange",
"\n",
"}",
"\n",
"icList",
"=",
"append",
"(",
"icList",
",",
"ic",
")",
"\n",
"}",
"\n",
"nc",
":=",
"networkCreate",
"{",
"Name",
":",
"cmd",
".",
"Arg",
"(",
"0",
")",
",",
"NetworkType",
":",
"*",
"flDriver",
",",
"ID",
":",
"*",
"flID",
",",
"IPv4Conf",
":",
"icList",
",",
"DriverOpts",
":",
"driverOpts",
",",
"NetworkOpts",
":",
"networkOpts",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"POST\"",
",",
"\"/networks\"",
",",
"nc",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"replyID",
"string",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"replyID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"%s\\n\"",
",",
"\\n",
")",
"\n",
"replyID",
"\n",
"}"
] |
// CmdNetworkCreate handles Network Create UI
|
[
"CmdNetworkCreate",
"handles",
"Network",
"Create",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L43-L100
|
train
|
docker/libnetwork
|
client/network.go
|
CmdNetworkRm
|
func (cli *NetworkCli) CmdNetworkRm(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "rm", "NETWORK", "Deletes a network", false)
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
id, err := lookupNetworkID(cli, cmd.Arg(0))
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/networks/"+id, nil, nil))
if err != nil {
return err
}
return nil
}
|
go
|
func (cli *NetworkCli) CmdNetworkRm(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "rm", "NETWORK", "Deletes a network", false)
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
id, err := lookupNetworkID(cli, cmd.Arg(0))
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/networks/"+id, nil, nil))
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdNetworkRm",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"rm\"",
",",
"\"NETWORK\"",
",",
"\"Deletes a network\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"id",
",",
"err",
":=",
"lookupNetworkID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"DELETE\"",
",",
"\"/networks/\"",
"+",
"id",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CmdNetworkRm handles Network Delete UI
|
[
"CmdNetworkRm",
"handles",
"Network",
"Delete",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L103-L119
|
train
|
docker/libnetwork
|
client/network.go
|
CmdNetworkLs
|
func (cli *NetworkCli) CmdNetworkLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "", "Lists all the networks created by the user", false)
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show the latest network created")
last := cmd.Int([]string{"n"}, -1, "Show n last created networks")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/networks", nil, nil))
if err != nil {
return err
}
if *last == -1 && *nLatest {
*last = 1
}
var networkResources []networkResource
err = json.Unmarshal(obj, &networkResources)
if err != nil {
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "NETWORK ID\tNAME\tTYPE")
}
for _, networkResource := range networkResources {
ID := networkResource.ID
netName := networkResource.Name
if !*noTrunc {
ID = stringid.TruncateID(ID)
}
if *quiet {
fmt.Fprintln(wr, ID)
continue
}
netType := networkResource.Type
fmt.Fprintf(wr, "%s\t%s\t%s\t",
ID,
netName,
netType)
fmt.Fprint(wr, "\n")
}
wr.Flush()
return nil
}
|
go
|
func (cli *NetworkCli) CmdNetworkLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "", "Lists all the networks created by the user", false)
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show the latest network created")
last := cmd.Int([]string{"n"}, -1, "Show n last created networks")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/networks", nil, nil))
if err != nil {
return err
}
if *last == -1 && *nLatest {
*last = 1
}
var networkResources []networkResource
err = json.Unmarshal(obj, &networkResources)
if err != nil {
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "NETWORK ID\tNAME\tTYPE")
}
for _, networkResource := range networkResources {
ID := networkResource.ID
netName := networkResource.Name
if !*noTrunc {
ID = stringid.TruncateID(ID)
}
if *quiet {
fmt.Fprintln(wr, ID)
continue
}
netType := networkResource.Type
fmt.Fprintf(wr, "%s\t%s\t%s\t",
ID,
netName,
netType)
fmt.Fprint(wr, "\n")
}
wr.Flush()
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdNetworkLs",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"ls\"",
",",
"\"\"",
",",
"\"Lists all the networks created by the user\"",
",",
"false",
")",
"\n",
"quiet",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"q\"",
",",
"\"-quiet\"",
"}",
",",
"false",
",",
"\"Only display numeric IDs\"",
")",
"\n",
"noTrunc",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"#notrunc\"",
",",
"\"-no-trunc\"",
"}",
",",
"false",
",",
"\"Do not truncate the output\"",
")",
"\n",
"nLatest",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"l\"",
",",
"\"-latest\"",
"}",
",",
"false",
",",
"\"Show the latest network created\"",
")",
"\n",
"last",
":=",
"cmd",
".",
"Int",
"(",
"[",
"]",
"string",
"{",
"\"n\"",
"}",
",",
"-",
"1",
",",
"\"Show n last created networks\"",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/networks\"",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"*",
"last",
"==",
"-",
"1",
"&&",
"*",
"nLatest",
"{",
"*",
"last",
"=",
"1",
"\n",
"}",
"\n",
"var",
"networkResources",
"[",
"]",
"networkResource",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"networkResources",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"wr",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"cli",
".",
"out",
",",
"20",
",",
"1",
",",
"3",
",",
"' '",
",",
"0",
")",
"\n",
"if",
"!",
"*",
"quiet",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"NETWORK ID\\tNAME\\tTYPE\"",
")",
"\n",
"}",
"\n",
"\\t",
"\n",
"\\t",
"\n",
"for",
"_",
",",
"networkResource",
":=",
"range",
"networkResources",
"{",
"ID",
":=",
"networkResource",
".",
"ID",
"\n",
"netName",
":=",
"networkResource",
".",
"Name",
"\n",
"if",
"!",
"*",
"noTrunc",
"{",
"ID",
"=",
"stringid",
".",
"TruncateID",
"(",
"ID",
")",
"\n",
"}",
"\n",
"if",
"*",
"quiet",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"ID",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"netType",
":=",
"networkResource",
".",
"Type",
"\n",
"fmt",
".",
"Fprintf",
"(",
"wr",
",",
"\"%s\\t%s\\t%s\\t\"",
",",
"\\t",
",",
"\\t",
",",
"\\t",
")",
"\n",
"ID",
"\n",
"}",
"\n",
"}"
] |
// CmdNetworkLs handles Network List UI
|
[
"CmdNetworkLs",
"handles",
"Network",
"List",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L122-L172
|
train
|
docker/libnetwork
|
client/network.go
|
CmdNetworkInfo
|
func (cli *NetworkCli) CmdNetworkInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "NETWORK", "Displays detailed information on a network", false)
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
id, err := lookupNetworkID(cli, cmd.Arg(0))
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/networks/"+id, nil, nil))
if err != nil {
return err
}
networkResource := &networkResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(networkResource); err != nil {
return err
}
fmt.Fprintf(cli.out, "Network Id: %s\n", networkResource.ID)
fmt.Fprintf(cli.out, "Name: %s\n", networkResource.Name)
fmt.Fprintf(cli.out, "Type: %s\n", networkResource.Type)
if networkResource.Services != nil {
for _, serviceResource := range networkResource.Services {
fmt.Fprintf(cli.out, " Service Id: %s\n", serviceResource.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", serviceResource.Name)
}
}
return nil
}
|
go
|
func (cli *NetworkCli) CmdNetworkInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "NETWORK", "Displays detailed information on a network", false)
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
id, err := lookupNetworkID(cli, cmd.Arg(0))
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/networks/"+id, nil, nil))
if err != nil {
return err
}
networkResource := &networkResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(networkResource); err != nil {
return err
}
fmt.Fprintf(cli.out, "Network Id: %s\n", networkResource.ID)
fmt.Fprintf(cli.out, "Name: %s\n", networkResource.Name)
fmt.Fprintf(cli.out, "Type: %s\n", networkResource.Type)
if networkResource.Services != nil {
for _, serviceResource := range networkResource.Services {
fmt.Fprintf(cli.out, " Service Id: %s\n", serviceResource.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", serviceResource.Name)
}
}
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdNetworkInfo",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"info\"",
",",
"\"NETWORK\"",
",",
"\"Displays detailed information on a network\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"id",
",",
"err",
":=",
"lookupNetworkID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/networks/\"",
"+",
"id",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"networkResource",
":=",
"&",
"networkResource",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"obj",
")",
")",
".",
"Decode",
"(",
"networkResource",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"Network Id: %s\\n\"",
",",
"\\n",
")",
"\n",
"networkResource",
".",
"ID",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"Name: %s\\n\"",
",",
"\\n",
")",
"\n",
"networkResource",
".",
"Name",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"Type: %s\\n\"",
",",
"\\n",
")",
"\n",
"}"
] |
// CmdNetworkInfo handles Network Info UI
|
[
"CmdNetworkInfo",
"handles",
"Network",
"Info",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L175-L207
|
train
|
docker/libnetwork
|
client/network.go
|
lookupNetworkID
|
func lookupNetworkID(cli *NetworkCli, nameID string) (string, error) {
obj, statusCode, err := readBody(cli.call("GET", "/networks?name="+nameID, nil, nil))
if err != nil {
return "", err
}
if statusCode != http.StatusOK {
return "", fmt.Errorf("name query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj))
}
var list []*networkResource
err = json.Unmarshal(obj, &list)
if err != nil {
return "", err
}
if len(list) > 0 {
// name query filter will always return a single-element collection
return list[0].ID, nil
}
// Check for Partial-id
obj, statusCode, err = readBody(cli.call("GET", "/networks?partial-id="+nameID, nil, nil))
if err != nil {
return "", err
}
if statusCode != http.StatusOK {
return "", fmt.Errorf("partial-id match query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj))
}
err = json.Unmarshal(obj, &list)
if err != nil {
return "", err
}
if len(list) == 0 {
return "", fmt.Errorf("resource not found %s", nameID)
}
if len(list) > 1 {
return "", fmt.Errorf("multiple Networks matching the partial identifier (%s). Please use full identifier", nameID)
}
return list[0].ID, nil
}
|
go
|
func lookupNetworkID(cli *NetworkCli, nameID string) (string, error) {
obj, statusCode, err := readBody(cli.call("GET", "/networks?name="+nameID, nil, nil))
if err != nil {
return "", err
}
if statusCode != http.StatusOK {
return "", fmt.Errorf("name query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj))
}
var list []*networkResource
err = json.Unmarshal(obj, &list)
if err != nil {
return "", err
}
if len(list) > 0 {
// name query filter will always return a single-element collection
return list[0].ID, nil
}
// Check for Partial-id
obj, statusCode, err = readBody(cli.call("GET", "/networks?partial-id="+nameID, nil, nil))
if err != nil {
return "", err
}
if statusCode != http.StatusOK {
return "", fmt.Errorf("partial-id match query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj))
}
err = json.Unmarshal(obj, &list)
if err != nil {
return "", err
}
if len(list) == 0 {
return "", fmt.Errorf("resource not found %s", nameID)
}
if len(list) > 1 {
return "", fmt.Errorf("multiple Networks matching the partial identifier (%s). Please use full identifier", nameID)
}
return list[0].ID, nil
}
|
[
"func",
"lookupNetworkID",
"(",
"cli",
"*",
"NetworkCli",
",",
"nameID",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"obj",
",",
"statusCode",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/networks?name=\"",
"+",
"nameID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"statusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"name query failed for %s due to : statuscode(%d) %v\"",
",",
"nameID",
",",
"statusCode",
",",
"string",
"(",
"obj",
")",
")",
"\n",
"}",
"\n",
"var",
"list",
"[",
"]",
"*",
"networkResource",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"list",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"list",
")",
">",
"0",
"{",
"return",
"list",
"[",
"0",
"]",
".",
"ID",
",",
"nil",
"\n",
"}",
"\n",
"obj",
",",
"statusCode",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/networks?partial-id=\"",
"+",
"nameID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"statusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"partial-id match query failed for %s due to : statuscode(%d) %v\"",
",",
"nameID",
",",
"statusCode",
",",
"string",
"(",
"obj",
")",
")",
"\n",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"list",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"list",
")",
"==",
"0",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"resource not found %s\"",
",",
"nameID",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"list",
")",
">",
"1",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"multiple Networks matching the partial identifier (%s). Please use full identifier\"",
",",
"nameID",
")",
"\n",
"}",
"\n",
"return",
"list",
"[",
"0",
"]",
".",
"ID",
",",
"nil",
"\n",
"}"
] |
// Helper function to predict if a string is a name or id or partial-id
// This provides a best-effort mechanism to identify an id with the help of GET Filter APIs
// Being a UI, its most likely that name will be used by the user, which is used to lookup
// the corresponding ID. If ID is not found, this function will assume that the passed string
// is an ID by itself.
|
[
"Helper",
"function",
"to",
"predict",
"if",
"a",
"string",
"is",
"a",
"name",
"or",
"id",
"or",
"partial",
"-",
"id",
"This",
"provides",
"a",
"best",
"-",
"effort",
"mechanism",
"to",
"identify",
"an",
"id",
"with",
"the",
"help",
"of",
"GET",
"Filter",
"APIs",
"Being",
"a",
"UI",
"its",
"most",
"likely",
"that",
"name",
"will",
"be",
"used",
"by",
"the",
"user",
"which",
"is",
"used",
"to",
"lookup",
"the",
"corresponding",
"ID",
".",
"If",
"ID",
"is",
"not",
"found",
"this",
"function",
"will",
"assume",
"that",
"the",
"passed",
"string",
"is",
"an",
"ID",
"by",
"itself",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L215-L256
|
train
|
docker/libnetwork
|
drivers/ipvlan/ipvlan.go
|
Init
|
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
c := driverapi.Capability{
DataScope: datastore.LocalScope,
ConnectivityScope: datastore.GlobalScope,
}
d := &driver{
networks: networkTable{},
}
d.initStore(config)
return dc.RegisterDriver(ipvlanType, d, c)
}
|
go
|
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
c := driverapi.Capability{
DataScope: datastore.LocalScope,
ConnectivityScope: datastore.GlobalScope,
}
d := &driver{
networks: networkTable{},
}
d.initStore(config)
return dc.RegisterDriver(ipvlanType, d, c)
}
|
[
"func",
"Init",
"(",
"dc",
"driverapi",
".",
"DriverCallback",
",",
"config",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"c",
":=",
"driverapi",
".",
"Capability",
"{",
"DataScope",
":",
"datastore",
".",
"LocalScope",
",",
"ConnectivityScope",
":",
"datastore",
".",
"GlobalScope",
",",
"}",
"\n",
"d",
":=",
"&",
"driver",
"{",
"networks",
":",
"networkTable",
"{",
"}",
",",
"}",
"\n",
"d",
".",
"initStore",
"(",
"config",
")",
"\n",
"return",
"dc",
".",
"RegisterDriver",
"(",
"ipvlanType",
",",
"d",
",",
"c",
")",
"\n",
"}"
] |
// Init initializes and registers the libnetwork ipvlan driver
|
[
"Init",
"initializes",
"and",
"registers",
"the",
"libnetwork",
"ipvlan",
"driver"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan.go#L59-L70
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
DefaultConfig
|
func DefaultConfig() *Config {
hostname, _ := os.Hostname()
return &Config{
NodeID: stringid.TruncateID(stringid.GenerateRandomID()),
Hostname: hostname,
BindAddr: "0.0.0.0",
PacketBufferSize: 1400,
StatsPrintPeriod: 5 * time.Minute,
HealthPrintPeriod: 1 * time.Minute,
reapEntryInterval: 30 * time.Minute,
}
}
|
go
|
func DefaultConfig() *Config {
hostname, _ := os.Hostname()
return &Config{
NodeID: stringid.TruncateID(stringid.GenerateRandomID()),
Hostname: hostname,
BindAddr: "0.0.0.0",
PacketBufferSize: 1400,
StatsPrintPeriod: 5 * time.Minute,
HealthPrintPeriod: 1 * time.Minute,
reapEntryInterval: 30 * time.Minute,
}
}
|
[
"func",
"DefaultConfig",
"(",
")",
"*",
"Config",
"{",
"hostname",
",",
"_",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"return",
"&",
"Config",
"{",
"NodeID",
":",
"stringid",
".",
"TruncateID",
"(",
"stringid",
".",
"GenerateRandomID",
"(",
")",
")",
",",
"Hostname",
":",
"hostname",
",",
"BindAddr",
":",
"\"0.0.0.0\"",
",",
"PacketBufferSize",
":",
"1400",
",",
"StatsPrintPeriod",
":",
"5",
"*",
"time",
".",
"Minute",
",",
"HealthPrintPeriod",
":",
"1",
"*",
"time",
".",
"Minute",
",",
"reapEntryInterval",
":",
"30",
"*",
"time",
".",
"Minute",
",",
"}",
"\n",
"}"
] |
// DefaultConfig returns a NetworkDB config with default values
|
[
"DefaultConfig",
"returns",
"a",
"NetworkDB",
"config",
"with",
"default",
"values"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L225-L236
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
New
|
func New(c *Config) (*NetworkDB, error) {
// The garbage collection logic for entries leverage the presence of the network.
// For this reason the expiration time of the network is put slightly higher than the entry expiration so that
// there is at least 5 extra cycle to make sure that all the entries are properly deleted before deleting the network.
c.reapNetworkInterval = c.reapEntryInterval + 5*reapPeriod
nDB := &NetworkDB{
config: c,
indexes: make(map[int]*radix.Tree),
networks: make(map[string]map[string]*network),
nodes: make(map[string]*node),
failedNodes: make(map[string]*node),
leftNodes: make(map[string]*node),
networkNodes: make(map[string][]string),
bulkSyncAckTbl: make(map[string]chan struct{}),
broadcaster: events.NewBroadcaster(),
}
nDB.indexes[byTable] = radix.New()
nDB.indexes[byNetwork] = radix.New()
logrus.Infof("New memberlist node - Node:%v will use memberlist nodeID:%v with config:%+v", c.Hostname, c.NodeID, c)
if err := nDB.clusterInit(); err != nil {
return nil, err
}
return nDB, nil
}
|
go
|
func New(c *Config) (*NetworkDB, error) {
// The garbage collection logic for entries leverage the presence of the network.
// For this reason the expiration time of the network is put slightly higher than the entry expiration so that
// there is at least 5 extra cycle to make sure that all the entries are properly deleted before deleting the network.
c.reapNetworkInterval = c.reapEntryInterval + 5*reapPeriod
nDB := &NetworkDB{
config: c,
indexes: make(map[int]*radix.Tree),
networks: make(map[string]map[string]*network),
nodes: make(map[string]*node),
failedNodes: make(map[string]*node),
leftNodes: make(map[string]*node),
networkNodes: make(map[string][]string),
bulkSyncAckTbl: make(map[string]chan struct{}),
broadcaster: events.NewBroadcaster(),
}
nDB.indexes[byTable] = radix.New()
nDB.indexes[byNetwork] = radix.New()
logrus.Infof("New memberlist node - Node:%v will use memberlist nodeID:%v with config:%+v", c.Hostname, c.NodeID, c)
if err := nDB.clusterInit(); err != nil {
return nil, err
}
return nDB, nil
}
|
[
"func",
"New",
"(",
"c",
"*",
"Config",
")",
"(",
"*",
"NetworkDB",
",",
"error",
")",
"{",
"c",
".",
"reapNetworkInterval",
"=",
"c",
".",
"reapEntryInterval",
"+",
"5",
"*",
"reapPeriod",
"\n",
"nDB",
":=",
"&",
"NetworkDB",
"{",
"config",
":",
"c",
",",
"indexes",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"radix",
".",
"Tree",
")",
",",
"networks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"network",
")",
",",
"nodes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"node",
")",
",",
"failedNodes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"node",
")",
",",
"leftNodes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"node",
")",
",",
"networkNodes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
",",
"bulkSyncAckTbl",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"chan",
"struct",
"{",
"}",
")",
",",
"broadcaster",
":",
"events",
".",
"NewBroadcaster",
"(",
")",
",",
"}",
"\n",
"nDB",
".",
"indexes",
"[",
"byTable",
"]",
"=",
"radix",
".",
"New",
"(",
")",
"\n",
"nDB",
".",
"indexes",
"[",
"byNetwork",
"]",
"=",
"radix",
".",
"New",
"(",
")",
"\n",
"logrus",
".",
"Infof",
"(",
"\"New memberlist node - Node:%v will use memberlist nodeID:%v with config:%+v\"",
",",
"c",
".",
"Hostname",
",",
"c",
".",
"NodeID",
",",
"c",
")",
"\n",
"if",
"err",
":=",
"nDB",
".",
"clusterInit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nDB",
",",
"nil",
"\n",
"}"
] |
// New creates a new instance of NetworkDB using the Config passed by
// the caller.
|
[
"New",
"creates",
"a",
"new",
"instance",
"of",
"NetworkDB",
"using",
"the",
"Config",
"passed",
"by",
"the",
"caller",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L240-L267
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
Close
|
func (nDB *NetworkDB) Close() {
if err := nDB.clusterLeave(); err != nil {
logrus.Errorf("%v(%v) Could not close DB: %v", nDB.config.Hostname, nDB.config.NodeID, err)
}
//Avoid (*Broadcaster).run goroutine leak
nDB.broadcaster.Close()
}
|
go
|
func (nDB *NetworkDB) Close() {
if err := nDB.clusterLeave(); err != nil {
logrus.Errorf("%v(%v) Could not close DB: %v", nDB.config.Hostname, nDB.config.NodeID, err)
}
//Avoid (*Broadcaster).run goroutine leak
nDB.broadcaster.Close()
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"Close",
"(",
")",
"{",
"if",
"err",
":=",
"nDB",
".",
"clusterLeave",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"%v(%v) Could not close DB: %v\"",
",",
"nDB",
".",
"config",
".",
"Hostname",
",",
"nDB",
".",
"config",
".",
"NodeID",
",",
"err",
")",
"\n",
"}",
"\n",
"nDB",
".",
"broadcaster",
".",
"Close",
"(",
")",
"\n",
"}"
] |
// Close destroys this NetworkDB instance by leave the cluster,
// stopping timers, canceling goroutines etc.
|
[
"Close",
"destroys",
"this",
"NetworkDB",
"instance",
"by",
"leave",
"the",
"cluster",
"stopping",
"timers",
"canceling",
"goroutines",
"etc",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L281-L288
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
ClusterPeers
|
func (nDB *NetworkDB) ClusterPeers() []PeerInfo {
nDB.RLock()
defer nDB.RUnlock()
peers := make([]PeerInfo, 0, len(nDB.nodes))
for _, node := range nDB.nodes {
peers = append(peers, PeerInfo{
Name: node.Name,
IP: node.Node.Addr.String(),
})
}
return peers
}
|
go
|
func (nDB *NetworkDB) ClusterPeers() []PeerInfo {
nDB.RLock()
defer nDB.RUnlock()
peers := make([]PeerInfo, 0, len(nDB.nodes))
for _, node := range nDB.nodes {
peers = append(peers, PeerInfo{
Name: node.Name,
IP: node.Node.Addr.String(),
})
}
return peers
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"ClusterPeers",
"(",
")",
"[",
"]",
"PeerInfo",
"{",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"peers",
":=",
"make",
"(",
"[",
"]",
"PeerInfo",
",",
"0",
",",
"len",
"(",
"nDB",
".",
"nodes",
")",
")",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nDB",
".",
"nodes",
"{",
"peers",
"=",
"append",
"(",
"peers",
",",
"PeerInfo",
"{",
"Name",
":",
"node",
".",
"Name",
",",
"IP",
":",
"node",
".",
"Node",
".",
"Addr",
".",
"String",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"peers",
"\n",
"}"
] |
// ClusterPeers returns all the gossip cluster peers.
|
[
"ClusterPeers",
"returns",
"all",
"the",
"gossip",
"cluster",
"peers",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L291-L302
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
Peers
|
func (nDB *NetworkDB) Peers(nid string) []PeerInfo {
nDB.RLock()
defer nDB.RUnlock()
peers := make([]PeerInfo, 0, len(nDB.networkNodes[nid]))
for _, nodeName := range nDB.networkNodes[nid] {
if node, ok := nDB.nodes[nodeName]; ok {
peers = append(peers, PeerInfo{
Name: node.Name,
IP: node.Addr.String(),
})
} else {
// Added for testing purposes, this condition should never happen else mean that the network list
// is out of sync with the node list
peers = append(peers, PeerInfo{Name: nodeName, IP: "unknown"})
}
}
return peers
}
|
go
|
func (nDB *NetworkDB) Peers(nid string) []PeerInfo {
nDB.RLock()
defer nDB.RUnlock()
peers := make([]PeerInfo, 0, len(nDB.networkNodes[nid]))
for _, nodeName := range nDB.networkNodes[nid] {
if node, ok := nDB.nodes[nodeName]; ok {
peers = append(peers, PeerInfo{
Name: node.Name,
IP: node.Addr.String(),
})
} else {
// Added for testing purposes, this condition should never happen else mean that the network list
// is out of sync with the node list
peers = append(peers, PeerInfo{Name: nodeName, IP: "unknown"})
}
}
return peers
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"Peers",
"(",
"nid",
"string",
")",
"[",
"]",
"PeerInfo",
"{",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"peers",
":=",
"make",
"(",
"[",
"]",
"PeerInfo",
",",
"0",
",",
"len",
"(",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
")",
")",
"\n",
"for",
"_",
",",
"nodeName",
":=",
"range",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"{",
"if",
"node",
",",
"ok",
":=",
"nDB",
".",
"nodes",
"[",
"nodeName",
"]",
";",
"ok",
"{",
"peers",
"=",
"append",
"(",
"peers",
",",
"PeerInfo",
"{",
"Name",
":",
"node",
".",
"Name",
",",
"IP",
":",
"node",
".",
"Addr",
".",
"String",
"(",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"peers",
"=",
"append",
"(",
"peers",
",",
"PeerInfo",
"{",
"Name",
":",
"nodeName",
",",
"IP",
":",
"\"unknown\"",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"peers",
"\n",
"}"
] |
// Peers returns the gossip peers for a given network.
|
[
"Peers",
"returns",
"the",
"gossip",
"peers",
"for",
"a",
"given",
"network",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L305-L322
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
GetTableByNetwork
|
func (nDB *NetworkDB) GetTableByNetwork(tname, nid string) map[string]*TableElem {
entries := make(map[string]*TableElem)
nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s/%s", tname, nid), func(k string, v interface{}) bool {
entry := v.(*entry)
if entry.deleting {
return false
}
key := k[strings.LastIndex(k, "/")+1:]
entries[key] = &TableElem{Value: entry.value, owner: entry.node}
return false
})
return entries
}
|
go
|
func (nDB *NetworkDB) GetTableByNetwork(tname, nid string) map[string]*TableElem {
entries := make(map[string]*TableElem)
nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s/%s", tname, nid), func(k string, v interface{}) bool {
entry := v.(*entry)
if entry.deleting {
return false
}
key := k[strings.LastIndex(k, "/")+1:]
entries[key] = &TableElem{Value: entry.value, owner: entry.node}
return false
})
return entries
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"GetTableByNetwork",
"(",
"tname",
",",
"nid",
"string",
")",
"map",
"[",
"string",
"]",
"*",
"TableElem",
"{",
"entries",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"TableElem",
")",
"\n",
"nDB",
".",
"indexes",
"[",
"byTable",
"]",
".",
"WalkPrefix",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"/%s/%s\"",
",",
"tname",
",",
"nid",
")",
",",
"func",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"entry",
":=",
"v",
".",
"(",
"*",
"entry",
")",
"\n",
"if",
"entry",
".",
"deleting",
"{",
"return",
"false",
"\n",
"}",
"\n",
"key",
":=",
"k",
"[",
"strings",
".",
"LastIndex",
"(",
"k",
",",
"\"/\"",
")",
"+",
"1",
":",
"]",
"\n",
"entries",
"[",
"key",
"]",
"=",
"&",
"TableElem",
"{",
"Value",
":",
"entry",
".",
"value",
",",
"owner",
":",
"entry",
".",
"node",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"entries",
"\n",
"}"
] |
// GetTableByNetwork walks the networkdb by the give table and network id and
// returns a map of keys and values
|
[
"GetTableByNetwork",
"walks",
"the",
"networkdb",
"by",
"the",
"give",
"table",
"and",
"network",
"id",
"and",
"returns",
"a",
"map",
"of",
"keys",
"and",
"values"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L413-L425
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
WalkTable
|
func (nDB *NetworkDB) WalkTable(tname string, fn func(string, string, []byte, bool) bool) error {
nDB.RLock()
values := make(map[string]interface{})
nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s", tname), func(path string, v interface{}) bool {
values[path] = v
return false
})
nDB.RUnlock()
for k, v := range values {
params := strings.Split(k[1:], "/")
nid := params[1]
key := params[2]
if fn(nid, key, v.(*entry).value, v.(*entry).deleting) {
return nil
}
}
return nil
}
|
go
|
func (nDB *NetworkDB) WalkTable(tname string, fn func(string, string, []byte, bool) bool) error {
nDB.RLock()
values := make(map[string]interface{})
nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s", tname), func(path string, v interface{}) bool {
values[path] = v
return false
})
nDB.RUnlock()
for k, v := range values {
params := strings.Split(k[1:], "/")
nid := params[1]
key := params[2]
if fn(nid, key, v.(*entry).value, v.(*entry).deleting) {
return nil
}
}
return nil
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"WalkTable",
"(",
"tname",
"string",
",",
"fn",
"func",
"(",
"string",
",",
"string",
",",
"[",
"]",
"byte",
",",
"bool",
")",
"bool",
")",
"error",
"{",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"values",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"nDB",
".",
"indexes",
"[",
"byTable",
"]",
".",
"WalkPrefix",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"/%s\"",
",",
"tname",
")",
",",
"func",
"(",
"path",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"values",
"[",
"path",
"]",
"=",
"v",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"values",
"{",
"params",
":=",
"strings",
".",
"Split",
"(",
"k",
"[",
"1",
":",
"]",
",",
"\"/\"",
")",
"\n",
"nid",
":=",
"params",
"[",
"1",
"]",
"\n",
"key",
":=",
"params",
"[",
"2",
"]",
"\n",
"if",
"fn",
"(",
"nid",
",",
"key",
",",
"v",
".",
"(",
"*",
"entry",
")",
".",
"value",
",",
"v",
".",
"(",
"*",
"entry",
")",
".",
"deleting",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// WalkTable walks a single table in NetworkDB and invokes the passed
// function for each entry in the table passing the network, key,
// value. The walk stops if the passed function returns a true.
|
[
"WalkTable",
"walks",
"a",
"single",
"table",
"in",
"NetworkDB",
"and",
"invokes",
"the",
"passed",
"function",
"for",
"each",
"entry",
"in",
"the",
"table",
"passing",
"the",
"network",
"key",
"value",
".",
"The",
"walk",
"stops",
"if",
"the",
"passed",
"function",
"returns",
"a",
"true",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L569-L588
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
JoinNetwork
|
func (nDB *NetworkDB) JoinNetwork(nid string) error {
ltime := nDB.networkClock.Increment()
nDB.Lock()
nodeNetworks, ok := nDB.networks[nDB.config.NodeID]
if !ok {
nodeNetworks = make(map[string]*network)
nDB.networks[nDB.config.NodeID] = nodeNetworks
}
n, ok := nodeNetworks[nid]
var entries int
if ok {
entries = n.entriesNumber
}
nodeNetworks[nid] = &network{id: nid, ltime: ltime, entriesNumber: entries}
nodeNetworks[nid].tableBroadcasts = &memberlist.TransmitLimitedQueue{
NumNodes: func() int {
//TODO fcrisciani this can be optimized maybe avoiding the lock?
// this call is done each GetBroadcasts call to evaluate the number of
// replicas for the message
nDB.RLock()
defer nDB.RUnlock()
return len(nDB.networkNodes[nid])
},
RetransmitMult: 4,
}
nDB.addNetworkNode(nid, nDB.config.NodeID)
networkNodes := nDB.networkNodes[nid]
n = nodeNetworks[nid]
nDB.Unlock()
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeJoin, ltime); err != nil {
return fmt.Errorf("failed to send leave network event for %s: %v", nid, err)
}
logrus.Debugf("%v(%v): joined network %s", nDB.config.Hostname, nDB.config.NodeID, nid)
if _, err := nDB.bulkSync(networkNodes, true); err != nil {
logrus.Errorf("Error bulk syncing while joining network %s: %v", nid, err)
}
// Mark the network as being synced
// note this is a best effort, we are not checking the result of the bulk sync
nDB.Lock()
n.inSync = true
nDB.Unlock()
return nil
}
|
go
|
func (nDB *NetworkDB) JoinNetwork(nid string) error {
ltime := nDB.networkClock.Increment()
nDB.Lock()
nodeNetworks, ok := nDB.networks[nDB.config.NodeID]
if !ok {
nodeNetworks = make(map[string]*network)
nDB.networks[nDB.config.NodeID] = nodeNetworks
}
n, ok := nodeNetworks[nid]
var entries int
if ok {
entries = n.entriesNumber
}
nodeNetworks[nid] = &network{id: nid, ltime: ltime, entriesNumber: entries}
nodeNetworks[nid].tableBroadcasts = &memberlist.TransmitLimitedQueue{
NumNodes: func() int {
//TODO fcrisciani this can be optimized maybe avoiding the lock?
// this call is done each GetBroadcasts call to evaluate the number of
// replicas for the message
nDB.RLock()
defer nDB.RUnlock()
return len(nDB.networkNodes[nid])
},
RetransmitMult: 4,
}
nDB.addNetworkNode(nid, nDB.config.NodeID)
networkNodes := nDB.networkNodes[nid]
n = nodeNetworks[nid]
nDB.Unlock()
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeJoin, ltime); err != nil {
return fmt.Errorf("failed to send leave network event for %s: %v", nid, err)
}
logrus.Debugf("%v(%v): joined network %s", nDB.config.Hostname, nDB.config.NodeID, nid)
if _, err := nDB.bulkSync(networkNodes, true); err != nil {
logrus.Errorf("Error bulk syncing while joining network %s: %v", nid, err)
}
// Mark the network as being synced
// note this is a best effort, we are not checking the result of the bulk sync
nDB.Lock()
n.inSync = true
nDB.Unlock()
return nil
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"JoinNetwork",
"(",
"nid",
"string",
")",
"error",
"{",
"ltime",
":=",
"nDB",
".",
"networkClock",
".",
"Increment",
"(",
")",
"\n",
"nDB",
".",
"Lock",
"(",
")",
"\n",
"nodeNetworks",
",",
"ok",
":=",
"nDB",
".",
"networks",
"[",
"nDB",
".",
"config",
".",
"NodeID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"nodeNetworks",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"network",
")",
"\n",
"nDB",
".",
"networks",
"[",
"nDB",
".",
"config",
".",
"NodeID",
"]",
"=",
"nodeNetworks",
"\n",
"}",
"\n",
"n",
",",
"ok",
":=",
"nodeNetworks",
"[",
"nid",
"]",
"\n",
"var",
"entries",
"int",
"\n",
"if",
"ok",
"{",
"entries",
"=",
"n",
".",
"entriesNumber",
"\n",
"}",
"\n",
"nodeNetworks",
"[",
"nid",
"]",
"=",
"&",
"network",
"{",
"id",
":",
"nid",
",",
"ltime",
":",
"ltime",
",",
"entriesNumber",
":",
"entries",
"}",
"\n",
"nodeNetworks",
"[",
"nid",
"]",
".",
"tableBroadcasts",
"=",
"&",
"memberlist",
".",
"TransmitLimitedQueue",
"{",
"NumNodes",
":",
"func",
"(",
")",
"int",
"{",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
")",
"\n",
"}",
",",
"RetransmitMult",
":",
"4",
",",
"}",
"\n",
"nDB",
".",
"addNetworkNode",
"(",
"nid",
",",
"nDB",
".",
"config",
".",
"NodeID",
")",
"\n",
"networkNodes",
":=",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"\n",
"n",
"=",
"nodeNetworks",
"[",
"nid",
"]",
"\n",
"nDB",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"nDB",
".",
"sendNetworkEvent",
"(",
"nid",
",",
"NetworkEventTypeJoin",
",",
"ltime",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to send leave network event for %s: %v\"",
",",
"nid",
",",
"err",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"%v(%v): joined network %s\"",
",",
"nDB",
".",
"config",
".",
"Hostname",
",",
"nDB",
".",
"config",
".",
"NodeID",
",",
"nid",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"nDB",
".",
"bulkSync",
"(",
"networkNodes",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"Error bulk syncing while joining network %s: %v\"",
",",
"nid",
",",
"err",
")",
"\n",
"}",
"\n",
"nDB",
".",
"Lock",
"(",
")",
"\n",
"n",
".",
"inSync",
"=",
"true",
"\n",
"nDB",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// JoinNetwork joins this node to a given network and propagates this
// event across the cluster. This triggers this node joining the
// sub-cluster of this network and participates in the network-scoped
// gossip and bulk sync for this network.
|
[
"JoinNetwork",
"joins",
"this",
"node",
"to",
"a",
"given",
"network",
"and",
"propagates",
"this",
"event",
"across",
"the",
"cluster",
".",
"This",
"triggers",
"this",
"node",
"joining",
"the",
"sub",
"-",
"cluster",
"of",
"this",
"network",
"and",
"participates",
"in",
"the",
"network",
"-",
"scoped",
"gossip",
"and",
"bulk",
"sync",
"for",
"this",
"network",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L594-L641
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
LeaveNetwork
|
func (nDB *NetworkDB) LeaveNetwork(nid string) error {
ltime := nDB.networkClock.Increment()
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil {
return fmt.Errorf("failed to send leave network event for %s: %v", nid, err)
}
nDB.Lock()
defer nDB.Unlock()
// Remove myself from the list of the nodes participating to the network
nDB.deleteNetworkNode(nid, nDB.config.NodeID)
// Update all the local entries marking them for deletion and delete all the remote entries
nDB.deleteNodeNetworkEntries(nid, nDB.config.NodeID)
nodeNetworks, ok := nDB.networks[nDB.config.NodeID]
if !ok {
return fmt.Errorf("could not find self node for network %s while trying to leave", nid)
}
n, ok := nodeNetworks[nid]
if !ok {
return fmt.Errorf("could not find network %s while trying to leave", nid)
}
logrus.Debugf("%v(%v): leaving network %s", nDB.config.Hostname, nDB.config.NodeID, nid)
n.ltime = ltime
n.reapTime = nDB.config.reapNetworkInterval
n.leaving = true
return nil
}
|
go
|
func (nDB *NetworkDB) LeaveNetwork(nid string) error {
ltime := nDB.networkClock.Increment()
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil {
return fmt.Errorf("failed to send leave network event for %s: %v", nid, err)
}
nDB.Lock()
defer nDB.Unlock()
// Remove myself from the list of the nodes participating to the network
nDB.deleteNetworkNode(nid, nDB.config.NodeID)
// Update all the local entries marking them for deletion and delete all the remote entries
nDB.deleteNodeNetworkEntries(nid, nDB.config.NodeID)
nodeNetworks, ok := nDB.networks[nDB.config.NodeID]
if !ok {
return fmt.Errorf("could not find self node for network %s while trying to leave", nid)
}
n, ok := nodeNetworks[nid]
if !ok {
return fmt.Errorf("could not find network %s while trying to leave", nid)
}
logrus.Debugf("%v(%v): leaving network %s", nDB.config.Hostname, nDB.config.NodeID, nid)
n.ltime = ltime
n.reapTime = nDB.config.reapNetworkInterval
n.leaving = true
return nil
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"LeaveNetwork",
"(",
"nid",
"string",
")",
"error",
"{",
"ltime",
":=",
"nDB",
".",
"networkClock",
".",
"Increment",
"(",
")",
"\n",
"if",
"err",
":=",
"nDB",
".",
"sendNetworkEvent",
"(",
"nid",
",",
"NetworkEventTypeLeave",
",",
"ltime",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to send leave network event for %s: %v\"",
",",
"nid",
",",
"err",
")",
"\n",
"}",
"\n",
"nDB",
".",
"Lock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"Unlock",
"(",
")",
"\n",
"nDB",
".",
"deleteNetworkNode",
"(",
"nid",
",",
"nDB",
".",
"config",
".",
"NodeID",
")",
"\n",
"nDB",
".",
"deleteNodeNetworkEntries",
"(",
"nid",
",",
"nDB",
".",
"config",
".",
"NodeID",
")",
"\n",
"nodeNetworks",
",",
"ok",
":=",
"nDB",
".",
"networks",
"[",
"nDB",
".",
"config",
".",
"NodeID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"could not find self node for network %s while trying to leave\"",
",",
"nid",
")",
"\n",
"}",
"\n",
"n",
",",
"ok",
":=",
"nodeNetworks",
"[",
"nid",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"could not find network %s while trying to leave\"",
",",
"nid",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"%v(%v): leaving network %s\"",
",",
"nDB",
".",
"config",
".",
"Hostname",
",",
"nDB",
".",
"config",
".",
"NodeID",
",",
"nid",
")",
"\n",
"n",
".",
"ltime",
"=",
"ltime",
"\n",
"n",
".",
"reapTime",
"=",
"nDB",
".",
"config",
".",
"reapNetworkInterval",
"\n",
"n",
".",
"leaving",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// LeaveNetwork leaves this node from a given network and propagates
// this event across the cluster. This triggers this node leaving the
// sub-cluster of this network and as a result will no longer
// participate in the network-scoped gossip and bulk sync for this
// network. Also remove all the table entries for this network from
// networkdb
|
[
"LeaveNetwork",
"leaves",
"this",
"node",
"from",
"a",
"given",
"network",
"and",
"propagates",
"this",
"event",
"across",
"the",
"cluster",
".",
"This",
"triggers",
"this",
"node",
"leaving",
"the",
"sub",
"-",
"cluster",
"of",
"this",
"network",
"and",
"as",
"a",
"result",
"will",
"no",
"longer",
"participate",
"in",
"the",
"network",
"-",
"scoped",
"gossip",
"and",
"bulk",
"sync",
"for",
"this",
"network",
".",
"Also",
"remove",
"all",
"the",
"table",
"entries",
"for",
"this",
"network",
"from",
"networkdb"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L649-L679
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
addNetworkNode
|
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) {
nodes := nDB.networkNodes[nid]
for _, node := range nodes {
if node == nodeName {
return
}
}
nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName)
}
|
go
|
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) {
nodes := nDB.networkNodes[nid]
for _, node := range nodes {
if node == nodeName {
return
}
}
nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName)
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"addNetworkNode",
"(",
"nid",
"string",
",",
"nodeName",
"string",
")",
"{",
"nodes",
":=",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"if",
"node",
"==",
"nodeName",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"=",
"append",
"(",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
",",
"nodeName",
")",
"\n",
"}"
] |
// addNetworkNode adds the node to the list of nodes which participate
// in the passed network only if it is not already present. Caller
// should hold the NetworkDB lock while calling this
|
[
"addNetworkNode",
"adds",
"the",
"node",
"to",
"the",
"list",
"of",
"nodes",
"which",
"participate",
"in",
"the",
"passed",
"network",
"only",
"if",
"it",
"is",
"not",
"already",
"present",
".",
"Caller",
"should",
"hold",
"the",
"NetworkDB",
"lock",
"while",
"calling",
"this"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L684-L693
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
deleteNetworkNode
|
func (nDB *NetworkDB) deleteNetworkNode(nid string, nodeName string) {
nodes, ok := nDB.networkNodes[nid]
if !ok || len(nodes) == 0 {
return
}
newNodes := make([]string, 0, len(nodes)-1)
for _, name := range nodes {
if name == nodeName {
continue
}
newNodes = append(newNodes, name)
}
nDB.networkNodes[nid] = newNodes
}
|
go
|
func (nDB *NetworkDB) deleteNetworkNode(nid string, nodeName string) {
nodes, ok := nDB.networkNodes[nid]
if !ok || len(nodes) == 0 {
return
}
newNodes := make([]string, 0, len(nodes)-1)
for _, name := range nodes {
if name == nodeName {
continue
}
newNodes = append(newNodes, name)
}
nDB.networkNodes[nid] = newNodes
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"deleteNetworkNode",
"(",
"nid",
"string",
",",
"nodeName",
"string",
")",
"{",
"nodes",
",",
"ok",
":=",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"nodes",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"newNodes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"nodes",
")",
"-",
"1",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"nodes",
"{",
"if",
"name",
"==",
"nodeName",
"{",
"continue",
"\n",
"}",
"\n",
"newNodes",
"=",
"append",
"(",
"newNodes",
",",
"name",
")",
"\n",
"}",
"\n",
"nDB",
".",
"networkNodes",
"[",
"nid",
"]",
"=",
"newNodes",
"\n",
"}"
] |
// Deletes the node from the list of nodes which participate in the
// passed network. Caller should hold the NetworkDB lock while calling
// this
|
[
"Deletes",
"the",
"node",
"from",
"the",
"list",
"of",
"nodes",
"which",
"participate",
"in",
"the",
"passed",
"network",
".",
"Caller",
"should",
"hold",
"the",
"NetworkDB",
"lock",
"while",
"calling",
"this"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L698-L711
|
train
|
docker/libnetwork
|
networkdb/networkdb.go
|
findCommonNetworks
|
func (nDB *NetworkDB) findCommonNetworks(nodeName string) []string {
nDB.RLock()
defer nDB.RUnlock()
var networks []string
for nid := range nDB.networks[nDB.config.NodeID] {
if n, ok := nDB.networks[nodeName][nid]; ok {
if !n.leaving {
networks = append(networks, nid)
}
}
}
return networks
}
|
go
|
func (nDB *NetworkDB) findCommonNetworks(nodeName string) []string {
nDB.RLock()
defer nDB.RUnlock()
var networks []string
for nid := range nDB.networks[nDB.config.NodeID] {
if n, ok := nDB.networks[nodeName][nid]; ok {
if !n.leaving {
networks = append(networks, nid)
}
}
}
return networks
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"findCommonNetworks",
"(",
"nodeName",
"string",
")",
"[",
"]",
"string",
"{",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"networks",
"[",
"]",
"string",
"\n",
"for",
"nid",
":=",
"range",
"nDB",
".",
"networks",
"[",
"nDB",
".",
"config",
".",
"NodeID",
"]",
"{",
"if",
"n",
",",
"ok",
":=",
"nDB",
".",
"networks",
"[",
"nodeName",
"]",
"[",
"nid",
"]",
";",
"ok",
"{",
"if",
"!",
"n",
".",
"leaving",
"{",
"networks",
"=",
"append",
"(",
"networks",
",",
"nid",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"networks",
"\n",
"}"
] |
// findCommonnetworks find the networks that both this node and the
// passed node have joined.
|
[
"findCommonnetworks",
"find",
"the",
"networks",
"that",
"both",
"this",
"node",
"and",
"the",
"passed",
"node",
"have",
"joined",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L715-L729
|
train
|
docker/libnetwork
|
networkdb/cluster.go
|
SetKey
|
func (nDB *NetworkDB) SetKey(key []byte) {
logrus.Debugf("Adding key %.5s", hex.EncodeToString(key))
nDB.Lock()
defer nDB.Unlock()
for _, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
return
}
}
nDB.config.Keys = append(nDB.config.Keys, key)
if nDB.keyring != nil {
nDB.keyring.AddKey(key)
}
}
|
go
|
func (nDB *NetworkDB) SetKey(key []byte) {
logrus.Debugf("Adding key %.5s", hex.EncodeToString(key))
nDB.Lock()
defer nDB.Unlock()
for _, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
return
}
}
nDB.config.Keys = append(nDB.config.Keys, key)
if nDB.keyring != nil {
nDB.keyring.AddKey(key)
}
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"SetKey",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"Adding key %.5s\"",
",",
"hex",
".",
"EncodeToString",
"(",
"key",
")",
")",
"\n",
"nDB",
".",
"Lock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"dbKey",
":=",
"range",
"nDB",
".",
"config",
".",
"Keys",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"key",
",",
"dbKey",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"nDB",
".",
"config",
".",
"Keys",
"=",
"append",
"(",
"nDB",
".",
"config",
".",
"Keys",
",",
"key",
")",
"\n",
"if",
"nDB",
".",
"keyring",
"!=",
"nil",
"{",
"nDB",
".",
"keyring",
".",
"AddKey",
"(",
"key",
")",
"\n",
"}",
"\n",
"}"
] |
// SetKey adds a new key to the key ring
|
[
"SetKey",
"adds",
"a",
"new",
"key",
"to",
"the",
"key",
"ring"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L57-L70
|
train
|
docker/libnetwork
|
networkdb/cluster.go
|
SetPrimaryKey
|
func (nDB *NetworkDB) SetPrimaryKey(key []byte) {
logrus.Debugf("Primary Key %.5s", hex.EncodeToString(key))
nDB.RLock()
defer nDB.RUnlock()
for _, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
if nDB.keyring != nil {
nDB.keyring.UseKey(dbKey)
}
break
}
}
}
|
go
|
func (nDB *NetworkDB) SetPrimaryKey(key []byte) {
logrus.Debugf("Primary Key %.5s", hex.EncodeToString(key))
nDB.RLock()
defer nDB.RUnlock()
for _, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
if nDB.keyring != nil {
nDB.keyring.UseKey(dbKey)
}
break
}
}
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"SetPrimaryKey",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"Primary Key %.5s\"",
",",
"hex",
".",
"EncodeToString",
"(",
"key",
")",
")",
"\n",
"nDB",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"dbKey",
":=",
"range",
"nDB",
".",
"config",
".",
"Keys",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"key",
",",
"dbKey",
")",
"{",
"if",
"nDB",
".",
"keyring",
"!=",
"nil",
"{",
"nDB",
".",
"keyring",
".",
"UseKey",
"(",
"dbKey",
")",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// SetPrimaryKey sets the given key as the primary key. This should have
// been added apriori through SetKey
|
[
"SetPrimaryKey",
"sets",
"the",
"given",
"key",
"as",
"the",
"primary",
"key",
".",
"This",
"should",
"have",
"been",
"added",
"apriori",
"through",
"SetKey"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L74-L86
|
train
|
docker/libnetwork
|
networkdb/cluster.go
|
RemoveKey
|
func (nDB *NetworkDB) RemoveKey(key []byte) {
logrus.Debugf("Remove Key %.5s", hex.EncodeToString(key))
nDB.Lock()
defer nDB.Unlock()
for i, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
nDB.config.Keys = append(nDB.config.Keys[:i], nDB.config.Keys[i+1:]...)
if nDB.keyring != nil {
nDB.keyring.RemoveKey(dbKey)
}
break
}
}
}
|
go
|
func (nDB *NetworkDB) RemoveKey(key []byte) {
logrus.Debugf("Remove Key %.5s", hex.EncodeToString(key))
nDB.Lock()
defer nDB.Unlock()
for i, dbKey := range nDB.config.Keys {
if bytes.Equal(key, dbKey) {
nDB.config.Keys = append(nDB.config.Keys[:i], nDB.config.Keys[i+1:]...)
if nDB.keyring != nil {
nDB.keyring.RemoveKey(dbKey)
}
break
}
}
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"RemoveKey",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"Remove Key %.5s\"",
",",
"hex",
".",
"EncodeToString",
"(",
"key",
")",
")",
"\n",
"nDB",
".",
"Lock",
"(",
")",
"\n",
"defer",
"nDB",
".",
"Unlock",
"(",
")",
"\n",
"for",
"i",
",",
"dbKey",
":=",
"range",
"nDB",
".",
"config",
".",
"Keys",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"key",
",",
"dbKey",
")",
"{",
"nDB",
".",
"config",
".",
"Keys",
"=",
"append",
"(",
"nDB",
".",
"config",
".",
"Keys",
"[",
":",
"i",
"]",
",",
"nDB",
".",
"config",
".",
"Keys",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"if",
"nDB",
".",
"keyring",
"!=",
"nil",
"{",
"nDB",
".",
"keyring",
".",
"RemoveKey",
"(",
"dbKey",
")",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// RemoveKey removes a key from the key ring. The key being removed
// can't be the primary key
|
[
"RemoveKey",
"removes",
"a",
"key",
"from",
"the",
"key",
"ring",
".",
"The",
"key",
"being",
"removed",
"can",
"t",
"be",
"the",
"primary",
"key"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L90-L103
|
train
|
docker/libnetwork
|
networkdb/cluster.go
|
mRandomNodes
|
func (nDB *NetworkDB) mRandomNodes(m int, nodes []string) []string {
n := len(nodes)
mNodes := make([]string, 0, m)
OUTER:
// Probe up to 3*n times, with large n this is not necessary
// since k << n, but with small n we want search to be
// exhaustive
for i := 0; i < 3*n && len(mNodes) < m; i++ {
// Get random node
idx := randomOffset(n)
node := nodes[idx]
if node == nDB.config.NodeID {
continue
}
// Check if we have this node already
for j := 0; j < len(mNodes); j++ {
if node == mNodes[j] {
continue OUTER
}
}
// Append the node
mNodes = append(mNodes, node)
}
return mNodes
}
|
go
|
func (nDB *NetworkDB) mRandomNodes(m int, nodes []string) []string {
n := len(nodes)
mNodes := make([]string, 0, m)
OUTER:
// Probe up to 3*n times, with large n this is not necessary
// since k << n, but with small n we want search to be
// exhaustive
for i := 0; i < 3*n && len(mNodes) < m; i++ {
// Get random node
idx := randomOffset(n)
node := nodes[idx]
if node == nDB.config.NodeID {
continue
}
// Check if we have this node already
for j := 0; j < len(mNodes); j++ {
if node == mNodes[j] {
continue OUTER
}
}
// Append the node
mNodes = append(mNodes, node)
}
return mNodes
}
|
[
"func",
"(",
"nDB",
"*",
"NetworkDB",
")",
"mRandomNodes",
"(",
"m",
"int",
",",
"nodes",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"n",
":=",
"len",
"(",
"nodes",
")",
"\n",
"mNodes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"m",
")",
"\n",
"OUTER",
":",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"3",
"*",
"n",
"&&",
"len",
"(",
"mNodes",
")",
"<",
"m",
";",
"i",
"++",
"{",
"idx",
":=",
"randomOffset",
"(",
"n",
")",
"\n",
"node",
":=",
"nodes",
"[",
"idx",
"]",
"\n",
"if",
"node",
"==",
"nDB",
".",
"config",
".",
"NodeID",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"len",
"(",
"mNodes",
")",
";",
"j",
"++",
"{",
"if",
"node",
"==",
"mNodes",
"[",
"j",
"]",
"{",
"continue",
"OUTER",
"\n",
"}",
"\n",
"}",
"\n",
"mNodes",
"=",
"append",
"(",
"mNodes",
",",
"node",
")",
"\n",
"}",
"\n",
"return",
"mNodes",
"\n",
"}"
] |
// mRandomNodes is used to select up to m random nodes. It is possible
// that less than m nodes are returned.
|
[
"mRandomNodes",
"is",
"used",
"to",
"select",
"up",
"to",
"m",
"random",
"nodes",
".",
"It",
"is",
"possible",
"that",
"less",
"than",
"m",
"nodes",
"are",
"returned",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L733-L761
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
New
|
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg plugingetter.PluginGetter) (*DrvRegistry, error) {
r := &DrvRegistry{
drivers: make(driverTable),
ipamDrivers: make(ipamTable),
dfn: dfn,
ifn: ifn,
pluginGetter: pg,
}
return r, nil
}
|
go
|
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg plugingetter.PluginGetter) (*DrvRegistry, error) {
r := &DrvRegistry{
drivers: make(driverTable),
ipamDrivers: make(ipamTable),
dfn: dfn,
ifn: ifn,
pluginGetter: pg,
}
return r, nil
}
|
[
"func",
"New",
"(",
"lDs",
",",
"gDs",
"interface",
"{",
"}",
",",
"dfn",
"DriverNotifyFunc",
",",
"ifn",
"IPAMNotifyFunc",
",",
"pg",
"plugingetter",
".",
"PluginGetter",
")",
"(",
"*",
"DrvRegistry",
",",
"error",
")",
"{",
"r",
":=",
"&",
"DrvRegistry",
"{",
"drivers",
":",
"make",
"(",
"driverTable",
")",
",",
"ipamDrivers",
":",
"make",
"(",
"ipamTable",
")",
",",
"dfn",
":",
"dfn",
",",
"ifn",
":",
"ifn",
",",
"pluginGetter",
":",
"pg",
",",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] |
// New returns a new driver registry handle.
|
[
"New",
"returns",
"a",
"new",
"driver",
"registry",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L58-L68
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
AddDriver
|
func (r *DrvRegistry) AddDriver(ntype string, fn InitFunc, config map[string]interface{}) error {
return fn(r, config)
}
|
go
|
func (r *DrvRegistry) AddDriver(ntype string, fn InitFunc, config map[string]interface{}) error {
return fn(r, config)
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"AddDriver",
"(",
"ntype",
"string",
",",
"fn",
"InitFunc",
",",
"config",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"fn",
"(",
"r",
",",
"config",
")",
"\n",
"}"
] |
// AddDriver adds a network driver to the registry.
|
[
"AddDriver",
"adds",
"a",
"network",
"driver",
"to",
"the",
"registry",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L71-L73
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
WalkIPAMs
|
func (r *DrvRegistry) WalkIPAMs(ifn IPAMWalkFunc) {
type ipamVal struct {
name string
data *ipamData
}
r.Lock()
ivl := make([]ipamVal, 0, len(r.ipamDrivers))
for k, v := range r.ipamDrivers {
ivl = append(ivl, ipamVal{name: k, data: v})
}
r.Unlock()
for _, iv := range ivl {
if ifn(iv.name, iv.data.driver, iv.data.capability) {
break
}
}
}
|
go
|
func (r *DrvRegistry) WalkIPAMs(ifn IPAMWalkFunc) {
type ipamVal struct {
name string
data *ipamData
}
r.Lock()
ivl := make([]ipamVal, 0, len(r.ipamDrivers))
for k, v := range r.ipamDrivers {
ivl = append(ivl, ipamVal{name: k, data: v})
}
r.Unlock()
for _, iv := range ivl {
if ifn(iv.name, iv.data.driver, iv.data.capability) {
break
}
}
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"WalkIPAMs",
"(",
"ifn",
"IPAMWalkFunc",
")",
"{",
"type",
"ipamVal",
"struct",
"{",
"name",
"string",
"\n",
"data",
"*",
"ipamData",
"\n",
"}",
"\n",
"r",
".",
"Lock",
"(",
")",
"\n",
"ivl",
":=",
"make",
"(",
"[",
"]",
"ipamVal",
",",
"0",
",",
"len",
"(",
"r",
".",
"ipamDrivers",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"r",
".",
"ipamDrivers",
"{",
"ivl",
"=",
"append",
"(",
"ivl",
",",
"ipamVal",
"{",
"name",
":",
"k",
",",
"data",
":",
"v",
"}",
")",
"\n",
"}",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"iv",
":=",
"range",
"ivl",
"{",
"if",
"ifn",
"(",
"iv",
".",
"name",
",",
"iv",
".",
"data",
".",
"driver",
",",
"iv",
".",
"data",
".",
"capability",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// WalkIPAMs walks the IPAM drivers registered in the registry and invokes the passed walk function and each one of them.
|
[
"WalkIPAMs",
"walks",
"the",
"IPAM",
"drivers",
"registered",
"in",
"the",
"registry",
"and",
"invokes",
"the",
"passed",
"walk",
"function",
"and",
"each",
"one",
"of",
"them",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L76-L94
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
WalkDrivers
|
func (r *DrvRegistry) WalkDrivers(dfn DriverWalkFunc) {
type driverVal struct {
name string
data *driverData
}
r.Lock()
dvl := make([]driverVal, 0, len(r.drivers))
for k, v := range r.drivers {
dvl = append(dvl, driverVal{name: k, data: v})
}
r.Unlock()
for _, dv := range dvl {
if dfn(dv.name, dv.data.driver, dv.data.capability) {
break
}
}
}
|
go
|
func (r *DrvRegistry) WalkDrivers(dfn DriverWalkFunc) {
type driverVal struct {
name string
data *driverData
}
r.Lock()
dvl := make([]driverVal, 0, len(r.drivers))
for k, v := range r.drivers {
dvl = append(dvl, driverVal{name: k, data: v})
}
r.Unlock()
for _, dv := range dvl {
if dfn(dv.name, dv.data.driver, dv.data.capability) {
break
}
}
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"WalkDrivers",
"(",
"dfn",
"DriverWalkFunc",
")",
"{",
"type",
"driverVal",
"struct",
"{",
"name",
"string",
"\n",
"data",
"*",
"driverData",
"\n",
"}",
"\n",
"r",
".",
"Lock",
"(",
")",
"\n",
"dvl",
":=",
"make",
"(",
"[",
"]",
"driverVal",
",",
"0",
",",
"len",
"(",
"r",
".",
"drivers",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"r",
".",
"drivers",
"{",
"dvl",
"=",
"append",
"(",
"dvl",
",",
"driverVal",
"{",
"name",
":",
"k",
",",
"data",
":",
"v",
"}",
")",
"\n",
"}",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"dv",
":=",
"range",
"dvl",
"{",
"if",
"dfn",
"(",
"dv",
".",
"name",
",",
"dv",
".",
"data",
".",
"driver",
",",
"dv",
".",
"data",
".",
"capability",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// WalkDrivers walks the network drivers registered in the registry and invokes the passed walk function and each one of them.
|
[
"WalkDrivers",
"walks",
"the",
"network",
"drivers",
"registered",
"in",
"the",
"registry",
"and",
"invokes",
"the",
"passed",
"walk",
"function",
"and",
"each",
"one",
"of",
"them",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L97-L115
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
Driver
|
func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) {
r.Lock()
defer r.Unlock()
d, ok := r.drivers[name]
if !ok {
return nil, nil
}
return d.driver, &d.capability
}
|
go
|
func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) {
r.Lock()
defer r.Unlock()
d, ok := r.drivers[name]
if !ok {
return nil, nil
}
return d.driver, &d.capability
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"Driver",
"(",
"name",
"string",
")",
"(",
"driverapi",
".",
"Driver",
",",
"*",
"driverapi",
".",
"Capability",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"d",
",",
"ok",
":=",
"r",
".",
"drivers",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"d",
".",
"driver",
",",
"&",
"d",
".",
"capability",
"\n",
"}"
] |
// Driver returns the actual network driver instance and its capability which registered with the passed name.
|
[
"Driver",
"returns",
"the",
"actual",
"network",
"driver",
"instance",
"and",
"its",
"capability",
"which",
"registered",
"with",
"the",
"passed",
"name",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L118-L128
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
IPAM
|
func (r *DrvRegistry) IPAM(name string) (ipamapi.Ipam, *ipamapi.Capability) {
r.Lock()
defer r.Unlock()
i, ok := r.ipamDrivers[name]
if !ok {
return nil, nil
}
return i.driver, i.capability
}
|
go
|
func (r *DrvRegistry) IPAM(name string) (ipamapi.Ipam, *ipamapi.Capability) {
r.Lock()
defer r.Unlock()
i, ok := r.ipamDrivers[name]
if !ok {
return nil, nil
}
return i.driver, i.capability
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"IPAM",
"(",
"name",
"string",
")",
"(",
"ipamapi",
".",
"Ipam",
",",
"*",
"ipamapi",
".",
"Capability",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"i",
",",
"ok",
":=",
"r",
".",
"ipamDrivers",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"i",
".",
"driver",
",",
"i",
".",
"capability",
"\n",
"}"
] |
// IPAM returns the actual IPAM driver instance and its capability which registered with the passed name.
|
[
"IPAM",
"returns",
"the",
"actual",
"IPAM",
"driver",
"instance",
"and",
"its",
"capability",
"which",
"registered",
"with",
"the",
"passed",
"name",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L131-L141
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
IPAMDefaultAddressSpaces
|
func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) {
r.Lock()
defer r.Unlock()
i, ok := r.ipamDrivers[name]
if !ok {
return "", "", fmt.Errorf("ipam %s not found", name)
}
return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil
}
|
go
|
func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) {
r.Lock()
defer r.Unlock()
i, ok := r.ipamDrivers[name]
if !ok {
return "", "", fmt.Errorf("ipam %s not found", name)
}
return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"IPAMDefaultAddressSpaces",
"(",
"name",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"i",
",",
"ok",
":=",
"r",
".",
"ipamDrivers",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"\"",
",",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"ipam %s not found\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"i",
".",
"defaultLocalAddressSpace",
",",
"i",
".",
"defaultGlobalAddressSpace",
",",
"nil",
"\n",
"}"
] |
// IPAMDefaultAddressSpaces returns the default address space strings for the passed IPAM driver name.
|
[
"IPAMDefaultAddressSpaces",
"returns",
"the",
"default",
"address",
"space",
"strings",
"for",
"the",
"passed",
"IPAM",
"driver",
"name",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L144-L154
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
RegisterDriver
|
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error {
if strings.TrimSpace(ntype) == "" {
return errors.New("network type string cannot be empty")
}
r.Lock()
dd, ok := r.drivers[ntype]
r.Unlock()
if ok && dd.driver.IsBuiltIn() {
return driverapi.ErrActiveRegistration(ntype)
}
if r.dfn != nil {
if err := r.dfn(ntype, driver, capability); err != nil {
return err
}
}
dData := &driverData{driver, capability}
r.Lock()
r.drivers[ntype] = dData
r.Unlock()
return nil
}
|
go
|
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error {
if strings.TrimSpace(ntype) == "" {
return errors.New("network type string cannot be empty")
}
r.Lock()
dd, ok := r.drivers[ntype]
r.Unlock()
if ok && dd.driver.IsBuiltIn() {
return driverapi.ErrActiveRegistration(ntype)
}
if r.dfn != nil {
if err := r.dfn(ntype, driver, capability); err != nil {
return err
}
}
dData := &driverData{driver, capability}
r.Lock()
r.drivers[ntype] = dData
r.Unlock()
return nil
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"RegisterDriver",
"(",
"ntype",
"string",
",",
"driver",
"driverapi",
".",
"Driver",
",",
"capability",
"driverapi",
".",
"Capability",
")",
"error",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"ntype",
")",
"==",
"\"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"network type string cannot be empty\"",
")",
"\n",
"}",
"\n",
"r",
".",
"Lock",
"(",
")",
"\n",
"dd",
",",
"ok",
":=",
"r",
".",
"drivers",
"[",
"ntype",
"]",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"if",
"ok",
"&&",
"dd",
".",
"driver",
".",
"IsBuiltIn",
"(",
")",
"{",
"return",
"driverapi",
".",
"ErrActiveRegistration",
"(",
"ntype",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"dfn",
"!=",
"nil",
"{",
"if",
"err",
":=",
"r",
".",
"dfn",
"(",
"ntype",
",",
"driver",
",",
"capability",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"dData",
":=",
"&",
"driverData",
"{",
"driver",
",",
"capability",
"}",
"\n",
"r",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"drivers",
"[",
"ntype",
"]",
"=",
"dData",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RegisterDriver registers the network driver when it gets discovered.
|
[
"RegisterDriver",
"registers",
"the",
"network",
"driver",
"when",
"it",
"gets",
"discovered",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L162-L188
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
RegisterIpamDriver
|
func (r *DrvRegistry) RegisterIpamDriver(name string, driver ipamapi.Ipam) error {
return r.registerIpamDriver(name, driver, &ipamapi.Capability{})
}
|
go
|
func (r *DrvRegistry) RegisterIpamDriver(name string, driver ipamapi.Ipam) error {
return r.registerIpamDriver(name, driver, &ipamapi.Capability{})
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"RegisterIpamDriver",
"(",
"name",
"string",
",",
"driver",
"ipamapi",
".",
"Ipam",
")",
"error",
"{",
"return",
"r",
".",
"registerIpamDriver",
"(",
"name",
",",
"driver",
",",
"&",
"ipamapi",
".",
"Capability",
"{",
"}",
")",
"\n",
"}"
] |
// RegisterIpamDriver registers the IPAM driver discovered with default capabilities.
|
[
"RegisterIpamDriver",
"registers",
"the",
"IPAM",
"driver",
"discovered",
"with",
"default",
"capabilities",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L221-L223
|
train
|
docker/libnetwork
|
drvregistry/drvregistry.go
|
RegisterIpamDriverWithCapabilities
|
func (r *DrvRegistry) RegisterIpamDriverWithCapabilities(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error {
return r.registerIpamDriver(name, driver, caps)
}
|
go
|
func (r *DrvRegistry) RegisterIpamDriverWithCapabilities(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error {
return r.registerIpamDriver(name, driver, caps)
}
|
[
"func",
"(",
"r",
"*",
"DrvRegistry",
")",
"RegisterIpamDriverWithCapabilities",
"(",
"name",
"string",
",",
"driver",
"ipamapi",
".",
"Ipam",
",",
"caps",
"*",
"ipamapi",
".",
"Capability",
")",
"error",
"{",
"return",
"r",
".",
"registerIpamDriver",
"(",
"name",
",",
"driver",
",",
"caps",
")",
"\n",
"}"
] |
// RegisterIpamDriverWithCapabilities registers the IPAM driver discovered with specified capabilities.
|
[
"RegisterIpamDriverWithCapabilities",
"registers",
"the",
"IPAM",
"driver",
"discovered",
"with",
"specified",
"capabilities",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L226-L228
|
train
|
docker/libnetwork
|
drivers/bridge/netlink_deprecated_linux.go
|
getIfSocket
|
func getIfSocket() (fd int, err error) {
for _, socket := range []int{
syscall.AF_INET,
syscall.AF_PACKET,
syscall.AF_INET6,
} {
if fd, err = syscall.Socket(socket, syscall.SOCK_DGRAM, 0); err == nil {
break
}
}
if err == nil {
return fd, nil
}
return -1, err
}
|
go
|
func getIfSocket() (fd int, err error) {
for _, socket := range []int{
syscall.AF_INET,
syscall.AF_PACKET,
syscall.AF_INET6,
} {
if fd, err = syscall.Socket(socket, syscall.SOCK_DGRAM, 0); err == nil {
break
}
}
if err == nil {
return fd, nil
}
return -1, err
}
|
[
"func",
"getIfSocket",
"(",
")",
"(",
"fd",
"int",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"socket",
":=",
"range",
"[",
"]",
"int",
"{",
"syscall",
".",
"AF_INET",
",",
"syscall",
".",
"AF_PACKET",
",",
"syscall",
".",
"AF_INET6",
",",
"}",
"{",
"if",
"fd",
",",
"err",
"=",
"syscall",
".",
"Socket",
"(",
"socket",
",",
"syscall",
".",
"SOCK_DGRAM",
",",
"0",
")",
";",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"fd",
",",
"nil",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"err",
"\n",
"}"
] |
// THIS CODE DOES NOT COMMUNICATE WITH KERNEL VIA RTNETLINK INTERFACE
// IT IS HERE FOR BACKWARDS COMPATIBILITY WITH OLDER LINUX KERNELS
// WHICH SHIP WITH OLDER NOT ENTIRELY FUNCTIONAL VERSION OF NETLINK
|
[
"THIS",
"CODE",
"DOES",
"NOT",
"COMMUNICATE",
"WITH",
"KERNEL",
"VIA",
"RTNETLINK",
"INTERFACE",
"IT",
"IS",
"HERE",
"FOR",
"BACKWARDS",
"COMPATIBILITY",
"WITH",
"OLDER",
"LINUX",
"KERNELS",
"WHICH",
"SHIP",
"WITH",
"OLDER",
"NOT",
"ENTIRELY",
"FUNCTIONAL",
"VERSION",
"OF",
"NETLINK"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/netlink_deprecated_linux.go#L35-L49
|
train
|
docker/libnetwork
|
drivers/bridge/netlink_deprecated_linux.go
|
ioctlAddToBridge
|
func ioctlAddToBridge(iface, master *net.Interface) error {
return ifIoctBridge(iface, master, ioctlBrAddIf)
}
|
go
|
func ioctlAddToBridge(iface, master *net.Interface) error {
return ifIoctBridge(iface, master, ioctlBrAddIf)
}
|
[
"func",
"ioctlAddToBridge",
"(",
"iface",
",",
"master",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"return",
"ifIoctBridge",
"(",
"iface",
",",
"master",
",",
"ioctlBrAddIf",
")",
"\n",
"}"
] |
// Add a slave to a bridge device. This is more backward-compatible than
// netlink.NetworkSetMaster and works on RHEL 6.
|
[
"Add",
"a",
"slave",
"to",
"a",
"bridge",
"device",
".",
"This",
"is",
"more",
"backward",
"-",
"compatible",
"than",
"netlink",
".",
"NetworkSetMaster",
"and",
"works",
"on",
"RHEL",
"6",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/netlink_deprecated_linux.go#L75-L77
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionHostname
|
func OptionHostname(name string) SandboxOption {
return func(sb *sandbox) {
sb.config.hostName = name
}
}
|
go
|
func OptionHostname(name string) SandboxOption {
return func(sb *sandbox) {
sb.config.hostName = name
}
}
|
[
"func",
"OptionHostname",
"(",
"name",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"hostName",
"=",
"name",
"\n",
"}",
"\n",
"}"
] |
// OptionHostname function returns an option setter for hostname option to
// be passed to NewSandbox method.
|
[
"OptionHostname",
"function",
"returns",
"an",
"option",
"setter",
"for",
"hostname",
"option",
"to",
"be",
"passed",
"to",
"NewSandbox",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1038-L1042
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionDomainname
|
func OptionDomainname(name string) SandboxOption {
return func(sb *sandbox) {
sb.config.domainName = name
}
}
|
go
|
func OptionDomainname(name string) SandboxOption {
return func(sb *sandbox) {
sb.config.domainName = name
}
}
|
[
"func",
"OptionDomainname",
"(",
"name",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"domainName",
"=",
"name",
"\n",
"}",
"\n",
"}"
] |
// OptionDomainname function returns an option setter for domainname option to
// be passed to NewSandbox method.
|
[
"OptionDomainname",
"function",
"returns",
"an",
"option",
"setter",
"for",
"domainname",
"option",
"to",
"be",
"passed",
"to",
"NewSandbox",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1046-L1050
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionHostsPath
|
func OptionHostsPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.hostsPath = path
}
}
|
go
|
func OptionHostsPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.hostsPath = path
}
}
|
[
"func",
"OptionHostsPath",
"(",
"path",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"hostsPath",
"=",
"path",
"\n",
"}",
"\n",
"}"
] |
// OptionHostsPath function returns an option setter for hostspath option to
// be passed to NewSandbox method.
|
[
"OptionHostsPath",
"function",
"returns",
"an",
"option",
"setter",
"for",
"hostspath",
"option",
"to",
"be",
"passed",
"to",
"NewSandbox",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1054-L1058
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionOriginHostsPath
|
func OptionOriginHostsPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.originHostsPath = path
}
}
|
go
|
func OptionOriginHostsPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.originHostsPath = path
}
}
|
[
"func",
"OptionOriginHostsPath",
"(",
"path",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"originHostsPath",
"=",
"path",
"\n",
"}",
"\n",
"}"
] |
// OptionOriginHostsPath function returns an option setter for origin hosts file path
// to be passed to NewSandbox method.
|
[
"OptionOriginHostsPath",
"function",
"returns",
"an",
"option",
"setter",
"for",
"origin",
"hosts",
"file",
"path",
"to",
"be",
"passed",
"to",
"NewSandbox",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1062-L1066
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionParentUpdate
|
func OptionParentUpdate(cid string, name, ip string) SandboxOption {
return func(sb *sandbox) {
sb.config.parentUpdates = append(sb.config.parentUpdates, parentUpdate{cid: cid, name: name, ip: ip})
}
}
|
go
|
func OptionParentUpdate(cid string, name, ip string) SandboxOption {
return func(sb *sandbox) {
sb.config.parentUpdates = append(sb.config.parentUpdates, parentUpdate{cid: cid, name: name, ip: ip})
}
}
|
[
"func",
"OptionParentUpdate",
"(",
"cid",
"string",
",",
"name",
",",
"ip",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"parentUpdates",
"=",
"append",
"(",
"sb",
".",
"config",
".",
"parentUpdates",
",",
"parentUpdate",
"{",
"cid",
":",
"cid",
",",
"name",
":",
"name",
",",
"ip",
":",
"ip",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// OptionParentUpdate function returns an option setter for parent container
// which needs to update the IP address for the linked container.
|
[
"OptionParentUpdate",
"function",
"returns",
"an",
"option",
"setter",
"for",
"parent",
"container",
"which",
"needs",
"to",
"update",
"the",
"IP",
"address",
"for",
"the",
"linked",
"container",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1078-L1082
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionResolvConfPath
|
func OptionResolvConfPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.resolvConfPath = path
}
}
|
go
|
func OptionResolvConfPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.resolvConfPath = path
}
}
|
[
"func",
"OptionResolvConfPath",
"(",
"path",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"resolvConfPath",
"=",
"path",
"\n",
"}",
"\n",
"}"
] |
// OptionResolvConfPath function returns an option setter for resolvconfpath option to
// be passed to net container methods.
|
[
"OptionResolvConfPath",
"function",
"returns",
"an",
"option",
"setter",
"for",
"resolvconfpath",
"option",
"to",
"be",
"passed",
"to",
"net",
"container",
"methods",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1086-L1090
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionOriginResolvConfPath
|
func OptionOriginResolvConfPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.originResolvConfPath = path
}
}
|
go
|
func OptionOriginResolvConfPath(path string) SandboxOption {
return func(sb *sandbox) {
sb.config.originResolvConfPath = path
}
}
|
[
"func",
"OptionOriginResolvConfPath",
"(",
"path",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"originResolvConfPath",
"=",
"path",
"\n",
"}",
"\n",
"}"
] |
// OptionOriginResolvConfPath function returns an option setter to set the path to the
// origin resolv.conf file to be passed to net container methods.
|
[
"OptionOriginResolvConfPath",
"function",
"returns",
"an",
"option",
"setter",
"to",
"set",
"the",
"path",
"to",
"the",
"origin",
"resolv",
".",
"conf",
"file",
"to",
"be",
"passed",
"to",
"net",
"container",
"methods",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1094-L1098
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionDNS
|
func OptionDNS(dns string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsList = append(sb.config.dnsList, dns)
}
}
|
go
|
func OptionDNS(dns string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsList = append(sb.config.dnsList, dns)
}
}
|
[
"func",
"OptionDNS",
"(",
"dns",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"dnsList",
"=",
"append",
"(",
"sb",
".",
"config",
".",
"dnsList",
",",
"dns",
")",
"\n",
"}",
"\n",
"}"
] |
// OptionDNS function returns an option setter for dns entry option to
// be passed to container Create method.
|
[
"OptionDNS",
"function",
"returns",
"an",
"option",
"setter",
"for",
"dns",
"entry",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1102-L1106
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionDNSSearch
|
func OptionDNSSearch(search string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsSearchList = append(sb.config.dnsSearchList, search)
}
}
|
go
|
func OptionDNSSearch(search string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsSearchList = append(sb.config.dnsSearchList, search)
}
}
|
[
"func",
"OptionDNSSearch",
"(",
"search",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"dnsSearchList",
"=",
"append",
"(",
"sb",
".",
"config",
".",
"dnsSearchList",
",",
"search",
")",
"\n",
"}",
"\n",
"}"
] |
// OptionDNSSearch function returns an option setter for dns search entry option to
// be passed to container Create method.
|
[
"OptionDNSSearch",
"function",
"returns",
"an",
"option",
"setter",
"for",
"dns",
"search",
"entry",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1110-L1114
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionDNSOptions
|
func OptionDNSOptions(options string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsOptionsList = append(sb.config.dnsOptionsList, options)
}
}
|
go
|
func OptionDNSOptions(options string) SandboxOption {
return func(sb *sandbox) {
sb.config.dnsOptionsList = append(sb.config.dnsOptionsList, options)
}
}
|
[
"func",
"OptionDNSOptions",
"(",
"options",
"string",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"sb",
".",
"config",
".",
"dnsOptionsList",
"=",
"append",
"(",
"sb",
".",
"config",
".",
"dnsOptionsList",
",",
"options",
")",
"\n",
"}",
"\n",
"}"
] |
// OptionDNSOptions function returns an option setter for dns options entry option to
// be passed to container Create method.
|
[
"OptionDNSOptions",
"function",
"returns",
"an",
"option",
"setter",
"for",
"dns",
"options",
"entry",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1118-L1122
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionGeneric
|
func OptionGeneric(generic map[string]interface{}) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{}, len(generic))
}
for k, v := range generic {
sb.config.generic[k] = v
}
}
}
|
go
|
func OptionGeneric(generic map[string]interface{}) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{}, len(generic))
}
for k, v := range generic {
sb.config.generic[k] = v
}
}
}
|
[
"func",
"OptionGeneric",
"(",
"generic",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"if",
"sb",
".",
"config",
".",
"generic",
"==",
"nil",
"{",
"sb",
".",
"config",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"generic",
")",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"generic",
"{",
"sb",
".",
"config",
".",
"generic",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// OptionGeneric function returns an option setter for Generic configuration
// that is not managed by libNetwork but can be used by the Drivers during the call to
// net container creation method. Container Labels are a good example.
|
[
"OptionGeneric",
"function",
"returns",
"an",
"option",
"setter",
"for",
"Generic",
"configuration",
"that",
"is",
"not",
"managed",
"by",
"libNetwork",
"but",
"can",
"be",
"used",
"by",
"the",
"Drivers",
"during",
"the",
"call",
"to",
"net",
"container",
"creation",
"method",
".",
"Container",
"Labels",
"are",
"a",
"good",
"example",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1143-L1152
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionExposedPorts
|
func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{})
}
// Defensive copy
eps := make([]types.TransportPort, len(exposedPorts))
copy(eps, exposedPorts)
// Store endpoint label and in generic because driver needs it
sb.config.exposedPorts = eps
sb.config.generic[netlabel.ExposedPorts] = eps
}
}
|
go
|
func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{})
}
// Defensive copy
eps := make([]types.TransportPort, len(exposedPorts))
copy(eps, exposedPorts)
// Store endpoint label and in generic because driver needs it
sb.config.exposedPorts = eps
sb.config.generic[netlabel.ExposedPorts] = eps
}
}
|
[
"func",
"OptionExposedPorts",
"(",
"exposedPorts",
"[",
"]",
"types",
".",
"TransportPort",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"if",
"sb",
".",
"config",
".",
"generic",
"==",
"nil",
"{",
"sb",
".",
"config",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"eps",
":=",
"make",
"(",
"[",
"]",
"types",
".",
"TransportPort",
",",
"len",
"(",
"exposedPorts",
")",
")",
"\n",
"copy",
"(",
"eps",
",",
"exposedPorts",
")",
"\n",
"sb",
".",
"config",
".",
"exposedPorts",
"=",
"eps",
"\n",
"sb",
".",
"config",
".",
"generic",
"[",
"netlabel",
".",
"ExposedPorts",
"]",
"=",
"eps",
"\n",
"}",
"\n",
"}"
] |
// OptionExposedPorts function returns an option setter for the container exposed
// ports option to be passed to container Create method.
|
[
"OptionExposedPorts",
"function",
"returns",
"an",
"option",
"setter",
"for",
"the",
"container",
"exposed",
"ports",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1156-L1168
|
train
|
docker/libnetwork
|
sandbox.go
|
OptionPortMapping
|
func OptionPortMapping(portBindings []types.PortBinding) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{})
}
// Store a copy of the bindings as generic data to pass to the driver
pbs := make([]types.PortBinding, len(portBindings))
copy(pbs, portBindings)
sb.config.generic[netlabel.PortMap] = pbs
}
}
|
go
|
func OptionPortMapping(portBindings []types.PortBinding) SandboxOption {
return func(sb *sandbox) {
if sb.config.generic == nil {
sb.config.generic = make(map[string]interface{})
}
// Store a copy of the bindings as generic data to pass to the driver
pbs := make([]types.PortBinding, len(portBindings))
copy(pbs, portBindings)
sb.config.generic[netlabel.PortMap] = pbs
}
}
|
[
"func",
"OptionPortMapping",
"(",
"portBindings",
"[",
"]",
"types",
".",
"PortBinding",
")",
"SandboxOption",
"{",
"return",
"func",
"(",
"sb",
"*",
"sandbox",
")",
"{",
"if",
"sb",
".",
"config",
".",
"generic",
"==",
"nil",
"{",
"sb",
".",
"config",
".",
"generic",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"pbs",
":=",
"make",
"(",
"[",
"]",
"types",
".",
"PortBinding",
",",
"len",
"(",
"portBindings",
")",
")",
"\n",
"copy",
"(",
"pbs",
",",
"portBindings",
")",
"\n",
"sb",
".",
"config",
".",
"generic",
"[",
"netlabel",
".",
"PortMap",
"]",
"=",
"pbs",
"\n",
"}",
"\n",
"}"
] |
// OptionPortMapping function returns an option setter for the mapping
// ports option to be passed to container Create method.
|
[
"OptionPortMapping",
"function",
"returns",
"an",
"option",
"setter",
"for",
"the",
"mapping",
"ports",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1172-L1182
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.