id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
7,700 | cortesi/modd | daemon.go | NewDaemonPen | func NewDaemonPen(block conf.Block, vars map[string]string, log termlog.TermLog) (*DaemonPen, error) {
d := make([]*daemon, len(block.Daemons))
for i, dmn := range block.Daemons {
vcmd := varcmd.VarCmd{Block: nil, Modified: nil, Vars: vars}
finalcmd, err := vcmd.Render(dmn.Command)
if err != nil {
return nil, err
}
dmn.Command = finalcmd
var indir string
if block.InDir != "" {
indir = block.InDir
} else {
indir, err = os.Getwd()
if err != nil {
return nil, err
}
}
sh, err := shell.GetShellName(vars[shellVarName])
if err != nil {
return nil, err
}
d[i] = &daemon{
conf: dmn,
log: log.Stream(niceHeader("daemon: ", dmn.Command)),
shell: sh,
indir: indir,
}
}
return &DaemonPen{daemons: d}, nil
} | go | func NewDaemonPen(block conf.Block, vars map[string]string, log termlog.TermLog) (*DaemonPen, error) {
d := make([]*daemon, len(block.Daemons))
for i, dmn := range block.Daemons {
vcmd := varcmd.VarCmd{Block: nil, Modified: nil, Vars: vars}
finalcmd, err := vcmd.Render(dmn.Command)
if err != nil {
return nil, err
}
dmn.Command = finalcmd
var indir string
if block.InDir != "" {
indir = block.InDir
} else {
indir, err = os.Getwd()
if err != nil {
return nil, err
}
}
sh, err := shell.GetShellName(vars[shellVarName])
if err != nil {
return nil, err
}
d[i] = &daemon{
conf: dmn,
log: log.Stream(niceHeader("daemon: ", dmn.Command)),
shell: sh,
indir: indir,
}
}
return &DaemonPen{daemons: d}, nil
} | [
"func",
"NewDaemonPen",
"(",
"block",
"conf",
".",
"Block",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
",",
"log",
"termlog",
".",
"TermLog",
")",
"(",
"*",
"DaemonPen",
",",
"error",
")",
"{",
"d",
":=",
"make",
"(",
"[",
"]",
"*",
"daemon"... | // NewDaemonPen creates a new DaemonPen | [
"NewDaemonPen",
"creates",
"a",
"new",
"DaemonPen"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L113-L144 |
7,701 | cortesi/modd | daemon.go | Restart | func (dp *DaemonPen) Restart() {
dp.Lock()
defer dp.Unlock()
if dp.daemons != nil {
for _, d := range dp.daemons {
d.Restart()
}
}
} | go | func (dp *DaemonPen) Restart() {
dp.Lock()
defer dp.Unlock()
if dp.daemons != nil {
for _, d := range dp.daemons {
d.Restart()
}
}
} | [
"func",
"(",
"dp",
"*",
"DaemonPen",
")",
"Restart",
"(",
")",
"{",
"dp",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dp",
".",
"Unlock",
"(",
")",
"\n",
"if",
"dp",
".",
"daemons",
"!=",
"nil",
"{",
"for",
"_",
",",
"d",
":=",
"range",
"dp",
".",... | // Restart all daemons in the pen, or start them if they're not running yet. | [
"Restart",
"all",
"daemons",
"in",
"the",
"pen",
"or",
"start",
"them",
"if",
"they",
"re",
"not",
"running",
"yet",
"."
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L147-L155 |
7,702 | cortesi/modd | daemon.go | Shutdown | func (dp *DaemonPen) Shutdown(sig os.Signal) {
dp.Lock()
defer dp.Unlock()
if dp.daemons != nil {
for _, d := range dp.daemons {
d.Shutdown(sig)
}
}
} | go | func (dp *DaemonPen) Shutdown(sig os.Signal) {
dp.Lock()
defer dp.Unlock()
if dp.daemons != nil {
for _, d := range dp.daemons {
d.Shutdown(sig)
}
}
} | [
"func",
"(",
"dp",
"*",
"DaemonPen",
")",
"Shutdown",
"(",
"sig",
"os",
".",
"Signal",
")",
"{",
"dp",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dp",
".",
"Unlock",
"(",
")",
"\n",
"if",
"dp",
".",
"daemons",
"!=",
"nil",
"{",
"for",
"_",
",",
"... | // Shutdown all daemons in the pen | [
"Shutdown",
"all",
"daemons",
"in",
"the",
"pen"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L158-L166 |
7,703 | cortesi/modd | daemon.go | NewDaemonWorld | func NewDaemonWorld(cnf *conf.Config, log termlog.TermLog) (*DaemonWorld, error) {
daemonPens := make([]*DaemonPen, len(cnf.Blocks))
for i, b := range cnf.Blocks {
d, err := NewDaemonPen(b, cnf.GetVariables(), log)
if err != nil {
return nil, err
}
daemonPens[i] = d
}
return &DaemonWorld{daemonPens}, nil
} | go | func NewDaemonWorld(cnf *conf.Config, log termlog.TermLog) (*DaemonWorld, error) {
daemonPens := make([]*DaemonPen, len(cnf.Blocks))
for i, b := range cnf.Blocks {
d, err := NewDaemonPen(b, cnf.GetVariables(), log)
if err != nil {
return nil, err
}
daemonPens[i] = d
}
return &DaemonWorld{daemonPens}, nil
} | [
"func",
"NewDaemonWorld",
"(",
"cnf",
"*",
"conf",
".",
"Config",
",",
"log",
"termlog",
".",
"TermLog",
")",
"(",
"*",
"DaemonWorld",
",",
"error",
")",
"{",
"daemonPens",
":=",
"make",
"(",
"[",
"]",
"*",
"DaemonPen",
",",
"len",
"(",
"cnf",
".",
... | // NewDaemonWorld creates a DaemonWorld | [
"NewDaemonWorld",
"creates",
"a",
"DaemonWorld"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L174-L185 |
7,704 | cortesi/modd | daemon.go | Shutdown | func (dw *DaemonWorld) Shutdown(s os.Signal) {
for _, dp := range dw.DaemonPens {
dp.Shutdown(s)
}
} | go | func (dw *DaemonWorld) Shutdown(s os.Signal) {
for _, dp := range dw.DaemonPens {
dp.Shutdown(s)
}
} | [
"func",
"(",
"dw",
"*",
"DaemonWorld",
")",
"Shutdown",
"(",
"s",
"os",
".",
"Signal",
")",
"{",
"for",
"_",
",",
"dp",
":=",
"range",
"dw",
".",
"DaemonPens",
"{",
"dp",
".",
"Shutdown",
"(",
"s",
")",
"\n",
"}",
"\n",
"}"
] | // Shutdown all daemons with signal s | [
"Shutdown",
"all",
"daemons",
"with",
"signal",
"s"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L188-L192 |
7,705 | cortesi/modd | proc.go | shortCommand | func shortCommand(command string) string {
ret := command
parts := strings.Split(command, "\n")
for _, i := range parts {
i = strings.TrimLeft(i, " \t#")
i = strings.TrimRight(i, " \t\\")
if i != "" {
ret = i
break
}
}
return ret
} | go | func shortCommand(command string) string {
ret := command
parts := strings.Split(command, "\n")
for _, i := range parts {
i = strings.TrimLeft(i, " \t#")
i = strings.TrimRight(i, " \t\\")
if i != "" {
ret = i
break
}
}
return ret
} | [
"func",
"shortCommand",
"(",
"command",
"string",
")",
"string",
"{",
"ret",
":=",
"command",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"command",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"parts",
"{",
"i",
"... | // shortCommand shortens a command to a name we can use in a notification
// header. | [
"shortCommand",
"shortens",
"a",
"command",
"to",
"a",
"name",
"we",
"can",
"use",
"in",
"a",
"notification",
"header",
"."
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/proc.go#L14-L26 |
7,706 | cortesi/modd | proc.go | niceHeader | func niceHeader(preamble string, command string) string {
pre := termlog.DefaultPalette.Timestamp.SprintFunc()(preamble)
command = termlog.DefaultPalette.Header.SprintFunc()(shortCommand(command))
return pre + command
} | go | func niceHeader(preamble string, command string) string {
pre := termlog.DefaultPalette.Timestamp.SprintFunc()(preamble)
command = termlog.DefaultPalette.Header.SprintFunc()(shortCommand(command))
return pre + command
} | [
"func",
"niceHeader",
"(",
"preamble",
"string",
",",
"command",
"string",
")",
"string",
"{",
"pre",
":=",
"termlog",
".",
"DefaultPalette",
".",
"Timestamp",
".",
"SprintFunc",
"(",
")",
"(",
"preamble",
")",
"\n",
"command",
"=",
"termlog",
".",
"Defaul... | // niceHeader tries to produce a nicer process name. We condense whitespace to
// make commands split over multiple lines with indentation more legible, and
// limit the line length to 80 characters. | [
"niceHeader",
"tries",
"to",
"produce",
"a",
"nicer",
"process",
"name",
".",
"We",
"condense",
"whitespace",
"to",
"make",
"commands",
"split",
"over",
"multiple",
"lines",
"with",
"indentation",
"more",
"legible",
"and",
"limit",
"the",
"line",
"length",
"to... | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/proc.go#L31-L35 |
7,707 | cortesi/modd | conf/parse.go | unquote | func unquote(s string) string {
quote := s[0:1]
s = s[1 : len(s)-1]
s = strings.Replace(s, `\`+quote, quote, -1)
return s
} | go | func unquote(s string) string {
quote := s[0:1]
s = s[1 : len(s)-1]
s = strings.Replace(s, `\`+quote, quote, -1)
return s
} | [
"func",
"unquote",
"(",
"s",
"string",
")",
"string",
"{",
"quote",
":=",
"s",
"[",
"0",
":",
"1",
"]",
"\n",
"s",
"=",
"s",
"[",
"1",
":",
"len",
"(",
"s",
")",
"-",
"1",
"]",
"\n",
"s",
"=",
"strings",
".",
"Replace",
"(",
"s",
",",
"`\... | // Dreadfully naive at the momet, but then so is the lexer. | [
"Dreadfully",
"naive",
"at",
"the",
"momet",
"but",
"then",
"so",
"is",
"the",
"lexer",
"."
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/parse.go#L25-L30 |
7,708 | cortesi/modd | conf/parse.go | Parse | func Parse(name string, text string) (*Config, error) {
p := &parser{name: name, text: text}
err := p.parse()
if err != nil {
return nil, err
}
return p.config, nil
} | go | func Parse(name string, text string) (*Config, error) {
p := &parser{name: name, text: text}
err := p.parse()
if err != nil {
return nil, err
}
return p.config, nil
} | [
"func",
"Parse",
"(",
"name",
"string",
",",
"text",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"p",
":=",
"&",
"parser",
"{",
"name",
":",
"name",
",",
"text",
":",
"text",
"}",
"\n",
"err",
":=",
"p",
".",
"parse",
"(",
")",
... | // Parse parses a string, and returns a completed Config | [
"Parse",
"parses",
"a",
"string",
"and",
"returns",
"a",
"completed",
"Config"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/parse.go#L268-L275 |
7,709 | cortesi/modd | conf/conf.go | Equals | func (c *Config) Equals(other *Config) bool {
if (c.Blocks != nil || len(c.Blocks) != 0) || (other.Blocks != nil || len(other.Blocks) != 0) {
if !reflect.DeepEqual(c.Blocks, other.Blocks) {
return false
}
}
if (c.variables != nil || len(c.variables) != 0) || (other.variables != nil || len(other.variables) != 0) {
if !reflect.DeepEqual(c.variables, other.variables) {
return false
}
}
return true
} | go | func (c *Config) Equals(other *Config) bool {
if (c.Blocks != nil || len(c.Blocks) != 0) || (other.Blocks != nil || len(other.Blocks) != 0) {
if !reflect.DeepEqual(c.Blocks, other.Blocks) {
return false
}
}
if (c.variables != nil || len(c.variables) != 0) || (other.variables != nil || len(other.variables) != 0) {
if !reflect.DeepEqual(c.variables, other.variables) {
return false
}
}
return true
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Equals",
"(",
"other",
"*",
"Config",
")",
"bool",
"{",
"if",
"(",
"c",
".",
"Blocks",
"!=",
"nil",
"||",
"len",
"(",
"c",
".",
"Blocks",
")",
"!=",
"0",
")",
"||",
"(",
"other",
".",
"Blocks",
"!=",
"ni... | // Equals checks if this Config equals another | [
"Equals",
"checks",
"if",
"this",
"Config",
"equals",
"another"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/conf.go#L61-L73 |
7,710 | cortesi/modd | conf/conf.go | IncludePatterns | func (c *Config) IncludePatterns() []string {
pmap := map[string]bool{}
for _, b := range c.Blocks {
for _, p := range b.Include {
pmap[p] = true
}
}
paths := make([]string, len(pmap))
i := 0
for k := range pmap {
paths[i] = k
i++
}
sort.Strings(paths)
return paths
} | go | func (c *Config) IncludePatterns() []string {
pmap := map[string]bool{}
for _, b := range c.Blocks {
for _, p := range b.Include {
pmap[p] = true
}
}
paths := make([]string, len(pmap))
i := 0
for k := range pmap {
paths[i] = k
i++
}
sort.Strings(paths)
return paths
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"IncludePatterns",
"(",
")",
"[",
"]",
"string",
"{",
"pmap",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"c",
".",
"Blocks",
"{",
"for",
"_",
",",
"p",
"... | // IncludePatterns retrieves all include patterns from all blocks. | [
"IncludePatterns",
"retrieves",
"all",
"include",
"patterns",
"from",
"all",
"blocks",
"."
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/conf.go#L76-L91 |
7,711 | cortesi/modd | conf/conf.go | GetVariables | func (c *Config) GetVariables() map[string]string {
n := map[string]string{}
for k, v := range c.variables {
n[k] = v
}
return n
} | go | func (c *Config) GetVariables() map[string]string {
n := map[string]string{}
for k, v := range c.variables {
n[k] = v
}
return n
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"GetVariables",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"n",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"variables",
"{",
"n",
"[",... | // GetVariables returns a copy of the Variables map | [
"GetVariables",
"returns",
"a",
"copy",
"of",
"the",
"Variables",
"map"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/conf.go#L112-L118 |
7,712 | cortesi/modd | conf/conf.go | CommonExcludes | func (c *Config) CommonExcludes(excludes []string) {
for i, b := range c.Blocks {
if !b.NoCommonFilter {
b.Exclude = append(b.Exclude, excludes...)
}
c.Blocks[i] = b
}
} | go | func (c *Config) CommonExcludes(excludes []string) {
for i, b := range c.Blocks {
if !b.NoCommonFilter {
b.Exclude = append(b.Exclude, excludes...)
}
c.Blocks[i] = b
}
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"CommonExcludes",
"(",
"excludes",
"[",
"]",
"string",
")",
"{",
"for",
"i",
",",
"b",
":=",
"range",
"c",
".",
"Blocks",
"{",
"if",
"!",
"b",
".",
"NoCommonFilter",
"{",
"b",
".",
"Exclude",
"=",
"append",
"... | // CommonExcludes extends all blocks that require it with a common exclusion
// set | [
"CommonExcludes",
"extends",
"all",
"blocks",
"that",
"require",
"it",
"with",
"a",
"common",
"exclusion",
"set"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/conf.go#L122-L129 |
7,713 | cortesi/modd | shell/shell.go | CheckShell | func CheckShell(shell string) (string, error) {
if _, ok := ValidShells[shell]; !ok {
return "", fmt.Errorf("unsupported shell: %q", shell)
}
switch shell {
case "powershell":
if _, err := exec.LookPath("powershell"); err == nil {
return "powershell", nil
} else if _, err := exec.LookPath("pwsh"); err == nil {
return "pwsh", nil
} else {
return "", fmt.Errorf("powershell/pwsh not on path")
}
case "modd":
// When testing, we're running under a special compiled test executable,
// so we look for an instance of modd on our path.
if shellTesting {
return exec.LookPath("modd")
}
return os.Executable()
default:
return exec.LookPath(shell)
}
} | go | func CheckShell(shell string) (string, error) {
if _, ok := ValidShells[shell]; !ok {
return "", fmt.Errorf("unsupported shell: %q", shell)
}
switch shell {
case "powershell":
if _, err := exec.LookPath("powershell"); err == nil {
return "powershell", nil
} else if _, err := exec.LookPath("pwsh"); err == nil {
return "pwsh", nil
} else {
return "", fmt.Errorf("powershell/pwsh not on path")
}
case "modd":
// When testing, we're running under a special compiled test executable,
// so we look for an instance of modd on our path.
if shellTesting {
return exec.LookPath("modd")
}
return os.Executable()
default:
return exec.LookPath(shell)
}
} | [
"func",
"CheckShell",
"(",
"shell",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"ValidShells",
"[",
"shell",
"]",
";",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
... | // CheckShell checks that a shell is supported, and returns the correct command name | [
"CheckShell",
"checks",
"that",
"a",
"shell",
"is",
"supported",
"and",
"returns",
"the",
"correct",
"command",
"name"
] | e30792b1408111a0b23229f18d207a21af1e3bed | https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/shell/shell.go#L176-L199 |
7,714 | contiv/netplugin | objdb/etcdService.go | RegisterService | func (ep *EtcdClient) RegisterService(serviceInfo ServiceInfo) error {
keyName := "/contiv.io/service/" + serviceInfo.ServiceName + "/" +
serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port)
ttl := time.Duration(serviceInfo.TTL) * time.Second
log.Infof("Registering service key: %s, value: %+v", keyName, serviceInfo)
// if there is a previously registered service, stop refreshing it
if ep.serviceDb[keyName] != nil {
ep.serviceDb[keyName].stopChan <- true
}
// JSON format the object
jsonVal, err := json.Marshal(serviceInfo)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
// create service state
srvState := etcdServiceState{
ServiceName: serviceInfo.ServiceName,
KeyName: keyName,
TTL: ttl,
HostAddr: serviceInfo.HostAddr,
Port: serviceInfo.Port,
stopChan: make(chan bool, 1),
Hostname: serviceInfo.Hostname,
}
// Run refresh in background
go ep.refreshService(&srvState, string(jsonVal[:]))
// Store it in DB
ep.serviceDb[keyName] = &srvState
return nil
} | go | func (ep *EtcdClient) RegisterService(serviceInfo ServiceInfo) error {
keyName := "/contiv.io/service/" + serviceInfo.ServiceName + "/" +
serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port)
ttl := time.Duration(serviceInfo.TTL) * time.Second
log.Infof("Registering service key: %s, value: %+v", keyName, serviceInfo)
// if there is a previously registered service, stop refreshing it
if ep.serviceDb[keyName] != nil {
ep.serviceDb[keyName].stopChan <- true
}
// JSON format the object
jsonVal, err := json.Marshal(serviceInfo)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
// create service state
srvState := etcdServiceState{
ServiceName: serviceInfo.ServiceName,
KeyName: keyName,
TTL: ttl,
HostAddr: serviceInfo.HostAddr,
Port: serviceInfo.Port,
stopChan: make(chan bool, 1),
Hostname: serviceInfo.Hostname,
}
// Run refresh in background
go ep.refreshService(&srvState, string(jsonVal[:]))
// Store it in DB
ep.serviceDb[keyName] = &srvState
return nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"RegisterService",
"(",
"serviceInfo",
"ServiceInfo",
")",
"error",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"serviceInfo",
".",
"ServiceName",
"+",
"\"",
"\"",
"+",
"serviceInfo",
".",
"HostAddr",
"+",
"\"",
"\"",
... | // RegisterService Register a service
// Service is registered with a ttl for 60sec and a goroutine is created
// to refresh the ttl. | [
"RegisterService",
"Register",
"a",
"service",
"Service",
"is",
"registered",
"with",
"a",
"ttl",
"for",
"60sec",
"and",
"a",
"goroutine",
"is",
"created",
"to",
"refresh",
"the",
"ttl",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdService.go#L47-L84 |
7,715 | contiv/netplugin | objdb/etcdService.go | GetService | func (ep *EtcdClient) GetService(name string) ([]ServiceInfo, error) {
keyName := "/contiv.io/service/" + name + "/"
_, srvcList, err := ep.getServiceState(keyName)
return srvcList, err
} | go | func (ep *EtcdClient) GetService(name string) ([]ServiceInfo, error) {
keyName := "/contiv.io/service/" + name + "/"
_, srvcList, err := ep.getServiceState(keyName)
return srvcList, err
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"GetService",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"ServiceInfo",
",",
"error",
")",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
"\n\n",
"_",
",",
"srvcList",
",",
"err",
":=",
... | // GetService lists all end points for a service | [
"GetService",
"lists",
"all",
"end",
"points",
"for",
"a",
"service"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdService.go#L87-L92 |
7,716 | contiv/netplugin | objdb/etcdService.go | initServiceState | func (ep *EtcdClient) initServiceState(key string, eventCh chan WatchServiceEvent) (uint64, error) {
mIndex, srvcList, err := ep.getServiceState(key)
if err != nil {
return mIndex, err
}
// walk each service and inject it as an add event
for _, srvInfo := range srvcList {
log.Debugf("Sending service add event: %+v", srvInfo)
// Send Add event
eventCh <- WatchServiceEvent{
EventType: WatchServiceEventAdd,
ServiceInfo: srvInfo,
}
}
return mIndex, nil
} | go | func (ep *EtcdClient) initServiceState(key string, eventCh chan WatchServiceEvent) (uint64, error) {
mIndex, srvcList, err := ep.getServiceState(key)
if err != nil {
return mIndex, err
}
// walk each service and inject it as an add event
for _, srvInfo := range srvcList {
log.Debugf("Sending service add event: %+v", srvInfo)
// Send Add event
eventCh <- WatchServiceEvent{
EventType: WatchServiceEventAdd,
ServiceInfo: srvInfo,
}
}
return mIndex, nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"initServiceState",
"(",
"key",
"string",
",",
"eventCh",
"chan",
"WatchServiceEvent",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"mIndex",
",",
"srvcList",
",",
"err",
":=",
"ep",
".",
"getServiceState",
"(",
... | // initServiceState reads the current state and injects it to the channel
// additionally, it returns the next index to watch | [
"initServiceState",
"reads",
"the",
"current",
"state",
"and",
"injects",
"it",
"to",
"the",
"channel",
"additionally",
"it",
"returns",
"the",
"next",
"index",
"to",
"watch"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdService.go#L145-L162 |
7,717 | contiv/netplugin | objdb/etcdService.go | DeregisterService | func (ep *EtcdClient) DeregisterService(serviceInfo ServiceInfo) error {
keyName := "/contiv.io/service/" + serviceInfo.ServiceName + "/" +
serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port)
// Find it in the database
srvState := ep.serviceDb[keyName]
if srvState == nil {
log.Errorf("Could not find the service in db %s", keyName)
return errors.New("Service not found")
}
// stop the refresh thread and delete service
srvState.stopChan <- true
delete(ep.serviceDb, keyName)
// Delete the service instance
_, err := ep.kapi.Delete(context.Background(), keyName, nil)
if err != nil {
log.Errorf("Error deleting key %s. Err: %v", keyName, err)
return err
}
return nil
} | go | func (ep *EtcdClient) DeregisterService(serviceInfo ServiceInfo) error {
keyName := "/contiv.io/service/" + serviceInfo.ServiceName + "/" +
serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port)
// Find it in the database
srvState := ep.serviceDb[keyName]
if srvState == nil {
log.Errorf("Could not find the service in db %s", keyName)
return errors.New("Service not found")
}
// stop the refresh thread and delete service
srvState.stopChan <- true
delete(ep.serviceDb, keyName)
// Delete the service instance
_, err := ep.kapi.Delete(context.Background(), keyName, nil)
if err != nil {
log.Errorf("Error deleting key %s. Err: %v", keyName, err)
return err
}
return nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"DeregisterService",
"(",
"serviceInfo",
"ServiceInfo",
")",
"error",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"serviceInfo",
".",
"ServiceName",
"+",
"\"",
"\"",
"+",
"serviceInfo",
".",
"HostAddr",
"+",
"\"",
"\""... | // DeregisterService Deregister a service
// This removes the service from the registry and stops the refresh groutine | [
"DeregisterService",
"Deregister",
"a",
"service",
"This",
"removes",
"the",
"service",
"from",
"the",
"registry",
"and",
"stops",
"the",
"refresh",
"groutine"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdService.go#L279-L302 |
7,718 | contiv/netplugin | objdb/etcdService.go | refreshService | func (ep *EtcdClient) refreshService(srvState *etcdServiceState, keyVal string) {
// Set it via etcd client
_, err := ep.kapi.Set(context.Background(), srvState.KeyName, keyVal, &client.SetOptions{TTL: srvState.TTL})
if err != nil {
log.Errorf("Error setting key %s, Err: %v", srvState.KeyName, err)
}
// Loop forever
for {
select {
case <-time.After(srvState.TTL / 3):
log.Debugf("Refreshing key: %s", srvState.KeyName)
_, err := ep.kapi.Set(context.Background(), srvState.KeyName, keyVal, &client.SetOptions{TTL: srvState.TTL})
if err != nil {
log.Errorf("Error setting key %s, Err: %v", srvState.KeyName, err)
}
case <-srvState.stopChan:
log.Infof("Stop refreshing key: %s", srvState.KeyName)
return
}
}
} | go | func (ep *EtcdClient) refreshService(srvState *etcdServiceState, keyVal string) {
// Set it via etcd client
_, err := ep.kapi.Set(context.Background(), srvState.KeyName, keyVal, &client.SetOptions{TTL: srvState.TTL})
if err != nil {
log.Errorf("Error setting key %s, Err: %v", srvState.KeyName, err)
}
// Loop forever
for {
select {
case <-time.After(srvState.TTL / 3):
log.Debugf("Refreshing key: %s", srvState.KeyName)
_, err := ep.kapi.Set(context.Background(), srvState.KeyName, keyVal, &client.SetOptions{TTL: srvState.TTL})
if err != nil {
log.Errorf("Error setting key %s, Err: %v", srvState.KeyName, err)
}
case <-srvState.stopChan:
log.Infof("Stop refreshing key: %s", srvState.KeyName)
return
}
}
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"refreshService",
"(",
"srvState",
"*",
"etcdServiceState",
",",
"keyVal",
"string",
")",
"{",
"// Set it via etcd client",
"_",
",",
"err",
":=",
"ep",
".",
"kapi",
".",
"Set",
"(",
"context",
".",
"Background",
... | // Keep refreshing the service every 30sec | [
"Keep",
"refreshing",
"the",
"service",
"every",
"30sec"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdService.go#L305-L328 |
7,719 | contiv/netplugin | drivers/endpointstate.go | Matches | func (s *OperEndpointState) Matches(c *mastercfg.CfgEndpointState) bool {
return s.NetID == c.NetID &&
s.EndpointID == c.EndpointID &&
s.IPAddress == c.IPAddress &&
s.IPv6Address == c.IPv6Address &&
s.MacAddress == c.MacAddress &&
s.HomingHost == c.HomingHost &&
s.IntfName == c.IntfName &&
s.VtepIP == c.VtepIP
} | go | func (s *OperEndpointState) Matches(c *mastercfg.CfgEndpointState) bool {
return s.NetID == c.NetID &&
s.EndpointID == c.EndpointID &&
s.IPAddress == c.IPAddress &&
s.IPv6Address == c.IPv6Address &&
s.MacAddress == c.MacAddress &&
s.HomingHost == c.HomingHost &&
s.IntfName == c.IntfName &&
s.VtepIP == c.VtepIP
} | [
"func",
"(",
"s",
"*",
"OperEndpointState",
")",
"Matches",
"(",
"c",
"*",
"mastercfg",
".",
"CfgEndpointState",
")",
"bool",
"{",
"return",
"s",
".",
"NetID",
"==",
"c",
".",
"NetID",
"&&",
"s",
".",
"EndpointID",
"==",
"c",
".",
"EndpointID",
"&&",
... | // Matches matches the fields updated from configuration state | [
"Matches",
"matches",
"the",
"fields",
"updated",
"from",
"configuration",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/endpointstate.go#L43-L52 |
7,720 | contiv/netplugin | drivers/endpointstate.go | ReadAll | func (s *OperEndpointState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(endpointOperPathPrefix, s, json.Unmarshal)
} | go | func (s *OperEndpointState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(endpointOperPathPrefix, s, json.Unmarshal)
} | [
"func",
"(",
"s",
"*",
"OperEndpointState",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"s",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"endpointOperPathPrefix",
",",
"s",
",",
"json",
".",
"Unmar... | // ReadAll reads all state into separate objects. | [
"ReadAll",
"reads",
"all",
"state",
"into",
"separate",
"objects",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/endpointstate.go#L67-L69 |
7,721 | contiv/netplugin | objdb/etcdClient.go | NewClient | func (ep *etcdPlugin) NewClient(endpoints []string) (API, error) {
var err error
var ec = new(EtcdClient)
ep.mutex.Lock()
defer ep.mutex.Unlock()
// Setup default url
if len(endpoints) == 0 {
endpoints = []string{"http://127.0.0.1:2379"}
}
etcdConfig := client.Config{
Endpoints: endpoints,
}
// Create a new client
ec.client, err = client.New(etcdConfig)
if err != nil {
log.Fatalf("Error creating etcd client. Err: %v", err)
return nil, err
}
// create keys api
ec.kapi = client.NewKeysAPI(ec.client)
// Initialize service DB
ec.serviceDb = make(map[string]*etcdServiceState)
// Make sure we can read from etcd
_, err = ec.kapi.Get(context.Background(), "/", &client.GetOptions{Recursive: true, Sort: true})
if err != nil {
log.Errorf("Failed to connect to etcd. Err: %v", err)
return nil, err
}
return ec, nil
} | go | func (ep *etcdPlugin) NewClient(endpoints []string) (API, error) {
var err error
var ec = new(EtcdClient)
ep.mutex.Lock()
defer ep.mutex.Unlock()
// Setup default url
if len(endpoints) == 0 {
endpoints = []string{"http://127.0.0.1:2379"}
}
etcdConfig := client.Config{
Endpoints: endpoints,
}
// Create a new client
ec.client, err = client.New(etcdConfig)
if err != nil {
log.Fatalf("Error creating etcd client. Err: %v", err)
return nil, err
}
// create keys api
ec.kapi = client.NewKeysAPI(ec.client)
// Initialize service DB
ec.serviceDb = make(map[string]*etcdServiceState)
// Make sure we can read from etcd
_, err = ec.kapi.Get(context.Background(), "/", &client.GetOptions{Recursive: true, Sort: true})
if err != nil {
log.Errorf("Failed to connect to etcd. Err: %v", err)
return nil, err
}
return ec, nil
} | [
"func",
"(",
"ep",
"*",
"etcdPlugin",
")",
"NewClient",
"(",
"endpoints",
"[",
"]",
"string",
")",
"(",
"API",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"ec",
"=",
"new",
"(",
"EtcdClient",
")",
"\n\n",
"ep",
".",
"mutex",
".",
... | // Initialize the etcd client | [
"Initialize",
"the",
"etcd",
"client"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L51-L88 |
7,722 | contiv/netplugin | objdb/etcdClient.go | GetObj | func (ep *EtcdClient) GetObj(key string, retVal interface{}) error {
keyName := "/contiv.io/obj/" + key
// Get the object from etcd client
resp, err := ep.kapi.Get(context.Background(), keyName, &client.GetOptions{Quorum: true})
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
resp, err = ep.kapi.Get(context.Background(), keyName, &client.GetOptions{Quorum: true})
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error getting key %s. Err: %v", keyName, err)
return err
}
}
// Parse JSON response
if err := json.Unmarshal([]byte(resp.Node.Value), retVal); err != nil {
log.Errorf("Error parsing object %s, Err %v", resp.Node.Value, err)
return err
}
return nil
} | go | func (ep *EtcdClient) GetObj(key string, retVal interface{}) error {
keyName := "/contiv.io/obj/" + key
// Get the object from etcd client
resp, err := ep.kapi.Get(context.Background(), keyName, &client.GetOptions{Quorum: true})
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
resp, err = ep.kapi.Get(context.Background(), keyName, &client.GetOptions{Quorum: true})
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error getting key %s. Err: %v", keyName, err)
return err
}
}
// Parse JSON response
if err := json.Unmarshal([]byte(resp.Node.Value), retVal); err != nil {
log.Errorf("Error parsing object %s, Err %v", resp.Node.Value, err)
return err
}
return nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"GetObj",
"(",
"key",
"string",
",",
"retVal",
"interface",
"{",
"}",
")",
"error",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"key",
"\n\n",
"// Get the object from etcd client",
"resp",
",",
"err",
":=",
"ep",
"."... | // GetObj Get an object | [
"GetObj",
"Get",
"an",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L91-L122 |
7,723 | contiv/netplugin | objdb/etcdClient.go | recursAddNode | func recursAddNode(node *client.Node, list []string) []string {
for _, innerNode := range node.Nodes {
// add only the files.
if !innerNode.Dir {
list = append(list, innerNode.Value)
} else {
list = recursAddNode(innerNode, list)
}
}
return list
} | go | func recursAddNode(node *client.Node, list []string) []string {
for _, innerNode := range node.Nodes {
// add only the files.
if !innerNode.Dir {
list = append(list, innerNode.Value)
} else {
list = recursAddNode(innerNode, list)
}
}
return list
} | [
"func",
"recursAddNode",
"(",
"node",
"*",
"client",
".",
"Node",
",",
"list",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"innerNode",
":=",
"range",
"node",
".",
"Nodes",
"{",
"// add only the files.",
"if",
"!",
"innerNode",
"... | // Recursive function to look thru each directory and get the files | [
"Recursive",
"function",
"to",
"look",
"thru",
"each",
"directory",
"and",
"get",
"the",
"files"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L125-L136 |
7,724 | contiv/netplugin | objdb/etcdClient.go | ListDir | func (ep *EtcdClient) ListDir(key string) ([]string, error) {
keyName := "/contiv.io/obj/" + key
getOpts := client.GetOptions{
Recursive: true,
Sort: true,
Quorum: true,
}
// Get the object from etcd client
resp, err := ep.kapi.Get(context.Background(), keyName, &getOpts)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
resp, err = ep.kapi.Get(context.Background(), keyName, &getOpts)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
return nil, err
}
}
if !resp.Node.Dir {
log.Errorf("ListDir response is not a directory")
return nil, errors.New("Response is not directory")
}
var retList []string
// Call a recursive function to recurse thru each directory and get all files
// Warning: assumes directory itep is not interesting to the caller
// Warning2: there is also an assumption that keynames are not required
// Which means, caller has to derive the key from value :(
retList = recursAddNode(resp.Node, retList)
return retList, nil
} | go | func (ep *EtcdClient) ListDir(key string) ([]string, error) {
keyName := "/contiv.io/obj/" + key
getOpts := client.GetOptions{
Recursive: true,
Sort: true,
Quorum: true,
}
// Get the object from etcd client
resp, err := ep.kapi.Get(context.Background(), keyName, &getOpts)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
resp, err = ep.kapi.Get(context.Background(), keyName, &getOpts)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
return nil, err
}
}
if !resp.Node.Dir {
log.Errorf("ListDir response is not a directory")
return nil, errors.New("Response is not directory")
}
var retList []string
// Call a recursive function to recurse thru each directory and get all files
// Warning: assumes directory itep is not interesting to the caller
// Warning2: there is also an assumption that keynames are not required
// Which means, caller has to derive the key from value :(
retList = recursAddNode(resp.Node, retList)
return retList, nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"ListDir",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"key",
"\n\n",
"getOpts",
":=",
"client",
".",
"GetOptions",
"{",
"Recursive",
":",
... | // ListDir Get a list of objects in a directory | [
"ListDir",
"Get",
"a",
"list",
"of",
"objects",
"in",
"a",
"directory"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L139-L181 |
7,725 | contiv/netplugin | objdb/etcdClient.go | SetObj | func (ep *EtcdClient) SetObj(key string, value interface{}) error {
keyName := "/contiv.io/obj/" + key
// JSON format the object
jsonVal, err := json.Marshal(value)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
// Set it via etcd client
_, err = ep.kapi.Set(context.Background(), keyName, string(jsonVal[:]), nil)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
_, err = ep.kapi.Set(context.Background(), keyName, string(jsonVal[:]), nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error setting key %s, Err: %v", keyName, err)
return err
}
}
return nil
} | go | func (ep *EtcdClient) SetObj(key string, value interface{}) error {
keyName := "/contiv.io/obj/" + key
// JSON format the object
jsonVal, err := json.Marshal(value)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
// Set it via etcd client
_, err = ep.kapi.Set(context.Background(), keyName, string(jsonVal[:]), nil)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
_, err = ep.kapi.Set(context.Background(), keyName, string(jsonVal[:]), nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error setting key %s, Err: %v", keyName, err)
return err
}
}
return nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"SetObj",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"key",
"\n\n",
"// JSON format the object",
"jsonVal",
",",
"err",
":=",
"json",
".",
"... | // SetObj Save an object, create if it doesnt exist | [
"SetObj",
"Save",
"an",
"object",
"create",
"if",
"it",
"doesnt",
"exist"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L184-L216 |
7,726 | contiv/netplugin | objdb/etcdClient.go | DelObj | func (ep *EtcdClient) DelObj(key string) error {
keyName := "/contiv.io/obj/" + key
// Remove it via etcd client
_, err := ep.kapi.Delete(context.Background(), keyName, nil)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
_, err = ep.kapi.Delete(context.Background(), keyName, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error removing key %s, Err: %v", keyName, err)
return err
}
}
return nil
} | go | func (ep *EtcdClient) DelObj(key string) error {
keyName := "/contiv.io/obj/" + key
// Remove it via etcd client
_, err := ep.kapi.Delete(context.Background(), keyName, nil)
if err != nil {
// Retry few times if cluster is unavailable
if err.Error() == client.ErrClusterUnavailable.Error() {
for i := 0; i < maxEtcdRetries; i++ {
_, err = ep.kapi.Delete(context.Background(), keyName, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
if err != nil {
log.Errorf("Error removing key %s, Err: %v", keyName, err)
return err
}
}
return nil
} | [
"func",
"(",
"ep",
"*",
"EtcdClient",
")",
"DelObj",
"(",
"key",
"string",
")",
"error",
"{",
"keyName",
":=",
"\"",
"\"",
"+",
"key",
"\n\n",
"// Remove it via etcd client",
"_",
",",
"err",
":=",
"ep",
".",
"kapi",
".",
"Delete",
"(",
"context",
".",... | // DelObj Remove an object | [
"DelObj",
"Remove",
"an",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdClient.go#L219-L244 |
7,727 | contiv/netplugin | netplugin/agent/state_event.go | addVxGWRoutes | func addVxGWRoutes(netPlugin *plugin.NetPlugin, gwIP string) {
readNet := &mastercfg.CfgNetworkState{}
readNet.StateDriver = netPlugin.StateDriver
netCfgs, err := readNet.ReadAll()
if err != nil {
log.Errorf("Error reading netCfgs: %v", err)
return
}
for _, netCfg := range netCfgs {
net := netCfg.(*mastercfg.CfgNetworkState)
if net.NwType != "infra" && net.PktTagType == "vxlan" {
route := fmt.Sprintf("%s/%d", net.SubnetIP, net.SubnetLen)
err = netutils.AddIPRoute(route, gwIP)
if err != nil {
log.Errorf("Adding route %s --> %s: err: %v",
route, gwIP, err)
}
}
}
// route add cluster-ip
clusterNet := k8splugin.GetK8sClusterIPRange()
log.Infof("configuring cluster-ip route [%s]", clusterNet)
if len(clusterNet) > 0 {
if err = netutils.AddIPRoute(clusterNet, gwIP); err != nil {
log.Errorf("Adding route [%s] --> %s: err: %v",
clusterNet, gwIP, err)
}
}
} | go | func addVxGWRoutes(netPlugin *plugin.NetPlugin, gwIP string) {
readNet := &mastercfg.CfgNetworkState{}
readNet.StateDriver = netPlugin.StateDriver
netCfgs, err := readNet.ReadAll()
if err != nil {
log.Errorf("Error reading netCfgs: %v", err)
return
}
for _, netCfg := range netCfgs {
net := netCfg.(*mastercfg.CfgNetworkState)
if net.NwType != "infra" && net.PktTagType == "vxlan" {
route := fmt.Sprintf("%s/%d", net.SubnetIP, net.SubnetLen)
err = netutils.AddIPRoute(route, gwIP)
if err != nil {
log.Errorf("Adding route %s --> %s: err: %v",
route, gwIP, err)
}
}
}
// route add cluster-ip
clusterNet := k8splugin.GetK8sClusterIPRange()
log.Infof("configuring cluster-ip route [%s]", clusterNet)
if len(clusterNet) > 0 {
if err = netutils.AddIPRoute(clusterNet, gwIP); err != nil {
log.Errorf("Adding route [%s] --> %s: err: %v",
clusterNet, gwIP, err)
}
}
} | [
"func",
"addVxGWRoutes",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"gwIP",
"string",
")",
"{",
"readNet",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"readNet",
".",
"StateDriver",
"=",
"netPlugin",
".",
"StateDriver",
"\n",... | // Add routes for existing vxlan networks | [
"Add",
"routes",
"for",
"existing",
"vxlan",
"networks"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L58-L87 |
7,728 | contiv/netplugin | netplugin/agent/state_event.go | processInfraNwCreate | func processInfraNwCreate(netPlugin *plugin.NetPlugin, nwCfg *mastercfg.CfgNetworkState, opts core.InstanceInfo) (err error) {
pluginHost := opts.HostLabel
// Build endpoint request
mreq := master.CreateEndpointRequest{
TenantName: nwCfg.Tenant,
NetworkName: nwCfg.NetworkName,
EndpointID: pluginHost,
ConfigEP: intent.ConfigEP{
Container: pluginHost,
Host: pluginHost,
},
}
var mresp master.CreateEndpointResponse
err = cluster.MasterPostReq("/plugin/createEndpoint", &mreq, &mresp)
if err != nil {
log.Errorf("master failed to create endpoint %s", err)
return err
}
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Take lock to ensure netPlugin processes only one cmd at a time
// Ask netplugin to create the endpoint
netID := nwCfg.NetworkName + "." + nwCfg.Tenant
err = netPlugin.CreateEndpoint(netID + "-" + pluginHost)
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
return err
}
// Assign IP to interface
ipCIDR := fmt.Sprintf("%s/%d", mresp.EndpointConfig.IPAddress, nwCfg.SubnetLen)
err = netutils.SetInterfaceIP(nwCfg.NetworkName, ipCIDR)
if err != nil {
log.Errorf("Could not assign ip: %s", err)
return err
}
// add host access routes for vxlan networks
if nwCfg.NetworkName == contivVxGWName {
addVxGWRoutes(netPlugin, mresp.EndpointConfig.IPAddress)
}
return nil
} | go | func processInfraNwCreate(netPlugin *plugin.NetPlugin, nwCfg *mastercfg.CfgNetworkState, opts core.InstanceInfo) (err error) {
pluginHost := opts.HostLabel
// Build endpoint request
mreq := master.CreateEndpointRequest{
TenantName: nwCfg.Tenant,
NetworkName: nwCfg.NetworkName,
EndpointID: pluginHost,
ConfigEP: intent.ConfigEP{
Container: pluginHost,
Host: pluginHost,
},
}
var mresp master.CreateEndpointResponse
err = cluster.MasterPostReq("/plugin/createEndpoint", &mreq, &mresp)
if err != nil {
log.Errorf("master failed to create endpoint %s", err)
return err
}
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Take lock to ensure netPlugin processes only one cmd at a time
// Ask netplugin to create the endpoint
netID := nwCfg.NetworkName + "." + nwCfg.Tenant
err = netPlugin.CreateEndpoint(netID + "-" + pluginHost)
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
return err
}
// Assign IP to interface
ipCIDR := fmt.Sprintf("%s/%d", mresp.EndpointConfig.IPAddress, nwCfg.SubnetLen)
err = netutils.SetInterfaceIP(nwCfg.NetworkName, ipCIDR)
if err != nil {
log.Errorf("Could not assign ip: %s", err)
return err
}
// add host access routes for vxlan networks
if nwCfg.NetworkName == contivVxGWName {
addVxGWRoutes(netPlugin, mresp.EndpointConfig.IPAddress)
}
return nil
} | [
"func",
"processInfraNwCreate",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"nwCfg",
"*",
"mastercfg",
".",
"CfgNetworkState",
",",
"opts",
"core",
".",
"InstanceInfo",
")",
"(",
"err",
"error",
")",
"{",
"pluginHost",
":=",
"opts",
".",
"HostLab... | // Process Infra Nw Create
// Auto allocate an endpoint for this node | [
"Process",
"Infra",
"Nw",
"Create",
"Auto",
"allocate",
"an",
"endpoint",
"for",
"this",
"node"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L123-L170 |
7,729 | contiv/netplugin | netplugin/agent/state_event.go | processInfraNwDelete | func processInfraNwDelete(netPlugin *plugin.NetPlugin, nwCfg *mastercfg.CfgNetworkState, opts core.InstanceInfo) (err error) {
pluginHost := opts.HostLabel
if nwCfg.NetworkName == contivVxGWName {
gwIP, err := getVxGWIP(netPlugin, nwCfg.Tenant, pluginHost)
if err == nil {
delVxGWRoutes(netPlugin, gwIP)
}
}
// Build endpoint request
mreq := master.DeleteEndpointRequest{
TenantName: nwCfg.Tenant,
NetworkName: nwCfg.NetworkName,
EndpointID: pluginHost,
}
var mresp master.DeleteEndpointResponse
err = cluster.MasterPostReq("/plugin/deleteEndpoint", &mreq, &mresp)
if err != nil {
log.Errorf("master failed to delete endpoint %s", err)
return err
}
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Network delete will take care of infra nw EP delete in plugin
return err
} | go | func processInfraNwDelete(netPlugin *plugin.NetPlugin, nwCfg *mastercfg.CfgNetworkState, opts core.InstanceInfo) (err error) {
pluginHost := opts.HostLabel
if nwCfg.NetworkName == contivVxGWName {
gwIP, err := getVxGWIP(netPlugin, nwCfg.Tenant, pluginHost)
if err == nil {
delVxGWRoutes(netPlugin, gwIP)
}
}
// Build endpoint request
mreq := master.DeleteEndpointRequest{
TenantName: nwCfg.Tenant,
NetworkName: nwCfg.NetworkName,
EndpointID: pluginHost,
}
var mresp master.DeleteEndpointResponse
err = cluster.MasterPostReq("/plugin/deleteEndpoint", &mreq, &mresp)
if err != nil {
log.Errorf("master failed to delete endpoint %s", err)
return err
}
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Network delete will take care of infra nw EP delete in plugin
return err
} | [
"func",
"processInfraNwDelete",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"nwCfg",
"*",
"mastercfg",
".",
"CfgNetworkState",
",",
"opts",
"core",
".",
"InstanceInfo",
")",
"(",
"err",
"error",
")",
"{",
"pluginHost",
":=",
"opts",
".",
"HostLab... | // Process Infra Nw Delete
// Delete the auto allocated endpoint | [
"Process",
"Infra",
"Nw",
"Delete",
"Delete",
"the",
"auto",
"allocated",
"endpoint"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L174-L201 |
7,730 | contiv/netplugin | netplugin/agent/state_event.go | processEpState | func processEpState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, epID string) error {
// take a lock in netplugin to ensure we are programming one event at a time.
// Also network create events need to be processed before endpoint creates
// and reverse shall happen for deletes. That order is ensured by netmaster,
// so we don't need to worry about that here
// read endpoint config
epCfg := &mastercfg.CfgEndpointState{}
epCfg.StateDriver = netPlugin.StateDriver
err := epCfg.Read(epID)
if err != nil {
log.Errorf("Failed to read config for ep '%s' \n", epID)
return err
}
eptype := "local"
if checkRemoteHost(epCfg.VtepIP, epCfg.HomingHost, opts.HostLabel) {
eptype = "remote"
}
// Create the endpoint
if eptype == "local" {
err = netPlugin.CreateEndpoint(epID)
} else {
err = netPlugin.CreateRemoteEndpoint(epID)
}
if err != nil {
log.Errorf("Endpoint operation create failed. Error: %s", err)
return err
}
log.Infof("Endpoint operation create succeeded")
return err
} | go | func processEpState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, epID string) error {
// take a lock in netplugin to ensure we are programming one event at a time.
// Also network create events need to be processed before endpoint creates
// and reverse shall happen for deletes. That order is ensured by netmaster,
// so we don't need to worry about that here
// read endpoint config
epCfg := &mastercfg.CfgEndpointState{}
epCfg.StateDriver = netPlugin.StateDriver
err := epCfg.Read(epID)
if err != nil {
log.Errorf("Failed to read config for ep '%s' \n", epID)
return err
}
eptype := "local"
if checkRemoteHost(epCfg.VtepIP, epCfg.HomingHost, opts.HostLabel) {
eptype = "remote"
}
// Create the endpoint
if eptype == "local" {
err = netPlugin.CreateEndpoint(epID)
} else {
err = netPlugin.CreateRemoteEndpoint(epID)
}
if err != nil {
log.Errorf("Endpoint operation create failed. Error: %s", err)
return err
}
log.Infof("Endpoint operation create succeeded")
return err
} | [
"func",
"processEpState",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"opts",
"core",
".",
"InstanceInfo",
",",
"epID",
"string",
")",
"error",
"{",
"// take a lock in netplugin to ensure we are programming one event at a time.",
"// Also network create events nee... | // processEpState restores endpoint state | [
"processEpState",
"restores",
"endpoint",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L240-L274 |
7,731 | contiv/netplugin | netplugin/agent/state_event.go | processRemoteEpState | func processRemoteEpState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, epCfg *mastercfg.CfgEndpointState, isDelete bool) error {
if !checkRemoteHost(epCfg.VtepIP, epCfg.HomingHost, opts.HostLabel) {
// Skip local endpoint update, as they are handled directly in dockplugin
return nil
}
if isDelete {
// Delete remote endpoint
err := netPlugin.DeleteRemoteEndpoint(epCfg.ID)
if err != nil {
log.Errorf("Endpoint %s delete operation failed. Error: %s", epCfg.ID, err)
return err
}
log.Infof("Endpoint %s delete operation succeeded", epCfg.ID)
} else {
// Create remote endpoint
err := netPlugin.CreateRemoteEndpoint(epCfg.ID)
if err != nil {
log.Errorf("Endpoint %s create operation failed. Error: %s", epCfg.ID, err)
return err
}
log.Infof("Endpoint %s create operation succeeded", epCfg.ID)
}
return nil
} | go | func processRemoteEpState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, epCfg *mastercfg.CfgEndpointState, isDelete bool) error {
if !checkRemoteHost(epCfg.VtepIP, epCfg.HomingHost, opts.HostLabel) {
// Skip local endpoint update, as they are handled directly in dockplugin
return nil
}
if isDelete {
// Delete remote endpoint
err := netPlugin.DeleteRemoteEndpoint(epCfg.ID)
if err != nil {
log.Errorf("Endpoint %s delete operation failed. Error: %s", epCfg.ID, err)
return err
}
log.Infof("Endpoint %s delete operation succeeded", epCfg.ID)
} else {
// Create remote endpoint
err := netPlugin.CreateRemoteEndpoint(epCfg.ID)
if err != nil {
log.Errorf("Endpoint %s create operation failed. Error: %s", epCfg.ID, err)
return err
}
log.Infof("Endpoint %s create operation succeeded", epCfg.ID)
}
return nil
} | [
"func",
"processRemoteEpState",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"opts",
"core",
".",
"InstanceInfo",
",",
"epCfg",
"*",
"mastercfg",
".",
"CfgEndpointState",
",",
"isDelete",
"bool",
")",
"error",
"{",
"if",
"!",
"checkRemoteHost",
"(",... | // processRemoteEpState updates endpoint state | [
"processRemoteEpState",
"updates",
"endpoint",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L277-L302 |
7,732 | contiv/netplugin | netplugin/agent/state_event.go | processServiceLBEvent | func processServiceLBEvent(netPlugin *plugin.NetPlugin, svcLBCfg *mastercfg.CfgServiceLBState, isDelete bool) error {
var err error
portSpecList := []core.PortSpec{}
portSpec := core.PortSpec{}
serviceID := svcLBCfg.ID
log.Infof("Recevied Process Service load balancer event {%v}", svcLBCfg)
//create portspect list from state.
//Ports format: servicePort:ProviderPort:Protocol
for _, port := range svcLBCfg.Ports {
portInfo := strings.Split(port, ":")
if len(portInfo) != 3 {
return errors.New("invalid Port Format")
}
svcPort := portInfo[0]
provPort := portInfo[1]
portSpec.Protocol = portInfo[2]
sPort, _ := strconv.ParseUint(svcPort, 10, 16)
portSpec.SvcPort = uint16(sPort)
pPort, _ := strconv.ParseUint(provPort, 10, 16)
portSpec.ProvPort = uint16(pPort)
portSpecList = append(portSpecList, portSpec)
}
spec := &core.ServiceSpec{
IPAddress: svcLBCfg.IPAddress,
Ports: portSpecList,
}
operStr := ""
if isDelete {
err = netPlugin.DeleteServiceLB(serviceID, spec)
operStr = "delete"
} else {
err = netPlugin.AddServiceLB(serviceID, spec)
operStr = "create"
}
if err != nil {
log.Errorf("Service Load Balancer %s failed.Error:%s", operStr, err)
return err
}
log.Infof("Service Load Balancer %s succeeded", operStr)
return nil
} | go | func processServiceLBEvent(netPlugin *plugin.NetPlugin, svcLBCfg *mastercfg.CfgServiceLBState, isDelete bool) error {
var err error
portSpecList := []core.PortSpec{}
portSpec := core.PortSpec{}
serviceID := svcLBCfg.ID
log.Infof("Recevied Process Service load balancer event {%v}", svcLBCfg)
//create portspect list from state.
//Ports format: servicePort:ProviderPort:Protocol
for _, port := range svcLBCfg.Ports {
portInfo := strings.Split(port, ":")
if len(portInfo) != 3 {
return errors.New("invalid Port Format")
}
svcPort := portInfo[0]
provPort := portInfo[1]
portSpec.Protocol = portInfo[2]
sPort, _ := strconv.ParseUint(svcPort, 10, 16)
portSpec.SvcPort = uint16(sPort)
pPort, _ := strconv.ParseUint(provPort, 10, 16)
portSpec.ProvPort = uint16(pPort)
portSpecList = append(portSpecList, portSpec)
}
spec := &core.ServiceSpec{
IPAddress: svcLBCfg.IPAddress,
Ports: portSpecList,
}
operStr := ""
if isDelete {
err = netPlugin.DeleteServiceLB(serviceID, spec)
operStr = "delete"
} else {
err = netPlugin.AddServiceLB(serviceID, spec)
operStr = "create"
}
if err != nil {
log.Errorf("Service Load Balancer %s failed.Error:%s", operStr, err)
return err
}
log.Infof("Service Load Balancer %s succeeded", operStr)
return nil
} | [
"func",
"processServiceLBEvent",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"svcLBCfg",
"*",
"mastercfg",
".",
"CfgServiceLBState",
",",
"isDelete",
"bool",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"portSpecList",
":=",
"[",
"]",
"core",
... | //processServiceLBEvent processes service load balancer object events | [
"processServiceLBEvent",
"processes",
"service",
"load",
"balancer",
"object",
"events"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L438-L488 |
7,733 | contiv/netplugin | netplugin/agent/state_event.go | processSvcProviderUpdEvent | func processSvcProviderUpdEvent(netPlugin *plugin.NetPlugin, svcProvider *mastercfg.SvcProvider, isDelete bool) error {
if isDelete {
//ignore delete event since servicelb delete will take care of this.
return nil
}
netPlugin.SvcProviderUpdate(svcProvider.ServiceName, svcProvider.Providers)
return nil
} | go | func processSvcProviderUpdEvent(netPlugin *plugin.NetPlugin, svcProvider *mastercfg.SvcProvider, isDelete bool) error {
if isDelete {
//ignore delete event since servicelb delete will take care of this.
return nil
}
netPlugin.SvcProviderUpdate(svcProvider.ServiceName, svcProvider.Providers)
return nil
} | [
"func",
"processSvcProviderUpdEvent",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"svcProvider",
"*",
"mastercfg",
".",
"SvcProvider",
",",
"isDelete",
"bool",
")",
"error",
"{",
"if",
"isDelete",
"{",
"//ignore delete event since servicelb delete will take ... | //processSvcProviderUpdEvent updates service provider events | [
"processSvcProviderUpdEvent",
"updates",
"service",
"provider",
"events"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L491-L498 |
7,734 | contiv/netplugin | netplugin/agent/state_event.go | processPolicyRuleState | func processPolicyRuleState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, ruleID string, isDelete bool) error {
// read policy config
ruleCfg := &mastercfg.CfgPolicyRule{}
ruleCfg.StateDriver = netPlugin.StateDriver
err := ruleCfg.Read(ruleID)
if err != nil {
log.Errorf("Failed to read config for policy rule '%s' \n", ruleID)
return err
}
if isDelete {
// Delete endpoint
err = netPlugin.DelPolicyRule(ruleID)
if err != nil {
log.Errorf("PolicyRule %s delete operation failed. Error: %s", ruleID, err)
return err
}
log.Infof("PolicyRule %s delete operation succeeded", ruleID)
} else {
// Create endpoint
err = netPlugin.AddPolicyRule(ruleID)
if err != nil {
log.Errorf("PolicyRule %s create operation failed. Error: %s", ruleID, err)
return err
}
log.Infof("PolicyRule %s create operation succeeded", ruleID)
}
return err
} | go | func processPolicyRuleState(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, ruleID string, isDelete bool) error {
// read policy config
ruleCfg := &mastercfg.CfgPolicyRule{}
ruleCfg.StateDriver = netPlugin.StateDriver
err := ruleCfg.Read(ruleID)
if err != nil {
log.Errorf("Failed to read config for policy rule '%s' \n", ruleID)
return err
}
if isDelete {
// Delete endpoint
err = netPlugin.DelPolicyRule(ruleID)
if err != nil {
log.Errorf("PolicyRule %s delete operation failed. Error: %s", ruleID, err)
return err
}
log.Infof("PolicyRule %s delete operation succeeded", ruleID)
} else {
// Create endpoint
err = netPlugin.AddPolicyRule(ruleID)
if err != nil {
log.Errorf("PolicyRule %s create operation failed. Error: %s", ruleID, err)
return err
}
log.Infof("PolicyRule %s create operation succeeded", ruleID)
}
return err
} | [
"func",
"processPolicyRuleState",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"opts",
"core",
".",
"InstanceInfo",
",",
"ruleID",
"string",
",",
"isDelete",
"bool",
")",
"error",
"{",
"// read policy config",
"ruleCfg",
":=",
"&",
"mastercfg",
".",
... | // processPolicyRuleState updates policy rule state | [
"processPolicyRuleState",
"updates",
"policy",
"rule",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/state_event.go#L501-L530 |
7,735 | contiv/netplugin | netmaster/resources/vxlanresource.go | ReadAll | func (r *AutoVXLANCfgResource) ReadAll() ([]core.State, error) {
return r.StateDriver.ReadAllState(vXLANResourceConfigPathPrefix, r,
json.Unmarshal)
} | go | func (r *AutoVXLANCfgResource) ReadAll() ([]core.State, error) {
return r.StateDriver.ReadAllState(vXLANResourceConfigPathPrefix, r,
json.Unmarshal)
} | [
"func",
"(",
"r",
"*",
"AutoVXLANCfgResource",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"r",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"vXLANResourceConfigPathPrefix",
",",
"r",
",",
"json",
"."... | // ReadAll reads all the state from the resource. | [
"ReadAll",
"reads",
"all",
"the",
"state",
"from",
"the",
"resource",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L77-L80 |
7,736 | contiv/netplugin | netmaster/resources/vxlanresource.go | Init | func (r *AutoVXLANCfgResource) Init(rsrcCfg interface{}) error {
cfg, ok := rsrcCfg.(*AutoVXLANCfgResource)
if !ok {
return core.Errorf("Invalid vxlan resource config.")
}
r.VXLANs = cfg.VXLANs
r.LocalVLANs = cfg.LocalVLANs
err := r.Write()
if err != nil {
return err
}
defer func() {
if err != nil {
r.Clear()
}
}()
oper := &AutoVXLANOperResource{FreeVXLANs: r.VXLANs, FreeLocalVLANs: r.LocalVLANs}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
return oper.Write()
} | go | func (r *AutoVXLANCfgResource) Init(rsrcCfg interface{}) error {
cfg, ok := rsrcCfg.(*AutoVXLANCfgResource)
if !ok {
return core.Errorf("Invalid vxlan resource config.")
}
r.VXLANs = cfg.VXLANs
r.LocalVLANs = cfg.LocalVLANs
err := r.Write()
if err != nil {
return err
}
defer func() {
if err != nil {
r.Clear()
}
}()
oper := &AutoVXLANOperResource{FreeVXLANs: r.VXLANs, FreeLocalVLANs: r.LocalVLANs}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
return oper.Write()
} | [
"func",
"(",
"r",
"*",
"AutoVXLANCfgResource",
")",
"Init",
"(",
"rsrcCfg",
"interface",
"{",
"}",
")",
"error",
"{",
"cfg",
",",
"ok",
":=",
"rsrcCfg",
".",
"(",
"*",
"AutoVXLANCfgResource",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"core",
".",
"E... | // Init the resource. | [
"Init",
"the",
"resource",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L83-L104 |
7,737 | contiv/netplugin | netmaster/resources/vxlanresource.go | Reinit | func (r *AutoVXLANCfgResource) Reinit(rsrcCfg interface{}) error {
cfg, ok := rsrcCfg.(*AutoVXLANCfgResource)
if !ok {
return core.Errorf("Invalid vxlan resource config.")
}
prevVXLANs := r.VXLANs
prevFreeStart := r.FreeVXLANsStart
r.VXLANs = cfg.VXLANs
r.LocalVLANs = cfg.LocalVLANs
r.FreeVXLANsStart = cfg.FreeVXLANsStart
err := r.Write()
if err != nil {
return err
}
defer func() {
if err != nil {
r.Clear()
}
}()
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
err = oper.Read(r.ID)
if err != nil {
return err
}
prevVXLANs.InPlaceSymmetricDifference(oper.FreeVXLANs)
oper.FreeVXLANs = r.VXLANs
for i, e := prevVXLANs.NextSet(0); e; i, e = prevVXLANs.NextSet(i + 1) {
vxlan := i + prevFreeStart
oper.FreeVXLANs.Clear(vxlan - r.FreeVXLANsStart)
}
oper.FreeLocalVLANs = oper.FreeLocalVLANs.Intersection(r.LocalVLANs)
return oper.Write()
} | go | func (r *AutoVXLANCfgResource) Reinit(rsrcCfg interface{}) error {
cfg, ok := rsrcCfg.(*AutoVXLANCfgResource)
if !ok {
return core.Errorf("Invalid vxlan resource config.")
}
prevVXLANs := r.VXLANs
prevFreeStart := r.FreeVXLANsStart
r.VXLANs = cfg.VXLANs
r.LocalVLANs = cfg.LocalVLANs
r.FreeVXLANsStart = cfg.FreeVXLANsStart
err := r.Write()
if err != nil {
return err
}
defer func() {
if err != nil {
r.Clear()
}
}()
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
err = oper.Read(r.ID)
if err != nil {
return err
}
prevVXLANs.InPlaceSymmetricDifference(oper.FreeVXLANs)
oper.FreeVXLANs = r.VXLANs
for i, e := prevVXLANs.NextSet(0); e; i, e = prevVXLANs.NextSet(i + 1) {
vxlan := i + prevFreeStart
oper.FreeVXLANs.Clear(vxlan - r.FreeVXLANsStart)
}
oper.FreeLocalVLANs = oper.FreeLocalVLANs.Intersection(r.LocalVLANs)
return oper.Write()
} | [
"func",
"(",
"r",
"*",
"AutoVXLANCfgResource",
")",
"Reinit",
"(",
"rsrcCfg",
"interface",
"{",
"}",
")",
"error",
"{",
"cfg",
",",
"ok",
":=",
"rsrcCfg",
".",
"(",
"*",
"AutoVXLANCfgResource",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"core",
".",
... | // Reinit the resource. | [
"Reinit",
"the",
"resource",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L124-L168 |
7,738 | contiv/netplugin | netmaster/resources/vxlanresource.go | Allocate | func (r *AutoVXLANCfgResource) Allocate(reqVal interface{}) (interface{}, error) {
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
err := oper.Read(r.ID)
if err != nil {
return nil, err
}
var vxlan uint
if (reqVal != nil) && (reqVal.(uint) != 0) {
vxlan = reqVal.(uint)
if !oper.FreeVXLANs.Test(vxlan) {
return nil, fmt.Errorf("requested vxlan not available")
}
} else {
ok := false
vxlan, ok = oper.FreeVXLANs.NextSet(0)
if !ok {
return nil, errors.New("no vxlans available")
}
}
vlan, ok := oper.FreeLocalVLANs.NextSet(0)
if !ok {
return nil, errors.New("no local vlans available")
}
oper.FreeVXLANs.Clear(vxlan)
oper.FreeLocalVLANs.Clear(vlan)
err = oper.Write()
if err != nil {
return nil, err
}
return VXLANVLANPair{VXLAN: vxlan, VLAN: vlan}, nil
} | go | func (r *AutoVXLANCfgResource) Allocate(reqVal interface{}) (interface{}, error) {
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
err := oper.Read(r.ID)
if err != nil {
return nil, err
}
var vxlan uint
if (reqVal != nil) && (reqVal.(uint) != 0) {
vxlan = reqVal.(uint)
if !oper.FreeVXLANs.Test(vxlan) {
return nil, fmt.Errorf("requested vxlan not available")
}
} else {
ok := false
vxlan, ok = oper.FreeVXLANs.NextSet(0)
if !ok {
return nil, errors.New("no vxlans available")
}
}
vlan, ok := oper.FreeLocalVLANs.NextSet(0)
if !ok {
return nil, errors.New("no local vlans available")
}
oper.FreeVXLANs.Clear(vxlan)
oper.FreeLocalVLANs.Clear(vlan)
err = oper.Write()
if err != nil {
return nil, err
}
return VXLANVLANPair{VXLAN: vxlan, VLAN: vlan}, nil
} | [
"func",
"(",
"r",
"*",
"AutoVXLANCfgResource",
")",
"Allocate",
"(",
"reqVal",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"oper",
":=",
"&",
"AutoVXLANOperResource",
"{",
"}",
"\n",
"oper",
".",
"StateDriver",
"=",
... | // Allocate allocates a new resource. | [
"Allocate",
"allocates",
"a",
"new",
"resource",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L226-L261 |
7,739 | contiv/netplugin | netmaster/resources/vxlanresource.go | Deallocate | func (r *AutoVXLANCfgResource) Deallocate(value interface{}) error {
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
err := oper.Read(r.ID)
if err != nil {
return err
}
pair, ok := value.(VXLANVLANPair)
if !ok {
return core.Errorf("Invalid type for vxlan-vlan pair")
}
vxlan := pair.VXLAN
oper.FreeVXLANs.Set(vxlan)
vlan := pair.VLAN
oper.FreeLocalVLANs.Set(vlan)
return oper.Write()
} | go | func (r *AutoVXLANCfgResource) Deallocate(value interface{}) error {
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
err := oper.Read(r.ID)
if err != nil {
return err
}
pair, ok := value.(VXLANVLANPair)
if !ok {
return core.Errorf("Invalid type for vxlan-vlan pair")
}
vxlan := pair.VXLAN
oper.FreeVXLANs.Set(vxlan)
vlan := pair.VLAN
oper.FreeLocalVLANs.Set(vlan)
return oper.Write()
} | [
"func",
"(",
"r",
"*",
"AutoVXLANCfgResource",
")",
"Deallocate",
"(",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"oper",
":=",
"&",
"AutoVXLANOperResource",
"{",
"}",
"\n",
"oper",
".",
"StateDriver",
"=",
"r",
".",
"StateDriver",
"\n",
"err",
"... | // Deallocate removes and cleans up a resource. | [
"Deallocate",
"removes",
"and",
"cleans",
"up",
"a",
"resource",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L264-L282 |
7,740 | contiv/netplugin | netmaster/resources/vxlanresource.go | ReadAll | func (r *AutoVXLANOperResource) ReadAll() ([]core.State, error) {
return r.StateDriver.ReadAllState(vXLANResourceOperPathPrefix, r,
json.Unmarshal)
} | go | func (r *AutoVXLANOperResource) ReadAll() ([]core.State, error) {
return r.StateDriver.ReadAllState(vXLANResourceOperPathPrefix, r,
json.Unmarshal)
} | [
"func",
"(",
"r",
"*",
"AutoVXLANOperResource",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"r",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"vXLANResourceOperPathPrefix",
",",
"r",
",",
"json",
".",... | // ReadAll the state for the given type. | [
"ReadAll",
"the",
"state",
"for",
"the",
"given",
"type",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vxlanresource.go#L304-L307 |
7,741 | contiv/netplugin | state/fakestatedriver.go | Init | func (d *FakeStateDriver) Init(instInfo *core.InstanceInfo) error {
d.TestState = make(map[string]valueData)
return nil
} | go | func (d *FakeStateDriver) Init(instInfo *core.InstanceInfo) error {
d.TestState = make(map[string]valueData)
return nil
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"Init",
"(",
"instInfo",
"*",
"core",
".",
"InstanceInfo",
")",
"error",
"{",
"d",
".",
"TestState",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"valueData",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Init the driver | [
"Init",
"the",
"driver"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L26-L30 |
7,742 | contiv/netplugin | state/fakestatedriver.go | Write | func (d *FakeStateDriver) Write(key string, value []byte) error {
val := valueData{value: value}
d.TestState[key] = val
return nil
} | go | func (d *FakeStateDriver) Write(key string, value []byte) error {
val := valueData{value: value}
d.TestState[key] = val
return nil
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"Write",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"val",
":=",
"valueData",
"{",
"value",
":",
"value",
"}",
"\n",
"d",
".",
"TestState",
"[",
"key",
"]",
"=",
"val",
... | // Write value to key | [
"Write",
"value",
"to",
"key"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L38-L43 |
7,743 | contiv/netplugin | state/fakestatedriver.go | Read | func (d *FakeStateDriver) Read(key string) ([]byte, error) {
if val, ok := d.TestState[key]; ok {
return val.value, nil
}
return []byte{}, core.Errorf("key not found! key: %v", key)
} | go | func (d *FakeStateDriver) Read(key string) ([]byte, error) {
if val, ok := d.TestState[key]; ok {
return val.value, nil
}
return []byte{}, core.Errorf("key not found! key: %v", key)
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"Read",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"d",
".",
"TestState",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"val",
".",
"value"... | // Read value from key | [
"Read",
"value",
"from",
"key"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L46-L52 |
7,744 | contiv/netplugin | state/fakestatedriver.go | ReadAll | func (d *FakeStateDriver) ReadAll(baseKey string) ([][]byte, error) {
values := [][]byte{}
for key, val := range d.TestState {
if strings.Contains(key, baseKey) {
values = append(values, val.value)
}
}
return values, nil
} | go | func (d *FakeStateDriver) ReadAll(baseKey string) ([][]byte, error) {
values := [][]byte{}
for key, val := range d.TestState {
if strings.Contains(key, baseKey) {
values = append(values, val.value)
}
}
return values, nil
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"ReadAll",
"(",
"baseKey",
"string",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"values",
":=",
"[",
"]",
"[",
"]",
"byte",
"{",
"}",
"\n\n",
"for",
"key",
",",
"val",
":=",
"ran... | // ReadAll values from baseKey | [
"ReadAll",
"values",
"from",
"baseKey"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L55-L64 |
7,745 | contiv/netplugin | state/fakestatedriver.go | WatchAll | func (d *FakeStateDriver) WatchAll(baseKey string, rsps chan [2][]byte) error {
log.Warnf("watchall not supported")
select {} // block forever
} | go | func (d *FakeStateDriver) WatchAll(baseKey string, rsps chan [2][]byte) error {
log.Warnf("watchall not supported")
select {} // block forever
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"WatchAll",
"(",
"baseKey",
"string",
",",
"rsps",
"chan",
"[",
"2",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
")",
"\n",
"select",
"{",
"}",
"// block forever",
"... | // WatchAll values from baseKey | [
"WatchAll",
"values",
"from",
"baseKey"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L67-L70 |
7,746 | contiv/netplugin | state/fakestatedriver.go | ClearState | func (d *FakeStateDriver) ClearState(key string) error {
if _, ok := d.TestState[key]; ok {
delete(d.TestState, key)
}
return nil
} | go | func (d *FakeStateDriver) ClearState(key string) error {
if _, ok := d.TestState[key]; ok {
delete(d.TestState, key)
}
return nil
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"ClearState",
"(",
"key",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"d",
".",
"TestState",
"[",
"key",
"]",
";",
"ok",
"{",
"delete",
"(",
"d",
".",
"TestState",
",",
"key",
")",
"\n",... | // ClearState clears key | [
"ClearState",
"clears",
"key"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L73-L78 |
7,747 | contiv/netplugin | state/fakestatedriver.go | ReadAllState | func (d *FakeStateDriver) ReadAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error) ([]core.State, error) {
return readAllStateCommon(d, baseKey, sType, unmarshal)
} | go | func (d *FakeStateDriver) ReadAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error) ([]core.State, error) {
return readAllStateCommon(d, baseKey, sType, unmarshal)
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"ReadAllState",
"(",
"baseKey",
"string",
",",
"sType",
"core",
".",
"State",
",",
"unmarshal",
"func",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
")",
"error",
")",
"(",
"[",
"]",
"core",
".",
... | // ReadAllState reads all state from baseKey of a given type | [
"ReadAllState",
"reads",
"all",
"state",
"from",
"baseKey",
"of",
"a",
"given",
"type"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L92-L95 |
7,748 | contiv/netplugin | state/fakestatedriver.go | WatchAllState | func (d *FakeStateDriver) WatchAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error, rsps chan core.WatchState) error {
return core.Errorf("not supported")
} | go | func (d *FakeStateDriver) WatchAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error, rsps chan core.WatchState) error {
return core.Errorf("not supported")
} | [
"func",
"(",
"d",
"*",
"FakeStateDriver",
")",
"WatchAllState",
"(",
"baseKey",
"string",
",",
"sType",
"core",
".",
"State",
",",
"unmarshal",
"func",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
")",
"error",
",",
"rsps",
"chan",
"core",
".",
... | // WatchAllState reads all state from baseKey of a given type | [
"WatchAllState",
"reads",
"all",
"state",
"from",
"baseKey",
"of",
"a",
"given",
"type"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/fakestatedriver.go#L98-L101 |
7,749 | contiv/netplugin | netmaster/master/servicelb.go | DeleteServiceLB | func DeleteServiceLB(stateDriver core.StateDriver, serviceName string, tenantName string) error {
log.Infof("Received Delete Service Load Balancer %s on %s", serviceName, tenantName)
serviceLBState := &mastercfg.CfgServiceLBState{}
serviceLBState.StateDriver = stateDriver
serviceLBState.ID = GetServiceID(serviceName, tenantName)
mastercfg.SvcMutex.RLock()
err := serviceLBState.Read(serviceLBState.ID)
if err != nil {
mastercfg.SvcMutex.RUnlock()
log.Errorf("Error reading service lb config for service %s in tenant %s", serviceName, tenantName)
return err
}
mastercfg.SvcMutex.RUnlock()
// find the network from network id
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := serviceLBState.Network + "." + serviceLBState.Tenant
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("network %s is not operational. Service object deletion failed", networkID)
return err
}
err = networkReleaseAddress(nwCfg, nil, serviceLBState.IPAddress)
if err != nil {
log.Errorf("Network release address failed %s", err)
}
serviceID := GetServiceID(serviceLBState.ServiceName, serviceLBState.Tenant)
mastercfg.SvcMutex.Lock()
//Remove the service ID from the provider cache
for _, providerInfo := range mastercfg.ServiceLBDb[serviceID].Providers {
containerID := providerInfo.ContainerID
for i, service := range mastercfg.ProviderDb[containerID].Services {
if service == serviceID {
mastercfg.ProviderDb[containerID].Services =
append(mastercfg.ProviderDb[containerID].Services[:i],
mastercfg.ProviderDb[containerID].Services[i+1:]...)
}
}
}
//Remove the service from the service cache
delete(mastercfg.ServiceLBDb, serviceID)
SvcProviderUpdate(serviceID, true)
err = serviceLBState.Clear()
if err != nil {
mastercfg.SvcMutex.Unlock()
log.Errorf("Error deleing service lb config for service %s in tenant %s", serviceName, tenantName)
return err
}
mastercfg.SvcMutex.Unlock()
return nil
} | go | func DeleteServiceLB(stateDriver core.StateDriver, serviceName string, tenantName string) error {
log.Infof("Received Delete Service Load Balancer %s on %s", serviceName, tenantName)
serviceLBState := &mastercfg.CfgServiceLBState{}
serviceLBState.StateDriver = stateDriver
serviceLBState.ID = GetServiceID(serviceName, tenantName)
mastercfg.SvcMutex.RLock()
err := serviceLBState.Read(serviceLBState.ID)
if err != nil {
mastercfg.SvcMutex.RUnlock()
log.Errorf("Error reading service lb config for service %s in tenant %s", serviceName, tenantName)
return err
}
mastercfg.SvcMutex.RUnlock()
// find the network from network id
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := serviceLBState.Network + "." + serviceLBState.Tenant
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("network %s is not operational. Service object deletion failed", networkID)
return err
}
err = networkReleaseAddress(nwCfg, nil, serviceLBState.IPAddress)
if err != nil {
log.Errorf("Network release address failed %s", err)
}
serviceID := GetServiceID(serviceLBState.ServiceName, serviceLBState.Tenant)
mastercfg.SvcMutex.Lock()
//Remove the service ID from the provider cache
for _, providerInfo := range mastercfg.ServiceLBDb[serviceID].Providers {
containerID := providerInfo.ContainerID
for i, service := range mastercfg.ProviderDb[containerID].Services {
if service == serviceID {
mastercfg.ProviderDb[containerID].Services =
append(mastercfg.ProviderDb[containerID].Services[:i],
mastercfg.ProviderDb[containerID].Services[i+1:]...)
}
}
}
//Remove the service from the service cache
delete(mastercfg.ServiceLBDb, serviceID)
SvcProviderUpdate(serviceID, true)
err = serviceLBState.Clear()
if err != nil {
mastercfg.SvcMutex.Unlock()
log.Errorf("Error deleing service lb config for service %s in tenant %s", serviceName, tenantName)
return err
}
mastercfg.SvcMutex.Unlock()
return nil
} | [
"func",
"DeleteServiceLB",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"serviceName",
"string",
",",
"tenantName",
"string",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"serviceName",
",",
"tenantName",
")",
"\n",
"serviceLBState",
... | //DeleteServiceLB deletes from etcd state | [
"DeleteServiceLB",
"deletes",
"from",
"etcd",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/servicelb.go#L147-L207 |
7,750 | contiv/netplugin | netmaster/master/servicelb.go | RestoreServiceProviderLBDb | func RestoreServiceProviderLBDb() {
log.Infof("Restoring ProviderDb and ServiceDB cache")
svcLBState := &mastercfg.CfgServiceLBState{}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Error Restoring Service and ProviderDb Err:%s", err)
return
}
svcLBState.StateDriver = stateDriver
svcLBCfgs, err := svcLBState.ReadAll()
if err == nil {
mastercfg.SvcMutex.Lock()
for _, svcLBCfg := range svcLBCfgs {
svcLB := svcLBCfg.(*mastercfg.CfgServiceLBState)
//mastercfg.ServiceLBDb = make(map[string]*mastercfg.ServiceLBInfo)
serviceID := GetServiceID(svcLB.ServiceName, svcLB.Tenant)
mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
IPAddress: svcLB.IPAddress,
Tenant: svcLB.Tenant,
ServiceName: svcLB.ServiceName,
Network: svcLB.Network,
}
mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, svcLB.Ports...)
mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)
for k, v := range svcLB.Selectors {
mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
}
for providerID, providerInfo := range svcLB.Providers {
mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
providerDBId := providerInfo.ContainerID
mastercfg.ProviderDb[providerDBId] = providerInfo
}
}
mastercfg.SvcMutex.Unlock()
}
//Recover from endpoint state as well .
epCfgState := mastercfg.CfgEndpointState{}
epCfgState.StateDriver = stateDriver
epCfgs, err := epCfgState.ReadAll()
if err == nil {
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
providerDBId := ep.ContainerID
if ep.Labels != nil && mastercfg.ProviderDb[providerDBId] == nil {
//Create provider info and store it in provider db
providerInfo := &mastercfg.Provider{}
providerInfo.ContainerID = ep.ContainerID
providerInfo.Network = strings.Split(ep.NetID, ".")[0]
providerInfo.Tenant = strings.Split(ep.NetID, ".")[1]
providerInfo.Labels = make(map[string]string)
providerInfo.IPAddress = ep.IPAddress
for k, v := range ep.Labels {
providerInfo.Labels[k] = v
}
mastercfg.SvcMutex.Lock()
mastercfg.ProviderDb[providerDBId] = providerInfo
mastercfg.SvcMutex.Unlock()
}
}
}
} | go | func RestoreServiceProviderLBDb() {
log.Infof("Restoring ProviderDb and ServiceDB cache")
svcLBState := &mastercfg.CfgServiceLBState{}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Error Restoring Service and ProviderDb Err:%s", err)
return
}
svcLBState.StateDriver = stateDriver
svcLBCfgs, err := svcLBState.ReadAll()
if err == nil {
mastercfg.SvcMutex.Lock()
for _, svcLBCfg := range svcLBCfgs {
svcLB := svcLBCfg.(*mastercfg.CfgServiceLBState)
//mastercfg.ServiceLBDb = make(map[string]*mastercfg.ServiceLBInfo)
serviceID := GetServiceID(svcLB.ServiceName, svcLB.Tenant)
mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
IPAddress: svcLB.IPAddress,
Tenant: svcLB.Tenant,
ServiceName: svcLB.ServiceName,
Network: svcLB.Network,
}
mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, svcLB.Ports...)
mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)
for k, v := range svcLB.Selectors {
mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
}
for providerID, providerInfo := range svcLB.Providers {
mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
providerDBId := providerInfo.ContainerID
mastercfg.ProviderDb[providerDBId] = providerInfo
}
}
mastercfg.SvcMutex.Unlock()
}
//Recover from endpoint state as well .
epCfgState := mastercfg.CfgEndpointState{}
epCfgState.StateDriver = stateDriver
epCfgs, err := epCfgState.ReadAll()
if err == nil {
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
providerDBId := ep.ContainerID
if ep.Labels != nil && mastercfg.ProviderDb[providerDBId] == nil {
//Create provider info and store it in provider db
providerInfo := &mastercfg.Provider{}
providerInfo.ContainerID = ep.ContainerID
providerInfo.Network = strings.Split(ep.NetID, ".")[0]
providerInfo.Tenant = strings.Split(ep.NetID, ".")[1]
providerInfo.Labels = make(map[string]string)
providerInfo.IPAddress = ep.IPAddress
for k, v := range ep.Labels {
providerInfo.Labels[k] = v
}
mastercfg.SvcMutex.Lock()
mastercfg.ProviderDb[providerDBId] = providerInfo
mastercfg.SvcMutex.Unlock()
}
}
}
} | [
"func",
"RestoreServiceProviderLBDb",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"svcLBState",
":=",
"&",
"mastercfg",
".",
"CfgServiceLBState",
"{",
"}",
"\n",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")... | //RestoreServiceProviderLBDb restores provider and servicelb db | [
"RestoreServiceProviderLBDb",
"restores",
"provider",
"and",
"servicelb",
"db"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/servicelb.go#L210-L279 |
7,751 | contiv/netplugin | utils/netutils/netutils.go | IsOverlappingSubnetv6 | func IsOverlappingSubnetv6(inputIPv6Subnet string, existingIPv6Subnet string) bool {
inputIPv6StartRange, inputIPv6EndRange := getIPv6Range(inputIPv6Subnet)
existingIPv6StartRange, existingIPv6EndRange := getIPv6Range(existingIPv6Subnet)
inputStartRange := ipv6ToBigint(inputIPv6StartRange)
inputEndRange := ipv6ToBigint(inputIPv6EndRange)
existingStartRange := ipv6ToBigint(existingIPv6StartRange)
existingEndRange := ipv6ToBigint(existingIPv6EndRange)
if (existingStartRange.Cmp(inputStartRange) <= 0 && inputStartRange.Cmp(existingEndRange) <= 0) ||
(existingStartRange.Cmp(inputEndRange) <= 0 && inputEndRange.Cmp(existingEndRange) <= 0) {
return true
}
if (inputStartRange.Cmp(existingStartRange) <= 0 && existingStartRange.Cmp(inputEndRange) <= 0) ||
(inputStartRange.Cmp(existingEndRange) <= 0 && existingEndRange.Cmp(inputEndRange) <= 0) {
return true
}
return false
} | go | func IsOverlappingSubnetv6(inputIPv6Subnet string, existingIPv6Subnet string) bool {
inputIPv6StartRange, inputIPv6EndRange := getIPv6Range(inputIPv6Subnet)
existingIPv6StartRange, existingIPv6EndRange := getIPv6Range(existingIPv6Subnet)
inputStartRange := ipv6ToBigint(inputIPv6StartRange)
inputEndRange := ipv6ToBigint(inputIPv6EndRange)
existingStartRange := ipv6ToBigint(existingIPv6StartRange)
existingEndRange := ipv6ToBigint(existingIPv6EndRange)
if (existingStartRange.Cmp(inputStartRange) <= 0 && inputStartRange.Cmp(existingEndRange) <= 0) ||
(existingStartRange.Cmp(inputEndRange) <= 0 && inputEndRange.Cmp(existingEndRange) <= 0) {
return true
}
if (inputStartRange.Cmp(existingStartRange) <= 0 && existingStartRange.Cmp(inputEndRange) <= 0) ||
(inputStartRange.Cmp(existingEndRange) <= 0 && existingEndRange.Cmp(inputEndRange) <= 0) {
return true
}
return false
} | [
"func",
"IsOverlappingSubnetv6",
"(",
"inputIPv6Subnet",
"string",
",",
"existingIPv6Subnet",
"string",
")",
"bool",
"{",
"inputIPv6StartRange",
",",
"inputIPv6EndRange",
":=",
"getIPv6Range",
"(",
"inputIPv6Subnet",
")",
"\n",
"existingIPv6StartRange",
",",
"existingIPv6... | // IsOverlappingSubnetv6 verifies the Overlapping of subnet for v6 networks | [
"IsOverlappingSubnetv6",
"verifies",
"the",
"Overlapping",
"of",
"subnet",
"for",
"v6",
"networks"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L79-L99 |
7,752 | contiv/netplugin | utils/netutils/netutils.go | IsOverlappingSubnet | func IsOverlappingSubnet(inputSubnet string, existingSubnet string) bool {
inputSubnetIP, inputSubnetLen, _ := ParseCIDR(inputSubnet)
existingSubnetIP, existingSubnetLen, _ := ParseCIDR(existingSubnet)
inputStartRange, _ := ipv4ToUint32(getFirstAddrInRange(inputSubnetIP))
inputEndRange, _ := ipv4ToUint32(getLastAddrInRange(inputSubnetIP, inputSubnetLen))
existingStartRange, _ := ipv4ToUint32(getFirstAddrInRange(existingSubnetIP))
existingEndRange, _ := ipv4ToUint32(getLastAddrInRange(existingSubnetIP, existingSubnetLen))
if (existingStartRange <= inputStartRange && inputStartRange <= existingEndRange) ||
(existingStartRange <= inputEndRange && inputEndRange <= existingEndRange) {
return true
}
if (inputStartRange <= existingStartRange && existingStartRange <= inputEndRange) ||
(inputStartRange <= existingEndRange && existingEndRange <= inputEndRange) {
return true
}
return false
} | go | func IsOverlappingSubnet(inputSubnet string, existingSubnet string) bool {
inputSubnetIP, inputSubnetLen, _ := ParseCIDR(inputSubnet)
existingSubnetIP, existingSubnetLen, _ := ParseCIDR(existingSubnet)
inputStartRange, _ := ipv4ToUint32(getFirstAddrInRange(inputSubnetIP))
inputEndRange, _ := ipv4ToUint32(getLastAddrInRange(inputSubnetIP, inputSubnetLen))
existingStartRange, _ := ipv4ToUint32(getFirstAddrInRange(existingSubnetIP))
existingEndRange, _ := ipv4ToUint32(getLastAddrInRange(existingSubnetIP, existingSubnetLen))
if (existingStartRange <= inputStartRange && inputStartRange <= existingEndRange) ||
(existingStartRange <= inputEndRange && inputEndRange <= existingEndRange) {
return true
}
if (inputStartRange <= existingStartRange && existingStartRange <= inputEndRange) ||
(inputStartRange <= existingEndRange && existingEndRange <= inputEndRange) {
return true
}
return false
} | [
"func",
"IsOverlappingSubnet",
"(",
"inputSubnet",
"string",
",",
"existingSubnet",
"string",
")",
"bool",
"{",
"inputSubnetIP",
",",
"inputSubnetLen",
",",
"_",
":=",
"ParseCIDR",
"(",
"inputSubnet",
")",
"\n",
"existingSubnetIP",
",",
"existingSubnetLen",
",",
"... | // IsOverlappingSubnet verifies the Overlapping of subnet | [
"IsOverlappingSubnet",
"verifies",
"the",
"Overlapping",
"of",
"subnet"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L102-L122 |
7,753 | contiv/netplugin | utils/netutils/netutils.go | ValidateNetworkRangeParams | func ValidateNetworkRangeParams(ipRange string, subnetLen uint) error {
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipRange))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipRange, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipRange, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipRange, subnetLen))
if rangeMin < firstAddr || rangeMax > lastAddr || rangeMin > rangeMax {
return core.Errorf("Network subnet format not valid")
}
if subnetLen > 32 || subnetLen < 8 {
return core.Errorf("subnet length %d not supported", subnetLen)
}
return nil
} | go | func ValidateNetworkRangeParams(ipRange string, subnetLen uint) error {
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipRange))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipRange, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipRange, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipRange, subnetLen))
if rangeMin < firstAddr || rangeMax > lastAddr || rangeMin > rangeMax {
return core.Errorf("Network subnet format not valid")
}
if subnetLen > 32 || subnetLen < 8 {
return core.Errorf("subnet length %d not supported", subnetLen)
}
return nil
} | [
"func",
"ValidateNetworkRangeParams",
"(",
"ipRange",
"string",
",",
"subnetLen",
"uint",
")",
"error",
"{",
"rangeMin",
",",
"_",
":=",
"ipv4ToUint32",
"(",
"getFirstAddrInRange",
"(",
"ipRange",
")",
")",
"\n",
"rangeMax",
",",
"_",
":=",
"ipv4ToUint32",
"("... | // ValidateNetworkRangeParams verifies the network range format | [
"ValidateNetworkRangeParams",
"verifies",
"the",
"network",
"range",
"format"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L155-L169 |
7,754 | contiv/netplugin | utils/netutils/netutils.go | ClearReservedEntries | func ClearReservedEntries(b *bitset.BitSet, subnetLen uint) {
maxSize := (1 << (32 - subnetLen)) - 1
b.Clear(uint(maxSize))
b.Clear(uint(0))
} | go | func ClearReservedEntries(b *bitset.BitSet, subnetLen uint) {
maxSize := (1 << (32 - subnetLen)) - 1
b.Clear(uint(maxSize))
b.Clear(uint(0))
} | [
"func",
"ClearReservedEntries",
"(",
"b",
"*",
"bitset",
".",
"BitSet",
",",
"subnetLen",
"uint",
")",
"{",
"maxSize",
":=",
"(",
"1",
"<<",
"(",
"32",
"-",
"subnetLen",
")",
")",
"-",
"1",
"\n",
"b",
".",
"Clear",
"(",
"uint",
"(",
"maxSize",
")",... | // ClearReservedEntries clears reserved bits | [
"ClearReservedEntries",
"clears",
"reserved",
"bits"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L182-L186 |
7,755 | contiv/netplugin | utils/netutils/netutils.go | ClearIPAddrRange | func ClearIPAddrRange(ipAllocMap *bitset.BitSet, ipPool string, nwSubnetIP string, nwSubnetLen uint) error {
addrRangeList := strings.Split(ipPool, "-")
hostMin, err := GetIPNumber(nwSubnetIP, nwSubnetLen, 32, addrRangeList[0])
if err != nil {
log.Errorf("Error parsing first address %s. Err: %v", addrRangeList[0], err)
return err
}
hostMax, err := GetIPNumber(nwSubnetIP, nwSubnetLen, 32, addrRangeList[1])
if err != nil {
log.Errorf("Error parsing last address %s. Err: %v", addrRangeList[1], err)
return err
}
// Clear a range
for i := hostMin; i <= hostMax; i++ {
ipAllocMap.Clear(uint(i))
}
return nil
} | go | func ClearIPAddrRange(ipAllocMap *bitset.BitSet, ipPool string, nwSubnetIP string, nwSubnetLen uint) error {
addrRangeList := strings.Split(ipPool, "-")
hostMin, err := GetIPNumber(nwSubnetIP, nwSubnetLen, 32, addrRangeList[0])
if err != nil {
log.Errorf("Error parsing first address %s. Err: %v", addrRangeList[0], err)
return err
}
hostMax, err := GetIPNumber(nwSubnetIP, nwSubnetLen, 32, addrRangeList[1])
if err != nil {
log.Errorf("Error parsing last address %s. Err: %v", addrRangeList[1], err)
return err
}
// Clear a range
for i := hostMin; i <= hostMax; i++ {
ipAllocMap.Clear(uint(i))
}
return nil
} | [
"func",
"ClearIPAddrRange",
"(",
"ipAllocMap",
"*",
"bitset",
".",
"BitSet",
",",
"ipPool",
"string",
",",
"nwSubnetIP",
"string",
",",
"nwSubnetLen",
"uint",
")",
"error",
"{",
"addrRangeList",
":=",
"strings",
".",
"Split",
"(",
"ipPool",
",",
"\"",
"\"",
... | // ClearIPAddrRange marks range of IP address as used | [
"ClearIPAddrRange",
"marks",
"range",
"of",
"IP",
"address",
"as",
"used"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L208-L230 |
7,756 | contiv/netplugin | utils/netutils/netutils.go | GetIPAddrRange | func GetIPAddrRange(ipCIDR string, subnetLen uint) string {
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipCIDR))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipCIDR, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipCIDR, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipCIDR, subnetLen))
if rangeMin < firstAddr {
rangeMin = firstAddr
}
if rangeMax > lastAddr {
rangeMax = lastAddr
}
minAddr, _ := ipv4Uint32ToString(rangeMin)
maxAddr, _ := ipv4Uint32ToString(rangeMax)
return minAddr + "-" + maxAddr
} | go | func GetIPAddrRange(ipCIDR string, subnetLen uint) string {
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipCIDR))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipCIDR, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipCIDR, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipCIDR, subnetLen))
if rangeMin < firstAddr {
rangeMin = firstAddr
}
if rangeMax > lastAddr {
rangeMax = lastAddr
}
minAddr, _ := ipv4Uint32ToString(rangeMin)
maxAddr, _ := ipv4Uint32ToString(rangeMax)
return minAddr + "-" + maxAddr
} | [
"func",
"GetIPAddrRange",
"(",
"ipCIDR",
"string",
",",
"subnetLen",
"uint",
")",
"string",
"{",
"rangeMin",
",",
"_",
":=",
"ipv4ToUint32",
"(",
"getFirstAddrInRange",
"(",
"ipCIDR",
")",
")",
"\n",
"rangeMax",
",",
"_",
":=",
"ipv4ToUint32",
"(",
"getLastA... | // GetIPAddrRange returns IP CIDR as a ip address range | [
"GetIPAddrRange",
"returns",
"IP",
"CIDR",
"as",
"a",
"ip",
"address",
"range"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L290-L307 |
7,757 | contiv/netplugin | utils/netutils/netutils.go | ClearBitsOutsideRange | func ClearBitsOutsideRange(ipAllocMap *bitset.BitSet, ipRange string, subnetLen uint) {
var i uint32
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipRange))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipRange, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipRange, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipRange, subnetLen))
// Set bits lower than rangeMin as used
for i = 0; i < (rangeMin - firstAddr); i++ {
ipAllocMap.Clear(uint(i))
}
// Set bits greater than the rangeMax as used
for i = ((rangeMin - firstAddr) + ((rangeMax - rangeMin) + 1)); i < (lastAddr - firstAddr); i++ {
ipAllocMap.Clear(uint(i))
}
} | go | func ClearBitsOutsideRange(ipAllocMap *bitset.BitSet, ipRange string, subnetLen uint) {
var i uint32
rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipRange))
rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipRange, subnetLen))
firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipRange, subnetLen))
lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipRange, subnetLen))
// Set bits lower than rangeMin as used
for i = 0; i < (rangeMin - firstAddr); i++ {
ipAllocMap.Clear(uint(i))
}
// Set bits greater than the rangeMax as used
for i = ((rangeMin - firstAddr) + ((rangeMax - rangeMin) + 1)); i < (lastAddr - firstAddr); i++ {
ipAllocMap.Clear(uint(i))
}
} | [
"func",
"ClearBitsOutsideRange",
"(",
"ipAllocMap",
"*",
"bitset",
".",
"BitSet",
",",
"ipRange",
"string",
",",
"subnetLen",
"uint",
")",
"{",
"var",
"i",
"uint32",
"\n",
"rangeMin",
",",
"_",
":=",
"ipv4ToUint32",
"(",
"getFirstAddrInRange",
"(",
"ipRange",
... | // ClearBitsOutsideRange sets all IPs outside range as used | [
"ClearBitsOutsideRange",
"sets",
"all",
"IPs",
"outside",
"range",
"as",
"used"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L310-L326 |
7,758 | contiv/netplugin | utils/netutils/netutils.go | CreateBitset | func CreateBitset(numBitsWide uint) *bitset.BitSet {
maxSize := 1 << numBitsWide
return bitset.New(uint(maxSize))
} | go | func CreateBitset(numBitsWide uint) *bitset.BitSet {
maxSize := 1 << numBitsWide
return bitset.New(uint(maxSize))
} | [
"func",
"CreateBitset",
"(",
"numBitsWide",
"uint",
")",
"*",
"bitset",
".",
"BitSet",
"{",
"maxSize",
":=",
"1",
"<<",
"numBitsWide",
"\n",
"return",
"bitset",
".",
"New",
"(",
"uint",
"(",
"maxSize",
")",
")",
"\n",
"}"
] | // CreateBitset initializes a bit set with 2^numBitsWide bits | [
"CreateBitset",
"initializes",
"a",
"bit",
"set",
"with",
"2^numBitsWide",
"bits"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L329-L332 |
7,759 | contiv/netplugin | utils/netutils/netutils.go | GetSubnetIP | func GetSubnetIP(subnetIP string, subnetLen uint, allocSubnetLen, hostID uint) (string, error) {
if subnetIP == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 32 || subnetLen < 8 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return "", core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return "", core.Errorf("host id %d is beyond subnet's capacity %d",
hostID, maxHosts)
}
hostIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return "", core.Errorf("unable to convert subnet %s to uint32", subnetIP)
}
hostIPUint32 += uint32(hostID << (32 - allocSubnetLen))
return ipv4Uint32ToString(hostIPUint32)
} | go | func GetSubnetIP(subnetIP string, subnetLen uint, allocSubnetLen, hostID uint) (string, error) {
if subnetIP == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 32 || subnetLen < 8 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return "", core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return "", core.Errorf("host id %d is beyond subnet's capacity %d",
hostID, maxHosts)
}
hostIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return "", core.Errorf("unable to convert subnet %s to uint32", subnetIP)
}
hostIPUint32 += uint32(hostID << (32 - allocSubnetLen))
return ipv4Uint32ToString(hostIPUint32)
} | [
"func",
"GetSubnetIP",
"(",
"subnetIP",
"string",
",",
"subnetLen",
"uint",
",",
"allocSubnetLen",
",",
"hostID",
"uint",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"subnetIP",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"core",
".",
"Erro... | // GetSubnetIP given a subnet IP and host identifier, calculates an IP within
// the subnet for use. | [
"GetSubnetIP",
"given",
"a",
"subnet",
"IP",
"and",
"host",
"identifier",
"calculates",
"an",
"IP",
"within",
"the",
"subnet",
"for",
"use",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L368-L393 |
7,760 | contiv/netplugin | utils/netutils/netutils.go | GetIPNumber | func GetIPNumber(subnetIP string, subnetLen uint, allocSubnetLen uint, hostIP string) (uint, error) {
if subnetLen > 32 || subnetLen < 8 {
return 0, core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return 0, core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
hostIPUint32, err := ipv4ToUint32(hostIP)
if err != nil {
return 0, core.Errorf("unable to convert hostIP %s to uint32", hostIP)
}
subnetIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return 0, core.Errorf("unable to convert subnetIP %s to uint32", subnetIP)
}
hostID := uint((hostIPUint32 - subnetIPUint32) >> (32 - allocSubnetLen))
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return 0, core.Errorf("hostIP %s is exceeding beyond subnet %s/%d, hostID %d",
hostIP, subnetIP, subnetLen, hostID)
}
return uint(hostID), nil
} | go | func GetIPNumber(subnetIP string, subnetLen uint, allocSubnetLen uint, hostIP string) (uint, error) {
if subnetLen > 32 || subnetLen < 8 {
return 0, core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return 0, core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
hostIPUint32, err := ipv4ToUint32(hostIP)
if err != nil {
return 0, core.Errorf("unable to convert hostIP %s to uint32", hostIP)
}
subnetIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return 0, core.Errorf("unable to convert subnetIP %s to uint32", subnetIP)
}
hostID := uint((hostIPUint32 - subnetIPUint32) >> (32 - allocSubnetLen))
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return 0, core.Errorf("hostIP %s is exceeding beyond subnet %s/%d, hostID %d",
hostIP, subnetIP, subnetLen, hostID)
}
return uint(hostID), nil
} | [
"func",
"GetIPNumber",
"(",
"subnetIP",
"string",
",",
"subnetLen",
"uint",
",",
"allocSubnetLen",
"uint",
",",
"hostIP",
"string",
")",
"(",
"uint",
",",
"error",
")",
"{",
"if",
"subnetLen",
">",
"32",
"||",
"subnetLen",
"<",
"8",
"{",
"return",
"0",
... | // GetIPNumber obtains the host id from the host IP. SEe `GetSubnetIP` for more information. | [
"GetIPNumber",
"obtains",
"the",
"host",
"id",
"from",
"the",
"host",
"IP",
".",
"SEe",
"GetSubnetIP",
"for",
"more",
"information",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L396-L423 |
7,761 | contiv/netplugin | utils/netutils/netutils.go | ReserveIPv6HostID | func ReserveIPv6HostID(hostID string, IPv6AllocMap *map[string]bool) {
if hostID == "" {
return
}
if *IPv6AllocMap == nil {
*IPv6AllocMap = make(map[string]bool)
}
(*IPv6AllocMap)[hostID] = true
} | go | func ReserveIPv6HostID(hostID string, IPv6AllocMap *map[string]bool) {
if hostID == "" {
return
}
if *IPv6AllocMap == nil {
*IPv6AllocMap = make(map[string]bool)
}
(*IPv6AllocMap)[hostID] = true
} | [
"func",
"ReserveIPv6HostID",
"(",
"hostID",
"string",
",",
"IPv6AllocMap",
"*",
"map",
"[",
"string",
"]",
"bool",
")",
"{",
"if",
"hostID",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"if",
"*",
"IPv6AllocMap",
"==",
"nil",
"{",
"*",
"IPv6AllocM... | // ReserveIPv6HostID sets the hostId in the AllocMap | [
"ReserveIPv6HostID",
"sets",
"the",
"hostId",
"in",
"the",
"AllocMap"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L426-L434 |
7,762 | contiv/netplugin | utils/netutils/netutils.go | GetNextIPv6HostID | func GetNextIPv6HostID(hostID, subnetAddr string, subnetLen uint, IPv6AllocMap map[string]bool) (string, error) {
if hostID == "" {
hostID = "::"
}
if subnetLen == 0 {
return "", core.Errorf("subnet length %d is invalid", subnetLen)
}
hostidIP := net.ParseIP(hostID)
// start with the carryOver 1 to get the next hostID
var carryOver = 1
var allocd = true
for allocd == true {
// Add 1 to hostID
for i := len(hostidIP) - 1; i >= 0; i-- {
var temp int
temp = int(hostidIP[i]) + carryOver
if temp > int(0xFF) {
hostidIP[i] = 0
carryOver = 1
} else {
hostidIP[i] = uint8(temp)
carryOver = 0
break
}
}
// Check if this hostID is already allocated
if _, allocd = IPv6AllocMap[hostidIP.String()]; allocd == true {
// Already allocated find the next hostID
carryOver = 1
} else {
// allocd == false. check if we reached MaxHosts
offset := (subnetLen - 1) / 8
masklen := subnetLen % 8
mask := ((1 << masklen) - 1) << (8 - masklen)
if (hostidIP[offset] & byte(mask)) != 0 {
// if hostID is outside subnet range,
// check if we have reached MaxHosts
maxHosts := math.Pow(2, float64(128-subnetLen)) - 1
if float64(len(IPv6AllocMap)) < maxHosts {
hostID = "::"
hostidIP = net.ParseIP(hostID)
carryOver = 1
allocd = true // continue the loop
} else {
return "", core.Errorf("Reached MaxHosts (%v). Cannot allocate more hosts", maxHosts)
}
}
}
}
return hostidIP.String(), nil
} | go | func GetNextIPv6HostID(hostID, subnetAddr string, subnetLen uint, IPv6AllocMap map[string]bool) (string, error) {
if hostID == "" {
hostID = "::"
}
if subnetLen == 0 {
return "", core.Errorf("subnet length %d is invalid", subnetLen)
}
hostidIP := net.ParseIP(hostID)
// start with the carryOver 1 to get the next hostID
var carryOver = 1
var allocd = true
for allocd == true {
// Add 1 to hostID
for i := len(hostidIP) - 1; i >= 0; i-- {
var temp int
temp = int(hostidIP[i]) + carryOver
if temp > int(0xFF) {
hostidIP[i] = 0
carryOver = 1
} else {
hostidIP[i] = uint8(temp)
carryOver = 0
break
}
}
// Check if this hostID is already allocated
if _, allocd = IPv6AllocMap[hostidIP.String()]; allocd == true {
// Already allocated find the next hostID
carryOver = 1
} else {
// allocd == false. check if we reached MaxHosts
offset := (subnetLen - 1) / 8
masklen := subnetLen % 8
mask := ((1 << masklen) - 1) << (8 - masklen)
if (hostidIP[offset] & byte(mask)) != 0 {
// if hostID is outside subnet range,
// check if we have reached MaxHosts
maxHosts := math.Pow(2, float64(128-subnetLen)) - 1
if float64(len(IPv6AllocMap)) < maxHosts {
hostID = "::"
hostidIP = net.ParseIP(hostID)
carryOver = 1
allocd = true // continue the loop
} else {
return "", core.Errorf("Reached MaxHosts (%v). Cannot allocate more hosts", maxHosts)
}
}
}
}
return hostidIP.String(), nil
} | [
"func",
"GetNextIPv6HostID",
"(",
"hostID",
",",
"subnetAddr",
"string",
",",
"subnetLen",
"uint",
",",
"IPv6AllocMap",
"map",
"[",
"string",
"]",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"hostID",
"==",
"\"",
"\"",
"{",
"hostID",
"=",
... | // GetNextIPv6HostID returns the next available hostId in the AllocMap | [
"GetNextIPv6HostID",
"returns",
"the",
"next",
"available",
"hostId",
"in",
"the",
"AllocMap"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L437-L490 |
7,763 | contiv/netplugin | utils/netutils/netutils.go | GetSubnetIPv6 | func GetSubnetIPv6(subnetAddr string, subnetLen uint, hostID string) (string, error) {
if subnetAddr == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
subnetIP := net.ParseIP(subnetAddr)
hostidIP := net.ParseIP(hostID)
hostIP := net.IPv6zero
var offset int
for offset = 0; offset < int(subnetLen/8); offset++ {
hostIP[offset] = subnetIP[offset]
}
// copy the overlapping byte in subnetIP and hostID
if subnetLen%8 != 0 && subnetIP[offset] != 0 {
if hostidIP[offset]&subnetIP[offset] != 0 {
return "", core.Errorf("host id %s exceeds subnet %s capacity ",
hostID, subnetAddr)
}
hostIP[offset] = hostidIP[offset] | subnetIP[offset]
offset++
}
for ; offset < len(hostidIP); offset++ {
hostIP[offset] = hostidIP[offset]
}
return hostIP.String(), nil
} | go | func GetSubnetIPv6(subnetAddr string, subnetLen uint, hostID string) (string, error) {
if subnetAddr == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
subnetIP := net.ParseIP(subnetAddr)
hostidIP := net.ParseIP(hostID)
hostIP := net.IPv6zero
var offset int
for offset = 0; offset < int(subnetLen/8); offset++ {
hostIP[offset] = subnetIP[offset]
}
// copy the overlapping byte in subnetIP and hostID
if subnetLen%8 != 0 && subnetIP[offset] != 0 {
if hostidIP[offset]&subnetIP[offset] != 0 {
return "", core.Errorf("host id %s exceeds subnet %s capacity ",
hostID, subnetAddr)
}
hostIP[offset] = hostidIP[offset] | subnetIP[offset]
offset++
}
for ; offset < len(hostidIP); offset++ {
hostIP[offset] = hostidIP[offset]
}
return hostIP.String(), nil
} | [
"func",
"GetSubnetIPv6",
"(",
"subnetAddr",
"string",
",",
"subnetLen",
"uint",
",",
"hostID",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"subnetAddr",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"core",
".",
"Errorf",
"(",
"\"",... | // GetSubnetIPv6 given a subnet IP and host identifier, calculates an IPv6 address
// within the subnet for use. | [
"GetSubnetIPv6",
"given",
"a",
"subnet",
"IP",
"and",
"host",
"identifier",
"calculates",
"an",
"IPv6",
"address",
"within",
"the",
"subnet",
"for",
"use",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L494-L525 |
7,764 | contiv/netplugin | utils/netutils/netutils.go | GetIPv6HostID | func GetIPv6HostID(subnetAddr string, subnetLen uint, hostAddr string) (string, error) {
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
// Initialize hostID
hostID := net.IPv6zero
var offset uint
// get the overlapping byte
offset = subnetLen / 8
subnetIP := net.ParseIP(subnetAddr)
if subnetIP == nil {
return "", core.Errorf("Invalid subnetAddr %s ", subnetAddr)
}
s := uint8(subnetIP[offset])
hostIP := net.ParseIP(hostAddr)
if hostIP == nil {
return "", core.Errorf("Invalid hostAddr %s ", hostAddr)
}
h := uint8(hostIP[offset])
hostID[offset] = byte(h - s)
// Copy the rest of the bytes
for i := (offset + 1); i < 16; i++ {
hostID[i] = hostIP[i]
offset++
}
return hostID.String(), nil
} | go | func GetIPv6HostID(subnetAddr string, subnetLen uint, hostAddr string) (string, error) {
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
// Initialize hostID
hostID := net.IPv6zero
var offset uint
// get the overlapping byte
offset = subnetLen / 8
subnetIP := net.ParseIP(subnetAddr)
if subnetIP == nil {
return "", core.Errorf("Invalid subnetAddr %s ", subnetAddr)
}
s := uint8(subnetIP[offset])
hostIP := net.ParseIP(hostAddr)
if hostIP == nil {
return "", core.Errorf("Invalid hostAddr %s ", hostAddr)
}
h := uint8(hostIP[offset])
hostID[offset] = byte(h - s)
// Copy the rest of the bytes
for i := (offset + 1); i < 16; i++ {
hostID[i] = hostIP[i]
offset++
}
return hostID.String(), nil
} | [
"func",
"GetIPv6HostID",
"(",
"subnetAddr",
"string",
",",
"subnetLen",
"uint",
",",
"hostAddr",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"subnetLen",
">",
"128",
"||",
"subnetLen",
"<",
"16",
"{",
"return",
"\"",
"\"",
",",
"core",
... | // GetIPv6HostID obtains the host id from the host IP. SEe `GetSubnetIP` for more information. | [
"GetIPv6HostID",
"obtains",
"the",
"host",
"id",
"from",
"the",
"host",
"IP",
".",
"SEe",
"GetSubnetIP",
"for",
"more",
"information",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L528-L557 |
7,765 | contiv/netplugin | utils/netutils/netutils.go | ParseTagRanges | func ParseTagRanges(ranges string, tagType string) ([]TagRange, error) {
var err error
if ranges == "" {
return []TagRange{{0, 0}}, nil
}
if tagType != "vlan" && tagType != "vxlan" {
return nil, core.Errorf("invalid tag type %s", tagType)
}
rangesStr := strings.Split(ranges, ",")
if len(rangesStr) > 1 && tagType == "vxlan" {
return nil, core.Errorf("do not support more than 2 vxlan tag ranges")
}
tagRanges := make([]TagRange, len(rangesStr), len(rangesStr))
for idx, oneRangeStr := range rangesStr {
oneRangeStr = strings.Trim(oneRangeStr, " ")
tagNums := strings.Split(oneRangeStr, "-")
if len(tagNums) > 2 {
return nil, core.Errorf("invalid tags %s, correct '10-50,70-100'",
oneRangeStr)
}
tagRanges[idx].Min, err = strconv.Atoi(tagNums[0])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Min, err)
}
tagRanges[idx].Max, err = strconv.Atoi(tagNums[1])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Max, err)
}
if tagRanges[idx].Min > tagRanges[idx].Max {
return nil, core.Errorf("invalid range %s, min is greater than max",
oneRangeStr)
}
if tagRanges[idx].Min < 1 {
return nil, core.Errorf("invalid range %s, values less than 1",
oneRangeStr)
}
if tagType == "vlan" && tagRanges[idx].Max > 4095 {
return nil, core.Errorf("invalid range %s, vlan values exceed 4095 max allowed",
oneRangeStr)
}
if tagType == "vxlan" && tagRanges[idx].Max > 65535 {
return nil, core.Errorf("invalid range %s, vlan values exceed 65535 max allowed",
oneRangeStr)
}
if tagType == "vxlan" &&
(tagRanges[idx].Max-tagRanges[idx].Min > 16000) {
return nil, core.Errorf("does not allow vxlan range to exceed 16000 range %s",
oneRangeStr)
}
}
return tagRanges, nil
} | go | func ParseTagRanges(ranges string, tagType string) ([]TagRange, error) {
var err error
if ranges == "" {
return []TagRange{{0, 0}}, nil
}
if tagType != "vlan" && tagType != "vxlan" {
return nil, core.Errorf("invalid tag type %s", tagType)
}
rangesStr := strings.Split(ranges, ",")
if len(rangesStr) > 1 && tagType == "vxlan" {
return nil, core.Errorf("do not support more than 2 vxlan tag ranges")
}
tagRanges := make([]TagRange, len(rangesStr), len(rangesStr))
for idx, oneRangeStr := range rangesStr {
oneRangeStr = strings.Trim(oneRangeStr, " ")
tagNums := strings.Split(oneRangeStr, "-")
if len(tagNums) > 2 {
return nil, core.Errorf("invalid tags %s, correct '10-50,70-100'",
oneRangeStr)
}
tagRanges[idx].Min, err = strconv.Atoi(tagNums[0])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Min, err)
}
tagRanges[idx].Max, err = strconv.Atoi(tagNums[1])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Max, err)
}
if tagRanges[idx].Min > tagRanges[idx].Max {
return nil, core.Errorf("invalid range %s, min is greater than max",
oneRangeStr)
}
if tagRanges[idx].Min < 1 {
return nil, core.Errorf("invalid range %s, values less than 1",
oneRangeStr)
}
if tagType == "vlan" && tagRanges[idx].Max > 4095 {
return nil, core.Errorf("invalid range %s, vlan values exceed 4095 max allowed",
oneRangeStr)
}
if tagType == "vxlan" && tagRanges[idx].Max > 65535 {
return nil, core.Errorf("invalid range %s, vlan values exceed 65535 max allowed",
oneRangeStr)
}
if tagType == "vxlan" &&
(tagRanges[idx].Max-tagRanges[idx].Min > 16000) {
return nil, core.Errorf("does not allow vxlan range to exceed 16000 range %s",
oneRangeStr)
}
}
return tagRanges, nil
} | [
"func",
"ParseTagRanges",
"(",
"ranges",
"string",
",",
"tagType",
"string",
")",
"(",
"[",
"]",
"TagRange",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"ranges",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"TagRange",
"{",
"{",
"0",
... | // ParseTagRanges takes a string such as 12-24,48-64 and turns it into a series
// of TagRange. | [
"ParseTagRanges",
"takes",
"a",
"string",
"such",
"as",
"12",
"-",
"24",
"48",
"-",
"64",
"and",
"turns",
"it",
"into",
"a",
"series",
"of",
"TagRange",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L568-L627 |
7,766 | contiv/netplugin | utils/netutils/netutils.go | ParseCIDR | func ParseCIDR(cidrStr string) (string, uint, error) {
strs := strings.Split(cidrStr, "/")
if len(strs) != 2 {
return "", 0, core.Errorf("invalid cidr format")
}
subnetStr := strs[0]
subnetLen, err := strconv.Atoi(strs[1])
if (IsIPv6(subnetStr) && subnetLen > 128) || err != nil || (!IsIPv6(subnetStr) && subnetLen > 32) {
return "", 0, core.Errorf("invalid mask in gateway/mask specification ")
}
return subnetStr, uint(subnetLen), nil
} | go | func ParseCIDR(cidrStr string) (string, uint, error) {
strs := strings.Split(cidrStr, "/")
if len(strs) != 2 {
return "", 0, core.Errorf("invalid cidr format")
}
subnetStr := strs[0]
subnetLen, err := strconv.Atoi(strs[1])
if (IsIPv6(subnetStr) && subnetLen > 128) || err != nil || (!IsIPv6(subnetStr) && subnetLen > 32) {
return "", 0, core.Errorf("invalid mask in gateway/mask specification ")
}
return subnetStr, uint(subnetLen), nil
} | [
"func",
"ParseCIDR",
"(",
"cidrStr",
"string",
")",
"(",
"string",
",",
"uint",
",",
"error",
")",
"{",
"strs",
":=",
"strings",
".",
"Split",
"(",
"cidrStr",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"strs",
")",
"!=",
"2",
"{",
"return",
"\... | // ParseCIDR parses a CIDR string into a gateway IP and length. | [
"ParseCIDR",
"parses",
"a",
"CIDR",
"string",
"into",
"a",
"gateway",
"IP",
"and",
"length",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L630-L643 |
7,767 | contiv/netplugin | utils/netutils/netutils.go | GetInterfaceIP | func GetInterfaceIP(linkName string) (string, error) {
var addrs []netlink.Addr
localIPAddr := ""
link, err := netlink.LinkByName(linkName)
if err != nil {
return "", err
}
addrs, err = netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return "", err
}
if len(addrs) > 0 {
localIPAddr = addrs[0].IP.String()
}
err = core.Errorf("local ip not found")
if localIPAddr != "" {
err = nil
}
return localIPAddr, err
} | go | func GetInterfaceIP(linkName string) (string, error) {
var addrs []netlink.Addr
localIPAddr := ""
link, err := netlink.LinkByName(linkName)
if err != nil {
return "", err
}
addrs, err = netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return "", err
}
if len(addrs) > 0 {
localIPAddr = addrs[0].IP.String()
}
err = core.Errorf("local ip not found")
if localIPAddr != "" {
err = nil
}
return localIPAddr, err
} | [
"func",
"GetInterfaceIP",
"(",
"linkName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"addrs",
"[",
"]",
"netlink",
".",
"Addr",
"\n",
"localIPAddr",
":=",
"\"",
"\"",
"\n\n",
"link",
",",
"err",
":=",
"netlink",
".",
"LinkByName",
"(... | // GetInterfaceIP obtains the ip addr of a local interface on the host. | [
"GetInterfaceIP",
"obtains",
"the",
"ip",
"addr",
"of",
"a",
"local",
"interface",
"on",
"the",
"host",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L646-L668 |
7,768 | contiv/netplugin | utils/netutils/netutils.go | GetNetlinkAddrList | func GetNetlinkAddrList() ([]string, error) {
var addrList []string
// get the link list
linkList, err := netlink.LinkList()
if err != nil {
return addrList, err
}
log.Debugf("Got link list(%d): %+v", len(linkList), linkList)
// Loop thru each interface and add its ip addr to list
for _, link := range linkList {
if strings.HasPrefix(link.Attrs().Name, "docker") || strings.HasPrefix(link.Attrs().Name, "veth") ||
strings.HasPrefix(link.Attrs().Name, "vport") || strings.HasPrefix(link.Attrs().Name, "lo") {
continue
}
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return addrList, err
}
for _, addr := range addrs {
addrList = append(addrList, addr.IP.String())
}
}
return addrList, err
} | go | func GetNetlinkAddrList() ([]string, error) {
var addrList []string
// get the link list
linkList, err := netlink.LinkList()
if err != nil {
return addrList, err
}
log.Debugf("Got link list(%d): %+v", len(linkList), linkList)
// Loop thru each interface and add its ip addr to list
for _, link := range linkList {
if strings.HasPrefix(link.Attrs().Name, "docker") || strings.HasPrefix(link.Attrs().Name, "veth") ||
strings.HasPrefix(link.Attrs().Name, "vport") || strings.HasPrefix(link.Attrs().Name, "lo") {
continue
}
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
if err != nil {
return addrList, err
}
for _, addr := range addrs {
addrList = append(addrList, addr.IP.String())
}
}
return addrList, err
} | [
"func",
"GetNetlinkAddrList",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"addrList",
"[",
"]",
"string",
"\n",
"// get the link list",
"linkList",
",",
"err",
":=",
"netlink",
".",
"LinkList",
"(",
")",
"\n",
"if",
"err",
"!=",
"... | // GetNetlinkAddrList returns a list of local IP addresses | [
"GetNetlinkAddrList",
"returns",
"a",
"list",
"of",
"local",
"IP",
"addresses"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L698-L725 |
7,769 | contiv/netplugin | utils/netutils/netutils.go | GetLocalAddrList | func GetLocalAddrList() ([]string, error) {
var addrList []string
// get the link list
intfList, err := net.Interfaces()
if err != nil {
return addrList, err
}
log.Debugf("Got address list(%d): %+v", len(intfList), intfList)
// Loop thru each interface and add its ip addr to list
for _, intf := range intfList {
if strings.HasPrefix(intf.Name, "docker") || strings.HasPrefix(intf.Name, "veth") ||
strings.HasPrefix(intf.Name, "vport") || strings.HasPrefix(intf.Name, "lo") {
continue
}
addrs, err := intf.Addrs()
if err != nil {
return addrList, err
}
for _, addr := range addrs {
addrList = append(addrList, addr.String())
}
}
return addrList, err
} | go | func GetLocalAddrList() ([]string, error) {
var addrList []string
// get the link list
intfList, err := net.Interfaces()
if err != nil {
return addrList, err
}
log.Debugf("Got address list(%d): %+v", len(intfList), intfList)
// Loop thru each interface and add its ip addr to list
for _, intf := range intfList {
if strings.HasPrefix(intf.Name, "docker") || strings.HasPrefix(intf.Name, "veth") ||
strings.HasPrefix(intf.Name, "vport") || strings.HasPrefix(intf.Name, "lo") {
continue
}
addrs, err := intf.Addrs()
if err != nil {
return addrList, err
}
for _, addr := range addrs {
addrList = append(addrList, addr.String())
}
}
return addrList, err
} | [
"func",
"GetLocalAddrList",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"addrList",
"[",
"]",
"string",
"\n",
"// get the link list",
"intfList",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // GetLocalAddrList returns a list of local IP addresses | [
"GetLocalAddrList",
"returns",
"a",
"list",
"of",
"local",
"IP",
"addresses"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L728-L756 |
7,770 | contiv/netplugin | utils/netutils/netutils.go | GetHostLowestLinkMtu | func GetHostLowestLinkMtu() (int, error) {
lowestMTU := 9000 //Jumbo frame MTU
intfList, err := net.Interfaces()
if err != nil {
return 0, err
}
// Loop thru each interface and add its ip addr to list
for _, intf := range intfList {
if strings.HasPrefix(intf.Name, "docker") || strings.HasPrefix(intf.Name, "veth") ||
strings.HasPrefix(intf.Name, "vport") || strings.HasPrefix(intf.Name, "lo") {
continue
}
lowestMTU = int(math.Min(float64(lowestMTU), float64(intf.MTU)))
}
if lowestMTU == 0 {
return 0, errors.New("Failed to find minimum MTU")
}
return lowestMTU, nil
} | go | func GetHostLowestLinkMtu() (int, error) {
lowestMTU := 9000 //Jumbo frame MTU
intfList, err := net.Interfaces()
if err != nil {
return 0, err
}
// Loop thru each interface and add its ip addr to list
for _, intf := range intfList {
if strings.HasPrefix(intf.Name, "docker") || strings.HasPrefix(intf.Name, "veth") ||
strings.HasPrefix(intf.Name, "vport") || strings.HasPrefix(intf.Name, "lo") {
continue
}
lowestMTU = int(math.Min(float64(lowestMTU), float64(intf.MTU)))
}
if lowestMTU == 0 {
return 0, errors.New("Failed to find minimum MTU")
}
return lowestMTU, nil
} | [
"func",
"GetHostLowestLinkMtu",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"lowestMTU",
":=",
"9000",
"//Jumbo frame MTU",
"\n",
"intfList",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",... | //GetHostLowestLinkMtu return lowest mtu for host interface(excluding ovs
//interface | [
"GetHostLowestLinkMtu",
"return",
"lowest",
"mtu",
"for",
"host",
"interface",
"(",
"excluding",
"ovs",
"interface"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L760-L780 |
7,771 | contiv/netplugin | utils/netutils/netutils.go | IsAddrLocal | func IsAddrLocal(findAddr string) bool {
// get the local addr list
addrList, err := GetNetlinkAddrList()
if err != nil {
return false
}
// find the address
for _, addr := range addrList {
if addr == findAddr {
return true
}
}
return false
} | go | func IsAddrLocal(findAddr string) bool {
// get the local addr list
addrList, err := GetNetlinkAddrList()
if err != nil {
return false
}
// find the address
for _, addr := range addrList {
if addr == findAddr {
return true
}
}
return false
} | [
"func",
"IsAddrLocal",
"(",
"findAddr",
"string",
")",
"bool",
"{",
"// get the local addr list",
"addrList",
",",
"err",
":=",
"GetNetlinkAddrList",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// find the address",
"f... | // IsAddrLocal check if an address is local | [
"IsAddrLocal",
"check",
"if",
"an",
"address",
"is",
"local"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L783-L798 |
7,772 | contiv/netplugin | utils/netutils/netutils.go | GetFirstLocalAddr | func GetFirstLocalAddr() (string, error) {
// get the local addr list
addrList, err := GetNetlinkAddrList()
if err != nil {
return "", err
}
if len(addrList) > 0 {
return addrList[0], nil
}
return "", errors.New("no address was found")
} | go | func GetFirstLocalAddr() (string, error) {
// get the local addr list
addrList, err := GetNetlinkAddrList()
if err != nil {
return "", err
}
if len(addrList) > 0 {
return addrList[0], nil
}
return "", errors.New("no address was found")
} | [
"func",
"GetFirstLocalAddr",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// get the local addr list",
"addrList",
",",
"err",
":=",
"GetNetlinkAddrList",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\... | // GetFirstLocalAddr returns the first ip address | [
"GetFirstLocalAddr",
"returns",
"the",
"first",
"ip",
"address"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L801-L813 |
7,773 | contiv/netplugin | utils/netutils/netutils.go | GetDefaultAddr | func GetDefaultAddr() (string, error) {
// get the ip address by local hostname
localIP, err := GetMyAddr()
if err == nil && IsAddrLocal(localIP) {
return localIP, nil
}
// Return first available address if we could not find by hostname
return GetFirstLocalAddr()
} | go | func GetDefaultAddr() (string, error) {
// get the ip address by local hostname
localIP, err := GetMyAddr()
if err == nil && IsAddrLocal(localIP) {
return localIP, nil
}
// Return first available address if we could not find by hostname
return GetFirstLocalAddr()
} | [
"func",
"GetDefaultAddr",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// get the ip address by local hostname",
"localIP",
",",
"err",
":=",
"GetMyAddr",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"IsAddrLocal",
"(",
"localIP",
")",
"{",
"return",... | // GetDefaultAddr gets default address of local hostname | [
"GetDefaultAddr",
"gets",
"default",
"address",
"of",
"local",
"hostname"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L816-L825 |
7,774 | contiv/netplugin | utils/netutils/netutils.go | GetSubnetAddr | func GetSubnetAddr(ipStr string, length uint) string {
subnetStr := ipStr
if isSubnetIPRange(ipStr) {
subnetStr = strings.Split(ipStr, "-")[0]
}
subnet, _ := ipv4ToUint32(subnetStr)
subnetMask := -1 << (32 - length)
ipSubnet, _ := ipv4Uint32ToString(uint32(subnetMask) & subnet)
return ipSubnet
} | go | func GetSubnetAddr(ipStr string, length uint) string {
subnetStr := ipStr
if isSubnetIPRange(ipStr) {
subnetStr = strings.Split(ipStr, "-")[0]
}
subnet, _ := ipv4ToUint32(subnetStr)
subnetMask := -1 << (32 - length)
ipSubnet, _ := ipv4Uint32ToString(uint32(subnetMask) & subnet)
return ipSubnet
} | [
"func",
"GetSubnetAddr",
"(",
"ipStr",
"string",
",",
"length",
"uint",
")",
"string",
"{",
"subnetStr",
":=",
"ipStr",
"\n",
"if",
"isSubnetIPRange",
"(",
"ipStr",
")",
"{",
"subnetStr",
"=",
"strings",
".",
"Split",
"(",
"ipStr",
",",
"\"",
"\"",
")",
... | // GetSubnetAddr returns a subnet given a subnet range | [
"GetSubnetAddr",
"returns",
"a",
"subnet",
"given",
"a",
"subnet",
"range"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L828-L839 |
7,775 | contiv/netplugin | utils/netutils/netutils.go | getLastAddrInSubnet | func getLastAddrInSubnet(ipStr string, length uint) string {
subnetStr := ipStr
if isSubnetIPRange(ipStr) {
subnetStr = strings.Split(ipStr, "-")[0]
}
subnet, _ := ipv4ToUint32(subnetStr)
subnetMask := -1 << (32 - length)
lastIP, _ := ipv4Uint32ToString(uint32(^subnetMask) | subnet)
return lastIP
} | go | func getLastAddrInSubnet(ipStr string, length uint) string {
subnetStr := ipStr
if isSubnetIPRange(ipStr) {
subnetStr = strings.Split(ipStr, "-")[0]
}
subnet, _ := ipv4ToUint32(subnetStr)
subnetMask := -1 << (32 - length)
lastIP, _ := ipv4Uint32ToString(uint32(^subnetMask) | subnet)
return lastIP
} | [
"func",
"getLastAddrInSubnet",
"(",
"ipStr",
"string",
",",
"length",
"uint",
")",
"string",
"{",
"subnetStr",
":=",
"ipStr",
"\n",
"if",
"isSubnetIPRange",
"(",
"ipStr",
")",
"{",
"subnetStr",
"=",
"strings",
".",
"Split",
"(",
"ipStr",
",",
"\"",
"\"",
... | // getLastAddrInSubnet returns the last address in a subnet | [
"getLastAddrInSubnet",
"returns",
"the",
"last",
"address",
"in",
"a",
"subnet"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L842-L853 |
7,776 | contiv/netplugin | utils/netutils/netutils.go | getFirstAddrInRange | func getFirstAddrInRange(ipRange string) string {
firstIP := ipRange
if isSubnetIPRange(ipRange) {
firstIP = strings.Split(ipRange, "-")[0]
}
return firstIP
} | go | func getFirstAddrInRange(ipRange string) string {
firstIP := ipRange
if isSubnetIPRange(ipRange) {
firstIP = strings.Split(ipRange, "-")[0]
}
return firstIP
} | [
"func",
"getFirstAddrInRange",
"(",
"ipRange",
"string",
")",
"string",
"{",
"firstIP",
":=",
"ipRange",
"\n",
"if",
"isSubnetIPRange",
"(",
"ipRange",
")",
"{",
"firstIP",
"=",
"strings",
".",
"Split",
"(",
"ipRange",
",",
"\"",
"\"",
")",
"[",
"0",
"]"... | // getFirstAddrInRange returns the first IP in the subnet range | [
"getFirstAddrInRange",
"returns",
"the",
"first",
"IP",
"in",
"the",
"subnet",
"range"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L856-L863 |
7,777 | contiv/netplugin | utils/netutils/netutils.go | getLastAddrInRange | func getLastAddrInRange(ipRange string, subnetLen uint) string {
var lastIP string
if isSubnetIPRange(ipRange) {
lastIP = strings.Split(ipRange, "-")[1]
} else {
lastIP = getLastAddrInSubnet(ipRange, subnetLen)
}
return lastIP
} | go | func getLastAddrInRange(ipRange string, subnetLen uint) string {
var lastIP string
if isSubnetIPRange(ipRange) {
lastIP = strings.Split(ipRange, "-")[1]
} else {
lastIP = getLastAddrInSubnet(ipRange, subnetLen)
}
return lastIP
} | [
"func",
"getLastAddrInRange",
"(",
"ipRange",
"string",
",",
"subnetLen",
"uint",
")",
"string",
"{",
"var",
"lastIP",
"string",
"\n\n",
"if",
"isSubnetIPRange",
"(",
"ipRange",
")",
"{",
"lastIP",
"=",
"strings",
".",
"Split",
"(",
"ipRange",
",",
"\"",
"... | // getLastAddrInRange returns the first IP in the subnet range | [
"getLastAddrInRange",
"returns",
"the",
"first",
"IP",
"in",
"the",
"subnet",
"range"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L866-L876 |
7,778 | contiv/netplugin | utils/netutils/netutils.go | GetMyAddr | func GetMyAddr() (string, error) {
host, err := os.Hostname()
if err != nil {
return "", err
}
if host == "localhost" {
return "", errors.New("could not get hostname")
}
addrs, err := net.LookupIP(host)
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil && !ipv4.IsLoopback() {
return ipv4.String(), nil
}
}
return "", errors.New("could not find ip addr")
} | go | func GetMyAddr() (string, error) {
host, err := os.Hostname()
if err != nil {
return "", err
}
if host == "localhost" {
return "", errors.New("could not get hostname")
}
addrs, err := net.LookupIP(host)
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil && !ipv4.IsLoopback() {
return ipv4.String(), nil
}
}
return "", errors.New("could not find ip addr")
} | [
"func",
"GetMyAddr",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"host",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"host",
"==",
"\"",... | // GetMyAddr returns ip address of current host | [
"GetMyAddr",
"returns",
"ip",
"address",
"of",
"current",
"host"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L884-L906 |
7,779 | contiv/netplugin | utils/netutils/netutils.go | PortToHostIPMAC | func PortToHostIPMAC(port, subnet int) (string, string) {
b0 := subnet >> 24
b1 := (subnet >> 16) & 0xff
b2 := (port >> 8) & 0xff
b3 := port & 0xff
ipStr := fmt.Sprintf("%d.%d.%d.%d/16", b0, b1, b2, b3)
macStr := fmt.Sprintf("02:02:%02x:%02x:%02x:%02x", b0, b1, b2, b3)
return ipStr, macStr
} | go | func PortToHostIPMAC(port, subnet int) (string, string) {
b0 := subnet >> 24
b1 := (subnet >> 16) & 0xff
b2 := (port >> 8) & 0xff
b3 := port & 0xff
ipStr := fmt.Sprintf("%d.%d.%d.%d/16", b0, b1, b2, b3)
macStr := fmt.Sprintf("02:02:%02x:%02x:%02x:%02x", b0, b1, b2, b3)
return ipStr, macStr
} | [
"func",
"PortToHostIPMAC",
"(",
"port",
",",
"subnet",
"int",
")",
"(",
"string",
",",
"string",
")",
"{",
"b0",
":=",
"subnet",
">>",
"24",
"\n",
"b1",
":=",
"(",
"subnet",
">>",
"16",
")",
"&",
"0xff",
"\n",
"b2",
":=",
"(",
"port",
">>",
"8",
... | // PortToHostIPMAC gets IP and MAC based on port number | [
"PortToHostIPMAC",
"gets",
"IP",
"and",
"MAC",
"based",
"on",
"port",
"number"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L909-L918 |
7,780 | contiv/netplugin | utils/netutils/netutils.go | SetIPMasquerade | func SetIPMasquerade(intf, netmask string) error {
ipTablesPath, err := osexec.LookPath("iptables")
if err != nil {
return err
}
_, err = osexec.Command(ipTablesPath, "-t", "nat", "-C", "POSTROUTING", "-s", netmask,
"!", "-o", intf, "-j", "MASQUERADE").CombinedOutput()
// If the rule already exists, just return
if err == nil {
return nil
}
out, err := osexec.Command(ipTablesPath, "-t", "nat", "-A", "POSTROUTING", "-s", netmask,
"!", "-o", intf, "-j", "MASQUERADE").CombinedOutput()
if err != nil {
log.Errorf("Setting ip tables failed: %v %s", err, out)
} else {
log.Infof("####Set ip tables success: %s", out)
}
return err
} | go | func SetIPMasquerade(intf, netmask string) error {
ipTablesPath, err := osexec.LookPath("iptables")
if err != nil {
return err
}
_, err = osexec.Command(ipTablesPath, "-t", "nat", "-C", "POSTROUTING", "-s", netmask,
"!", "-o", intf, "-j", "MASQUERADE").CombinedOutput()
// If the rule already exists, just return
if err == nil {
return nil
}
out, err := osexec.Command(ipTablesPath, "-t", "nat", "-A", "POSTROUTING", "-s", netmask,
"!", "-o", intf, "-j", "MASQUERADE").CombinedOutput()
if err != nil {
log.Errorf("Setting ip tables failed: %v %s", err, out)
} else {
log.Infof("####Set ip tables success: %s", out)
}
return err
} | [
"func",
"SetIPMasquerade",
"(",
"intf",
",",
"netmask",
"string",
")",
"error",
"{",
"ipTablesPath",
",",
"err",
":=",
"osexec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
... | // SetIPMasquerade sets a ip masquerade rule. | [
"SetIPMasquerade",
"sets",
"a",
"ip",
"masquerade",
"rule",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L926-L948 |
7,781 | contiv/netplugin | utils/netutils/netutils.go | HostIPToGateway | func HostIPToGateway(hostIP string) (string, error) {
ip := strings.Split(hostIP, ".")
if len(ip) != 4 {
return "", errors.New("bad host IP")
}
return ip[0] + "." + ip[1] + ".255.254", nil
} | go | func HostIPToGateway(hostIP string) (string, error) {
ip := strings.Split(hostIP, ".")
if len(ip) != 4 {
return "", errors.New("bad host IP")
}
return ip[0] + "." + ip[1] + ".255.254", nil
} | [
"func",
"HostIPToGateway",
"(",
"hostIP",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ip",
":=",
"strings",
".",
"Split",
"(",
"hostIP",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"ip",
")",
"!=",
"4",
"{",
"return",
"\"",
"\"",
","... | // HostIPToGateway gets the gateway based on the IP | [
"HostIPToGateway",
"gets",
"the",
"gateway",
"based",
"on",
"the",
"IP"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L951-L958 |
7,782 | contiv/netplugin | utils/netutils/netutils.go | CIDRToMask | func CIDRToMask(cidr string) (int, error) {
_, net, err := net.ParseCIDR(cidr)
if err != nil {
return -1, err
}
ip := net.IP
if len(ip) == 16 {
return int(binary.BigEndian.Uint32(ip[12:16])), nil
}
return int(binary.BigEndian.Uint32(ip)), nil
} | go | func CIDRToMask(cidr string) (int, error) {
_, net, err := net.ParseCIDR(cidr)
if err != nil {
return -1, err
}
ip := net.IP
if len(ip) == 16 {
return int(binary.BigEndian.Uint32(ip[12:16])), nil
}
return int(binary.BigEndian.Uint32(ip)), nil
} | [
"func",
"CIDRToMask",
"(",
"cidr",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"_",
",",
"net",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"cidr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
... | // CIDRToMask converts a CIDR to corresponding network number | [
"CIDRToMask",
"converts",
"a",
"CIDR",
"to",
"corresponding",
"network",
"number"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L961-L971 |
7,783 | contiv/netplugin | utils/netutils/netutils.go | NextClear | func NextClear(allocMap bitset.BitSet, idx uint, subnetLen uint) (uint, bool) {
maxHosts := uint(1 << (32 - subnetLen))
value, found := allocMap.NextClear(idx)
if found && value >= maxHosts {
return 0, false
}
return value, found
} | go | func NextClear(allocMap bitset.BitSet, idx uint, subnetLen uint) (uint, bool) {
maxHosts := uint(1 << (32 - subnetLen))
value, found := allocMap.NextClear(idx)
if found && value >= maxHosts {
return 0, false
}
return value, found
} | [
"func",
"NextClear",
"(",
"allocMap",
"bitset",
".",
"BitSet",
",",
"idx",
"uint",
",",
"subnetLen",
"uint",
")",
"(",
"uint",
",",
"bool",
")",
"{",
"maxHosts",
":=",
"uint",
"(",
"1",
"<<",
"(",
"32",
"-",
"subnetLen",
")",
")",
"\n\n",
"value",
... | // NextClear wrapper around Bitset to check max id | [
"NextClear",
"wrapper",
"around",
"Bitset",
"to",
"check",
"max",
"id"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L1026-L1034 |
7,784 | contiv/netplugin | utils/netutils/netutils.go | AddIPRoute | func AddIPRoute(cidr, gw string) error {
_, dst, err := net.ParseCIDR(cidr)
if err != nil {
return err
}
gwIP := net.ParseIP(gw)
if gwIP == nil {
return fmt.Errorf("Unable to parse gw %s", gw)
}
match, err := netlink.RouteListFiltered(netlink.FAMILY_V4,
&netlink.Route{Dst: dst}, netlink.RT_FILTER_DST)
if err == nil && len(match) != 0 {
if len(match) == 1 && match[0].Gw.Equal(gwIP) {
// the exact same route exists -- be idempotent
log.Infof("Route %s --> %s present", cidr, gw)
return nil
}
log.Errorf("AddIPRoute(%s, %s): exists %+v", cidr, gw, match)
return fmt.Errorf("Route exists")
}
newRoute := netlink.Route{
Dst: dst,
Gw: gwIP,
}
return netlink.RouteAdd(&newRoute)
} | go | func AddIPRoute(cidr, gw string) error {
_, dst, err := net.ParseCIDR(cidr)
if err != nil {
return err
}
gwIP := net.ParseIP(gw)
if gwIP == nil {
return fmt.Errorf("Unable to parse gw %s", gw)
}
match, err := netlink.RouteListFiltered(netlink.FAMILY_V4,
&netlink.Route{Dst: dst}, netlink.RT_FILTER_DST)
if err == nil && len(match) != 0 {
if len(match) == 1 && match[0].Gw.Equal(gwIP) {
// the exact same route exists -- be idempotent
log.Infof("Route %s --> %s present", cidr, gw)
return nil
}
log.Errorf("AddIPRoute(%s, %s): exists %+v", cidr, gw, match)
return fmt.Errorf("Route exists")
}
newRoute := netlink.Route{
Dst: dst,
Gw: gwIP,
}
return netlink.RouteAdd(&newRoute)
} | [
"func",
"AddIPRoute",
"(",
"cidr",
",",
"gw",
"string",
")",
"error",
"{",
"_",
",",
"dst",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"cidr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"gwIP",
":=",
"net",... | // AddIPRoute adds the specified ip route | [
"AddIPRoute",
"adds",
"the",
"specified",
"ip",
"route"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L1070-L1101 |
7,785 | contiv/netplugin | utils/netutils/netutils.go | DelIPRoute | func DelIPRoute(cidr, gw string) error {
_, dst, err := net.ParseCIDR(cidr)
if err != nil {
return err
}
gwIP := net.ParseIP(gw)
if gwIP == nil {
return fmt.Errorf("Unable to parse gw %s", gw)
}
return netlink.RouteDel(&netlink.Route{Dst: dst, Gw: gwIP})
} | go | func DelIPRoute(cidr, gw string) error {
_, dst, err := net.ParseCIDR(cidr)
if err != nil {
return err
}
gwIP := net.ParseIP(gw)
if gwIP == nil {
return fmt.Errorf("Unable to parse gw %s", gw)
}
return netlink.RouteDel(&netlink.Route{Dst: dst, Gw: gwIP})
} | [
"func",
"DelIPRoute",
"(",
"cidr",
",",
"gw",
"string",
")",
"error",
"{",
"_",
",",
"dst",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"cidr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"gwIP",
":=",
"net",... | // DelIPRoute deletes the specified ip route | [
"DelIPRoute",
"deletes",
"the",
"specified",
"ip",
"route"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netutils/netutils.go#L1104-L1117 |
7,786 | contiv/netplugin | netmaster/gstate/gstate.go | ReadAll | func (gc *Cfg) ReadAll() ([]core.State, error) {
return gc.StateDriver.ReadAllState(cfgGlobalPrefix, gc, json.Unmarshal)
} | go | func (gc *Cfg) ReadAll() ([]core.State, error) {
return gc.StateDriver.ReadAllState(cfgGlobalPrefix, gc, json.Unmarshal)
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"gc",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"cfgGlobalPrefix",
",",
"gc",
",",
"json",
".",
"Unmarshal",
")",
"\... | // ReadAll global config state | [
"ReadAll",
"global",
"config",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L125-L127 |
7,787 | contiv/netplugin | netmaster/gstate/gstate.go | Clear | func (gc *Cfg) Clear() error {
key := cfgGlobalPath
return gc.StateDriver.ClearState(key)
} | go | func (gc *Cfg) Clear() error {
key := cfgGlobalPath
return gc.StateDriver.ClearState(key)
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"Clear",
"(",
")",
"error",
"{",
"key",
":=",
"cfgGlobalPath",
"\n",
"return",
"gc",
".",
"StateDriver",
".",
"ClearState",
"(",
"key",
")",
"\n",
"}"
] | // Clear the state | [
"Clear",
"the",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L130-L133 |
7,788 | contiv/netplugin | netmaster/gstate/gstate.go | ReadAll | func (g *Oper) ReadAll() ([]core.State, error) {
return g.StateDriver.ReadAllState(operGlobalPrefix, g, json.Unmarshal)
} | go | func (g *Oper) ReadAll() ([]core.State, error) {
return g.StateDriver.ReadAllState(operGlobalPrefix, g, json.Unmarshal)
} | [
"func",
"(",
"g",
"*",
"Oper",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"g",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"operGlobalPrefix",
",",
"g",
",",
"json",
".",
"Unmarshal",
")",
"\n... | // ReadAll the global oper state | [
"ReadAll",
"the",
"global",
"oper",
"state"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L148-L150 |
7,789 | contiv/netplugin | netmaster/gstate/gstate.go | GetVxlansInUse | func (gc *Cfg) GetVxlansInUse() (uint, string) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
log.Errorf("error getting resource manager: %s", err)
return 0, ""
}
ra := core.ResourceManager(tempRm)
return ra.GetResourceList("global", resources.AutoVXLANResource)
} | go | func (gc *Cfg) GetVxlansInUse() (uint, string) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
log.Errorf("error getting resource manager: %s", err)
return 0, ""
}
ra := core.ResourceManager(tempRm)
return ra.GetResourceList("global", resources.AutoVXLANResource)
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"GetVxlansInUse",
"(",
")",
"(",
"uint",
",",
"string",
")",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
... | // GetVxlansInUse gets the vlans that are currently in use | [
"GetVxlansInUse",
"gets",
"the",
"vlans",
"that",
"are",
"currently",
"in",
"use"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L187-L196 |
7,790 | contiv/netplugin | netmaster/gstate/gstate.go | AllocVXLAN | func (gc *Cfg) AllocVXLAN(reqVxlan uint) (vxlan uint, localVLAN uint, err error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, 0, err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return 0, 0, err
}
if reqVxlan != 0 && reqVxlan <= g.FreeVXLANsStart {
return 0, 0, errors.New("requested vxlan is out of range")
}
if (reqVxlan != 0) && (reqVxlan >= g.FreeVXLANsStart) {
reqVxlan = reqVxlan - g.FreeVXLANsStart
}
pair, err1 := ra.AllocateResourceVal("global", resources.AutoVXLANResource, reqVxlan)
if err1 != nil {
return 0, 0, err1
}
vxlan = pair.(resources.VXLANVLANPair).VXLAN + g.FreeVXLANsStart
localVLAN = pair.(resources.VXLANVLANPair).VLAN
return
} | go | func (gc *Cfg) AllocVXLAN(reqVxlan uint) (vxlan uint, localVLAN uint, err error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, 0, err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return 0, 0, err
}
if reqVxlan != 0 && reqVxlan <= g.FreeVXLANsStart {
return 0, 0, errors.New("requested vxlan is out of range")
}
if (reqVxlan != 0) && (reqVxlan >= g.FreeVXLANsStart) {
reqVxlan = reqVxlan - g.FreeVXLANsStart
}
pair, err1 := ra.AllocateResourceVal("global", resources.AutoVXLANResource, reqVxlan)
if err1 != nil {
return 0, 0, err1
}
vxlan = pair.(resources.VXLANVLANPair).VXLAN + g.FreeVXLANsStart
localVLAN = pair.(resources.VXLANVLANPair).VLAN
return
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"AllocVXLAN",
"(",
"reqVxlan",
"uint",
")",
"(",
"vxlan",
"uint",
",",
"localVLAN",
"uint",
",",
"err",
"error",
")",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if"... | // AllocVXLAN allocates a new vxlan; ids for both the vxlan and vlan are returned. | [
"AllocVXLAN",
"allocates",
"a",
"new",
"vxlan",
";",
"ids",
"for",
"both",
"the",
"vxlan",
"and",
"vlan",
"are",
"returned",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L199-L231 |
7,791 | contiv/netplugin | netmaster/gstate/gstate.go | FreeVXLAN | func (gc *Cfg) FreeVXLAN(vxlan uint, localVLAN uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return nil
}
return ra.DeallocateResourceVal("global", resources.AutoVXLANResource,
resources.VXLANVLANPair{
VXLAN: vxlan - g.FreeVXLANsStart,
VLAN: localVLAN})
} | go | func (gc *Cfg) FreeVXLAN(vxlan uint, localVLAN uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return nil
}
return ra.DeallocateResourceVal("global", resources.AutoVXLANResource,
resources.VXLANVLANPair{
VXLAN: vxlan - g.FreeVXLANsStart,
VLAN: localVLAN})
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"FreeVXLAN",
"(",
"vxlan",
"uint",
",",
"localVLAN",
"uint",
")",
"error",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",... | // FreeVXLAN returns a VXLAN id to the pool. | [
"FreeVXLAN",
"returns",
"a",
"VXLAN",
"id",
"to",
"the",
"pool",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L234-L252 |
7,792 | contiv/netplugin | netmaster/gstate/gstate.go | GetVlansInUse | func (gc *Cfg) GetVlansInUse() (uint, string) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
log.Errorf("error getting resource manager: %s", err)
return 0, ""
}
ra := core.ResourceManager(tempRm)
return ra.GetResourceList("global", resources.AutoVLANResource)
} | go | func (gc *Cfg) GetVlansInUse() (uint, string) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
log.Errorf("error getting resource manager: %s", err)
return 0, ""
}
ra := core.ResourceManager(tempRm)
return ra.GetResourceList("global", resources.AutoVLANResource)
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"GetVlansInUse",
"(",
")",
"(",
"uint",
",",
"string",
")",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
... | // GetVlansInUse gets the vlans that are currently in use | [
"GetVlansInUse",
"gets",
"the",
"vlans",
"that",
"are",
"currently",
"in",
"use"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L279-L288 |
7,793 | contiv/netplugin | netmaster/gstate/gstate.go | AllocVLAN | func (gc *Cfg) AllocVLAN(reqVlan uint) (uint, error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, err
}
ra := core.ResourceManager(tempRm)
vlan, err := ra.AllocateResourceVal("global", resources.AutoVLANResource, reqVlan)
if err != nil {
log.Errorf("alloc vlan failed: %q", err)
return 0, err
}
return vlan.(uint), err
} | go | func (gc *Cfg) AllocVLAN(reqVlan uint) (uint, error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, err
}
ra := core.ResourceManager(tempRm)
vlan, err := ra.AllocateResourceVal("global", resources.AutoVLANResource, reqVlan)
if err != nil {
log.Errorf("alloc vlan failed: %q", err)
return 0, err
}
return vlan.(uint), err
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"AllocVLAN",
"(",
"reqVlan",
"uint",
")",
"(",
"uint",
",",
"error",
")",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
... | // AllocVLAN allocates a new VLAN resource. Returns an ID. | [
"AllocVLAN",
"allocates",
"a",
"new",
"VLAN",
"resource",
".",
"Returns",
"an",
"ID",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L291-L305 |
7,794 | contiv/netplugin | netmaster/gstate/gstate.go | FreeVLAN | func (gc *Cfg) FreeVLAN(vlan uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
return ra.DeallocateResourceVal("global", resources.AutoVLANResource, vlan)
} | go | func (gc *Cfg) FreeVLAN(vlan uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
return ra.DeallocateResourceVal("global", resources.AutoVLANResource, vlan)
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"FreeVLAN",
"(",
"vlan",
"uint",
")",
"error",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ra",
... | // FreeVLAN releases a VLAN for a given ID. | [
"FreeVLAN",
"releases",
"a",
"VLAN",
"for",
"a",
"given",
"ID",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L308-L316 |
7,795 | contiv/netplugin | netmaster/gstate/gstate.go | DeleteResources | func (gc *Cfg) DeleteResources(res string) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
if res == "vlan" {
err = ra.UndefineResource("global", resources.AutoVLANResource)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
} else if res == "vxlan" {
err = ra.UndefineResource("global", resources.AutoVXLANResource)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
}
return err
} | go | func (gc *Cfg) DeleteResources(res string) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
if res == "vlan" {
err = ra.UndefineResource("global", resources.AutoVLANResource)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
} else if res == "vxlan" {
err = ra.UndefineResource("global", resources.AutoVXLANResource)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
}
return err
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"DeleteResources",
"(",
"res",
"string",
")",
"error",
"{",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
... | // DeleteResources deletes associated resources | [
"DeleteResources",
"deletes",
"associated",
"resources"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L377-L396 |
7,796 | contiv/netplugin | netmaster/gstate/gstate.go | UpdateResources | func (gc *Cfg) UpdateResources(res string) error {
log.Infof("Received update resource for res %s", res)
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
err = gc.checkErrors(res)
if err != nil {
return core.Errorf("process failed on error checks %s", err)
}
if res == "vlan" {
var vlanRsrcCfg *bitset.BitSet
vlanRsrcCfg, err = gc.initVLANBitset(gc.Auto.VLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVLANResource, vlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
} else if res == "vxlan" {
var vxlanRsrcCfg *resources.AutoVXLANCfgResource
vxlanRsrcCfg, err = gc.initVXLANBitset(gc.Auto.VXLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVXLANResource, vxlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
g := &Oper{FreeVXLANsStart: vxlanRsrcCfg.FreeVXLANsStart}
g.StateDriver = gc.StateDriver
err = g.Write()
if err != nil {
log.Errorf("error '%s' updating global oper state %v \n", err, g)
return err
}
}
return err
} | go | func (gc *Cfg) UpdateResources(res string) error {
log.Infof("Received update resource for res %s", res)
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
err = gc.checkErrors(res)
if err != nil {
return core.Errorf("process failed on error checks %s", err)
}
if res == "vlan" {
var vlanRsrcCfg *bitset.BitSet
vlanRsrcCfg, err = gc.initVLANBitset(gc.Auto.VLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVLANResource, vlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
} else if res == "vxlan" {
var vxlanRsrcCfg *resources.AutoVXLANCfgResource
vxlanRsrcCfg, err = gc.initVXLANBitset(gc.Auto.VXLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVXLANResource, vxlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
g := &Oper{FreeVXLANsStart: vxlanRsrcCfg.FreeVXLANsStart}
g.StateDriver = gc.StateDriver
err = g.Write()
if err != nil {
log.Errorf("error '%s' updating global oper state %v \n", err, g)
return err
}
}
return err
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"UpdateResources",
"(",
"res",
"string",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"res",
")",
"\n",
"tempRm",
",",
"err",
":=",
"resources",
".",
"GetStateResourceManager",
"(",
")",
"\n",
"if"... | // UpdateResources deletes associated resources | [
"UpdateResources",
"deletes",
"associated",
"resources"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L399-L443 |
7,797 | contiv/netplugin | netmaster/gstate/gstate.go | CheckInBitRange | func (gc *Cfg) CheckInBitRange(ranges, inUse, pktTagType string) bool {
tags := strings.Split(inUse, ",")
if len(inUse) == 0 {
return true
}
minUsed := 0
maxUsed := 0
if strings.Contains(tags[0], "-") {
minUsed, _ = strconv.Atoi(strings.Split(tags[0], "-")[0])
maxUsed, _ = strconv.Atoi(strings.Split(tags[0], "-")[1])
} else {
minUsed, _ = strconv.Atoi(tags[0])
maxUsed = minUsed
}
if len(inUse) > 1 {
if strings.Contains(tags[len(tags)-1], "-") {
maxUsed, _ = strconv.Atoi(strings.Split(tags[len(tags)-1], "-")[1])
} else {
maxUsed, _ = strconv.Atoi(strings.TrimSpace(tags[len(tags)-1]))
}
}
r, err := netutils.ParseTagRanges(ranges, pktTagType)
if err != nil {
return false
}
if r[0].Min > minUsed || r[0].Max < maxUsed {
return false
}
return true
} | go | func (gc *Cfg) CheckInBitRange(ranges, inUse, pktTagType string) bool {
tags := strings.Split(inUse, ",")
if len(inUse) == 0 {
return true
}
minUsed := 0
maxUsed := 0
if strings.Contains(tags[0], "-") {
minUsed, _ = strconv.Atoi(strings.Split(tags[0], "-")[0])
maxUsed, _ = strconv.Atoi(strings.Split(tags[0], "-")[1])
} else {
minUsed, _ = strconv.Atoi(tags[0])
maxUsed = minUsed
}
if len(inUse) > 1 {
if strings.Contains(tags[len(tags)-1], "-") {
maxUsed, _ = strconv.Atoi(strings.Split(tags[len(tags)-1], "-")[1])
} else {
maxUsed, _ = strconv.Atoi(strings.TrimSpace(tags[len(tags)-1]))
}
}
r, err := netutils.ParseTagRanges(ranges, pktTagType)
if err != nil {
return false
}
if r[0].Min > minUsed || r[0].Max < maxUsed {
return false
}
return true
} | [
"func",
"(",
"gc",
"*",
"Cfg",
")",
"CheckInBitRange",
"(",
"ranges",
",",
"inUse",
",",
"pktTagType",
"string",
")",
"bool",
"{",
"tags",
":=",
"strings",
".",
"Split",
"(",
"inUse",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"inUse",
")",
"=... | //CheckInBitRange to check if range includes inuse vlans | [
"CheckInBitRange",
"to",
"check",
"if",
"range",
"includes",
"inuse",
"vlans"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/gstate/gstate.go#L493-L527 |
7,798 | contiv/netplugin | state/etcdstatedriver.go | ClearState | func (d *EtcdStateDriver) ClearState(key string) error {
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()
_, err := d.KeysAPI.Delete(ctx, key, nil)
return err
} | go | func (d *EtcdStateDriver) ClearState(key string) error {
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()
_, err := d.KeysAPI.Delete(ctx, key, nil)
return err
} | [
"func",
"(",
"d",
"*",
"EtcdStateDriver",
")",
"ClearState",
"(",
"key",
"string",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"ctxTimeout",
")",
"\n",
"defer",
"cancel",... | // ClearState removes key from etcd | [
"ClearState",
"removes",
"key",
"from",
"etcd"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/etcdstatedriver.go#L229-L235 |
7,799 | contiv/netplugin | state/etcdstatedriver.go | WriteState | func (d *EtcdStateDriver) WriteState(key string, value core.State,
marshal func(interface{}) ([]byte, error)) error {
encodedState, err := marshal(value)
if err != nil {
return err
}
return d.Write(key, encodedState)
} | go | func (d *EtcdStateDriver) WriteState(key string, value core.State,
marshal func(interface{}) ([]byte, error)) error {
encodedState, err := marshal(value)
if err != nil {
return err
}
return d.Write(key, encodedState)
} | [
"func",
"(",
"d",
"*",
"EtcdStateDriver",
")",
"WriteState",
"(",
"key",
"string",
",",
"value",
"core",
".",
"State",
",",
"marshal",
"func",
"(",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
")",
"error",
"{",
"encodedState... | // WriteState writes a value of core.State into a key with a given marshaling function. | [
"WriteState",
"writes",
"a",
"value",
"of",
"core",
".",
"State",
"into",
"a",
"key",
"with",
"a",
"given",
"marshaling",
"function",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/etcdstatedriver.go#L357-L365 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.