repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L380-L383
go
train
//You can focus individual Its using FIt
func FIt(text string, body interface{}, timeout ...float64) bool
//You can focus individual Its using FIt func FIt(text string, body interface{}, timeout ...float64) bool
{ globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L386-L389
go
train
//You can mark Its as pending using PIt
func PIt(text string, _ ...interface{}) bool
//You can mark Its as pending using PIt func PIt(text string, _ ...interface{}) bool
{ globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L412-L415
go
train
//You can mark Specifys as pending using PSpecify
func PSpecify(text string, is ...interface{}) bool
//You can mark Specifys as pending using PSpecify func PSpecify(text string, is ...interface{}) bool
{ globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L430-L442
go
train
//By allows you to better document large Its. // //Generally you should try to keep your Its short and to the point. This is not always possible, however, //especially in the context of integration tests that capture a particular workflow. // //By allows you to document such flows. By must be called within a runnable node (It, BeforeEach, Measure, etc...) //By will simply log the passed in text to the GinkgoWriter. If By is handed a function it will immediately run the function.
func By(text string, callbacks ...func())
//By allows you to better document large Its. // //Generally you should try to keep your Its short and to the point. This is not always possible, however, //especially in the context of integration tests that capture a particular workflow. // //By allows you to document such flows. By must be called within a runnable node (It, BeforeEach, Measure, etc...) //By will simply log the passed in text to the GinkgoWriter. If By is handed a function it will immediately run the function. func By(text string, callbacks ...func())
{ preamble := "\x1b[1mSTEP\x1b[0m" if config.DefaultReporterConfig.NoColor { preamble = "STEP" } fmt.Fprintln(GinkgoWriter, preamble+": "+text) if len(callbacks) == 1 { callbacks[0]() } if len(callbacks) > 1 { panic("just one callback per By, please") } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L449-L452
go
train
//Measure blocks run the passed in body function repeatedly (determined by the samples argument) //and accumulate metrics provided to the Benchmarker by the body function. // //The body function must have the signature: // func(b Benchmarker)
func Measure(text string, body interface{}, samples int) bool
//Measure blocks run the passed in body function repeatedly (determined by the samples argument) //and accumulate metrics provided to the Benchmarker by the body function. // //The body function must have the signature: // func(b Benchmarker) func Measure(text string, body interface{}, samples int) bool
{ globalSuite.PushMeasureNode(text, body, types.FlagTypeNone, codelocation.New(1), samples) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L455-L458
go
train
//You can focus individual Measures using FMeasure
func FMeasure(text string, body interface{}, samples int) bool
//You can focus individual Measures using FMeasure func FMeasure(text string, body interface{}, samples int) bool
{ globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L461-L464
go
train
//You can mark Measurements as pending using PMeasure
func PMeasure(text string, _ ...interface{}) bool
//You can mark Measurements as pending using PMeasure func PMeasure(text string, _ ...interface{}) bool
{ globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L478-L481
go
train
//BeforeSuite blocks are run just once before any specs are run. When running in parallel, each //parallel node process will call BeforeSuite. // //BeforeSuite blocks can be made asynchronous by providing a body function that accepts a Done channel // //You may only register *one* BeforeSuite handler per test suite. You typically do so in your bootstrap file at the top level.
func BeforeSuite(body interface{}, timeout ...float64) bool
//BeforeSuite blocks are run just once before any specs are run. When running in parallel, each //parallel node process will call BeforeSuite. // //BeforeSuite blocks can be made asynchronous by providing a body function that accepts a Done channel // //You may only register *one* BeforeSuite handler per test suite. You typically do so in your bootstrap file at the top level. func BeforeSuite(body interface{}, timeout ...float64) bool
{ globalSuite.SetBeforeSuiteNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L491-L494
go
train
//AfterSuite blocks are *always* run after all the specs regardless of whether specs have passed or failed. //Moreover, if Ginkgo receives an interrupt signal (^C) it will attempt to run the AfterSuite before exiting. // //When running in parallel, each parallel node process will call AfterSuite. // //AfterSuite blocks can be made asynchronous by providing a body function that accepts a Done channel // //You may only register *one* AfterSuite handler per test suite. You typically do so in your bootstrap file at the top level.
func AfterSuite(body interface{}, timeout ...float64) bool
//AfterSuite blocks are *always* run after all the specs regardless of whether specs have passed or failed. //Moreover, if Ginkgo receives an interrupt signal (^C) it will attempt to run the AfterSuite before exiting. // //When running in parallel, each parallel node process will call AfterSuite. // //AfterSuite blocks can be made asynchronous by providing a body function that accepts a Done channel // //You may only register *one* AfterSuite handler per test suite. You typically do so in your bootstrap file at the top level. func AfterSuite(body interface{}, timeout ...float64) bool
{ globalSuite.SetAfterSuiteNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L536-L544
go
train
//SynchronizedBeforeSuite blocks are primarily meant to solve the problem of setting up singleton external resources shared across //nodes when running tests in parallel. For example, say you have a shared database that you can only start one instance of that //must be used in your tests. When running in parallel, only one node should set up the database and all other nodes should wait //until that node is done before running. // //SynchronizedBeforeSuite accomplishes this by taking *two* function arguments. The first is only run on parallel node #1. The second is //run on all nodes, but *only* after the first function completes succesfully. Ginkgo also makes it possible to send data from the first function (on Node 1) //to the second function (on all the other nodes). // //The functions have the following signatures. The first function (which only runs on node 1) has the signature: // // func() []byte // //or, to run asynchronously: // // func(done Done) []byte // //The byte array returned by the first function is then passed to the second function, which has the signature: // // func(data []byte) // //or, to run asynchronously: // // func(data []byte, done Done) // //Here's a simple pseudo-code example that starts a shared database on Node 1 and shares the database's address with the other nodes: // // var dbClient db.Client // var dbRunner db.Runner // // var _ = SynchronizedBeforeSuite(func() []byte { // dbRunner = db.NewRunner() // err := dbRunner.Start() // Ω(err).ShouldNot(HaveOccurred()) // return []byte(dbRunner.URL) // }, func(data []byte) { // dbClient = db.NewClient() // err := dbClient.Connect(string(data)) // Ω(err).ShouldNot(HaveOccurred()) // })
func SynchronizedBeforeSuite(node1Body interface{}, allNodesBody interface{}, timeout ...float64) bool
//SynchronizedBeforeSuite blocks are primarily meant to solve the problem of setting up singleton external resources shared across //nodes when running tests in parallel. For example, say you have a shared database that you can only start one instance of that //must be used in your tests. When running in parallel, only one node should set up the database and all other nodes should wait //until that node is done before running. // //SynchronizedBeforeSuite accomplishes this by taking *two* function arguments. The first is only run on parallel node #1. The second is //run on all nodes, but *only* after the first function completes succesfully. Ginkgo also makes it possible to send data from the first function (on Node 1) //to the second function (on all the other nodes). // //The functions have the following signatures. The first function (which only runs on node 1) has the signature: // // func() []byte // //or, to run asynchronously: // // func(done Done) []byte // //The byte array returned by the first function is then passed to the second function, which has the signature: // // func(data []byte) // //or, to run asynchronously: // // func(data []byte, done Done) // //Here's a simple pseudo-code example that starts a shared database on Node 1 and shares the database's address with the other nodes: // // var dbClient db.Client // var dbRunner db.Runner // // var _ = SynchronizedBeforeSuite(func() []byte { // dbRunner = db.NewRunner() // err := dbRunner.Start() // Ω(err).ShouldNot(HaveOccurred()) // return []byte(dbRunner.URL) // }, func(data []byte) { // dbClient = db.NewClient() // err := dbClient.Connect(string(data)) // Ω(err).ShouldNot(HaveOccurred()) // }) func SynchronizedBeforeSuite(node1Body interface{}, allNodesBody interface{}, timeout ...float64) bool
{ globalSuite.SetSynchronizedBeforeSuiteNode( node1Body, allNodesBody, codelocation.New(1), parseTimeout(timeout...), ) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L563-L571
go
train
//SynchronizedAfterSuite blocks complement the SynchronizedBeforeSuite blocks in solving the problem of setting up //external singleton resources shared across nodes when running tests in parallel. // //SynchronizedAfterSuite accomplishes this by taking *two* function arguments. The first runs on all nodes. The second runs only on parallel node #1 //and *only* after all other nodes have finished and exited. This ensures that node 1, and any resources it is running, remain alive until //all other nodes are finished. // //Both functions have the same signature: either func() or func(done Done) to run asynchronously. // //Here's a pseudo-code example that complements that given in SynchronizedBeforeSuite. Here, SynchronizedAfterSuite is used to tear down the shared database //only after all nodes have finished: // // var _ = SynchronizedAfterSuite(func() { // dbClient.Cleanup() // }, func() { // dbRunner.Stop() // })
func SynchronizedAfterSuite(allNodesBody interface{}, node1Body interface{}, timeout ...float64) bool
//SynchronizedAfterSuite blocks complement the SynchronizedBeforeSuite blocks in solving the problem of setting up //external singleton resources shared across nodes when running tests in parallel. // //SynchronizedAfterSuite accomplishes this by taking *two* function arguments. The first runs on all nodes. The second runs only on parallel node #1 //and *only* after all other nodes have finished and exited. This ensures that node 1, and any resources it is running, remain alive until //all other nodes are finished. // //Both functions have the same signature: either func() or func(done Done) to run asynchronously. // //Here's a pseudo-code example that complements that given in SynchronizedBeforeSuite. Here, SynchronizedAfterSuite is used to tear down the shared database //only after all nodes have finished: // // var _ = SynchronizedAfterSuite(func() { // dbClient.Cleanup() // }, func() { // dbRunner.Stop() // }) func SynchronizedAfterSuite(allNodesBody interface{}, node1Body interface{}, timeout ...float64) bool
{ globalSuite.SetSynchronizedAfterSuiteNode( allNodesBody, node1Body, codelocation.New(1), parseTimeout(timeout...), ) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L578-L581
go
train
//BeforeEach blocks are run before It blocks. When multiple BeforeEach blocks are defined in nested //Describe and Context blocks the outermost BeforeEach blocks are run first. // //Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts //a Done channel
func BeforeEach(body interface{}, timeout ...float64) bool
//BeforeEach blocks are run before It blocks. When multiple BeforeEach blocks are defined in nested //Describe and Context blocks the outermost BeforeEach blocks are run first. // //Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts //a Done channel func BeforeEach(body interface{}, timeout ...float64) bool
{ globalSuite.PushBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L588-L591
go
train
//JustBeforeEach blocks are run before It blocks but *after* all BeforeEach blocks. For more details, //read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_) // //Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts //a Done channel
func JustBeforeEach(body interface{}, timeout ...float64) bool
//JustBeforeEach blocks are run before It blocks but *after* all BeforeEach blocks. For more details, //read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_) // //Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts //a Done channel func JustBeforeEach(body interface{}, timeout ...float64) bool
{ globalSuite.PushJustBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L598-L601
go
train
//JustAfterEach blocks are run after It blocks but *before* all AfterEach blocks. For more details, //read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_) // //Like It blocks, JustAfterEach blocks can be made asynchronous by providing a body function that accepts //a Done channel
func JustAfterEach(body interface{}, timeout ...float64) bool
//JustAfterEach blocks are run after It blocks but *before* all AfterEach blocks. For more details, //read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_) // //Like It blocks, JustAfterEach blocks can be made asynchronous by providing a body function that accepts //a Done channel func JustAfterEach(body interface{}, timeout ...float64) bool
{ globalSuite.PushJustAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L608-L611
go
train
//AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested //Describe and Context blocks the innermost AfterEach blocks are run first. // //Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts //a Done channel
func AfterEach(body interface{}, timeout ...float64) bool
//AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested //Describe and Context blocks the innermost AfterEach blocks are run first. // //Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts //a Done channel func AfterEach(body interface{}, timeout ...float64) bool
{ globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
reporters/stenographer/support/go-isatty/isatty_linux.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/reporters/stenographer/support/go-isatty/isatty_linux.go#L14-L18
go
train
// IsTerminal return true if the file descriptor is terminal.
func IsTerminal(fd uintptr) bool
// IsTerminal return true if the file descriptor is terminal. func IsTerminal(fd uintptr) bool
{ var termios syscall.Termios _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) return err == 0 }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/macvlan/macvlan_store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_store.go#L46-L62
go
train
// initStore drivers are responsible for caching their own persistent state
func (d *driver) initStore(option map[string]interface{}) error
// initStore drivers are responsible for caching their own persistent state func (d *driver) initStore(option map[string]interface{}) error
{ if data, ok := option[netlabel.LocalKVClient]; ok { var err error dsc, ok := data.(discoverapi.DatastoreConfigData) if !ok { return types.InternalErrorf("incorrect data in datastore configuration: %v", data) } d.store, err = datastore.NewDataStoreFromConfig(dsc) if err != nil { return types.InternalErrorf("macvlan driver failed to initialize data store: %v", err) } return d.populateNetworks() } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/macvlan/macvlan_store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_store.go#L65-L82
go
train
// populateNetworks is invoked at driver init to recreate persistently stored networks
func (d *driver) populateNetworks() error
// populateNetworks is invoked at driver init to recreate persistently stored networks func (d *driver) populateNetworks() error
{ kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{}) if err != nil && err != datastore.ErrKeyNotFound { return fmt.Errorf("failed to get macvlan network configurations from store: %v", err) } // If empty it simply means no macvlan networks have been created yet if err == datastore.ErrKeyNotFound { return nil } for _, kvo := range kvol { config := kvo.(*configuration) if err = d.createNetwork(config); err != nil { logrus.Warnf("Could not create macvlan network for id %s from persistent state", config.ID) } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_endpoint.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_endpoint.go#L15-L62
go
train
// CreateEndpoint assigns the mac, ip and endpoint id for the new container
func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error
// CreateEndpoint assigns the mac, ip and endpoint id for the new container func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error
{ defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err } n, err := d.getNetwork(nid) if err != nil { return fmt.Errorf("network id %q not found", nid) } if ifInfo.MacAddress() != nil { return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType) } ep := &endpoint{ id: eid, nid: nid, addr: ifInfo.Address(), addrv6: ifInfo.AddressIPv6(), } if ep.addr == nil { return fmt.Errorf("create endpoint was not passed an IP address") } // disallow port mapping -p if opt, ok := epOptions[netlabel.PortMap]; ok { if _, ok := opt.([]types.PortBinding); ok { if len(opt.([]types.PortBinding)) > 0 { logrus.Warnf("%s driver does not support port mappings", ipvlanType) } } } // disallow port exposure --expose if opt, ok := epOptions[netlabel.ExposedPorts]; ok { if _, ok := opt.([]types.TransportPort); ok { if len(opt.([]types.TransportPort)) > 0 { logrus.Warnf("%s driver does not support port exposures", ipvlanType) } } } if err := d.storeUpdate(ep); err != nil { return fmt.Errorf("failed to save ipvlan endpoint %.7s to store: %v", ep.id, err) } n.addEndpoint(ep) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_endpoint.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_endpoint.go#L65-L89
go
train
// DeleteEndpoint remove the endpoint and associated netlink interface
func (d *driver) DeleteEndpoint(nid, eid string) error
// DeleteEndpoint remove the endpoint and associated netlink interface func (d *driver) DeleteEndpoint(nid, eid string) error
{ defer osl.InitOSContext()() if err := validateID(nid, eid); err != nil { return err } n := d.network(nid) if n == nil { return fmt.Errorf("network id %q not found", nid) } ep := n.endpoint(eid) if ep == nil { return fmt.Errorf("endpoint id %q not found", eid) } if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil { if err := ns.NlHandle().LinkDel(link); err != nil { logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id) } } if err := d.storeDelete(ep); err != nil { logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err) } n.deleteEndpoint(ep.id) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/kernel/knobs_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/kernel/knobs_linux.go#L19-L26
go
train
// readSystemProperty reads the value from the path under /proc/sys and returns it
func readSystemProperty(key string) (string, error)
// readSystemProperty reads the value from the path under /proc/sys and returns it func readSystemProperty(key string) (string, error)
{ keyPath := strings.Replace(key, ".", "/", -1) value, err := ioutil.ReadFile(path.Join("/proc/sys", keyPath)) if err != nil { return "", err } return strings.TrimSpace(string(value)), nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/kernel/knobs_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/kernel/knobs_linux.go#L29-L47
go
train
// ApplyOSTweaks applies the configuration values passed as arguments
func ApplyOSTweaks(osConfig map[string]*OSValue)
// ApplyOSTweaks applies the configuration values passed as arguments func ApplyOSTweaks(osConfig map[string]*OSValue)
{ for k, v := range osConfig { // read the existing property from disk oldv, err := readSystemProperty(k) if err != nil { logrus.WithError(err).Errorf("error reading the kernel parameter %s", k) continue } if propertyIsValid(oldv, v.Value, v.CheckFn) { // write new prop value to disk if err := writeSystemProperty(k, v.Value); err != nil { logrus.WithError(err).Errorf("error setting the kernel parameter %s = %s, (leaving as %s)", k, v.Value, oldv) continue } logrus.Debugf("updated kernel parameter %s = %s (was %s)", k, v.Value, oldv) } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/null/null.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/null/null.go#L73-L75
go
train
// Init registers a remote ipam when its plugin is activated
func Init(ic ipamapi.Callback, l, g interface{}) error
// Init registers a remote ipam when its plugin is activated func Init(ic ipamapi.Callback, l, g interface{}) error
{ return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{}) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
idm/idm.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L20-L34
go
train
// New returns an instance of id manager for a [start,end] set of numerical ids
func New(ds datastore.DataStore, id string, start, end uint64) (*Idm, error)
// New returns an instance of id manager for a [start,end] set of numerical ids func New(ds datastore.DataStore, id string, start, end uint64) (*Idm, error)
{ if id == "" { return nil, errors.New("Invalid id") } if end <= start { return nil, fmt.Errorf("Invalid set range: [%d, %d]", start, end) } h, err := bitseq.NewHandle("idm", ds, id, 1+end-start) if err != nil { return nil, fmt.Errorf("failed to initialize bit sequence handler: %s", err.Error()) } return &Idm{start: start, end: end, handle: h}, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
idm/idm.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L37-L43
go
train
// GetID returns the first available id in the set
func (i *Idm) GetID(serial bool) (uint64, error)
// GetID returns the first available id in the set func (i *Idm) GetID(serial bool) (uint64, error)
{ if i.handle == nil { return 0, errors.New("ID set is not initialized") } ordinal, err := i.handle.SetAny(serial) return i.start + ordinal, err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
idm/idm.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L46-L56
go
train
// GetSpecificID tries to reserve the specified id
func (i *Idm) GetSpecificID(id uint64) error
// GetSpecificID tries to reserve the specified id func (i *Idm) GetSpecificID(id uint64) error
{ if i.handle == nil { return errors.New("ID set is not initialized") } if id < i.start || id > i.end { return errors.New("Requested id does not belong to the set") } return i.handle.Set(id - i.start) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
idm/idm.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L59-L71
go
train
// GetIDInRange returns the first available id in the set within a [start,end] range
func (i *Idm) GetIDInRange(start, end uint64, serial bool) (uint64, error)
// GetIDInRange returns the first available id in the set within a [start,end] range func (i *Idm) GetIDInRange(start, end uint64, serial bool) (uint64, error)
{ if i.handle == nil { return 0, errors.New("ID set is not initialized") } if start < i.start || end > i.end { return 0, errors.New("Requested range does not belong to the set") } ordinal, err := i.handle.SetAnyInRange(start-i.start, end-i.start, serial) return i.start + ordinal, err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
idm/idm.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L74-L76
go
train
// Release releases the specified id
func (i *Idm) Release(id uint64)
// Release releases the specified id func (i *Idm) Release(id uint64)
{ i.handle.Unset(id - i.start) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L45-L59
go
train
// Equal checks if this instance of Transportport is equal to the passed one
func (t *TransportPort) Equal(o *TransportPort) bool
// Equal checks if this instance of Transportport is equal to the passed one func (t *TransportPort) Equal(o *TransportPort) bool
{ if t == o { return true } if o == nil { return false } if t.Proto != o.Proto || t.Port != o.Port { return false } return true }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L62-L64
go
train
// GetCopy returns a copy of this TransportPort structure instance
func (t *TransportPort) GetCopy() TransportPort
// GetCopy returns a copy of this TransportPort structure instance func (t *TransportPort) GetCopy() TransportPort
{ return TransportPort{Proto: t.Proto, Port: t.Port} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L67-L69
go
train
// String returns the TransportPort structure in string form
func (t *TransportPort) String() string
// String returns the TransportPort structure in string form func (t *TransportPort) String() string
{ return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L72-L82
go
train
// FromString reads the TransportPort structure from string
func (t *TransportPort) FromString(s string) error
// FromString reads the TransportPort structure from string func (t *TransportPort) FromString(s string) error
{ ps := strings.Split(s, "/") if len(ps) == 2 { t.Proto = ParseProtocol(ps[0]) if p, err := strconv.ParseUint(ps[1], 10, 16); err == nil { t.Port = uint16(p) return nil } } return BadRequestErrorf("invalid format for transport port: %s", s) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L95-L106
go
train
// HostAddr returns the host side transport address
func (p PortBinding) HostAddr() (net.Addr, error)
// HostAddr returns the host side transport address func (p PortBinding) HostAddr() (net.Addr, error)
{ switch p.Proto { case UDP: return &net.UDPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil case TCP: return &net.TCPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil case SCTP: return &sctp.SCTPAddr{IP: []net.IP{p.HostIP}, Port: int(p.HostPort)}, nil default: return nil, ErrInvalidProtocolBinding(p.Proto.String()) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L123-L132
go
train
// GetCopy returns a copy of this PortBinding structure instance
func (p *PortBinding) GetCopy() PortBinding
// GetCopy returns a copy of this PortBinding structure instance func (p *PortBinding) GetCopy() PortBinding
{ return PortBinding{ Proto: p.Proto, IP: GetIPCopy(p.IP), Port: p.Port, HostIP: GetIPCopy(p.HostIP), HostPort: p.HostPort, HostPortEnd: p.HostPortEnd, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L135-L146
go
train
// String returns the PortBinding structure in string form
func (p *PortBinding) String() string
// String returns the PortBinding structure in string form func (p *PortBinding) String() string
{ ret := fmt.Sprintf("%s/", p.Proto) if p.IP != nil { ret += p.IP.String() } ret = fmt.Sprintf("%s:%d/", ret, p.Port) if p.HostIP != nil { ret += p.HostIP.String() } ret = fmt.Sprintf("%s:%d", ret, p.HostPort) return ret }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L154-L172
go
train
// FromString reads the PortBinding structure from string s. // String s is a triple of "protocol/containerIP:port/hostIP:port" // containerIP and hostIP can be in dotted decimal ("192.0.2.1") or IPv6 ("2001:db8::68") form. // Zoned addresses ("169.254.0.23%eth0" or "fe80::1ff:fe23:4567:890a%eth0") are not supported. // If string s is incorrectly formatted or the IP addresses or ports cannot be parsed, FromString // returns an error.
func (p *PortBinding) FromString(s string) error
// FromString reads the PortBinding structure from string s. // String s is a triple of "protocol/containerIP:port/hostIP:port" // containerIP and hostIP can be in dotted decimal ("192.0.2.1") or IPv6 ("2001:db8::68") form. // Zoned addresses ("169.254.0.23%eth0" or "fe80::1ff:fe23:4567:890a%eth0") are not supported. // If string s is incorrectly formatted or the IP addresses or ports cannot be parsed, FromString // returns an error. func (p *PortBinding) FromString(s string) error
{ ps := strings.Split(s, "/") if len(ps) != 3 { return BadRequestErrorf("invalid format for port binding: %s", s) } p.Proto = ParseProtocol(ps[0]) var err error if p.IP, p.Port, err = parseIPPort(ps[1]); err != nil { return BadRequestErrorf("failed to parse Container IP/Port in port binding: %s", err.Error()) } if p.HostIP, p.HostPort, err = parseIPPort(ps[2]); err != nil { return BadRequestErrorf("failed to parse Host IP/Port in port binding: %s", err.Error()) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L194-L229
go
train
// Equal checks if this instance of PortBinding is equal to the passed one
func (p *PortBinding) Equal(o *PortBinding) bool
// Equal checks if this instance of PortBinding is equal to the passed one func (p *PortBinding) Equal(o *PortBinding) bool
{ if p == o { return true } if o == nil { return false } if p.Proto != o.Proto || p.Port != o.Port || p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd { return false } if p.IP != nil { if !p.IP.Equal(o.IP) { return false } } else { if o.IP != nil { return false } } if p.HostIP != nil { if !p.HostIP.Equal(o.HostIP) { return false } } else { if o.HostIP != nil { return false } } return true }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L268-L281
go
train
// ParseProtocol returns the respective Protocol type for the passed string
func ParseProtocol(s string) Protocol
// ParseProtocol returns the respective Protocol type for the passed string func ParseProtocol(s string) Protocol
{ switch strings.ToLower(s) { case "icmp": return ICMP case "udp": return UDP case "tcp": return TCP case "sctp": return SCTP default: return 0 } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L284-L291
go
train
// GetMacCopy returns a copy of the passed MAC address
func GetMacCopy(from net.HardwareAddr) net.HardwareAddr
// GetMacCopy returns a copy of the passed MAC address func GetMacCopy(from net.HardwareAddr) net.HardwareAddr
{ if from == nil { return nil } to := make(net.HardwareAddr, len(from)) copy(to, from) return to }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L294-L301
go
train
// GetIPCopy returns a copy of the passed IP address
func GetIPCopy(from net.IP) net.IP
// GetIPCopy returns a copy of the passed IP address func GetIPCopy(from net.IP) net.IP
{ if from == nil { return nil } to := make(net.IP, len(from)) copy(to, from) return to }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L304-L311
go
train
// GetIPNetCopy returns a copy of the passed IP Network
func GetIPNetCopy(from *net.IPNet) *net.IPNet
// GetIPNetCopy returns a copy of the passed IP Network func GetIPNetCopy(from *net.IPNet) *net.IPNet
{ if from == nil { return nil } bm := make(net.IPMask, len(from.Mask)) copy(bm, from.Mask) return &net.IPNet{IP: GetIPCopy(from.IP), Mask: bm} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L314-L321
go
train
// GetIPNetCanonical returns the canonical form for the passed network
func GetIPNetCanonical(nw *net.IPNet) *net.IPNet
// GetIPNetCanonical returns the canonical form for the passed network func GetIPNetCanonical(nw *net.IPNet) *net.IPNet
{ if nw == nil { return nil } c := GetIPNetCopy(nw) c.IP = c.IP.Mask(nw.Mask) return c }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L324-L332
go
train
// CompareIPNet returns equal if the two IP Networks are equal
func CompareIPNet(a, b *net.IPNet) bool
// CompareIPNet returns equal if the two IP Networks are equal func CompareIPNet(a, b *net.IPNet) bool
{ if a == b { return true } if a == nil || b == nil { return false } return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L337-L342
go
train
// GetMinimalIP returns the address in its shortest form // If ip contains an IPv4-mapped IPv6 address, the 4-octet form of the IPv4 address will be returned. // Otherwise ip is returned unchanged.
func GetMinimalIP(ip net.IP) net.IP
// GetMinimalIP returns the address in its shortest form // If ip contains an IPv4-mapped IPv6 address, the 4-octet form of the IPv4 address will be returned. // Otherwise ip is returned unchanged. func GetMinimalIP(ip net.IP) net.IP
{ if ip != nil && ip.To4() != nil { return ip.To4() } return ip }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L345-L357
go
train
// GetMinimalIPNet returns a copy of the passed IP Network with congruent ip and mask notation
func GetMinimalIPNet(nw *net.IPNet) *net.IPNet
// GetMinimalIPNet returns a copy of the passed IP Network with congruent ip and mask notation func GetMinimalIPNet(nw *net.IPNet) *net.IPNet
{ if nw == nil { return nil } if len(nw.IP) == 16 && nw.IP.To4() != nil { m := nw.Mask if len(m) == 16 { m = m[12:16] } return &net.IPNet{IP: nw.IP.To4(), Mask: m} } return nw }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L370-L383
go
train
// compareIPMask checks if the passed ip and mask are semantically compatible. // It returns the byte indexes for the address and mask so that caller can // do bitwise operations without modifying address representation.
func compareIPMask(ip net.IP, mask net.IPMask) (is int, ms int, err error)
// compareIPMask checks if the passed ip and mask are semantically compatible. // It returns the byte indexes for the address and mask so that caller can // do bitwise operations without modifying address representation. func compareIPMask(ip net.IP, mask net.IPMask) (is int, ms int, err error)
{ // Find the effective starting of address and mask if len(ip) == net.IPv6len && ip.To4() != nil { is = 12 } if len(ip[is:]) == net.IPv4len && len(mask) == net.IPv6len && bytes.Equal(mask[:12], v4inV6MaskPrefix) { ms = 12 } // Check if address and mask are semantically compatible if len(ip[is:]) != len(mask[ms:]) { err = fmt.Errorf("ip and mask are not compatible: (%#v, %#v)", ip, mask) } return }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L388-L402
go
train
// GetHostPartIP returns the host portion of the ip address identified by the mask. // IP address representation is not modified. If address and mask are not compatible // an error is returned.
func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error)
// GetHostPartIP returns the host portion of the ip address identified by the mask. // IP address representation is not modified. If address and mask are not compatible // an error is returned. func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error)
{ // Find the effective starting of address and mask is, ms, err := compareIPMask(ip, mask) if err != nil { return nil, fmt.Errorf("cannot compute host portion ip address because %s", err) } // Compute host portion out := GetIPCopy(ip) for i := 0; i < len(mask[ms:]); i++ { out[is+i] &= ^mask[ms+i] } return out, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L424-L430
go
train
// ParseCIDR returns the *net.IPNet represented by the passed CIDR notation
func ParseCIDR(cidr string) (n *net.IPNet, e error)
// ParseCIDR returns the *net.IPNet represented by the passed CIDR notation func ParseCIDR(cidr string) (n *net.IPNet, e error)
{ var i net.IP if i, n, e = net.ParseCIDR(cidr); e == nil { n.IP = i } return }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L451-L458
go
train
// GetCopy returns a copy of this StaticRoute structure
func (r *StaticRoute) GetCopy() *StaticRoute
// GetCopy returns a copy of this StaticRoute structure func (r *StaticRoute) GetCopy() *StaticRoute
{ d := GetIPNetCopy(r.Destination) nh := GetIPCopy(r.NextHop) return &StaticRoute{Destination: d, RouteType: r.RouteType, NextHop: nh, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L540-L542
go
train
/****************************** * Well-known Error Formatters ******************************/ // BadRequestErrorf creates an instance of BadRequestError
func BadRequestErrorf(format string, params ...interface{}) error
/****************************** * Well-known Error Formatters ******************************/ // BadRequestErrorf creates an instance of BadRequestError func BadRequestErrorf(format string, params ...interface{}) error
{ return badRequest(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L545-L547
go
train
// NotFoundErrorf creates an instance of NotFoundError
func NotFoundErrorf(format string, params ...interface{}) error
// NotFoundErrorf creates an instance of NotFoundError func NotFoundErrorf(format string, params ...interface{}) error
{ return notFound(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L550-L552
go
train
// ForbiddenErrorf creates an instance of ForbiddenError
func ForbiddenErrorf(format string, params ...interface{}) error
// ForbiddenErrorf creates an instance of ForbiddenError func ForbiddenErrorf(format string, params ...interface{}) error
{ return forbidden(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L555-L557
go
train
// NoServiceErrorf creates an instance of NoServiceError
func NoServiceErrorf(format string, params ...interface{}) error
// NoServiceErrorf creates an instance of NoServiceError func NoServiceErrorf(format string, params ...interface{}) error
{ return noService(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L560-L562
go
train
// NotImplementedErrorf creates an instance of NotImplementedError
func NotImplementedErrorf(format string, params ...interface{}) error
// NotImplementedErrorf creates an instance of NotImplementedError func NotImplementedErrorf(format string, params ...interface{}) error
{ return notImpl(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L565-L567
go
train
// TimeoutErrorf creates an instance of TimeoutError
func TimeoutErrorf(format string, params ...interface{}) error
// TimeoutErrorf creates an instance of TimeoutError func TimeoutErrorf(format string, params ...interface{}) error
{ return timeout(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L570-L572
go
train
// InternalErrorf creates an instance of InternalError
func InternalErrorf(format string, params ...interface{}) error
// InternalErrorf creates an instance of InternalError func InternalErrorf(format string, params ...interface{}) error
{ return internal(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L575-L577
go
train
// InternalMaskableErrorf creates an instance of InternalError and MaskableError
func InternalMaskableErrorf(format string, params ...interface{}) error
// InternalMaskableErrorf creates an instance of InternalError and MaskableError func InternalMaskableErrorf(format string, params ...interface{}) error
{ return maskInternal(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
types/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L580-L582
go
train
// RetryErrorf creates an instance of RetryError
func RetryErrorf(format string, params ...interface{}) error
// RetryErrorf creates an instance of RetryError func RetryErrorf(format string, params ...interface{}) error
{ return retry(fmt.Sprintf(format, params...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/macvlan/macvlan_state.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_state.go#L35-L45
go
train
// getNetworks Safely returns a slice of existing networks
func (d *driver) getNetworks() []*network
// getNetworks Safely returns a slice of existing networks func (d *driver) getNetworks() []*network
{ d.Lock() defer d.Unlock() ls := make([]*network, 0, len(d.networks)) for _, nw := range d.networks { ls = append(ls, nw) } return ls }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L58-L64
go
train
// LoadDefaultScopes loads default scope configs for scopes which // doesn't have explicit user specified configs.
func (c *Config) LoadDefaultScopes(dataDir string)
// LoadDefaultScopes loads default scope configs for scopes which // doesn't have explicit user specified configs. func (c *Config) LoadDefaultScopes(dataDir string)
{ for k, v := range datastore.DefaultScopes(dataDir) { if _, ok := c.Scopes[k]; !ok { c.Scopes[k] = v } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L67-L78
go
train
// ParseConfig parses the libnetwork configuration file
func ParseConfig(tomlCfgFile string) (*Config, error)
// ParseConfig parses the libnetwork configuration file func ParseConfig(tomlCfgFile string) (*Config, error)
{ cfg := &Config{ Scopes: map[string]*datastore.ScopeCfg{}, } if _, err := toml.DecodeFile(tomlCfgFile, cfg); err != nil { return nil, err } cfg.LoadDefaultScopes(cfg.Daemon.DataDir) return cfg, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L82-L94
go
train
// ParseConfigOptions parses the configuration options and returns // a reference to the corresponding Config structure
func ParseConfigOptions(cfgOptions ...Option) *Config
// ParseConfigOptions parses the configuration options and returns // a reference to the corresponding Config structure func ParseConfigOptions(cfgOptions ...Option) *Config
{ cfg := &Config{ Daemon: DaemonCfg{ DriverCfg: make(map[string]interface{}), }, Scopes: make(map[string]*datastore.ScopeCfg), } cfg.ProcessOptions(cfgOptions...) cfg.LoadDefaultScopes(cfg.Daemon.DataDir) return cfg }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L101-L106
go
train
// OptionDefaultNetwork function returns an option setter for a default network
func OptionDefaultNetwork(dn string) Option
// OptionDefaultNetwork function returns an option setter for a default network func OptionDefaultNetwork(dn string) Option
{ return func(c *Config) { logrus.Debugf("Option DefaultNetwork: %s", dn) c.Daemon.DefaultNetwork = strings.TrimSpace(dn) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L109-L114
go
train
// OptionDefaultDriver function returns an option setter for default driver
func OptionDefaultDriver(dd string) Option
// OptionDefaultDriver function returns an option setter for default driver func OptionDefaultDriver(dd string) Option
{ return func(c *Config) { logrus.Debugf("Option DefaultDriver: %s", dd) c.Daemon.DefaultDriver = strings.TrimSpace(dd) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L117-L121
go
train
// OptionDefaultAddressPoolConfig function returns an option setter for default address pool
func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Option
// OptionDefaultAddressPoolConfig function returns an option setter for default address pool func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Option
{ return func(c *Config) { c.Daemon.DefaultAddressPool = addressPool } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L124-L128
go
train
// OptionDriverConfig returns an option setter for driver configuration.
func OptionDriverConfig(networkType string, config map[string]interface{}) Option
// OptionDriverConfig returns an option setter for driver configuration. func OptionDriverConfig(networkType string, config map[string]interface{}) Option
{ return func(c *Config) { c.Daemon.DriverCfg[networkType] = config } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L131-L139
go
train
// OptionLabels function returns an option setter for labels
func OptionLabels(labels []string) Option
// OptionLabels function returns an option setter for labels func OptionLabels(labels []string) Option
{ return func(c *Config) { for _, label := range labels { if strings.HasPrefix(label, netlabel.Prefix) { c.Daemon.Labels = append(c.Daemon.Labels, label) } } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L142-L150
go
train
// OptionKVProvider function returns an option setter for kvstore provider
func OptionKVProvider(provider string) Option
// OptionKVProvider function returns an option setter for kvstore provider func OptionKVProvider(provider string) Option
{ return func(c *Config) { logrus.Debugf("Option OptionKVProvider: %s", provider) if _, ok := c.Scopes[datastore.GlobalScope]; !ok { c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{} } c.Scopes[datastore.GlobalScope].Client.Provider = strings.TrimSpace(provider) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L153-L161
go
train
// OptionKVProviderURL function returns an option setter for kvstore url
func OptionKVProviderURL(url string) Option
// OptionKVProviderURL function returns an option setter for kvstore url func OptionKVProviderURL(url string) Option
{ return func(c *Config) { logrus.Debugf("Option OptionKVProviderURL: %s", url) if _, ok := c.Scopes[datastore.GlobalScope]; !ok { c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{} } c.Scopes[datastore.GlobalScope].Client.Address = strings.TrimSpace(url) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L164-L195
go
train
// OptionKVOpts function returns an option setter for kvstore options
func OptionKVOpts(opts map[string]string) Option
// OptionKVOpts function returns an option setter for kvstore options func OptionKVOpts(opts map[string]string) Option
{ return func(c *Config) { if opts["kv.cacertfile"] != "" && opts["kv.certfile"] != "" && opts["kv.keyfile"] != "" { logrus.Info("Option Initializing KV with TLS") tlsConfig, err := tlsconfig.Client(tlsconfig.Options{ CAFile: opts["kv.cacertfile"], CertFile: opts["kv.certfile"], KeyFile: opts["kv.keyfile"], }) if err != nil { logrus.Errorf("Unable to set up TLS: %s", err) return } if _, ok := c.Scopes[datastore.GlobalScope]; !ok { c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{} } if c.Scopes[datastore.GlobalScope].Client.Config == nil { c.Scopes[datastore.GlobalScope].Client.Config = &store.Config{TLS: tlsConfig} } else { c.Scopes[datastore.GlobalScope].Client.Config.TLS = tlsConfig } // Workaround libkv/etcd bug for https c.Scopes[datastore.GlobalScope].Client.Config.ClientTLS = &store.ClientTLSConfig{ CACertFile: opts["kv.cacertfile"], CertFile: opts["kv.certfile"], KeyFile: opts["kv.keyfile"], } } else { logrus.Info("Option Initializing KV without TLS") } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L198-L202
go
train
// OptionDiscoveryWatcher function returns an option setter for discovery watcher
func OptionDiscoveryWatcher(watcher discovery.Watcher) Option
// OptionDiscoveryWatcher function returns an option setter for discovery watcher func OptionDiscoveryWatcher(watcher discovery.Watcher) Option
{ return func(c *Config) { c.Cluster.Watcher = watcher } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L205-L209
go
train
// OptionDiscoveryAddress function returns an option setter for self discovery address
func OptionDiscoveryAddress(address string) Option
// OptionDiscoveryAddress function returns an option setter for self discovery address func OptionDiscoveryAddress(address string) Option
{ return func(c *Config) { c.Cluster.Address = address } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L212-L216
go
train
// OptionDataDir function returns an option setter for data folder
func OptionDataDir(dataDir string) Option
// OptionDataDir function returns an option setter for data folder func OptionDataDir(dataDir string) Option
{ return func(c *Config) { c.Daemon.DataDir = dataDir } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L219-L224
go
train
// OptionExecRoot function returns an option setter for exec root folder
func OptionExecRoot(execRoot string) Option
// OptionExecRoot function returns an option setter for exec root folder func OptionExecRoot(execRoot string) Option
{ return func(c *Config) { c.Daemon.ExecRoot = execRoot osl.SetBasePath(execRoot) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L227-L231
go
train
// OptionPluginGetter returns a plugingetter for remote drivers.
func OptionPluginGetter(pg plugingetter.PluginGetter) Option
// OptionPluginGetter returns a plugingetter for remote drivers. func OptionPluginGetter(pg plugingetter.PluginGetter) Option
{ return func(c *Config) { c.PluginGetter = pg } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L234-L239
go
train
// OptionExperimental function returns an option setter for experimental daemon
func OptionExperimental(exp bool) Option
// OptionExperimental function returns an option setter for experimental daemon func OptionExperimental(exp bool) Option
{ return func(c *Config) { logrus.Debugf("Option Experimental: %v", exp) c.Daemon.Experimental = exp } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L242-L254
go
train
// OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU
func OptionNetworkControlPlaneMTU(exp int) Option
// OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU func OptionNetworkControlPlaneMTU(exp int) Option
{ return func(c *Config) { logrus.Debugf("Network Control Plane MTU: %d", exp) if exp < warningThNetworkControlPlaneMTU { logrus.Warnf("Received a MTU of %d, this value is very low, the network control plane can misbehave,"+ " defaulting to minimum value (%d)", exp, minimumNetworkControlPlaneMTU) if exp < minimumNetworkControlPlaneMTU { exp = minimumNetworkControlPlaneMTU } } c.Daemon.NetworkControlPlaneMTU = exp } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L257-L263
go
train
// ProcessOptions processes options and stores it in config
func (c *Config) ProcessOptions(options ...Option)
// ProcessOptions processes options and stores it in config func (c *Config) ProcessOptions(options ...Option)
{ for _, opt := range options { if opt != nil { opt(c) } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
config/config.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L293-L301
go
train
// OptionLocalKVProviderConfig function returns an option setter for kvstore config
func OptionLocalKVProviderConfig(config *store.Config) Option
// OptionLocalKVProviderConfig function returns an option setter for kvstore config func OptionLocalKVProviderConfig(config *store.Config) Option
{ return func(c *Config) { logrus.Debugf("Option OptionLocalKVProviderConfig: %v", config) if _, ok := c.Scopes[datastore.LocalScope]; !ok { c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{} } c.Scopes[datastore.LocalScope].Client.Config = config } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L41-L57
go
train
// FirewalldInit initializes firewalld management code.
func FirewalldInit() error
// FirewalldInit initializes firewalld management code. func FirewalldInit() error
{ var err error if connection, err = newConnection(); err != nil { return fmt.Errorf("Failed to connect to D-Bus system bus: %v", err) } firewalldRunning = checkRunning() if !firewalldRunning { connection.sysconn.Close() connection = nil } if connection != nil { go signalHandler() } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L60-L67
go
train
// New() establishes a connection to the system bus.
func newConnection() (*Conn, error)
// New() establishes a connection to the system bus. func newConnection() (*Conn, error)
{ c := new(Conn) if err := c.initConnection(); err != nil { return nil, err } return c, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L70-L93
go
train
// Initialize D-Bus connection.
func (c *Conn) initConnection() error
// Initialize D-Bus connection. func (c *Conn) initConnection() error
{ var err error c.sysconn, err = dbus.SystemBus() if err != nil { return err } // This never fails, even if the service is not running atm. c.sysobj = c.sysconn.Object(dbusInterface, dbus.ObjectPath(dbusPath)) rule := fmt.Sprintf("type='signal',path='%s',interface='%s',sender='%s',member='Reloaded'", dbusPath, dbusInterface, dbusInterface) c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule) rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'", dbusInterface) c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule) c.signal = make(chan *dbus.Signal, 10) c.sysconn.Signal(c.signal) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L138-L145
go
train
// OnReloaded add callback
func OnReloaded(callback func())
// OnReloaded add callback func OnReloaded(callback func())
{ for _, pf := range onReloaded { if pf == &callback { return } } onReloaded = append(onReloaded, &callback) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L148-L157
go
train
// Call some remote method to see whether the service is actually running.
func checkRunning() bool
// Call some remote method to see whether the service is actually running. func checkRunning() bool
{ var zone string var err error if connection != nil { err = connection.sysobj.Call(dbusInterface+".getDefaultZone", 0).Store(&zone) return err == nil } return false }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
iptables/firewalld.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L160-L167
go
train
// Passthrough method simply passes args through to iptables/ip6tables
func Passthrough(ipv IPV, args ...string) ([]byte, error)
// Passthrough method simply passes args through to iptables/ip6tables func Passthrough(ipv IPV, args ...string) ([]byte, error)
{ var output string logrus.Debugf("Firewalld passthrough: %s, %s", ipv, args) if err := connection.sysobj.Call(dbusInterface+".direct.passthrough", 0, ipv, args).Store(&output); err != nil { return nil, err } return []byte(output), nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/windows/overlay/ov_network_windows.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/ov_network_windows.go#L263-L284
go
train
// func (n *network) restoreNetworkEndpoints() error { // logrus.Infof("Restoring endpoints for overlay network: %s", n.id) // hnsresponse, err := hcsshim.HNSListEndpointRequest("GET", "", "") // if err != nil { // return err // } // for _, endpoint := range hnsresponse { // if endpoint.VirtualNetwork != n.hnsID { // continue // } // ep := n.convertToOverlayEndpoint(&endpoint) // if ep != nil { // logrus.Debugf("Restored endpoint:%s Remote:%t", ep.id, ep.remote) // n.addEndpoint(ep) // } // } // return nil // }
func (n *network) convertToOverlayEndpoint(v *hcsshim.HNSEndpoint) *endpoint
// func (n *network) restoreNetworkEndpoints() error { // logrus.Infof("Restoring endpoints for overlay network: %s", n.id) // hnsresponse, err := hcsshim.HNSListEndpointRequest("GET", "", "") // if err != nil { // return err // } // for _, endpoint := range hnsresponse { // if endpoint.VirtualNetwork != n.hnsID { // continue // } // ep := n.convertToOverlayEndpoint(&endpoint) // if ep != nil { // logrus.Debugf("Restored endpoint:%s Remote:%t", ep.id, ep.remote) // n.addEndpoint(ep) // } // } // return nil // } func (n *network) convertToOverlayEndpoint(v *hcsshim.HNSEndpoint) *endpoint
{ ep := &endpoint{ id: v.Name, profileID: v.Id, nid: n.id, remote: v.IsRemoteEndpoint, } mac, err := net.ParseMAC(v.MacAddress) if err != nil { return nil } ep.mac = mac ep.addr = &net.IPNet{ IP: v.IPAddress, Mask: net.CIDRMask(32, 32), } return ep }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/windows/overlay/ov_network_windows.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/ov_network_windows.go#L341-L349
go
train
// contains return true if the passed ip belongs to one the network's // subnets
func (n *network) contains(ip net.IP) bool
// contains return true if the passed ip belongs to one the network's // subnets func (n *network) contains(ip net.IP) bool
{ for _, s := range n.subnets { if s.subnetIP.Contains(ip) { return true } } return false }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/windows/overlay/ov_network_windows.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/ov_network_windows.go#L368-L384
go
train
// getMatchingSubnet return the network's subnet that matches the input
func (n *network) getMatchingSubnet(ip *net.IPNet) *subnet
// getMatchingSubnet return the network's subnet that matches the input func (n *network) getMatchingSubnet(ip *net.IPNet) *subnet
{ if ip == nil { return nil } for _, s := range n.subnets { // first check if the mask lengths are the same i, _ := s.subnetIP.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if s.subnetIP.IP.Equal(ip.IP) { return s } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/windows/overlay/overlay_windows.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/overlay_windows.go#L37-L75
go
train
// Init registers a new instance of overlay driver
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
// Init registers a new instance of overlay driver func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
{ c := driverapi.Capability{ DataScope: datastore.GlobalScope, ConnectivityScope: datastore.GlobalScope, } d := &driver{ networks: networkTable{}, config: config, } if data, ok := config[netlabel.GlobalKVClient]; ok { var err error dsc, ok := data.(discoverapi.DatastoreConfigData) if !ok { return types.InternalErrorf("incorrect data in datastore configuration: %v", data) } d.store, err = datastore.NewDataStoreFromConfig(dsc) if err != nil { return types.InternalErrorf("failed to initialize data store: %v", err) } } if data, ok := config[netlabel.LocalKVClient]; ok { var err error dsc, ok := data.(discoverapi.DatastoreConfigData) if !ok { return types.InternalErrorf("incorrect data in datastore configuration: %v", data) } d.localStore, err = datastore.NewDataStoreFromConfig(dsc) if err != nil { return types.InternalErrorf("failed to initialize local data store: %v", err) } } d.restoreHNSNetworks() return dc.RegisterDriver(networkType, d, c) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/windows/overlay/overlay_windows.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/overlay_windows.go#L152-L154
go
train
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
{ return types.NotImplementedErrorf("not implemented") }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L50-L52
go
train
// String returns the string form of the AddressRange object
func (r *AddressRange) String() string
// String returns the string form of the AddressRange object func (r *AddressRange) String() string
{ return fmt.Sprintf("Sub: %s, range [%d, %d]", r.Sub, r.Start, r.End) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L55-L62
go
train
// MarshalJSON returns the JSON encoding of the Range object
func (r *AddressRange) MarshalJSON() ([]byte, error)
// MarshalJSON returns the JSON encoding of the Range object func (r *AddressRange) MarshalJSON() ([]byte, error)
{ m := map[string]interface{}{ "Sub": r.Sub.String(), "Start": r.Start, "End": r.End, } return json.Marshal(m) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L65-L77
go
train
// UnmarshalJSON decodes data into the Range object
func (r *AddressRange) UnmarshalJSON(data []byte) error
// UnmarshalJSON decodes data into the Range object func (r *AddressRange) UnmarshalJSON(data []byte) error
{ m := map[string]interface{}{} err := json.Unmarshal(data, &m) if err != nil { return err } if r.Sub, err = types.ParseCIDR(m["Sub"].(string)); err != nil { return err } r.Start = uint64(m["Start"].(float64)) r.End = uint64(m["End"].(float64)) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L80-L86
go
train
// String returns the string form of the SubnetKey object
func (s *SubnetKey) String() string
// String returns the string form of the SubnetKey object func (s *SubnetKey) String() string
{ k := fmt.Sprintf("%s/%s", s.AddressSpace, s.Subnet) if s.ChildSubnet != "" { k = fmt.Sprintf("%s/%s", k, s.ChildSubnet) } return k }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L89-L105
go
train
// FromString populates the SubnetKey object reading it from string
func (s *SubnetKey) FromString(str string) error
// FromString populates the SubnetKey object reading it from string func (s *SubnetKey) FromString(str string) error
{ if str == "" || !strings.Contains(str, "/") { return types.BadRequestErrorf("invalid string form for subnetkey: %s", str) } p := strings.Split(str, "/") if len(p) != 3 && len(p) != 5 { return types.BadRequestErrorf("invalid string form for subnetkey: %s", str) } s.AddressSpace = p[0] s.Subnet = fmt.Sprintf("%s/%s", p[1], p[2]) if len(p) == 5 { s.ChildSubnet = fmt.Sprintf("%s/%s", p[3], p[4]) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L108-L111
go
train
// String returns the string form of the PoolData object
func (p *PoolData) String() string
// String returns the string form of the PoolData object func (p *PoolData) String() string
{ return fmt.Sprintf("ParentKey: %s, Pool: %s, Range: %s, RefCount: %d", p.ParentKey.String(), p.Pool.String(), p.Range, p.RefCount) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L114-L126
go
train
// MarshalJSON returns the JSON encoding of the PoolData object
func (p *PoolData) MarshalJSON() ([]byte, error)
// MarshalJSON returns the JSON encoding of the PoolData object func (p *PoolData) MarshalJSON() ([]byte, error)
{ m := map[string]interface{}{ "ParentKey": p.ParentKey, "RefCount": p.RefCount, } if p.Pool != nil { m["Pool"] = p.Pool.String() } if p.Range != nil { m["Range"] = p.Range } return json.Marshal(m) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L129-L154
go
train
// UnmarshalJSON decodes data into the PoolData object
func (p *PoolData) UnmarshalJSON(data []byte) error
// UnmarshalJSON decodes data into the PoolData object func (p *PoolData) UnmarshalJSON(data []byte) error
{ var ( err error t struct { ParentKey SubnetKey Pool string Range *AddressRange `json:",omitempty"` RefCount int } ) if err = json.Unmarshal(data, &t); err != nil { return err } p.ParentKey = t.ParentKey p.Range = t.Range p.RefCount = t.RefCount if t.Pool != "" { if p.Pool, err = types.ParseCIDR(t.Pool); err != nil { return err } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L157-L174
go
train
// MarshalJSON returns the JSON encoding of the addrSpace object
func (aSpace *addrSpace) MarshalJSON() ([]byte, error)
// MarshalJSON returns the JSON encoding of the addrSpace object func (aSpace *addrSpace) MarshalJSON() ([]byte, error)
{ aSpace.Lock() defer aSpace.Unlock() m := map[string]interface{}{ "Scope": string(aSpace.scope), } if aSpace.subnets != nil { s := map[string]*PoolData{} for k, v := range aSpace.subnets { s[k.String()] = v } m["Subnets"] = s } return json.Marshal(m) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L177-L208
go
train
// UnmarshalJSON decodes data into the addrSpace object
func (aSpace *addrSpace) UnmarshalJSON(data []byte) error
// UnmarshalJSON decodes data into the addrSpace object func (aSpace *addrSpace) UnmarshalJSON(data []byte) error
{ aSpace.Lock() defer aSpace.Unlock() m := map[string]interface{}{} err := json.Unmarshal(data, &m) if err != nil { return err } aSpace.scope = datastore.LocalScope s := m["Scope"].(string) if s == string(datastore.GlobalScope) { aSpace.scope = datastore.GlobalScope } if v, ok := m["Subnets"]; ok { sb, _ := json.Marshal(v) var s map[string]*PoolData err := json.Unmarshal(sb, &s) if err != nil { return err } for ks, v := range s { k := SubnetKey{} k.FromString(ks) aSpace.subnets[k] = v } } return nil }