repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
docker/libnetwork
|
iptables/conntrack.go
|
DeleteConntrackEntries
|
func DeleteConntrackEntries(nlh *netlink.Handle, ipv4List []net.IP, ipv6List []net.IP) (uint, uint, error) {
if !IsConntrackProgrammable(nlh) {
return 0, 0, ErrConntrackNotConfigurable
}
var totalIPv4FlowPurged uint
for _, ipAddress := range ipv4List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv4FlowPurged += flowPurged
}
var totalIPv6FlowPurged uint
for _, ipAddress := range ipv6List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET6, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv6FlowPurged += flowPurged
}
logrus.Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
return totalIPv4FlowPurged, totalIPv6FlowPurged, nil
}
|
go
|
func DeleteConntrackEntries(nlh *netlink.Handle, ipv4List []net.IP, ipv6List []net.IP) (uint, uint, error) {
if !IsConntrackProgrammable(nlh) {
return 0, 0, ErrConntrackNotConfigurable
}
var totalIPv4FlowPurged uint
for _, ipAddress := range ipv4List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv4FlowPurged += flowPurged
}
var totalIPv6FlowPurged uint
for _, ipAddress := range ipv6List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET6, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv6FlowPurged += flowPurged
}
logrus.Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
return totalIPv4FlowPurged, totalIPv6FlowPurged, nil
}
|
[
"func",
"DeleteConntrackEntries",
"(",
"nlh",
"*",
"netlink",
".",
"Handle",
",",
"ipv4List",
"[",
"]",
"net",
".",
"IP",
",",
"ipv6List",
"[",
"]",
"net",
".",
"IP",
")",
"(",
"uint",
",",
"uint",
",",
"error",
")",
"{",
"if",
"!",
"IsConntrackProgrammable",
"(",
"nlh",
")",
"{",
"return",
"0",
",",
"0",
",",
"ErrConntrackNotConfigurable",
"\n",
"}",
"\n",
"var",
"totalIPv4FlowPurged",
"uint",
"\n",
"for",
"_",
",",
"ipAddress",
":=",
"range",
"ipv4List",
"{",
"flowPurged",
",",
"err",
":=",
"purgeConntrackState",
"(",
"nlh",
",",
"syscall",
".",
"AF_INET",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"Failed to delete conntrack state for %s: %v\"",
",",
"ipAddress",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"totalIPv4FlowPurged",
"+=",
"flowPurged",
"\n",
"}",
"\n",
"var",
"totalIPv6FlowPurged",
"uint",
"\n",
"for",
"_",
",",
"ipAddress",
":=",
"range",
"ipv6List",
"{",
"flowPurged",
",",
"err",
":=",
"purgeConntrackState",
"(",
"nlh",
",",
"syscall",
".",
"AF_INET6",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"Failed to delete conntrack state for %s: %v\"",
",",
"ipAddress",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"totalIPv6FlowPurged",
"+=",
"flowPurged",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"DeleteConntrackEntries purged ipv4:%d, ipv6:%d\"",
",",
"totalIPv4FlowPurged",
",",
"totalIPv6FlowPurged",
")",
"\n",
"return",
"totalIPv4FlowPurged",
",",
"totalIPv6FlowPurged",
",",
"nil",
"\n",
"}"
] |
// DeleteConntrackEntries deletes all the conntrack connections on the host for the specified IP
// Returns the number of flows deleted for IPv4, IPv6 else error
|
[
"DeleteConntrackEntries",
"deletes",
"all",
"the",
"conntrack",
"connections",
"on",
"the",
"host",
"for",
"the",
"specified",
"IP",
"Returns",
"the",
"number",
"of",
"flows",
"deleted",
"for",
"IPv4",
"IPv6",
"else",
"error"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/conntrack.go#L24-L51
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServicePublish
|
func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "publish", "SERVICE[.NETWORK]", "Publish a new service on a network", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias to self")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
sc := serviceCreate{Name: sn, Network: nn, MyAliases: flAlias.GetAll()}
obj, _, err := readBody(cli.call("POST", "/services", sc, 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) CmdServicePublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "publish", "SERVICE[.NETWORK]", "Publish a new service on a network", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias to self")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
sc := serviceCreate{Name: sn, Network: nn, MyAliases: flAlias.GetAll()}
obj, _, err := readBody(cli.call("POST", "/services", sc, 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",
")",
"CmdServicePublish",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"publish\"",
",",
"\"SERVICE[.NETWORK]\"",
",",
"\"Publish a new service on a network\"",
",",
"false",
")",
"\n",
"flAlias",
":=",
"opts",
".",
"NewListOpts",
"(",
"netutils",
".",
"ValidateAlias",
")",
"\n",
"cmd",
".",
"Var",
"(",
"&",
"flAlias",
",",
"[",
"]",
"string",
"{",
"\"-alias\"",
"}",
",",
"\"Add alias to self\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"sc",
":=",
"serviceCreate",
"{",
"Name",
":",
"sn",
",",
"Network",
":",
"nn",
",",
"MyAliases",
":",
"flAlias",
".",
"GetAll",
"(",
")",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"POST\"",
",",
"\"/services\"",
",",
"sc",
",",
"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",
"}"
] |
// CmdServicePublish handles service create UI
|
[
"CmdServicePublish",
"handles",
"service",
"create",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L165-L190
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServiceUnpublish
|
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
sd := serviceDelete{Name: sn, Force: *force}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
return err
}
|
go
|
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
sd := serviceDelete{Name: sn, Force: *force}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
return err
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceUnpublish",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"unpublish\"",
",",
"\"SERVICE[.NETWORK]\"",
",",
"\"Removes a service\"",
",",
"false",
")",
"\n",
"force",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"f\"",
",",
"\"-force\"",
"}",
",",
"false",
",",
"\"force unpublish service\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sd",
":=",
"serviceDelete",
"{",
"Name",
":",
"sn",
",",
"Force",
":",
"*",
"force",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"DELETE\"",
",",
"\"/services/\"",
"+",
"serviceID",
",",
"sd",
",",
"nil",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// CmdServiceUnpublish handles service delete UI
|
[
"CmdServiceUnpublish",
"handles",
"service",
"delete",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L193-L212
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServiceLs
|
func (cli *NetworkCli) CmdServiceLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "SERVICE", "Lists all the services on a network", false)
flNetwork := cmd.String([]string{"net", "-network"}, "", "Only show the services that are published on the specified network")
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
var obj []byte
if *flNetwork == "" {
obj, _, err = readBody(cli.call("GET", "/services", nil, nil))
} else {
obj, _, err = readBody(cli.call("GET", "/services?network="+*flNetwork, nil, nil))
}
if err != nil {
return err
}
var serviceResources []serviceResource
err = json.Unmarshal(obj, &serviceResources)
if err != nil {
fmt.Println(err)
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "SERVICE ID\tNAME\tNETWORK\tCONTAINER\tSANDBOX")
}
for _, sr := range serviceResources {
ID := sr.ID
bkID, sbID, err := getBackendID(cli, ID)
if err != nil {
return err
}
if !*noTrunc {
ID = stringid.TruncateID(ID)
bkID = stringid.TruncateID(bkID)
sbID = stringid.TruncateID(sbID)
}
if !*quiet {
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t%s\n", ID, sr.Name, sr.Network, bkID, sbID)
} else {
fmt.Fprintln(wr, ID)
}
}
wr.Flush()
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "SERVICE", "Lists all the services on a network", false)
flNetwork := cmd.String([]string{"net", "-network"}, "", "Only show the services that are published on the specified network")
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
var obj []byte
if *flNetwork == "" {
obj, _, err = readBody(cli.call("GET", "/services", nil, nil))
} else {
obj, _, err = readBody(cli.call("GET", "/services?network="+*flNetwork, nil, nil))
}
if err != nil {
return err
}
var serviceResources []serviceResource
err = json.Unmarshal(obj, &serviceResources)
if err != nil {
fmt.Println(err)
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "SERVICE ID\tNAME\tNETWORK\tCONTAINER\tSANDBOX")
}
for _, sr := range serviceResources {
ID := sr.ID
bkID, sbID, err := getBackendID(cli, ID)
if err != nil {
return err
}
if !*noTrunc {
ID = stringid.TruncateID(ID)
bkID = stringid.TruncateID(bkID)
sbID = stringid.TruncateID(sbID)
}
if !*quiet {
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t%s\n", ID, sr.Name, sr.Network, bkID, sbID)
} else {
fmt.Fprintln(wr, ID)
}
}
wr.Flush()
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceLs",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"ls\"",
",",
"\"SERVICE\"",
",",
"\"Lists all the services on a network\"",
",",
"false",
")",
"\n",
"flNetwork",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"net\"",
",",
"\"-network\"",
"}",
",",
"\"\"",
",",
"\"Only show the services that are published on the specified network\"",
")",
"\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",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"obj",
"[",
"]",
"byte",
"\n",
"if",
"*",
"flNetwork",
"==",
"\"\"",
"{",
"obj",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/services\"",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"}",
"else",
"{",
"obj",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/services?network=\"",
"+",
"*",
"flNetwork",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"serviceResources",
"[",
"]",
"serviceResource",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"serviceResources",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"wr",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"cli",
".",
"out",
",",
"20",
",",
"1",
",",
"3",
",",
"' '",
",",
"0",
")",
"\n",
"if",
"!",
"*",
"quiet",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"SERVICE ID\\tNAME\\tNETWORK\\tCONTAINER\\tSANDBOX\"",
")",
"\n",
"}",
"\n",
"\\t",
"\n",
"\\t",
"\n",
"\\t",
"\n",
"}"
] |
// CmdServiceLs handles service list UI
|
[
"CmdServiceLs",
"handles",
"service",
"list",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L215-L269
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServiceInfo
|
func (cli *NetworkCli) CmdServiceInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "SERVICE[.NETWORK]", "Displays detailed information about a service", false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/services/"+serviceID, nil, nil))
if err != nil {
return err
}
sr := &serviceResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(sr); err != nil {
return err
}
fmt.Fprintf(cli.out, "Service Id: %s\n", sr.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", sr.Name)
fmt.Fprintf(cli.out, "\tNetwork: %s\n", sr.Network)
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "SERVICE[.NETWORK]", "Displays detailed information about a service", false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/services/"+serviceID, nil, nil))
if err != nil {
return err
}
sr := &serviceResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(sr); err != nil {
return err
}
fmt.Fprintf(cli.out, "Service Id: %s\n", sr.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", sr.Name)
fmt.Fprintf(cli.out, "\tNetwork: %s\n", sr.Network)
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceInfo",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"info\"",
",",
"\"SERVICE[.NETWORK]\"",
",",
"\"Displays detailed information about a service\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"GET\"",
",",
"\"/services/\"",
"+",
"serviceID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sr",
":=",
"&",
"serviceResource",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"obj",
")",
")",
".",
"Decode",
"(",
"sr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"Service Id: %s\\n\"",
",",
"\\n",
")",
"\n",
"sr",
".",
"ID",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"\\tName: %s\\n\"",
",",
"\\t",
")",
"\n",
"\\n",
"\n",
"}"
] |
// CmdServiceInfo handles service info UI
|
[
"CmdServiceInfo",
"handles",
"service",
"info",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L294-L324
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServiceAttach
|
func (cli *NetworkCli) CmdServiceAttach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "attach", "CONTAINER SERVICE[.NETWORK]", "Sets a container as a service backend", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias for another container")
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
nc := serviceAttach{SandboxID: sandboxID, Aliases: flAlias.GetAll()}
_, _, err = readBody(cli.call("POST", "/services/"+serviceID+"/backend", nc, nil))
return err
}
|
go
|
func (cli *NetworkCli) CmdServiceAttach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "attach", "CONTAINER SERVICE[.NETWORK]", "Sets a container as a service backend", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias for another container")
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
nc := serviceAttach{SandboxID: sandboxID, Aliases: flAlias.GetAll()}
_, _, err = readBody(cli.call("POST", "/services/"+serviceID+"/backend", nc, nil))
return err
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceAttach",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"attach\"",
",",
"\"CONTAINER SERVICE[.NETWORK]\"",
",",
"\"Sets a container as a service backend\"",
",",
"false",
")",
"\n",
"flAlias",
":=",
"opts",
".",
"NewListOpts",
"(",
"netutils",
".",
"ValidateAlias",
")",
"\n",
"cmd",
".",
"Var",
"(",
"&",
"flAlias",
",",
"[",
"]",
"string",
"{",
"\"-alias\"",
"}",
",",
"\"Add alias for another container\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"2",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"containerID",
",",
"err",
":=",
"lookupContainerID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sandboxID",
",",
"err",
":=",
"lookupSandboxID",
"(",
"cli",
",",
"containerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"1",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"nc",
":=",
"serviceAttach",
"{",
"SandboxID",
":",
"sandboxID",
",",
"Aliases",
":",
"flAlias",
".",
"GetAll",
"(",
")",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"POST\"",
",",
"\"/services/\"",
"+",
"serviceID",
"+",
"\"/backend\"",
",",
"nc",
",",
"nil",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// CmdServiceAttach handles service attach UI
|
[
"CmdServiceAttach",
"handles",
"service",
"attach",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L327-L358
|
train
|
docker/libnetwork
|
client/service.go
|
CmdServiceDetach
|
func (cli *NetworkCli) CmdServiceDetach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "detach", "CONTAINER SERVICE", "Removes a container from service backend", false)
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID+"/backend/"+sandboxID, nil, nil))
if err != nil {
return err
}
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceDetach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "detach", "CONTAINER SERVICE", "Removes a container from service backend", false)
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID+"/backend/"+sandboxID, nil, nil))
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceDetach",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"detach\"",
",",
"\"CONTAINER SERVICE\"",
",",
"\"Removes a container from service backend\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"2",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"1",
")",
")",
"\n",
"containerID",
",",
"err",
":=",
"lookupContainerID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sandboxID",
",",
"err",
":=",
"lookupSandboxID",
"(",
"cli",
",",
"containerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"DELETE\"",
",",
"\"/services/\"",
"+",
"serviceID",
"+",
"\"/backend/\"",
"+",
"sandboxID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CmdServiceDetach handles service detach UI
|
[
"CmdServiceDetach",
"handles",
"service",
"detach",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L361-L390
|
train
|
docker/libnetwork
|
ipam/store.go
|
SetValue
|
func (aSpace *addrSpace) SetValue(value []byte) error {
rc := &addrSpace{subnets: make(map[SubnetKey]*PoolData)}
if err := json.Unmarshal(value, rc); err != nil {
return err
}
aSpace.subnets = rc.subnets
return nil
}
|
go
|
func (aSpace *addrSpace) SetValue(value []byte) error {
rc := &addrSpace{subnets: make(map[SubnetKey]*PoolData)}
if err := json.Unmarshal(value, rc); err != nil {
return err
}
aSpace.subnets = rc.subnets
return nil
}
|
[
"func",
"(",
"aSpace",
"*",
"addrSpace",
")",
"SetValue",
"(",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"rc",
":=",
"&",
"addrSpace",
"{",
"subnets",
":",
"make",
"(",
"map",
"[",
"SubnetKey",
"]",
"*",
"PoolData",
")",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"value",
",",
"rc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"aSpace",
".",
"subnets",
"=",
"rc",
".",
"subnets",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetValue unmarshalls the data from the KV store.
|
[
"SetValue",
"unmarshalls",
"the",
"data",
"from",
"the",
"KV",
"store",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/store.go#L36-L43
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
New
|
func New(path string) (*Handle, error) {
setup()
n := netns.None()
if path != "" {
var err error
n, err = netns.GetFromPath(path)
if err != nil {
return nil, err
}
}
defer n.Close()
sock, err := nl.GetNetlinkSocketAt(n, netns.None(), syscall.NETLINK_GENERIC)
if err != nil {
return nil, err
}
// Add operation timeout to avoid deadlocks
tv := syscall.NsecToTimeval(netlinkSendSocketTimeout.Nanoseconds())
if err := sock.SetSendTimeout(&tv); err != nil {
return nil, err
}
tv = syscall.NsecToTimeval(netlinkRecvSocketsTimeout.Nanoseconds())
if err := sock.SetReceiveTimeout(&tv); err != nil {
return nil, err
}
return &Handle{sock: sock}, nil
}
|
go
|
func New(path string) (*Handle, error) {
setup()
n := netns.None()
if path != "" {
var err error
n, err = netns.GetFromPath(path)
if err != nil {
return nil, err
}
}
defer n.Close()
sock, err := nl.GetNetlinkSocketAt(n, netns.None(), syscall.NETLINK_GENERIC)
if err != nil {
return nil, err
}
// Add operation timeout to avoid deadlocks
tv := syscall.NsecToTimeval(netlinkSendSocketTimeout.Nanoseconds())
if err := sock.SetSendTimeout(&tv); err != nil {
return nil, err
}
tv = syscall.NsecToTimeval(netlinkRecvSocketsTimeout.Nanoseconds())
if err := sock.SetReceiveTimeout(&tv); err != nil {
return nil, err
}
return &Handle{sock: sock}, nil
}
|
[
"func",
"New",
"(",
"path",
"string",
")",
"(",
"*",
"Handle",
",",
"error",
")",
"{",
"setup",
"(",
")",
"\n",
"n",
":=",
"netns",
".",
"None",
"(",
")",
"\n",
"if",
"path",
"!=",
"\"\"",
"{",
"var",
"err",
"error",
"\n",
"n",
",",
"err",
"=",
"netns",
".",
"GetFromPath",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"defer",
"n",
".",
"Close",
"(",
")",
"\n",
"sock",
",",
"err",
":=",
"nl",
".",
"GetNetlinkSocketAt",
"(",
"n",
",",
"netns",
".",
"None",
"(",
")",
",",
"syscall",
".",
"NETLINK_GENERIC",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tv",
":=",
"syscall",
".",
"NsecToTimeval",
"(",
"netlinkSendSocketTimeout",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"sock",
".",
"SetSendTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tv",
"=",
"syscall",
".",
"NsecToTimeval",
"(",
"netlinkRecvSocketsTimeout",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"sock",
".",
"SetReceiveTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Handle",
"{",
"sock",
":",
"sock",
"}",
",",
"nil",
"\n",
"}"
] |
// New provides a new ipvs handle in the namespace pointed to by the
// passed path. It will return a valid handle or an error in case an
// error occurred while creating the handle.
|
[
"New",
"provides",
"a",
"new",
"ipvs",
"handle",
"in",
"the",
"namespace",
"pointed",
"to",
"by",
"the",
"passed",
"path",
".",
"It",
"will",
"return",
"a",
"valid",
"handle",
"or",
"an",
"error",
"in",
"case",
"an",
"error",
"occurred",
"while",
"creating",
"the",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L88-L116
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
NewService
|
func (i *Handle) NewService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdNewService)
}
|
go
|
func (i *Handle) NewService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdNewService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"NewService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdNewService",
")",
"\n",
"}"
] |
// NewService creates a new ipvs service in the passed handle.
|
[
"NewService",
"creates",
"a",
"new",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L127-L129
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
IsServicePresent
|
func (i *Handle) IsServicePresent(s *Service) bool {
return nil == i.doCmd(s, nil, ipvsCmdGetService)
}
|
go
|
func (i *Handle) IsServicePresent(s *Service) bool {
return nil == i.doCmd(s, nil, ipvsCmdGetService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"IsServicePresent",
"(",
"s",
"*",
"Service",
")",
"bool",
"{",
"return",
"nil",
"==",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdGetService",
")",
"\n",
"}"
] |
// IsServicePresent queries for the ipvs service in the passed handle.
|
[
"IsServicePresent",
"queries",
"for",
"the",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L132-L134
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
UpdateService
|
func (i *Handle) UpdateService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdSetService)
}
|
go
|
func (i *Handle) UpdateService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdSetService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"UpdateService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdSetService",
")",
"\n",
"}"
] |
// UpdateService updates an already existing service in the passed
// handle.
|
[
"UpdateService",
"updates",
"an",
"already",
"existing",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L138-L140
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
DelService
|
func (i *Handle) DelService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdDelService)
}
|
go
|
func (i *Handle) DelService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdDelService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"DelService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdDelService",
")",
"\n",
"}"
] |
// DelService deletes an already existing service in the passed
// handle.
|
[
"DelService",
"deletes",
"an",
"already",
"existing",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L144-L146
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
Flush
|
func (i *Handle) Flush() error {
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
return err
}
|
go
|
func (i *Handle) Flush() error {
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
return err
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"Flush",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"i",
".",
"doCmdWithoutAttr",
"(",
"ipvsCmdFlush",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Flush deletes all existing services in the passed
// handle.
|
[
"Flush",
"deletes",
"all",
"existing",
"services",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L150-L153
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
NewDestination
|
func (i *Handle) NewDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdNewDest)
}
|
go
|
func (i *Handle) NewDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdNewDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"NewDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdNewDest",
")",
"\n",
"}"
] |
// NewDestination creates a new real server in the passed ipvs
// service which should already be existing in the passed handle.
|
[
"NewDestination",
"creates",
"a",
"new",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"which",
"should",
"already",
"be",
"existing",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L157-L159
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
UpdateDestination
|
func (i *Handle) UpdateDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdSetDest)
}
|
go
|
func (i *Handle) UpdateDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdSetDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"UpdateDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdSetDest",
")",
"\n",
"}"
] |
// UpdateDestination updates an already existing real server in the
// passed ipvs service in the passed handle.
|
[
"UpdateDestination",
"updates",
"an",
"already",
"existing",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L163-L165
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
DelDestination
|
func (i *Handle) DelDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdDelDest)
}
|
go
|
func (i *Handle) DelDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdDelDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"DelDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdDelDest",
")",
"\n",
"}"
] |
// DelDestination deletes an already existing real server in the
// passed ipvs service in the passed handle.
|
[
"DelDestination",
"deletes",
"an",
"already",
"existing",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L169-L171
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
GetDestinations
|
func (i *Handle) GetDestinations(s *Service) ([]*Destination, error) {
return i.doGetDestinationsCmd(s, nil)
}
|
go
|
func (i *Handle) GetDestinations(s *Service) ([]*Destination, error) {
return i.doGetDestinationsCmd(s, nil)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"GetDestinations",
"(",
"s",
"*",
"Service",
")",
"(",
"[",
"]",
"*",
"Destination",
",",
"error",
")",
"{",
"return",
"i",
".",
"doGetDestinationsCmd",
"(",
"s",
",",
"nil",
")",
"\n",
"}"
] |
// GetDestinations returns an array of Destinations configured for this Service
|
[
"GetDestinations",
"returns",
"an",
"array",
"of",
"Destinations",
"configured",
"for",
"this",
"Service"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L179-L181
|
train
|
docker/libnetwork
|
ipvs/ipvs.go
|
GetService
|
func (i *Handle) GetService(s *Service) (*Service, error) {
res, err := i.doGetServicesCmd(s)
if err != nil {
return nil, err
}
// We are looking for exactly one service otherwise error out
if len(res) != 1 {
return nil, fmt.Errorf("Expected only one service obtained=%d", len(res))
}
return res[0], nil
}
|
go
|
func (i *Handle) GetService(s *Service) (*Service, error) {
res, err := i.doGetServicesCmd(s)
if err != nil {
return nil, err
}
// We are looking for exactly one service otherwise error out
if len(res) != 1 {
return nil, fmt.Errorf("Expected only one service obtained=%d", len(res))
}
return res[0], nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"GetService",
"(",
"s",
"*",
"Service",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"i",
".",
"doGetServicesCmd",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"res",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Expected only one service obtained=%d\"",
",",
"len",
"(",
"res",
")",
")",
"\n",
"}",
"\n",
"return",
"res",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] |
// GetService gets details of a specific IPVS services, useful in updating statisics etc.,
|
[
"GetService",
"gets",
"details",
"of",
"a",
"specific",
"IPVS",
"services",
"useful",
"in",
"updating",
"statisics",
"etc",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L184-L197
|
train
|
docker/libnetwork
|
portmapper/mapper.go
|
NewWithPortAllocator
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
return &PortMapper{
currentMappings: make(map[string]*mapping),
Allocator: allocator,
proxyPath: proxyPath,
}
}
|
go
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
return &PortMapper{
currentMappings: make(map[string]*mapping),
Allocator: allocator,
proxyPath: proxyPath,
}
}
|
[
"func",
"NewWithPortAllocator",
"(",
"allocator",
"*",
"portallocator",
".",
"PortAllocator",
",",
"proxyPath",
"string",
")",
"*",
"PortMapper",
"{",
"return",
"&",
"PortMapper",
"{",
"currentMappings",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"mapping",
")",
",",
"Allocator",
":",
"allocator",
",",
"proxyPath",
":",
"proxyPath",
",",
"}",
"\n",
"}"
] |
// NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator
|
[
"NewWithPortAllocator",
"returns",
"a",
"new",
"instance",
"of",
"PortMapper",
"which",
"will",
"use",
"the",
"specified",
"PortAllocator"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L39-L45
|
train
|
docker/libnetwork
|
portmapper/mapper.go
|
Map
|
func (pm *PortMapper) Map(container net.Addr, hostIP net.IP, hostPort int, useProxy bool) (host net.Addr, err error) {
return pm.MapRange(container, hostIP, hostPort, hostPort, useProxy)
}
|
go
|
func (pm *PortMapper) Map(container net.Addr, hostIP net.IP, hostPort int, useProxy bool) (host net.Addr, err error) {
return pm.MapRange(container, hostIP, hostPort, hostPort, useProxy)
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"Map",
"(",
"container",
"net",
".",
"Addr",
",",
"hostIP",
"net",
".",
"IP",
",",
"hostPort",
"int",
",",
"useProxy",
"bool",
")",
"(",
"host",
"net",
".",
"Addr",
",",
"err",
"error",
")",
"{",
"return",
"pm",
".",
"MapRange",
"(",
"container",
",",
"hostIP",
",",
"hostPort",
",",
"hostPort",
",",
"useProxy",
")",
"\n",
"}"
] |
// Map maps the specified container transport address to the host's network address and transport port
|
[
"Map",
"maps",
"the",
"specified",
"container",
"transport",
"address",
"to",
"the",
"host",
"s",
"network",
"address",
"and",
"transport",
"port"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L48-L50
|
train
|
docker/libnetwork
|
portmapper/mapper.go
|
Unmap
|
func (pm *PortMapper) Unmap(host net.Addr) error {
pm.lock.Lock()
defer pm.lock.Unlock()
key := getKey(host)
data, exists := pm.currentMappings[key]
if !exists {
return ErrPortNotMapped
}
if data.userlandProxy != nil {
data.userlandProxy.Stop()
}
delete(pm.currentMappings, key)
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.DeleteForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables delete: %s", err)
}
switch a := host.(type) {
case *net.TCPAddr:
return pm.Allocator.ReleasePort(a.IP, "tcp", a.Port)
case *net.UDPAddr:
return pm.Allocator.ReleasePort(a.IP, "udp", a.Port)
case *sctp.SCTPAddr:
if len(a.IP) == 0 {
return ErrSCTPAddrNoIP
}
return pm.Allocator.ReleasePort(a.IP[0], "sctp", a.Port)
}
return ErrUnknownBackendAddressType
}
|
go
|
func (pm *PortMapper) Unmap(host net.Addr) error {
pm.lock.Lock()
defer pm.lock.Unlock()
key := getKey(host)
data, exists := pm.currentMappings[key]
if !exists {
return ErrPortNotMapped
}
if data.userlandProxy != nil {
data.userlandProxy.Stop()
}
delete(pm.currentMappings, key)
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.DeleteForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables delete: %s", err)
}
switch a := host.(type) {
case *net.TCPAddr:
return pm.Allocator.ReleasePort(a.IP, "tcp", a.Port)
case *net.UDPAddr:
return pm.Allocator.ReleasePort(a.IP, "udp", a.Port)
case *sctp.SCTPAddr:
if len(a.IP) == 0 {
return ErrSCTPAddrNoIP
}
return pm.Allocator.ReleasePort(a.IP[0], "sctp", a.Port)
}
return ErrUnknownBackendAddressType
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"Unmap",
"(",
"host",
"net",
".",
"Addr",
")",
"error",
"{",
"pm",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pm",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"key",
":=",
"getKey",
"(",
"host",
")",
"\n",
"data",
",",
"exists",
":=",
"pm",
".",
"currentMappings",
"[",
"key",
"]",
"\n",
"if",
"!",
"exists",
"{",
"return",
"ErrPortNotMapped",
"\n",
"}",
"\n",
"if",
"data",
".",
"userlandProxy",
"!=",
"nil",
"{",
"data",
".",
"userlandProxy",
".",
"Stop",
"(",
")",
"\n",
"}",
"\n",
"delete",
"(",
"pm",
".",
"currentMappings",
",",
"key",
")",
"\n",
"containerIP",
",",
"containerPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"container",
")",
"\n",
"hostIP",
",",
"hostPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"host",
")",
"\n",
"if",
"err",
":=",
"pm",
".",
"DeleteForwardingTableEntry",
"(",
"data",
".",
"proto",
",",
"hostIP",
",",
"hostPort",
",",
"containerIP",
".",
"String",
"(",
")",
",",
"containerPort",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"Error on iptables delete: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"switch",
"a",
":=",
"host",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"TCPAddr",
":",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
",",
"\"tcp\"",
",",
"a",
".",
"Port",
")",
"\n",
"case",
"*",
"net",
".",
"UDPAddr",
":",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
",",
"\"udp\"",
",",
"a",
".",
"Port",
")",
"\n",
"case",
"*",
"sctp",
".",
"SCTPAddr",
":",
"if",
"len",
"(",
"a",
".",
"IP",
")",
"==",
"0",
"{",
"return",
"ErrSCTPAddrNoIP",
"\n",
"}",
"\n",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
"[",
"0",
"]",
",",
"\"sctp\"",
",",
"a",
".",
"Port",
")",
"\n",
"}",
"\n",
"return",
"ErrUnknownBackendAddressType",
"\n",
"}"
] |
// Unmap removes stored mapping for the specified host transport address
|
[
"Unmap",
"removes",
"stored",
"mapping",
"for",
"the",
"specified",
"host",
"transport",
"address"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L185-L219
|
train
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.