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
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,000 | contiv/netplugin | drivers/ovsd/ovsdriver.go | InspectNameserver | func (d *OvsDriver) InspectNameserver() ([]byte, error) {
if d.nameServer == nil {
return []byte{}, nil
}
ns, err := d.nameServer.InspectState()
jsonState, err := json.Marshal(ns)
if err != nil {
log.Errorf("Error encoding nameserver state. Err: %v", err)
return []byte{}, err
}
return jsonState, nil
} | go | func (d *OvsDriver) InspectNameserver() ([]byte, error) {
if d.nameServer == nil {
return []byte{}, nil
}
ns, err := d.nameServer.InspectState()
jsonState, err := json.Marshal(ns)
if err != nil {
log.Errorf("Error encoding nameserver state. Err: %v", err)
return []byte{}, err
}
return jsonState, nil
} | [
"func",
"(",
"d",
"*",
"OvsDriver",
")",
"InspectNameserver",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"d",
".",
"nameServer",
"==",
"nil",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"ns",
",",
"err",
":=",
"d",
".",
"nameServer",
".",
"InspectState",
"(",
")",
"\n",
"jsonState",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"ns",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"jsonState",
",",
"nil",
"\n",
"}"
]
| // InspectNameserver returns nameserver state as json string | [
"InspectNameserver",
"returns",
"nameserver",
"state",
"as",
"json",
"string"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L853-L866 |
8,001 | contiv/netplugin | objdb/consulClient.go | NewClient | func (cp *consulPlugin) NewClient(endpoints []string) (API, error) {
cc := new(ConsulClient)
if len(endpoints) == 0 {
endpoints = []string{"127.0.0.1:8500"}
}
// default consul config
cc.consulConfig = api.Config{Address: strings.TrimPrefix(endpoints[0], "http://")}
// Initialize service DB
cc.serviceDb = make(map[string]*consulServiceState)
// Init consul client
client, err := api.NewClient(&cc.consulConfig)
if err != nil {
log.Fatalf("Error initializing consul client")
return nil, err
}
cc.client = client
// verify we can reach the consul
_, _, err = client.KV().List("/", nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, _, err = client.KV().List("/", nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
log.Errorf("Error connecting to consul. Err: %v", err)
return nil, err
}
}
return cc, nil
} | go | func (cp *consulPlugin) NewClient(endpoints []string) (API, error) {
cc := new(ConsulClient)
if len(endpoints) == 0 {
endpoints = []string{"127.0.0.1:8500"}
}
// default consul config
cc.consulConfig = api.Config{Address: strings.TrimPrefix(endpoints[0], "http://")}
// Initialize service DB
cc.serviceDb = make(map[string]*consulServiceState)
// Init consul client
client, err := api.NewClient(&cc.consulConfig)
if err != nil {
log.Fatalf("Error initializing consul client")
return nil, err
}
cc.client = client
// verify we can reach the consul
_, _, err = client.KV().List("/", nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, _, err = client.KV().List("/", nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
log.Errorf("Error connecting to consul. Err: %v", err)
return nil, err
}
}
return cc, nil
} | [
"func",
"(",
"cp",
"*",
"consulPlugin",
")",
"NewClient",
"(",
"endpoints",
"[",
"]",
"string",
")",
"(",
"API",
",",
"error",
")",
"{",
"cc",
":=",
"new",
"(",
"ConsulClient",
")",
"\n\n",
"if",
"len",
"(",
"endpoints",
")",
"==",
"0",
"{",
"endpoints",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"// default consul config",
"cc",
".",
"consulConfig",
"=",
"api",
".",
"Config",
"{",
"Address",
":",
"strings",
".",
"TrimPrefix",
"(",
"endpoints",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"}",
"\n\n",
"// Initialize service DB",
"cc",
".",
"serviceDb",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"consulServiceState",
")",
"\n\n",
"// Init consul client",
"client",
",",
"err",
":=",
"api",
".",
"NewClient",
"(",
"&",
"cc",
".",
"consulConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cc",
".",
"client",
"=",
"client",
"\n\n",
"// verify we can reach the consul",
"_",
",",
"_",
",",
"err",
"=",
"client",
".",
"KV",
"(",
")",
".",
"List",
"(",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api",
".",
"IsServerError",
"(",
"err",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxConsulRetries",
";",
"i",
"++",
"{",
"_",
",",
"_",
",",
"err",
"=",
"client",
".",
"KV",
"(",
")",
".",
"List",
"(",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Retry after a delay",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// return error if it failed after retries",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"cc",
",",
"nil",
"\n",
"}"
]
| // Init initializes the consul client | [
"Init",
"initializes",
"the",
"consul",
"client"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulClient.go#L52-L98 |
8,002 | contiv/netplugin | objdb/consulClient.go | GetObj | func (cp *ConsulClient) GetObj(key string, retVal interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
resp, _, err := cp.client.KV().Get(key, &api.QueryOptions{RequireConsistent: true})
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
resp, _, err = cp.client.KV().Get(key, &api.QueryOptions{RequireConsistent: true})
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
return err
}
}
// Consul returns success and a nil kv when a key is not found,
// translate it to 'Key not found' error
if resp == nil {
return errors.New("Key not found")
}
// Parse JSON response
if err := json.Unmarshal(resp.Value, retVal); err != nil {
log.Errorf("Error parsing object %v, Err %v", resp.Value, err)
return err
}
return nil
} | go | func (cp *ConsulClient) GetObj(key string, retVal interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
resp, _, err := cp.client.KV().Get(key, &api.QueryOptions{RequireConsistent: true})
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
resp, _, err = cp.client.KV().Get(key, &api.QueryOptions{RequireConsistent: true})
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
return err
}
}
// Consul returns success and a nil kv when a key is not found,
// translate it to 'Key not found' error
if resp == nil {
return errors.New("Key not found")
}
// Parse JSON response
if err := json.Unmarshal(resp.Value, retVal); err != nil {
log.Errorf("Error parsing object %v, Err %v", resp.Value, err)
return err
}
return nil
} | [
"func",
"(",
"cp",
"*",
"ConsulClient",
")",
"GetObj",
"(",
"key",
"string",
",",
"retVal",
"interface",
"{",
"}",
")",
"error",
"{",
"key",
"=",
"processKey",
"(",
"\"",
"\"",
"+",
"processKey",
"(",
"key",
")",
")",
"\n\n",
"resp",
",",
"_",
",",
"err",
":=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Get",
"(",
"key",
",",
"&",
"api",
".",
"QueryOptions",
"{",
"RequireConsistent",
":",
"true",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api",
".",
"IsServerError",
"(",
"err",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxConsulRetries",
";",
"i",
"++",
"{",
"resp",
",",
"_",
",",
"err",
"=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Get",
"(",
"key",
",",
"&",
"api",
".",
"QueryOptions",
"{",
"RequireConsistent",
":",
"true",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Retry after a delay",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// return error if it failed after retries",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"// Consul returns success and a nil kv when a key is not found,",
"// translate it to 'Key not found' error",
"if",
"resp",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Parse JSON response",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
".",
"Value",
",",
"retVal",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Value",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // GetObj reads the object | [
"GetObj",
"reads",
"the",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulClient.go#L106-L142 |
8,003 | contiv/netplugin | objdb/consulClient.go | ListDir | func (cp *ConsulClient) ListDir(key string) ([]string, error) {
key = processKey("/contiv.io/obj/" + processKey(key))
kvs, _, err := cp.client.KV().List(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
kvs, _, err = cp.client.KV().List(key, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
return nil, err
}
}
// Consul returns success and a nil kv when a key is not found,
// translate it to 'Key not found' error
if kvs == nil {
return []string{}, nil
}
var keys []string
for _, kv := range kvs {
keys = append(keys, string(kv.Value))
}
return keys, nil
} | go | func (cp *ConsulClient) ListDir(key string) ([]string, error) {
key = processKey("/contiv.io/obj/" + processKey(key))
kvs, _, err := cp.client.KV().List(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
kvs, _, err = cp.client.KV().List(key, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
// return error if it failed after retries
if err != nil {
return nil, err
}
}
// Consul returns success and a nil kv when a key is not found,
// translate it to 'Key not found' error
if kvs == nil {
return []string{}, nil
}
var keys []string
for _, kv := range kvs {
keys = append(keys, string(kv.Value))
}
return keys, nil
} | [
"func",
"(",
"cp",
"*",
"ConsulClient",
")",
"ListDir",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"key",
"=",
"processKey",
"(",
"\"",
"\"",
"+",
"processKey",
"(",
"key",
")",
")",
"\n\n",
"kvs",
",",
"_",
",",
"err",
":=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"List",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api",
".",
"IsServerError",
"(",
"err",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxConsulRetries",
";",
"i",
"++",
"{",
"kvs",
",",
"_",
",",
"err",
"=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"List",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Retry after a delay",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// return error if it failed after retries",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"// Consul returns success and a nil kv when a key is not found,",
"// translate it to 'Key not found' error",
"if",
"kvs",
"==",
"nil",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"keys",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"kv",
":=",
"range",
"kvs",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"string",
"(",
"kv",
".",
"Value",
")",
")",
"\n",
"}",
"\n\n",
"return",
"keys",
",",
"nil",
"\n",
"}"
]
| // ListDir returns a list of keys in a directory | [
"ListDir",
"returns",
"a",
"list",
"of",
"keys",
"in",
"a",
"directory"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulClient.go#L145-L180 |
8,004 | contiv/netplugin | objdb/consulClient.go | SetObj | func (cp *ConsulClient) SetObj(key string, value interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
// JSON format the object
jsonVal, err := json.Marshal(value)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
_, err = cp.client.KV().Put(&api.KVPair{Key: key, Value: jsonVal}, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, err = cp.client.KV().Put(&api.KVPair{Key: key, Value: jsonVal}, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
}
return err
} | go | func (cp *ConsulClient) SetObj(key string, value interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
// JSON format the object
jsonVal, err := json.Marshal(value)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
_, err = cp.client.KV().Put(&api.KVPair{Key: key, Value: jsonVal}, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, err = cp.client.KV().Put(&api.KVPair{Key: key, Value: jsonVal}, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
}
return err
} | [
"func",
"(",
"cp",
"*",
"ConsulClient",
")",
"SetObj",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"key",
"=",
"processKey",
"(",
"\"",
"\"",
"+",
"processKey",
"(",
"key",
")",
")",
"\n\n",
"// JSON format the object",
"jsonVal",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Put",
"(",
"&",
"api",
".",
"KVPair",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"jsonVal",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api",
".",
"IsServerError",
"(",
"err",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxConsulRetries",
";",
"i",
"++",
"{",
"_",
",",
"err",
"=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Put",
"(",
"&",
"api",
".",
"KVPair",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"jsonVal",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Retry after a delay",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // SetObj writes an object | [
"SetObj",
"writes",
"an",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulClient.go#L183-L210 |
8,005 | contiv/netplugin | objdb/consulClient.go | DelObj | func (cp *ConsulClient) DelObj(key string) error {
key = processKey("/contiv.io/obj/" + processKey(key))
_, err := cp.client.KV().Delete(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, err = cp.client.KV().Delete(key, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
}
return err
} | go | func (cp *ConsulClient) DelObj(key string) error {
key = processKey("/contiv.io/obj/" + processKey(key))
_, err := cp.client.KV().Delete(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, err = cp.client.KV().Delete(key, nil)
if err == nil {
break
}
// Retry after a delay
time.Sleep(time.Second)
}
}
}
return err
} | [
"func",
"(",
"cp",
"*",
"ConsulClient",
")",
"DelObj",
"(",
"key",
"string",
")",
"error",
"{",
"key",
"=",
"processKey",
"(",
"\"",
"\"",
"+",
"processKey",
"(",
"key",
")",
")",
"\n",
"_",
",",
"err",
":=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Delete",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api",
".",
"IsServerError",
"(",
"err",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxConsulRetries",
";",
"i",
"++",
"{",
"_",
",",
"err",
"=",
"cp",
".",
"client",
".",
"KV",
"(",
")",
".",
"Delete",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Retry after a delay",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // DelObj deletes an object | [
"DelObj",
"deletes",
"an",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulClient.go#L213-L232 |
8,006 | contiv/netplugin | state/consulstatedriver.go | ClearState | func (d *ConsulStateDriver) ClearState(key string) error {
key = processKey(key)
_, err := d.Client.KV().Delete(key, nil)
return err
} | go | func (d *ConsulStateDriver) ClearState(key string) error {
key = processKey(key)
_, err := d.Client.KV().Delete(key, nil)
return err
} | [
"func",
"(",
"d",
"*",
"ConsulStateDriver",
")",
"ClearState",
"(",
"key",
"string",
")",
"error",
"{",
"key",
"=",
"processKey",
"(",
"key",
")",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"Client",
".",
"KV",
"(",
")",
".",
"Delete",
"(",
"key",
",",
"nil",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // ClearState removes key from etcd. | [
"ClearState",
"removes",
"key",
"from",
"etcd",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/consulstatedriver.go#L283-L287 |
8,007 | contiv/netplugin | state/consulstatedriver.go | ReadState | func (d *ConsulStateDriver) ReadState(key string, value core.State,
unmarshal func([]byte, interface{}) error) error {
key = processKey(key)
encodedState, err := d.Read(key)
if err != nil {
return err
}
return unmarshal(encodedState, value)
} | go | func (d *ConsulStateDriver) ReadState(key string, value core.State,
unmarshal func([]byte, interface{}) error) error {
key = processKey(key)
encodedState, err := d.Read(key)
if err != nil {
return err
}
return unmarshal(encodedState, value)
} | [
"func",
"(",
"d",
"*",
"ConsulStateDriver",
")",
"ReadState",
"(",
"key",
"string",
",",
"value",
"core",
".",
"State",
",",
"unmarshal",
"func",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"key",
"=",
"processKey",
"(",
"key",
")",
"\n",
"encodedState",
",",
"err",
":=",
"d",
".",
"Read",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"unmarshal",
"(",
"encodedState",
",",
"value",
")",
"\n",
"}"
]
| // ReadState reads key into a core.State with the unmarshaling function. | [
"ReadState",
"reads",
"key",
"into",
"a",
"core",
".",
"State",
"with",
"the",
"unmarshaling",
"function",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/consulstatedriver.go#L290-L299 |
8,008 | contiv/netplugin | state/consulstatedriver.go | ReadAllState | func (d *ConsulStateDriver) ReadAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error) ([]core.State, error) {
baseKey = processKey(baseKey)
return readAllStateCommon(d, baseKey, sType, unmarshal)
} | go | func (d *ConsulStateDriver) ReadAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error) ([]core.State, error) {
baseKey = processKey(baseKey)
return readAllStateCommon(d, baseKey, sType, unmarshal)
} | [
"func",
"(",
"d",
"*",
"ConsulStateDriver",
")",
"ReadAllState",
"(",
"baseKey",
"string",
",",
"sType",
"core",
".",
"State",
",",
"unmarshal",
"func",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
")",
"error",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"baseKey",
"=",
"processKey",
"(",
"baseKey",
")",
"\n",
"return",
"readAllStateCommon",
"(",
"d",
",",
"baseKey",
",",
"sType",
",",
"unmarshal",
")",
"\n",
"}"
]
| // ReadAllState Reads all the state from baseKey and returns a list of core.State. | [
"ReadAllState",
"Reads",
"all",
"the",
"state",
"from",
"baseKey",
"and",
"returns",
"a",
"list",
"of",
"core",
".",
"State",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/consulstatedriver.go#L302-L306 |
8,009 | contiv/netplugin | objdb/modeldb/modeldb.go | AddLink | func AddLink(link *Link, obj ModelObj) {
link.ObjType = obj.GetType()
link.ObjKey = obj.GetKey()
} | go | func AddLink(link *Link, obj ModelObj) {
link.ObjType = obj.GetType()
link.ObjKey = obj.GetKey()
} | [
"func",
"AddLink",
"(",
"link",
"*",
"Link",
",",
"obj",
"ModelObj",
")",
"{",
"link",
".",
"ObjType",
"=",
"obj",
".",
"GetType",
"(",
")",
"\n",
"link",
".",
"ObjKey",
"=",
"obj",
".",
"GetKey",
"(",
")",
"\n",
"}"
]
| // AddLink adds a one way link to target object | [
"AddLink",
"adds",
"a",
"one",
"way",
"link",
"to",
"target",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L41-L44 |
8,010 | contiv/netplugin | objdb/modeldb/modeldb.go | AddLinkSet | func AddLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// Allocate the linkset if its nil
if *linkSet == nil {
*linkSet = make(map[string]Link)
}
// add the link to map
(*linkSet)[obj.GetKey()] = Link{
ObjType: obj.GetType(),
ObjKey: obj.GetKey(),
}
return nil
} | go | func AddLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// Allocate the linkset if its nil
if *linkSet == nil {
*linkSet = make(map[string]Link)
}
// add the link to map
(*linkSet)[obj.GetKey()] = Link{
ObjType: obj.GetType(),
ObjKey: obj.GetKey(),
}
return nil
} | [
"func",
"AddLinkSet",
"(",
"linkSet",
"*",
"(",
"map",
"[",
"string",
"]",
"Link",
")",
",",
"obj",
"ModelObj",
")",
"error",
"{",
"// Allocate the linkset if its nil",
"if",
"*",
"linkSet",
"==",
"nil",
"{",
"*",
"linkSet",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Link",
")",
"\n",
"}",
"\n\n",
"// add the link to map",
"(",
"*",
"linkSet",
")",
"[",
"obj",
".",
"GetKey",
"(",
")",
"]",
"=",
"Link",
"{",
"ObjType",
":",
"obj",
".",
"GetType",
"(",
")",
",",
"ObjKey",
":",
"obj",
".",
"GetKey",
"(",
")",
",",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // AddLinkSet Aadds a link into linkset. initialize the linkset if required | [
"AddLinkSet",
"Aadds",
"a",
"link",
"into",
"linkset",
".",
"initialize",
"the",
"linkset",
"if",
"required"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L53-L66 |
8,011 | contiv/netplugin | objdb/modeldb/modeldb.go | RemoveLinkSet | func RemoveLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// check is linkset is nil
if *linkSet == nil {
return nil
}
// remove the link from map
delete(*linkSet, obj.GetKey())
return nil
} | go | func RemoveLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// check is linkset is nil
if *linkSet == nil {
return nil
}
// remove the link from map
delete(*linkSet, obj.GetKey())
return nil
} | [
"func",
"RemoveLinkSet",
"(",
"linkSet",
"*",
"(",
"map",
"[",
"string",
"]",
"Link",
")",
",",
"obj",
"ModelObj",
")",
"error",
"{",
"// check is linkset is nil",
"if",
"*",
"linkSet",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// remove the link from map",
"delete",
"(",
"*",
"linkSet",
",",
"obj",
".",
"GetKey",
"(",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // RemoveLinkSet removes a link from linkset | [
"RemoveLinkSet",
"removes",
"a",
"link",
"from",
"linkset"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L69-L79 |
8,012 | contiv/netplugin | objdb/modeldb/modeldb.go | WriteObj | func WriteObj(objType, objKey string, value interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.SetObj(key, value)
if err != nil {
log.Errorf("Error storing object %s. Err: %v", key, err)
return err
}
return nil
} | go | func WriteObj(objType, objKey string, value interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.SetObj(key, value)
if err != nil {
log.Errorf("Error storing object %s. Err: %v", key, err)
return err
}
return nil
} | [
"func",
"WriteObj",
"(",
"objType",
",",
"objKey",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"key",
":=",
"\"",
"\"",
"+",
"objType",
"+",
"\"",
"\"",
"+",
"objKey",
"\n",
"err",
":=",
"cdb",
".",
"SetObj",
"(",
"key",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // WriteObj writes the model to DB | [
"WriteObj",
"writes",
"the",
"model",
"to",
"DB"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L90-L99 |
8,013 | contiv/netplugin | objdb/modeldb/modeldb.go | ReadObj | func ReadObj(objType, objKey string, retVal interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.GetObj(key, retVal)
if err != nil {
log.Errorf("Error reading object: %s. Err: %v", key, err)
return err
}
return nil
} | go | func ReadObj(objType, objKey string, retVal interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.GetObj(key, retVal)
if err != nil {
log.Errorf("Error reading object: %s. Err: %v", key, err)
return err
}
return nil
} | [
"func",
"ReadObj",
"(",
"objType",
",",
"objKey",
"string",
",",
"retVal",
"interface",
"{",
"}",
")",
"error",
"{",
"key",
":=",
"\"",
"\"",
"+",
"objType",
"+",
"\"",
"\"",
"+",
"objKey",
"\n",
"err",
":=",
"cdb",
".",
"GetObj",
"(",
"key",
",",
"retVal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // ReadObj reads an object from DB | [
"ReadObj",
"reads",
"an",
"object",
"from",
"DB"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L102-L111 |
8,014 | contiv/netplugin | objdb/modeldb/modeldb.go | DeleteObj | func DeleteObj(objType, objKey string) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.DelObj(key)
if err != nil {
log.Errorf("Error deleting object: %s. Err: %v", key, err)
}
return nil
} | go | func DeleteObj(objType, objKey string) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.DelObj(key)
if err != nil {
log.Errorf("Error deleting object: %s. Err: %v", key, err)
}
return nil
} | [
"func",
"DeleteObj",
"(",
"objType",
",",
"objKey",
"string",
")",
"error",
"{",
"key",
":=",
"\"",
"\"",
"+",
"objType",
"+",
"\"",
"\"",
"+",
"objKey",
"\n",
"err",
":=",
"cdb",
".",
"DelObj",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // DeleteObj deletes and object from DB | [
"DeleteObj",
"deletes",
"and",
"object",
"from",
"DB"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L114-L122 |
8,015 | contiv/netplugin | objdb/modeldb/modeldb.go | ReadAllObj | func ReadAllObj(objType string) ([]string, error) {
key := "/modeldb/" + objType + "/"
return cdb.ListDir(key)
} | go | func ReadAllObj(objType string) ([]string, error) {
key := "/modeldb/" + objType + "/"
return cdb.ListDir(key)
} | [
"func",
"ReadAllObj",
"(",
"objType",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"key",
":=",
"\"",
"\"",
"+",
"objType",
"+",
"\"",
"\"",
"\n",
"return",
"cdb",
".",
"ListDir",
"(",
"key",
")",
"\n",
"}"
]
| // ReadAllObj reads all objects of a type | [
"ReadAllObj",
"reads",
"all",
"objects",
"of",
"a",
"type"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/modeldb/modeldb.go#L125-L128 |
8,016 | contiv/netplugin | netmaster/mastercfg/endpointGroupState.go | GetEndpointGroupID | func GetEndpointGroupID(stateDriver core.StateDriver, groupName, tenantName string) (int, error) {
// If service name is not specified, we are done
if groupName == "" {
return 0, nil
}
epgKey := GetEndpointGroupKey(groupName, tenantName)
cfgEpGroup := &EndpointGroupState{}
cfgEpGroup.StateDriver = stateDriver
err := cfgEpGroup.Read(epgKey)
if err != nil {
log.Errorf("Error finding epg: %s. Err: %v", epgKey, err)
return 0, core.Errorf("EPG not found")
}
// return endpoint group id
return cfgEpGroup.EndpointGroupID, nil
} | go | func GetEndpointGroupID(stateDriver core.StateDriver, groupName, tenantName string) (int, error) {
// If service name is not specified, we are done
if groupName == "" {
return 0, nil
}
epgKey := GetEndpointGroupKey(groupName, tenantName)
cfgEpGroup := &EndpointGroupState{}
cfgEpGroup.StateDriver = stateDriver
err := cfgEpGroup.Read(epgKey)
if err != nil {
log.Errorf("Error finding epg: %s. Err: %v", epgKey, err)
return 0, core.Errorf("EPG not found")
}
// return endpoint group id
return cfgEpGroup.EndpointGroupID, nil
} | [
"func",
"GetEndpointGroupID",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"groupName",
",",
"tenantName",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"// If service name is not specified, we are done",
"if",
"groupName",
"==",
"\"",
"\"",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"epgKey",
":=",
"GetEndpointGroupKey",
"(",
"groupName",
",",
"tenantName",
")",
"\n",
"cfgEpGroup",
":=",
"&",
"EndpointGroupState",
"{",
"}",
"\n",
"cfgEpGroup",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"cfgEpGroup",
".",
"Read",
"(",
"epgKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgKey",
",",
"err",
")",
"\n",
"return",
"0",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// return endpoint group id",
"return",
"cfgEpGroup",
".",
"EndpointGroupID",
",",
"nil",
"\n",
"}"
]
| // GetEndpointGroupID returns endpoint group Id for a service
// It autocreates the endpoint group if it doesnt exist | [
"GetEndpointGroupID",
"returns",
"endpoint",
"group",
"Id",
"for",
"a",
"service",
"It",
"autocreates",
"the",
"endpoint",
"group",
"if",
"it",
"doesnt",
"exist"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/endpointGroupState.go#L87-L104 |
8,017 | contiv/netplugin | netmaster/objApi/infraproxy.go | getGwCIDR | func getGwCIDR(epgObj *contivModel.EndpointGroup, stateDriver core.StateDriver) (string, error) {
// get the subnet info and add it to ans
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := epgObj.NetworkName + "." + epgObj.TenantName
nErr := nwCfg.Read(networkID)
if nErr != nil {
log.Errorf("Failed to network info %v %v ", networkID, nErr)
return "", nErr
}
gw := nwCfg.Gateway + "/" + strconv.Itoa(int(nwCfg.SubnetLen))
log.Debugf("GW is %s for epg %s", gw, epgObj.GroupName)
return gw, nil
} | go | func getGwCIDR(epgObj *contivModel.EndpointGroup, stateDriver core.StateDriver) (string, error) {
// get the subnet info and add it to ans
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := epgObj.NetworkName + "." + epgObj.TenantName
nErr := nwCfg.Read(networkID)
if nErr != nil {
log.Errorf("Failed to network info %v %v ", networkID, nErr)
return "", nErr
}
gw := nwCfg.Gateway + "/" + strconv.Itoa(int(nwCfg.SubnetLen))
log.Debugf("GW is %s for epg %s", gw, epgObj.GroupName)
return gw, nil
} | [
"func",
"getGwCIDR",
"(",
"epgObj",
"*",
"contivModel",
".",
"EndpointGroup",
",",
"stateDriver",
"core",
".",
"StateDriver",
")",
"(",
"string",
",",
"error",
")",
"{",
"// get the subnet info and add it to ans",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"networkID",
":=",
"epgObj",
".",
"NetworkName",
"+",
"\"",
"\"",
"+",
"epgObj",
".",
"TenantName",
"\n",
"nErr",
":=",
"nwCfg",
".",
"Read",
"(",
"networkID",
")",
"\n",
"if",
"nErr",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"networkID",
",",
"nErr",
")",
"\n",
"return",
"\"",
"\"",
",",
"nErr",
"\n",
"}",
"\n",
"gw",
":=",
"nwCfg",
".",
"Gateway",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"nwCfg",
".",
"SubnetLen",
")",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"gw",
",",
"epgObj",
".",
"GroupName",
")",
"\n",
"return",
"gw",
",",
"nil",
"\n",
"}"
]
| // getGwCIDR utility that reads the gw information | [
"getGwCIDR",
"utility",
"that",
"reads",
"the",
"gw",
"information"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/infraproxy.go#L162-L175 |
8,018 | contiv/netplugin | netmaster/objApi/infraproxy.go | addPolicyContracts | func addPolicyContracts(csMap map[string]*contrSpec, epg *epgSpec, policy *contivModel.Policy) error {
for ruleName := range policy.LinkSets.Rules {
rule := contivModel.FindRule(ruleName)
if rule == nil {
errStr := fmt.Sprintf("rule %v not found", ruleName)
return errors.New(errStr)
}
if rule.FromIpAddress != "" || rule.FromNetwork != "" ||
rule.ToIpAddress != "" || rule.ToNetwork != "" {
log.Errorf("rule: %+v is invalid for ACI mode", rule)
errStr := fmt.Sprintf("rule %s is invalid, only From/ToEndpointGroup may be specified in ACI mode", ruleName)
return errors.New(errStr)
}
if rule.Action == "deny" {
log.Debugf("==Ignoring deny rule %v", ruleName)
continue
}
filter := filterInfo{Protocol: rule.Protocol, ServPort: strconv.Itoa(rule.Port)}
cn := getContractName(policy.PolicyName, rule.FromEndpointGroup,
rule.ToEndpointGroup)
spec, found := csMap[cn]
if !found {
// add a link for this contract
lKind := cProvide
if rule.ToEndpointGroup != "" {
lKind = cConsume
}
cLink := contrLink{LinkKind: lKind,
ContractName: cn,
ContractKind: cInternal,
}
epg.ContractLinks = append(epg.ContractLinks, cLink)
spec = &contrSpec{Name: cn}
csMap[cn] = spec
}
spec.Filters = append(spec.Filters, filter)
}
return nil
} | go | func addPolicyContracts(csMap map[string]*contrSpec, epg *epgSpec, policy *contivModel.Policy) error {
for ruleName := range policy.LinkSets.Rules {
rule := contivModel.FindRule(ruleName)
if rule == nil {
errStr := fmt.Sprintf("rule %v not found", ruleName)
return errors.New(errStr)
}
if rule.FromIpAddress != "" || rule.FromNetwork != "" ||
rule.ToIpAddress != "" || rule.ToNetwork != "" {
log.Errorf("rule: %+v is invalid for ACI mode", rule)
errStr := fmt.Sprintf("rule %s is invalid, only From/ToEndpointGroup may be specified in ACI mode", ruleName)
return errors.New(errStr)
}
if rule.Action == "deny" {
log.Debugf("==Ignoring deny rule %v", ruleName)
continue
}
filter := filterInfo{Protocol: rule.Protocol, ServPort: strconv.Itoa(rule.Port)}
cn := getContractName(policy.PolicyName, rule.FromEndpointGroup,
rule.ToEndpointGroup)
spec, found := csMap[cn]
if !found {
// add a link for this contract
lKind := cProvide
if rule.ToEndpointGroup != "" {
lKind = cConsume
}
cLink := contrLink{LinkKind: lKind,
ContractName: cn,
ContractKind: cInternal,
}
epg.ContractLinks = append(epg.ContractLinks, cLink)
spec = &contrSpec{Name: cn}
csMap[cn] = spec
}
spec.Filters = append(spec.Filters, filter)
}
return nil
} | [
"func",
"addPolicyContracts",
"(",
"csMap",
"map",
"[",
"string",
"]",
"*",
"contrSpec",
",",
"epg",
"*",
"epgSpec",
",",
"policy",
"*",
"contivModel",
".",
"Policy",
")",
"error",
"{",
"for",
"ruleName",
":=",
"range",
"policy",
".",
"LinkSets",
".",
"Rules",
"{",
"rule",
":=",
"contivModel",
".",
"FindRule",
"(",
"ruleName",
")",
"\n",
"if",
"rule",
"==",
"nil",
"{",
"errStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ruleName",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"errStr",
")",
"\n",
"}",
"\n\n",
"if",
"rule",
".",
"FromIpAddress",
"!=",
"\"",
"\"",
"||",
"rule",
".",
"FromNetwork",
"!=",
"\"",
"\"",
"||",
"rule",
".",
"ToIpAddress",
"!=",
"\"",
"\"",
"||",
"rule",
".",
"ToNetwork",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rule",
")",
"\n",
"errStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ruleName",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"errStr",
")",
"\n",
"}",
"\n\n",
"if",
"rule",
".",
"Action",
"==",
"\"",
"\"",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"ruleName",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"filter",
":=",
"filterInfo",
"{",
"Protocol",
":",
"rule",
".",
"Protocol",
",",
"ServPort",
":",
"strconv",
".",
"Itoa",
"(",
"rule",
".",
"Port",
")",
"}",
"\n",
"cn",
":=",
"getContractName",
"(",
"policy",
".",
"PolicyName",
",",
"rule",
".",
"FromEndpointGroup",
",",
"rule",
".",
"ToEndpointGroup",
")",
"\n",
"spec",
",",
"found",
":=",
"csMap",
"[",
"cn",
"]",
"\n",
"if",
"!",
"found",
"{",
"// add a link for this contract",
"lKind",
":=",
"cProvide",
"\n",
"if",
"rule",
".",
"ToEndpointGroup",
"!=",
"\"",
"\"",
"{",
"lKind",
"=",
"cConsume",
"\n",
"}",
"\n",
"cLink",
":=",
"contrLink",
"{",
"LinkKind",
":",
"lKind",
",",
"ContractName",
":",
"cn",
",",
"ContractKind",
":",
"cInternal",
",",
"}",
"\n",
"epg",
".",
"ContractLinks",
"=",
"append",
"(",
"epg",
".",
"ContractLinks",
",",
"cLink",
")",
"\n\n",
"spec",
"=",
"&",
"contrSpec",
"{",
"Name",
":",
"cn",
"}",
"\n",
"csMap",
"[",
"cn",
"]",
"=",
"spec",
"\n",
"}",
"\n",
"spec",
".",
"Filters",
"=",
"append",
"(",
"spec",
".",
"Filters",
",",
"filter",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // addPolicyContracts adds contracts defined by attached policy
// additionally, it adds contract links from this epg to those contracts | [
"addPolicyContracts",
"adds",
"contracts",
"defined",
"by",
"attached",
"policy",
"additionally",
"it",
"adds",
"contract",
"links",
"from",
"this",
"epg",
"to",
"those",
"contracts"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/infraproxy.go#L191-L235 |
8,019 | contiv/netplugin | netmaster/objApi/infraproxy.go | CreateAppNw | func CreateAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
// Get the state driver
stateDriver, uErr := utils.GetStateDriver()
if uErr != nil {
return uErr
}
eMap := &epgMap{}
eMap.Specs = make(map[string]epgSpec)
eMap.Contracts = make(map[string]*contrSpec)
ans := &appNwSpec{}
ans.ACIGwAPIVersion = aciGwAPIVersion
gwConfig := contivModel.FindAciGw("aciGw")
if gwConfig == nil {
log.Infof("aciGw object not found -- gw will use env settings")
} else {
ans.GWConfig = gwConfig
log.Infof("gwConfig: %+v", gwConfig)
}
ans.TenantName = app.TenantName
ans.AppName = app.AppProfileName
// Gather all basic epg info into the epg map
for epgKey := range app.LinkSets.EndpointGroups {
epgObj := contivModel.FindEndpointGroup(epgKey)
if epgObj == nil {
err := fmt.Sprintf("Epg %v does not exist", epgKey)
log.Errorf("%v", err)
return errors.New(err)
}
if err := appendEpgInfo(eMap, epgObj, stateDriver); err != nil {
log.Errorf("Error getting epg info %v", err)
return err
}
}
// walk the map and add to ANS
for _, epg := range eMap.Specs {
ans.Epgs = append(ans.Epgs, epg)
log.Debugf("Added epg %v", epg.Name)
}
for _, contract := range eMap.Contracts {
ans.ContractDefs = append(ans.ContractDefs, *contract)
log.Debugf("Added contract %v", contract.Name)
}
log.Infof("Launching appNwSpec: %+v", ans)
lErr := ans.launch()
time.Sleep(2 * time.Second)
ans.notifyDP()
return lErr
} | go | func CreateAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
// Get the state driver
stateDriver, uErr := utils.GetStateDriver()
if uErr != nil {
return uErr
}
eMap := &epgMap{}
eMap.Specs = make(map[string]epgSpec)
eMap.Contracts = make(map[string]*contrSpec)
ans := &appNwSpec{}
ans.ACIGwAPIVersion = aciGwAPIVersion
gwConfig := contivModel.FindAciGw("aciGw")
if gwConfig == nil {
log.Infof("aciGw object not found -- gw will use env settings")
} else {
ans.GWConfig = gwConfig
log.Infof("gwConfig: %+v", gwConfig)
}
ans.TenantName = app.TenantName
ans.AppName = app.AppProfileName
// Gather all basic epg info into the epg map
for epgKey := range app.LinkSets.EndpointGroups {
epgObj := contivModel.FindEndpointGroup(epgKey)
if epgObj == nil {
err := fmt.Sprintf("Epg %v does not exist", epgKey)
log.Errorf("%v", err)
return errors.New(err)
}
if err := appendEpgInfo(eMap, epgObj, stateDriver); err != nil {
log.Errorf("Error getting epg info %v", err)
return err
}
}
// walk the map and add to ANS
for _, epg := range eMap.Specs {
ans.Epgs = append(ans.Epgs, epg)
log.Debugf("Added epg %v", epg.Name)
}
for _, contract := range eMap.Contracts {
ans.ContractDefs = append(ans.ContractDefs, *contract)
log.Debugf("Added contract %v", contract.Name)
}
log.Infof("Launching appNwSpec: %+v", ans)
lErr := ans.launch()
time.Sleep(2 * time.Second)
ans.notifyDP()
return lErr
} | [
"func",
"CreateAppNw",
"(",
"app",
"*",
"contivModel",
".",
"AppProfile",
")",
"error",
"{",
"aciPresent",
",",
"aErr",
":=",
"master",
".",
"IsAciConfigured",
"(",
")",
"\n",
"if",
"aErr",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aErr",
")",
"\n",
"return",
"aErr",
"\n",
"}",
"\n\n",
"if",
"!",
"aciPresent",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"uErr",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"uErr",
"!=",
"nil",
"{",
"return",
"uErr",
"\n",
"}",
"\n\n",
"eMap",
":=",
"&",
"epgMap",
"{",
"}",
"\n",
"eMap",
".",
"Specs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"epgSpec",
")",
"\n",
"eMap",
".",
"Contracts",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"contrSpec",
")",
"\n",
"ans",
":=",
"&",
"appNwSpec",
"{",
"}",
"\n\n",
"ans",
".",
"ACIGwAPIVersion",
"=",
"aciGwAPIVersion",
"\n",
"gwConfig",
":=",
"contivModel",
".",
"FindAciGw",
"(",
"\"",
"\"",
")",
"\n",
"if",
"gwConfig",
"==",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"ans",
".",
"GWConfig",
"=",
"gwConfig",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"gwConfig",
")",
"\n",
"}",
"\n",
"ans",
".",
"TenantName",
"=",
"app",
".",
"TenantName",
"\n",
"ans",
".",
"AppName",
"=",
"app",
".",
"AppProfileName",
"\n\n",
"// Gather all basic epg info into the epg map",
"for",
"epgKey",
":=",
"range",
"app",
".",
"LinkSets",
".",
"EndpointGroups",
"{",
"epgObj",
":=",
"contivModel",
".",
"FindEndpointGroup",
"(",
"epgKey",
")",
"\n",
"if",
"epgObj",
"==",
"nil",
"{",
"err",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"epgKey",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"appendEpgInfo",
"(",
"eMap",
",",
"epgObj",
",",
"stateDriver",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// walk the map and add to ANS",
"for",
"_",
",",
"epg",
":=",
"range",
"eMap",
".",
"Specs",
"{",
"ans",
".",
"Epgs",
"=",
"append",
"(",
"ans",
".",
"Epgs",
",",
"epg",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"epg",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"contract",
":=",
"range",
"eMap",
".",
"Contracts",
"{",
"ans",
".",
"ContractDefs",
"=",
"append",
"(",
"ans",
".",
"ContractDefs",
",",
"*",
"contract",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"contract",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ans",
")",
"\n",
"lErr",
":=",
"ans",
".",
"launch",
"(",
")",
"\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Second",
")",
"\n",
"ans",
".",
"notifyDP",
"(",
")",
"\n\n",
"return",
"lErr",
"\n",
"}"
]
| //CreateAppNw Fill in the Nw spec and launch the nw infra | [
"CreateAppNw",
"Fill",
"in",
"the",
"Nw",
"spec",
"and",
"launch",
"the",
"nw",
"infra"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/infraproxy.go#L342-L408 |
8,020 | contiv/netplugin | netmaster/objApi/infraproxy.go | DeleteAppNw | func DeleteAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
ans := &appNwSpec{}
ans.TenantName = app.TenantName
ans.AppName = app.AppProfileName
url := proxyURL + "deleteAppProf"
resp, err := httpPost(url, ans)
if err != nil {
log.Errorf("Delete failed. Error: %v", err)
return err
}
if resp.Result != "success" {
log.Errorf("Delete failed %v - %v", resp.Result, resp.Info)
}
time.Sleep(time.Second)
return nil
} | go | func DeleteAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
ans := &appNwSpec{}
ans.TenantName = app.TenantName
ans.AppName = app.AppProfileName
url := proxyURL + "deleteAppProf"
resp, err := httpPost(url, ans)
if err != nil {
log.Errorf("Delete failed. Error: %v", err)
return err
}
if resp.Result != "success" {
log.Errorf("Delete failed %v - %v", resp.Result, resp.Info)
}
time.Sleep(time.Second)
return nil
} | [
"func",
"DeleteAppNw",
"(",
"app",
"*",
"contivModel",
".",
"AppProfile",
")",
"error",
"{",
"aciPresent",
",",
"aErr",
":=",
"master",
".",
"IsAciConfigured",
"(",
")",
"\n",
"if",
"aErr",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aErr",
")",
"\n",
"return",
"aErr",
"\n",
"}",
"\n\n",
"if",
"!",
"aciPresent",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"ans",
":=",
"&",
"appNwSpec",
"{",
"}",
"\n",
"ans",
".",
"TenantName",
"=",
"app",
".",
"TenantName",
"\n",
"ans",
".",
"AppName",
"=",
"app",
".",
"AppProfileName",
"\n\n",
"url",
":=",
"proxyURL",
"+",
"\"",
"\"",
"\n",
"resp",
",",
"err",
":=",
"httpPost",
"(",
"url",
",",
"ans",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"Result",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Result",
",",
"resp",
".",
"Info",
")",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| //DeleteAppNw deletes the app profile from infra | [
"DeleteAppNw",
"deletes",
"the",
"app",
"profile",
"from",
"infra"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/infraproxy.go#L411-L440 |
8,021 | contiv/netplugin | objdb/consulLock.go | NewLock | func (cp *ConsulClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error) {
// Create a lock
return &consulLock{
name: name,
keyName: "contiv.io/lock/" + name,
myID: myID,
ttl: fmt.Sprintf("%ds", ttl),
eventChan: make(chan LockEvent, 1),
stopChan: make(chan struct{}, 1),
mutex: new(sync.Mutex),
client: cp.client,
}, nil
} | go | func (cp *ConsulClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error) {
// Create a lock
return &consulLock{
name: name,
keyName: "contiv.io/lock/" + name,
myID: myID,
ttl: fmt.Sprintf("%ds", ttl),
eventChan: make(chan LockEvent, 1),
stopChan: make(chan struct{}, 1),
mutex: new(sync.Mutex),
client: cp.client,
}, nil
} | [
"func",
"(",
"cp",
"*",
"ConsulClient",
")",
"NewLock",
"(",
"name",
"string",
",",
"myID",
"string",
",",
"ttl",
"uint64",
")",
"(",
"LockInterface",
",",
"error",
")",
"{",
"// Create a lock",
"return",
"&",
"consulLock",
"{",
"name",
":",
"name",
",",
"keyName",
":",
"\"",
"\"",
"+",
"name",
",",
"myID",
":",
"myID",
",",
"ttl",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ttl",
")",
",",
"eventChan",
":",
"make",
"(",
"chan",
"LockEvent",
",",
"1",
")",
",",
"stopChan",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
",",
"mutex",
":",
"new",
"(",
"sync",
".",
"Mutex",
")",
",",
"client",
":",
"cp",
".",
"client",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewLock returns a new lock instance | [
"NewLock",
"returns",
"a",
"new",
"lock",
"instance"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulLock.go#L43-L55 |
8,022 | contiv/netplugin | objdb/consulLock.go | IsReleased | func (lk *consulLock) IsReleased() bool {
lk.mutex.Lock()
defer lk.mutex.Unlock()
return lk.isReleased
} | go | func (lk *consulLock) IsReleased() bool {
lk.mutex.Lock()
defer lk.mutex.Unlock()
return lk.isReleased
} | [
"func",
"(",
"lk",
"*",
"consulLock",
")",
"IsReleased",
"(",
")",
"bool",
"{",
"lk",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lk",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"lk",
".",
"isReleased",
"\n",
"}"
]
| // IsReleased Checks if the lock is released | [
"IsReleased",
"Checks",
"if",
"the",
"lock",
"is",
"released"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulLock.go#L151-L155 |
8,023 | contiv/netplugin | objdb/consulLock.go | createSession | func (lk *consulLock) createSession() error {
// session configuration
sessCfg := api.SessionEntry{
Name: lk.keyName,
Behavior: "delete",
LockDelay: 10 * time.Millisecond,
TTL: lk.ttl,
}
// Create consul session
sessionID, _, err := lk.client.Session().CreateNoChecks(&sessCfg, nil)
if err != nil {
log.Errorf("Error Creating session for lock %s. Err: %v", lk.keyName, err)
return err
}
log.Infof("Created session: %s for lock %s/%s", sessionID, lk.name, lk.myID)
// save the session ID for later
lk.mutex.Lock()
lk.sessionID = sessionID
lk.mutex.Unlock()
return nil
} | go | func (lk *consulLock) createSession() error {
// session configuration
sessCfg := api.SessionEntry{
Name: lk.keyName,
Behavior: "delete",
LockDelay: 10 * time.Millisecond,
TTL: lk.ttl,
}
// Create consul session
sessionID, _, err := lk.client.Session().CreateNoChecks(&sessCfg, nil)
if err != nil {
log.Errorf("Error Creating session for lock %s. Err: %v", lk.keyName, err)
return err
}
log.Infof("Created session: %s for lock %s/%s", sessionID, lk.name, lk.myID)
// save the session ID for later
lk.mutex.Lock()
lk.sessionID = sessionID
lk.mutex.Unlock()
return nil
} | [
"func",
"(",
"lk",
"*",
"consulLock",
")",
"createSession",
"(",
")",
"error",
"{",
"// session configuration",
"sessCfg",
":=",
"api",
".",
"SessionEntry",
"{",
"Name",
":",
"lk",
".",
"keyName",
",",
"Behavior",
":",
"\"",
"\"",
",",
"LockDelay",
":",
"10",
"*",
"time",
".",
"Millisecond",
",",
"TTL",
":",
"lk",
".",
"ttl",
",",
"}",
"\n\n",
"// Create consul session",
"sessionID",
",",
"_",
",",
"err",
":=",
"lk",
".",
"client",
".",
"Session",
"(",
")",
".",
"CreateNoChecks",
"(",
"&",
"sessCfg",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lk",
".",
"keyName",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"sessionID",
",",
"lk",
".",
"name",
",",
"lk",
".",
"myID",
")",
"\n\n",
"// save the session ID for later",
"lk",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"lk",
".",
"sessionID",
"=",
"sessionID",
"\n",
"lk",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // createSession creates a consul-session for the lock | [
"createSession",
"creates",
"a",
"consul",
"-",
"session",
"for",
"the",
"lock"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulLock.go#L256-L280 |
8,024 | contiv/netplugin | objdb/consulLock.go | renewSession | func (lk *consulLock) renewSession() {
for {
err := lk.client.Session().RenewPeriodic(lk.ttl, lk.sessionID, nil, lk.stopChan)
if err == nil || lk.IsReleased() {
// If lock was released, exit this go routine
return
}
// Create new consul session
err = lk.createSession()
if err != nil {
log.Errorf("Error Creating session for lock %s. Err: %v", lk.keyName, err)
}
}
} | go | func (lk *consulLock) renewSession() {
for {
err := lk.client.Session().RenewPeriodic(lk.ttl, lk.sessionID, nil, lk.stopChan)
if err == nil || lk.IsReleased() {
// If lock was released, exit this go routine
return
}
// Create new consul session
err = lk.createSession()
if err != nil {
log.Errorf("Error Creating session for lock %s. Err: %v", lk.keyName, err)
}
}
} | [
"func",
"(",
"lk",
"*",
"consulLock",
")",
"renewSession",
"(",
")",
"{",
"for",
"{",
"err",
":=",
"lk",
".",
"client",
".",
"Session",
"(",
")",
".",
"RenewPeriodic",
"(",
"lk",
".",
"ttl",
",",
"lk",
".",
"sessionID",
",",
"nil",
",",
"lk",
".",
"stopChan",
")",
"\n",
"if",
"err",
"==",
"nil",
"||",
"lk",
".",
"IsReleased",
"(",
")",
"{",
"// If lock was released, exit this go routine",
"return",
"\n",
"}",
"\n\n",
"// Create new consul session",
"err",
"=",
"lk",
".",
"createSession",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lk",
".",
"keyName",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"}"
]
| // renewSession keeps the session alive.. If a session expires, it creates new one.. | [
"renewSession",
"keeps",
"the",
"session",
"alive",
"..",
"If",
"a",
"session",
"expires",
"it",
"creates",
"new",
"one",
".."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulLock.go#L283-L298 |
8,025 | contiv/netplugin | utils/stateutils.go | GetEndpoint | func GetEndpoint(epID string) (*drivers.OperEndpointState, error) {
// Get hold of the state driver
stateDriver, err := GetStateDriver()
if err != nil {
return nil, err
}
operEp := &drivers.OperEndpointState{}
operEp.StateDriver = stateDriver
err = operEp.Read(epID)
if err != nil {
return nil, err
}
return operEp, nil
} | go | func GetEndpoint(epID string) (*drivers.OperEndpointState, error) {
// Get hold of the state driver
stateDriver, err := GetStateDriver()
if err != nil {
return nil, err
}
operEp := &drivers.OperEndpointState{}
operEp.StateDriver = stateDriver
err = operEp.Read(epID)
if err != nil {
return nil, err
}
return operEp, nil
} | [
"func",
"GetEndpoint",
"(",
"epID",
"string",
")",
"(",
"*",
"drivers",
".",
"OperEndpointState",
",",
"error",
")",
"{",
"// Get hold of the state driver",
"stateDriver",
",",
"err",
":=",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"operEp",
":=",
"&",
"drivers",
".",
"OperEndpointState",
"{",
"}",
"\n",
"operEp",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"operEp",
".",
"Read",
"(",
"epID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"operEp",
",",
"nil",
"\n",
"}"
]
| // GetEndpoint is a utility that reads the EP oper state | [
"GetEndpoint",
"is",
"a",
"utility",
"that",
"reads",
"the",
"EP",
"oper",
"state"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/stateutils.go#L9-L24 |
8,026 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | NewOvsdbDriver | func NewOvsdbDriver(bridgeName string, failMode string, vxlanUDPPort int) (*OvsdbDriver, error) {
// Create a new driver instance
d := new(OvsdbDriver)
d.bridgeName = bridgeName
d.vxlanUDPPort = fmt.Sprintf("%d", vxlanUDPPort)
// Connect to OVS
ovs, err := libovsdb.ConnectUnix("")
if err != nil {
log.Fatalf("Error connecting to OVS. Err: %v", err)
return nil, err
}
d.ovs = ovs
// Initialize the cache
d.cache = make(map[string]map[libovsdb.UUID]libovsdb.Row)
d.ovs.Register(d)
initial, _ := d.ovs.MonitorAll(ovsDataBase, "")
d.populateCache(*initial)
// Create a bridge after registering for events as we depend on ovsdb cache.
// Since the same dirver is used as endpoint driver, only create the bridge
// if it's not already created
// XXX: revisit if the bridge-name needs to be configurable
brCreated := false
for _, row := range d.cache[bridgeTable] {
if row.Fields["name"] == bridgeName {
brCreated = true
break
}
}
if !brCreated {
err = d.createDeleteBridge(bridgeName, failMode, operCreateBridge)
if err != nil {
log.Fatalf("Error creating bridge %s. Err: %v", bridgeName, err)
return nil, err
}
}
return d, nil
} | go | func NewOvsdbDriver(bridgeName string, failMode string, vxlanUDPPort int) (*OvsdbDriver, error) {
// Create a new driver instance
d := new(OvsdbDriver)
d.bridgeName = bridgeName
d.vxlanUDPPort = fmt.Sprintf("%d", vxlanUDPPort)
// Connect to OVS
ovs, err := libovsdb.ConnectUnix("")
if err != nil {
log.Fatalf("Error connecting to OVS. Err: %v", err)
return nil, err
}
d.ovs = ovs
// Initialize the cache
d.cache = make(map[string]map[libovsdb.UUID]libovsdb.Row)
d.ovs.Register(d)
initial, _ := d.ovs.MonitorAll(ovsDataBase, "")
d.populateCache(*initial)
// Create a bridge after registering for events as we depend on ovsdb cache.
// Since the same dirver is used as endpoint driver, only create the bridge
// if it's not already created
// XXX: revisit if the bridge-name needs to be configurable
brCreated := false
for _, row := range d.cache[bridgeTable] {
if row.Fields["name"] == bridgeName {
brCreated = true
break
}
}
if !brCreated {
err = d.createDeleteBridge(bridgeName, failMode, operCreateBridge)
if err != nil {
log.Fatalf("Error creating bridge %s. Err: %v", bridgeName, err)
return nil, err
}
}
return d, nil
} | [
"func",
"NewOvsdbDriver",
"(",
"bridgeName",
"string",
",",
"failMode",
"string",
",",
"vxlanUDPPort",
"int",
")",
"(",
"*",
"OvsdbDriver",
",",
"error",
")",
"{",
"// Create a new driver instance",
"d",
":=",
"new",
"(",
"OvsdbDriver",
")",
"\n",
"d",
".",
"bridgeName",
"=",
"bridgeName",
"\n",
"d",
".",
"vxlanUDPPort",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"vxlanUDPPort",
")",
"\n\n",
"// Connect to OVS",
"ovs",
",",
"err",
":=",
"libovsdb",
".",
"ConnectUnix",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"d",
".",
"ovs",
"=",
"ovs",
"\n\n",
"// Initialize the cache",
"d",
".",
"cache",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"libovsdb",
".",
"UUID",
"]",
"libovsdb",
".",
"Row",
")",
"\n",
"d",
".",
"ovs",
".",
"Register",
"(",
"d",
")",
"\n",
"initial",
",",
"_",
":=",
"d",
".",
"ovs",
".",
"MonitorAll",
"(",
"ovsDataBase",
",",
"\"",
"\"",
")",
"\n",
"d",
".",
"populateCache",
"(",
"*",
"initial",
")",
"\n\n",
"// Create a bridge after registering for events as we depend on ovsdb cache.",
"// Since the same dirver is used as endpoint driver, only create the bridge",
"// if it's not already created",
"// XXX: revisit if the bridge-name needs to be configurable",
"brCreated",
":=",
"false",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"bridgeTable",
"]",
"{",
"if",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"==",
"bridgeName",
"{",
"brCreated",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"brCreated",
"{",
"err",
"=",
"d",
".",
"createDeleteBridge",
"(",
"bridgeName",
",",
"failMode",
",",
"operCreateBridge",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"bridgeName",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"d",
",",
"nil",
"\n",
"}"
]
| // NewOvsdbDriver creates a new OVSDB driver instance.
// Create one ovsdb driver instance per OVS bridge that needs to be managed | [
"NewOvsdbDriver",
"creates",
"a",
"new",
"OVSDB",
"driver",
"instance",
".",
"Create",
"one",
"ovsdb",
"driver",
"instance",
"per",
"OVS",
"bridge",
"that",
"needs",
"to",
"be",
"managed"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L49-L91 |
8,027 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | Update | func (d *OvsdbDriver) Update(context interface{}, tableUpdates libovsdb.TableUpdates) {
d.populateCache(tableUpdates)
intfUpds, ok := tableUpdates.Updates["Interface"]
if !ok {
return
}
for _, intfUpd := range intfUpds.Rows {
intf := intfUpd.New.Fields["name"]
oldLacpStatus, ok := intfUpd.Old.Fields["lacp_current"]
if !ok {
return
}
newLacpStatus, ok := intfUpd.New.Fields["lacp_current"]
if !ok {
return
}
if oldLacpStatus == newLacpStatus || d.ovsSwitch == nil {
return
}
linkUpd := ofnet.LinkUpdateInfo{
LinkName: intf.(string),
LacpStatus: newLacpStatus.(bool),
}
log.Debugf("LACP_UPD: Interface: %+v. LACP Status - (Old: %+v, New: %+v)\n", intf, oldLacpStatus, newLacpStatus)
d.ovsSwitch.HandleLinkUpdates(linkUpd)
}
} | go | func (d *OvsdbDriver) Update(context interface{}, tableUpdates libovsdb.TableUpdates) {
d.populateCache(tableUpdates)
intfUpds, ok := tableUpdates.Updates["Interface"]
if !ok {
return
}
for _, intfUpd := range intfUpds.Rows {
intf := intfUpd.New.Fields["name"]
oldLacpStatus, ok := intfUpd.Old.Fields["lacp_current"]
if !ok {
return
}
newLacpStatus, ok := intfUpd.New.Fields["lacp_current"]
if !ok {
return
}
if oldLacpStatus == newLacpStatus || d.ovsSwitch == nil {
return
}
linkUpd := ofnet.LinkUpdateInfo{
LinkName: intf.(string),
LacpStatus: newLacpStatus.(bool),
}
log.Debugf("LACP_UPD: Interface: %+v. LACP Status - (Old: %+v, New: %+v)\n", intf, oldLacpStatus, newLacpStatus)
d.ovsSwitch.HandleLinkUpdates(linkUpd)
}
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"Update",
"(",
"context",
"interface",
"{",
"}",
",",
"tableUpdates",
"libovsdb",
".",
"TableUpdates",
")",
"{",
"d",
".",
"populateCache",
"(",
"tableUpdates",
")",
"\n",
"intfUpds",
",",
"ok",
":=",
"tableUpdates",
".",
"Updates",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"intfUpd",
":=",
"range",
"intfUpds",
".",
"Rows",
"{",
"intf",
":=",
"intfUpd",
".",
"New",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"oldLacpStatus",
",",
"ok",
":=",
"intfUpd",
".",
"Old",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"newLacpStatus",
",",
"ok",
":=",
"intfUpd",
".",
"New",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"oldLacpStatus",
"==",
"newLacpStatus",
"||",
"d",
".",
"ovsSwitch",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"linkUpd",
":=",
"ofnet",
".",
"LinkUpdateInfo",
"{",
"LinkName",
":",
"intf",
".",
"(",
"string",
")",
",",
"LacpStatus",
":",
"newLacpStatus",
".",
"(",
"bool",
")",
",",
"}",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"intf",
",",
"oldLacpStatus",
",",
"newLacpStatus",
")",
"\n",
"d",
".",
"ovsSwitch",
".",
"HandleLinkUpdates",
"(",
"linkUpd",
")",
"\n",
"}",
"\n",
"}"
]
| // Update updates the ovsdb with the libovsdb.TableUpdates. | [
"Update",
"updates",
"the",
"ovsdb",
"with",
"the",
"libovsdb",
".",
"TableUpdates",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L142-L170 |
8,028 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | createDeleteBridge | func (d *OvsdbDriver) createDeleteBridge(bridgeName, failMode string, op oper) error {
namedUUIDStr := "netplugin"
brUUID := []libovsdb.UUID{{GoUuid: namedUUIDStr}}
protocols := []string{"OpenFlow10", "OpenFlow11", "OpenFlow12", "OpenFlow13"}
opStr := "insert"
if op != operCreateBridge {
opStr = "delete"
}
// simple insert/delete operation
brOp := libovsdb.Operation{}
if op == operCreateBridge {
bridge := make(map[string]interface{})
bridge["name"] = bridgeName
// Enable Openflow1.3
bridge["protocols"], _ = libovsdb.NewOvsSet(protocols)
// set fail-mode if required
if failMode != "" {
bridge["fail_mode"] = "secure"
}
brOp = libovsdb.Operation{
Op: opStr,
Table: bridgeTable,
Row: bridge,
UUIDName: namedUUIDStr,
}
} else {
condition := libovsdb.NewCondition("name", "==", bridgeName)
brOp = libovsdb.Operation{
Op: opStr,
Table: bridgeTable,
Where: []interface{}{condition},
}
// also fetch the br-uuid from cache
for uuid, row := range d.cache[bridgeTable] {
name := row.Fields["name"].(string)
if name == bridgeName {
brUUID = []libovsdb.UUID{uuid}
break
}
}
}
// Inserting/Deleting a Bridge row in Bridge table requires mutating
// the open_vswitch table.
mutateUUID := brUUID
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("bridges", opStr, mutateSet)
condition := libovsdb.NewCondition("_uuid", "==", d.getRootUUID())
// simple mutate operation
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: rootTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{brOp, mutateOp}
return d.performOvsdbOps(operations)
} | go | func (d *OvsdbDriver) createDeleteBridge(bridgeName, failMode string, op oper) error {
namedUUIDStr := "netplugin"
brUUID := []libovsdb.UUID{{GoUuid: namedUUIDStr}}
protocols := []string{"OpenFlow10", "OpenFlow11", "OpenFlow12", "OpenFlow13"}
opStr := "insert"
if op != operCreateBridge {
opStr = "delete"
}
// simple insert/delete operation
brOp := libovsdb.Operation{}
if op == operCreateBridge {
bridge := make(map[string]interface{})
bridge["name"] = bridgeName
// Enable Openflow1.3
bridge["protocols"], _ = libovsdb.NewOvsSet(protocols)
// set fail-mode if required
if failMode != "" {
bridge["fail_mode"] = "secure"
}
brOp = libovsdb.Operation{
Op: opStr,
Table: bridgeTable,
Row: bridge,
UUIDName: namedUUIDStr,
}
} else {
condition := libovsdb.NewCondition("name", "==", bridgeName)
brOp = libovsdb.Operation{
Op: opStr,
Table: bridgeTable,
Where: []interface{}{condition},
}
// also fetch the br-uuid from cache
for uuid, row := range d.cache[bridgeTable] {
name := row.Fields["name"].(string)
if name == bridgeName {
brUUID = []libovsdb.UUID{uuid}
break
}
}
}
// Inserting/Deleting a Bridge row in Bridge table requires mutating
// the open_vswitch table.
mutateUUID := brUUID
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("bridges", opStr, mutateSet)
condition := libovsdb.NewCondition("_uuid", "==", d.getRootUUID())
// simple mutate operation
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: rootTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{brOp, mutateOp}
return d.performOvsdbOps(operations)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"createDeleteBridge",
"(",
"bridgeName",
",",
"failMode",
"string",
",",
"op",
"oper",
")",
"error",
"{",
"namedUUIDStr",
":=",
"\"",
"\"",
"\n",
"brUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"namedUUIDStr",
"}",
"}",
"\n",
"protocols",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"opStr",
":=",
"\"",
"\"",
"\n",
"if",
"op",
"!=",
"operCreateBridge",
"{",
"opStr",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// simple insert/delete operation",
"brOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"}",
"\n",
"if",
"op",
"==",
"operCreateBridge",
"{",
"bridge",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"bridge",
"[",
"\"",
"\"",
"]",
"=",
"bridgeName",
"\n\n",
"// Enable Openflow1.3",
"bridge",
"[",
"\"",
"\"",
"]",
",",
"_",
"=",
"libovsdb",
".",
"NewOvsSet",
"(",
"protocols",
")",
"\n\n",
"// set fail-mode if required",
"if",
"failMode",
"!=",
"\"",
"\"",
"{",
"bridge",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"brOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"bridgeTable",
",",
"Row",
":",
"bridge",
",",
"UUIDName",
":",
"namedUUIDStr",
",",
"}",
"\n",
"}",
"else",
"{",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"bridgeName",
")",
"\n",
"brOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"bridgeTable",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n",
"// also fetch the br-uuid from cache",
"for",
"uuid",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"bridgeTable",
"]",
"{",
"name",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"name",
"==",
"bridgeName",
"{",
"brUUID",
"=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"uuid",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Inserting/Deleting a Bridge row in Bridge table requires mutating",
"// the open_vswitch table.",
"mutateUUID",
":=",
"brUUID",
"\n",
"mutateSet",
",",
"_",
":=",
"libovsdb",
".",
"NewOvsSet",
"(",
"mutateUUID",
")",
"\n",
"mutation",
":=",
"libovsdb",
".",
"NewMutation",
"(",
"\"",
"\"",
",",
"opStr",
",",
"mutateSet",
")",
"\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"d",
".",
"getRootUUID",
"(",
")",
")",
"\n\n",
"// simple mutate operation",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"rootTable",
",",
"Mutations",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"mutation",
"}",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n\n",
"operations",
":=",
"[",
"]",
"libovsdb",
".",
"Operation",
"{",
"brOp",
",",
"mutateOp",
"}",
"\n",
"return",
"d",
".",
"performOvsdbOps",
"(",
"operations",
")",
"\n",
"}"
]
| // Create or delete an OVS bridge instance | [
"Create",
"or",
"delete",
"an",
"OVS",
"bridge",
"instance"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L212-L275 |
8,029 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | GetPortOrIntfNameFromID | func (d *OvsdbDriver) GetPortOrIntfNameFromID(id string, isPort bool) (string, error) {
table := portTable
if !isPort {
table = interfaceTable
}
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk thru all ports
for _, row := range d.cache[table] {
if extIDs, ok := row.Fields["external_ids"]; ok {
extIDMap := extIDs.(libovsdb.OvsMap).GoMap
if portID, ok := extIDMap["endpoint-id"]; ok && portID == id {
return row.Fields["name"].(string), nil
}
}
}
return "", core.Errorf("Ovs port/intf not found for id: %s", id)
} | go | func (d *OvsdbDriver) GetPortOrIntfNameFromID(id string, isPort bool) (string, error) {
table := portTable
if !isPort {
table = interfaceTable
}
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk thru all ports
for _, row := range d.cache[table] {
if extIDs, ok := row.Fields["external_ids"]; ok {
extIDMap := extIDs.(libovsdb.OvsMap).GoMap
if portID, ok := extIDMap["endpoint-id"]; ok && portID == id {
return row.Fields["name"].(string), nil
}
}
}
return "", core.Errorf("Ovs port/intf not found for id: %s", id)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"GetPortOrIntfNameFromID",
"(",
"id",
"string",
",",
"isPort",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"table",
":=",
"portTable",
"\n",
"if",
"!",
"isPort",
"{",
"table",
"=",
"interfaceTable",
"\n",
"}",
"\n\n",
"d",
".",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"// walk thru all ports",
"for",
"_",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"table",
"]",
"{",
"if",
"extIDs",
",",
"ok",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"extIDMap",
":=",
"extIDs",
".",
"(",
"libovsdb",
".",
"OvsMap",
")",
".",
"GoMap",
"\n",
"if",
"portID",
",",
"ok",
":=",
"extIDMap",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"portID",
"==",
"id",
"{",
"return",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}"
]
| // GetPortOrIntfNameFromID gets interface name from id | [
"GetPortOrIntfNameFromID",
"gets",
"interface",
"name",
"from",
"id"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L278-L297 |
8,030 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | CreatePort | func (d *OvsdbDriver) CreatePort(intfName, intfType, id string, tag, burst int, bandwidth int64) error {
// intfName is assumed to be unique enough to become uuid
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
opStr := "insert"
var err error
// insert/delete a row in Interface table
idMap := make(map[string]string)
intfOp := libovsdb.Operation{}
intf := make(map[string]interface{})
intf["name"] = intfName
intf["type"] = intfType
if bandwidth != 0 {
intf["ingress_policing_rate"] = bandwidth
}
if burst != 0 {
intf["ingress_policing_burst"] = burst
}
idMap["endpoint-id"] = id
intf["external_ids"], err = libovsdb.NewOvsMap(idMap)
if err != nil {
return err
}
// interface table ops
intfOp = libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: intf,
UUIDName: intfUUIDStr,
}
// insert/delete a row in Port table
portOp := libovsdb.Operation{}
port := make(map[string]interface{})
port["name"] = intfName
if tag != 0 {
port["vlan_mode"] = "access"
port["tag"] = tag
} else {
port["vlan_mode"] = "trunk"
}
port["interfaces"], err = libovsdb.NewOvsSet(intfUUID)
if err != nil {
return err
}
port["external_ids"], err = libovsdb.NewOvsMap(idMap)
if err != nil {
return err
}
portOp = libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
return d.performOvsdbOps(operations)
} | go | func (d *OvsdbDriver) CreatePort(intfName, intfType, id string, tag, burst int, bandwidth int64) error {
// intfName is assumed to be unique enough to become uuid
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
opStr := "insert"
var err error
// insert/delete a row in Interface table
idMap := make(map[string]string)
intfOp := libovsdb.Operation{}
intf := make(map[string]interface{})
intf["name"] = intfName
intf["type"] = intfType
if bandwidth != 0 {
intf["ingress_policing_rate"] = bandwidth
}
if burst != 0 {
intf["ingress_policing_burst"] = burst
}
idMap["endpoint-id"] = id
intf["external_ids"], err = libovsdb.NewOvsMap(idMap)
if err != nil {
return err
}
// interface table ops
intfOp = libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: intf,
UUIDName: intfUUIDStr,
}
// insert/delete a row in Port table
portOp := libovsdb.Operation{}
port := make(map[string]interface{})
port["name"] = intfName
if tag != 0 {
port["vlan_mode"] = "access"
port["tag"] = tag
} else {
port["vlan_mode"] = "trunk"
}
port["interfaces"], err = libovsdb.NewOvsSet(intfUUID)
if err != nil {
return err
}
port["external_ids"], err = libovsdb.NewOvsMap(idMap)
if err != nil {
return err
}
portOp = libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
return d.performOvsdbOps(operations)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"CreatePort",
"(",
"intfName",
",",
"intfType",
",",
"id",
"string",
",",
"tag",
",",
"burst",
"int",
",",
"bandwidth",
"int64",
")",
"error",
"{",
"// intfName is assumed to be unique enough to become uuid",
"portUUIDStr",
":=",
"intfName",
"\n",
"intfUUIDStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"intfName",
")",
"\n",
"portUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"portUUIDStr",
"}",
"}",
"\n",
"intfUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"intfUUIDStr",
"}",
"}",
"\n",
"opStr",
":=",
"\"",
"\"",
"\n\n",
"var",
"err",
"error",
"\n\n",
"// insert/delete a row in Interface table",
"idMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"intfOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"}",
"\n",
"intf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"intfName",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"intfType",
"\n",
"if",
"bandwidth",
"!=",
"0",
"{",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"bandwidth",
"\n",
"}",
"\n",
"if",
"burst",
"!=",
"0",
"{",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"burst",
"\n",
"}",
"\n",
"idMap",
"[",
"\"",
"\"",
"]",
"=",
"id",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsMap",
"(",
"idMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// interface table ops",
"intfOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"interfaceTable",
",",
"Row",
":",
"intf",
",",
"UUIDName",
":",
"intfUUIDStr",
",",
"}",
"\n\n",
"// insert/delete a row in Port table",
"portOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"}",
"\n",
"port",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"intfName",
"\n",
"if",
"tag",
"!=",
"0",
"{",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"tag",
"\n",
"}",
"else",
"{",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"port",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsSet",
"(",
"intfUUID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"port",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsMap",
"(",
"idMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"portOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"portTable",
",",
"Row",
":",
"port",
",",
"UUIDName",
":",
"portUUIDStr",
",",
"}",
"\n\n",
"// mutate the Ports column of the row in the Bridge table",
"mutateSet",
",",
"_",
":=",
"libovsdb",
".",
"NewOvsSet",
"(",
"portUUID",
")",
"\n",
"mutation",
":=",
"libovsdb",
".",
"NewMutation",
"(",
"\"",
"\"",
",",
"opStr",
",",
"mutateSet",
")",
"\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"d",
".",
"bridgeName",
")",
"\n",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"bridgeTable",
",",
"Mutations",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"mutation",
"}",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n\n",
"operations",
":=",
"[",
"]",
"libovsdb",
".",
"Operation",
"{",
"intfOp",
",",
"portOp",
",",
"mutateOp",
"}",
"\n",
"return",
"d",
".",
"performOvsdbOps",
"(",
"operations",
")",
"\n",
"}"
]
| // CreatePort creates an OVS port | [
"CreatePort",
"creates",
"an",
"OVS",
"port"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L300-L374 |
8,031 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | GetInterfacesInPort | func (d *OvsdbDriver) GetInterfacesInPort(portName string) []string {
var intfList []string
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for _, row := range d.cache["Port"] {
name := row.Fields["name"].(string)
if name == portName {
// Port found
// Iterate over the list of interfaces
switch (row.Fields["interfaces"]).(type) {
case libovsdb.UUID: // Individual interface case
intfUUID := row.Fields["interfaces"].(libovsdb.UUID)
intfInfo := d.GetIntfInfo(intfUUID)
if reflect.DeepEqual(intfInfo, libovsdb.Row{}) {
log.Errorf("could not find interface with UUID: %+v", intfUUID)
break
}
intfList = append(intfList, intfInfo.Fields["name"].(string))
case libovsdb.OvsSet: // Port bond case
intfUUIDList := row.Fields["interfaces"].(libovsdb.OvsSet)
for _, intfUUID := range intfUUIDList.GoSet {
intfInfo := d.GetIntfInfo(intfUUID.(libovsdb.UUID))
if reflect.DeepEqual(intfInfo, libovsdb.Row{}) {
continue
}
intfList = append(intfList, intfInfo.Fields["name"].(string))
}
}
sort.Strings(intfList)
break
}
}
return intfList
} | go | func (d *OvsdbDriver) GetInterfacesInPort(portName string) []string {
var intfList []string
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for _, row := range d.cache["Port"] {
name := row.Fields["name"].(string)
if name == portName {
// Port found
// Iterate over the list of interfaces
switch (row.Fields["interfaces"]).(type) {
case libovsdb.UUID: // Individual interface case
intfUUID := row.Fields["interfaces"].(libovsdb.UUID)
intfInfo := d.GetIntfInfo(intfUUID)
if reflect.DeepEqual(intfInfo, libovsdb.Row{}) {
log.Errorf("could not find interface with UUID: %+v", intfUUID)
break
}
intfList = append(intfList, intfInfo.Fields["name"].(string))
case libovsdb.OvsSet: // Port bond case
intfUUIDList := row.Fields["interfaces"].(libovsdb.OvsSet)
for _, intfUUID := range intfUUIDList.GoSet {
intfInfo := d.GetIntfInfo(intfUUID.(libovsdb.UUID))
if reflect.DeepEqual(intfInfo, libovsdb.Row{}) {
continue
}
intfList = append(intfList, intfInfo.Fields["name"].(string))
}
}
sort.Strings(intfList)
break
}
}
return intfList
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"GetInterfacesInPort",
"(",
"portName",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"intfList",
"[",
"]",
"string",
"\n",
"d",
".",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"\"",
"\"",
"]",
"{",
"name",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"name",
"==",
"portName",
"{",
"// Port found",
"// Iterate over the list of interfaces",
"switch",
"(",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
")",
".",
"(",
"type",
")",
"{",
"case",
"libovsdb",
".",
"UUID",
":",
"// Individual interface case",
"intfUUID",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"libovsdb",
".",
"UUID",
")",
"\n",
"intfInfo",
":=",
"d",
".",
"GetIntfInfo",
"(",
"intfUUID",
")",
"\n",
"if",
"reflect",
".",
"DeepEqual",
"(",
"intfInfo",
",",
"libovsdb",
".",
"Row",
"{",
"}",
")",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"intfUUID",
")",
"\n",
"break",
"\n",
"}",
"\n",
"intfList",
"=",
"append",
"(",
"intfList",
",",
"intfInfo",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
")",
"\n",
"case",
"libovsdb",
".",
"OvsSet",
":",
"// Port bond case",
"intfUUIDList",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"libovsdb",
".",
"OvsSet",
")",
"\n",
"for",
"_",
",",
"intfUUID",
":=",
"range",
"intfUUIDList",
".",
"GoSet",
"{",
"intfInfo",
":=",
"d",
".",
"GetIntfInfo",
"(",
"intfUUID",
".",
"(",
"libovsdb",
".",
"UUID",
")",
")",
"\n",
"if",
"reflect",
".",
"DeepEqual",
"(",
"intfInfo",
",",
"libovsdb",
".",
"Row",
"{",
"}",
")",
"{",
"continue",
"\n",
"}",
"\n",
"intfList",
"=",
"append",
"(",
"intfList",
",",
"intfInfo",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"intfList",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"intfList",
"\n",
"}"
]
| // GetInterfacesInPort gets list of interfaces in a port in sorted order | [
"GetInterfacesInPort",
"gets",
"list",
"of",
"interfaces",
"in",
"a",
"port",
"in",
"sorted",
"order"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L377-L411 |
8,032 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | GetIntfInfo | func (d *OvsdbDriver) GetIntfInfo(uuid libovsdb.UUID) libovsdb.Row {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for intfUUID, row := range d.cache["Interface"] {
if intfUUID == uuid {
return row
}
}
return libovsdb.Row{}
} | go | func (d *OvsdbDriver) GetIntfInfo(uuid libovsdb.UUID) libovsdb.Row {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for intfUUID, row := range d.cache["Interface"] {
if intfUUID == uuid {
return row
}
}
return libovsdb.Row{}
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"GetIntfInfo",
"(",
"uuid",
"libovsdb",
".",
"UUID",
")",
"libovsdb",
".",
"Row",
"{",
"d",
".",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"intfUUID",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"\"",
"\"",
"]",
"{",
"if",
"intfUUID",
"==",
"uuid",
"{",
"return",
"row",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"libovsdb",
".",
"Row",
"{",
"}",
"\n",
"}"
]
| // GetIntfInfo gets interface information from "Interface" table | [
"GetIntfInfo",
"gets",
"interface",
"information",
"from",
"Interface",
"table"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L414-L425 |
8,033 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | CreatePortBond | func (d *OvsdbDriver) CreatePortBond(intfList []string, bondName string) error {
var err error
var ops []libovsdb.Operation
var intfUUIDList []libovsdb.UUID
opStr := "insert"
// Add all the interfaces to the interface table
for _, intf := range intfList {
intfUUIDStr := fmt.Sprintf("Intf%s", intf)
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
intfUUIDList = append(intfUUIDList, intfUUID...)
// insert/delete a row in Interface table
intfOp := libovsdb.Operation{}
iface := make(map[string]interface{})
iface["name"] = intf
// interface table ops
intfOp = libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: iface,
UUIDName: intfUUIDStr,
}
ops = append(ops, intfOp)
}
// Insert bond information in Port table
portOp := libovsdb.Operation{}
port := make(map[string]interface{})
port["name"] = bondName
port["vlan_mode"] = "trunk"
port["interfaces"], err = libovsdb.NewOvsSet(intfUUIDList)
if err != nil {
return err
}
// Set LACP and Hash properties
// "balance-tcp" - balances flows among slaves based on L2, L3, and L4 protocol information such as
// destination MAC address, IP address, and TCP port
// lacp-fallback-ab:true - Fall back to activ-backup mode when LACP negotiation fails
port["bond_mode"] = "balance-tcp"
port["lacp"] = "active"
lacpMap := make(map[string]string)
lacpMap["lacp-fallback-ab"] = "true"
port["other_config"], err = libovsdb.NewOvsMap(lacpMap)
portUUIDStr := bondName
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
portOp = libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
ops = append(ops, portOp)
// Mutate the Ports column of the row in the Bridge table to include bond name
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
ops = append(ops, mutateOp)
return d.performOvsdbOps(ops)
} | go | func (d *OvsdbDriver) CreatePortBond(intfList []string, bondName string) error {
var err error
var ops []libovsdb.Operation
var intfUUIDList []libovsdb.UUID
opStr := "insert"
// Add all the interfaces to the interface table
for _, intf := range intfList {
intfUUIDStr := fmt.Sprintf("Intf%s", intf)
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
intfUUIDList = append(intfUUIDList, intfUUID...)
// insert/delete a row in Interface table
intfOp := libovsdb.Operation{}
iface := make(map[string]interface{})
iface["name"] = intf
// interface table ops
intfOp = libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: iface,
UUIDName: intfUUIDStr,
}
ops = append(ops, intfOp)
}
// Insert bond information in Port table
portOp := libovsdb.Operation{}
port := make(map[string]interface{})
port["name"] = bondName
port["vlan_mode"] = "trunk"
port["interfaces"], err = libovsdb.NewOvsSet(intfUUIDList)
if err != nil {
return err
}
// Set LACP and Hash properties
// "balance-tcp" - balances flows among slaves based on L2, L3, and L4 protocol information such as
// destination MAC address, IP address, and TCP port
// lacp-fallback-ab:true - Fall back to activ-backup mode when LACP negotiation fails
port["bond_mode"] = "balance-tcp"
port["lacp"] = "active"
lacpMap := make(map[string]string)
lacpMap["lacp-fallback-ab"] = "true"
port["other_config"], err = libovsdb.NewOvsMap(lacpMap)
portUUIDStr := bondName
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
portOp = libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
ops = append(ops, portOp)
// Mutate the Ports column of the row in the Bridge table to include bond name
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
ops = append(ops, mutateOp)
return d.performOvsdbOps(ops)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"CreatePortBond",
"(",
"intfList",
"[",
"]",
"string",
",",
"bondName",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"ops",
"[",
"]",
"libovsdb",
".",
"Operation",
"\n",
"var",
"intfUUIDList",
"[",
"]",
"libovsdb",
".",
"UUID",
"\n",
"opStr",
":=",
"\"",
"\"",
"\n\n",
"// Add all the interfaces to the interface table",
"for",
"_",
",",
"intf",
":=",
"range",
"intfList",
"{",
"intfUUIDStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"intf",
")",
"\n",
"intfUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"intfUUIDStr",
"}",
"}",
"\n",
"intfUUIDList",
"=",
"append",
"(",
"intfUUIDList",
",",
"intfUUID",
"...",
")",
"\n\n",
"// insert/delete a row in Interface table",
"intfOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"}",
"\n",
"iface",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"iface",
"[",
"\"",
"\"",
"]",
"=",
"intf",
"\n\n",
"// interface table ops",
"intfOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"interfaceTable",
",",
"Row",
":",
"iface",
",",
"UUIDName",
":",
"intfUUIDStr",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"intfOp",
")",
"\n",
"}",
"\n\n",
"// Insert bond information in Port table",
"portOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"}",
"\n",
"port",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"bondName",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"port",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsSet",
"(",
"intfUUIDList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Set LACP and Hash properties",
"// \"balance-tcp\" - balances flows among slaves based on L2, L3, and L4 protocol information such as",
"// destination MAC address, IP address, and TCP port",
"// lacp-fallback-ab:true - Fall back to activ-backup mode when LACP negotiation fails",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"lacpMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"lacpMap",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"port",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsMap",
"(",
"lacpMap",
")",
"\n\n",
"portUUIDStr",
":=",
"bondName",
"\n",
"portUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"portUUIDStr",
"}",
"}",
"\n",
"portOp",
"=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"portTable",
",",
"Row",
":",
"port",
",",
"UUIDName",
":",
"portUUIDStr",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"portOp",
")",
"\n\n",
"// Mutate the Ports column of the row in the Bridge table to include bond name",
"mutateSet",
",",
"_",
":=",
"libovsdb",
".",
"NewOvsSet",
"(",
"portUUID",
")",
"\n",
"mutation",
":=",
"libovsdb",
".",
"NewMutation",
"(",
"\"",
"\"",
",",
"opStr",
",",
"mutateSet",
")",
"\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"d",
".",
"bridgeName",
")",
"\n",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"bridgeTable",
",",
"Mutations",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"mutation",
"}",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"mutateOp",
")",
"\n\n",
"return",
"d",
".",
"performOvsdbOps",
"(",
"ops",
")",
"\n\n",
"}"
]
| //CreatePortBond creates port bond in OVS | [
"CreatePortBond",
"creates",
"port",
"bond",
"in",
"OVS"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L428-L501 |
8,034 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | DeletePortBond | func (d *OvsdbDriver) DeletePortBond(bondName string, intfList []string) error {
var ops []libovsdb.Operation
var condition []interface{}
portUUIDStr := bondName
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
opStr := "delete"
for _, intfName := range intfList {
// insert/delete a row in Interface table
condition = libovsdb.NewCondition("name", "==", intfName)
intfOp := libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Where: []interface{}{condition},
}
ops = append(ops, intfOp)
}
// insert/delete a row in Port table
condition = libovsdb.NewCondition("name", "==", bondName)
portOp := libovsdb.Operation{
Op: opStr,
Table: portTable,
Where: []interface{}{condition},
}
ops = append(ops, portOp)
// also fetch the port-uuid from cache
d.cacheLock.RLock()
for uuid, row := range d.cache["Port"] {
name := row.Fields["name"].(string)
if name == bondName {
portUUID = []libovsdb.UUID{uuid}
break
}
}
d.cacheLock.RUnlock()
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition = libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
ops = append(ops, mutateOp)
// Perform OVS transaction
return d.performOvsdbOps(ops)
} | go | func (d *OvsdbDriver) DeletePortBond(bondName string, intfList []string) error {
var ops []libovsdb.Operation
var condition []interface{}
portUUIDStr := bondName
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
opStr := "delete"
for _, intfName := range intfList {
// insert/delete a row in Interface table
condition = libovsdb.NewCondition("name", "==", intfName)
intfOp := libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Where: []interface{}{condition},
}
ops = append(ops, intfOp)
}
// insert/delete a row in Port table
condition = libovsdb.NewCondition("name", "==", bondName)
portOp := libovsdb.Operation{
Op: opStr,
Table: portTable,
Where: []interface{}{condition},
}
ops = append(ops, portOp)
// also fetch the port-uuid from cache
d.cacheLock.RLock()
for uuid, row := range d.cache["Port"] {
name := row.Fields["name"].(string)
if name == bondName {
portUUID = []libovsdb.UUID{uuid}
break
}
}
d.cacheLock.RUnlock()
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition = libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
ops = append(ops, mutateOp)
// Perform OVS transaction
return d.performOvsdbOps(ops)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"DeletePortBond",
"(",
"bondName",
"string",
",",
"intfList",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"ops",
"[",
"]",
"libovsdb",
".",
"Operation",
"\n",
"var",
"condition",
"[",
"]",
"interface",
"{",
"}",
"\n",
"portUUIDStr",
":=",
"bondName",
"\n",
"portUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"portUUIDStr",
"}",
"}",
"\n",
"opStr",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"intfName",
":=",
"range",
"intfList",
"{",
"// insert/delete a row in Interface table",
"condition",
"=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"intfName",
")",
"\n",
"intfOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"interfaceTable",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"intfOp",
")",
"\n",
"}",
"\n\n",
"// insert/delete a row in Port table",
"condition",
"=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"bondName",
")",
"\n",
"portOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"portTable",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"portOp",
")",
"\n\n",
"// also fetch the port-uuid from cache",
"d",
".",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"for",
"uuid",
",",
"row",
":=",
"range",
"d",
".",
"cache",
"[",
"\"",
"\"",
"]",
"{",
"name",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"name",
"==",
"bondName",
"{",
"portUUID",
"=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"uuid",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"d",
".",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"// mutate the Ports column of the row in the Bridge table",
"mutateSet",
",",
"_",
":=",
"libovsdb",
".",
"NewOvsSet",
"(",
"portUUID",
")",
"\n",
"mutation",
":=",
"libovsdb",
".",
"NewMutation",
"(",
"\"",
"\"",
",",
"opStr",
",",
"mutateSet",
")",
"\n",
"condition",
"=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"d",
".",
"bridgeName",
")",
"\n",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"bridgeTable",
",",
"Mutations",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"mutation",
"}",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"mutateOp",
")",
"\n\n",
"// Perform OVS transaction",
"return",
"d",
".",
"performOvsdbOps",
"(",
"ops",
")",
"\n",
"}"
]
| // DeletePortBond deletes a port bond from OVS | [
"DeletePortBond",
"deletes",
"a",
"port",
"bond",
"from",
"OVS"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L504-L557 |
8,035 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | UpdatePolicingRate | func (d *OvsdbDriver) UpdatePolicingRate(intfName string, burst int, bandwidth int64) error {
bw := int(bandwidth)
intf := make(map[string]interface{})
intf["ingress_policing_rate"] = bw
intf["ingress_policing_burst"] = burst
condition := libovsdb.NewCondition("name", "==", intfName)
if condition == nil {
return errors.New("error getting the new condition")
}
mutateOp := libovsdb.Operation{
Op: "update",
Table: interfaceTable,
Row: intf,
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{mutateOp}
return d.performOvsdbOps(operations)
} | go | func (d *OvsdbDriver) UpdatePolicingRate(intfName string, burst int, bandwidth int64) error {
bw := int(bandwidth)
intf := make(map[string]interface{})
intf["ingress_policing_rate"] = bw
intf["ingress_policing_burst"] = burst
condition := libovsdb.NewCondition("name", "==", intfName)
if condition == nil {
return errors.New("error getting the new condition")
}
mutateOp := libovsdb.Operation{
Op: "update",
Table: interfaceTable,
Row: intf,
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{mutateOp}
return d.performOvsdbOps(operations)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"UpdatePolicingRate",
"(",
"intfName",
"string",
",",
"burst",
"int",
",",
"bandwidth",
"int64",
")",
"error",
"{",
"bw",
":=",
"int",
"(",
"bandwidth",
")",
"\n",
"intf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"bw",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"burst",
"\n\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"intfName",
")",
"\n",
"if",
"condition",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"interfaceTable",
",",
"Row",
":",
"intf",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n\n",
"operations",
":=",
"[",
"]",
"libovsdb",
".",
"Operation",
"{",
"mutateOp",
"}",
"\n",
"return",
"d",
".",
"performOvsdbOps",
"(",
"operations",
")",
"\n\n",
"}"
]
| //UpdatePolicingRate will update the ingress policing rate in interface table. | [
"UpdatePolicingRate",
"will",
"update",
"the",
"ingress",
"policing",
"rate",
"in",
"interface",
"table",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L560-L580 |
8,036 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | CreateVtep | func (d *OvsdbDriver) CreateVtep(intfName string, vtepRemoteIP string) error {
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
opStr := "insert"
intfType := "vxlan"
var err error
// insert/delete a row in Interface table
intf := make(map[string]interface{})
intf["name"] = intfName
intf["type"] = intfType
// Special handling for VTEP ports
intfOptions := make(map[string]interface{})
intfOptions["remote_ip"] = vtepRemoteIP
intfOptions["key"] = "flow" // Insert VNI per flow
intfOptions["tos"] = "inherit" // Copy DSCP from inner to outer IP header
intfOptions["dst_port"] = d.vxlanUDPPort // Set the UDP port for VXLAN
intf["options"], err = libovsdb.NewOvsMap(intfOptions)
if err != nil {
log.Errorf("error '%s' creating options from %v \n", err, intfOptions)
return err
}
// Add an entry in Interface table
intfOp := libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: intf,
UUIDName: intfUUIDStr,
}
// insert/delete a row in Port table
port := make(map[string]interface{})
port["name"] = intfName
port["vlan_mode"] = "trunk"
port["interfaces"], err = libovsdb.NewOvsSet(intfUUID)
if err != nil {
return err
}
// Add an entry in Port table
portOp := libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
// Perform OVS transaction
operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
return d.performOvsdbOps(operations)
} | go | func (d *OvsdbDriver) CreateVtep(intfName string, vtepRemoteIP string) error {
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
opStr := "insert"
intfType := "vxlan"
var err error
// insert/delete a row in Interface table
intf := make(map[string]interface{})
intf["name"] = intfName
intf["type"] = intfType
// Special handling for VTEP ports
intfOptions := make(map[string]interface{})
intfOptions["remote_ip"] = vtepRemoteIP
intfOptions["key"] = "flow" // Insert VNI per flow
intfOptions["tos"] = "inherit" // Copy DSCP from inner to outer IP header
intfOptions["dst_port"] = d.vxlanUDPPort // Set the UDP port for VXLAN
intf["options"], err = libovsdb.NewOvsMap(intfOptions)
if err != nil {
log.Errorf("error '%s' creating options from %v \n", err, intfOptions)
return err
}
// Add an entry in Interface table
intfOp := libovsdb.Operation{
Op: opStr,
Table: interfaceTable,
Row: intf,
UUIDName: intfUUIDStr,
}
// insert/delete a row in Port table
port := make(map[string]interface{})
port["name"] = intfName
port["vlan_mode"] = "trunk"
port["interfaces"], err = libovsdb.NewOvsSet(intfUUID)
if err != nil {
return err
}
// Add an entry in Port table
portOp := libovsdb.Operation{
Op: opStr,
Table: portTable,
Row: port,
UUIDName: portUUIDStr,
}
// mutate the Ports column of the row in the Bridge table
mutateSet, _ := libovsdb.NewOvsSet(portUUID)
mutation := libovsdb.NewMutation("ports", opStr, mutateSet)
condition := libovsdb.NewCondition("name", "==", d.bridgeName)
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: bridgeTable,
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
// Perform OVS transaction
operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
return d.performOvsdbOps(operations)
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"CreateVtep",
"(",
"intfName",
"string",
",",
"vtepRemoteIP",
"string",
")",
"error",
"{",
"portUUIDStr",
":=",
"intfName",
"\n",
"intfUUIDStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"intfName",
")",
"\n",
"portUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"portUUIDStr",
"}",
"}",
"\n",
"intfUUID",
":=",
"[",
"]",
"libovsdb",
".",
"UUID",
"{",
"{",
"GoUuid",
":",
"intfUUIDStr",
"}",
"}",
"\n",
"opStr",
":=",
"\"",
"\"",
"\n",
"intfType",
":=",
"\"",
"\"",
"\n",
"var",
"err",
"error",
"\n\n",
"// insert/delete a row in Interface table",
"intf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"intfName",
"\n",
"intf",
"[",
"\"",
"\"",
"]",
"=",
"intfType",
"\n\n",
"// Special handling for VTEP ports",
"intfOptions",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"intfOptions",
"[",
"\"",
"\"",
"]",
"=",
"vtepRemoteIP",
"\n",
"intfOptions",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"// Insert VNI per flow",
"\n",
"intfOptions",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"// Copy DSCP from inner to outer IP header",
"\n",
"intfOptions",
"[",
"\"",
"\"",
"]",
"=",
"d",
".",
"vxlanUDPPort",
"// Set the UDP port for VXLAN",
"\n\n",
"intf",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsMap",
"(",
"intfOptions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
",",
"intfOptions",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Add an entry in Interface table",
"intfOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"interfaceTable",
",",
"Row",
":",
"intf",
",",
"UUIDName",
":",
"intfUUIDStr",
",",
"}",
"\n\n",
"// insert/delete a row in Port table",
"port",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"intfName",
"\n",
"port",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n\n",
"port",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"libovsdb",
".",
"NewOvsSet",
"(",
"intfUUID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Add an entry in Port table",
"portOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"opStr",
",",
"Table",
":",
"portTable",
",",
"Row",
":",
"port",
",",
"UUIDName",
":",
"portUUIDStr",
",",
"}",
"\n\n",
"// mutate the Ports column of the row in the Bridge table",
"mutateSet",
",",
"_",
":=",
"libovsdb",
".",
"NewOvsSet",
"(",
"portUUID",
")",
"\n",
"mutation",
":=",
"libovsdb",
".",
"NewMutation",
"(",
"\"",
"\"",
",",
"opStr",
",",
"mutateSet",
")",
"\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"d",
".",
"bridgeName",
")",
"\n",
"mutateOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"bridgeTable",
",",
"Mutations",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"mutation",
"}",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n\n",
"// Perform OVS transaction",
"operations",
":=",
"[",
"]",
"libovsdb",
".",
"Operation",
"{",
"intfOp",
",",
"portOp",
",",
"mutateOp",
"}",
"\n",
"return",
"d",
".",
"performOvsdbOps",
"(",
"operations",
")",
"\n",
"}"
]
| // CreateVtep creates a VTEP port on the OVS | [
"CreateVtep",
"creates",
"a",
"VTEP",
"port",
"on",
"the",
"OVS"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L632-L699 |
8,037 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | GetOfpPortNo | func (d *OvsdbDriver) GetOfpPortNo(intfName string) (uint32, error) {
retryNo := 0
condition := libovsdb.NewCondition("name", "==", intfName)
selectOp := libovsdb.Operation{
Op: "select",
Table: "Interface",
Where: []interface{}{condition},
}
for {
row, err := d.ovs.Transact(ovsDataBase, selectOp)
if err == nil && len(row) > 0 && len(row[0].Rows) > 0 {
value := row[0].Rows[0]["ofport"]
if reflect.TypeOf(value).Kind() == reflect.Float64 {
//retry few more time. Due to asynchronous call between
//port creation and populating ovsdb entry for the interface
//may not be populated instantly.
if ofpPort := reflect.ValueOf(value).Float(); ofpPort != -1 {
return uint32(ofpPort), nil
}
}
}
time.Sleep(300 * time.Millisecond)
if retryNo == maxOfportRetry {
return 0, errors.New("ofPort not found")
}
retryNo++
}
} | go | func (d *OvsdbDriver) GetOfpPortNo(intfName string) (uint32, error) {
retryNo := 0
condition := libovsdb.NewCondition("name", "==", intfName)
selectOp := libovsdb.Operation{
Op: "select",
Table: "Interface",
Where: []interface{}{condition},
}
for {
row, err := d.ovs.Transact(ovsDataBase, selectOp)
if err == nil && len(row) > 0 && len(row[0].Rows) > 0 {
value := row[0].Rows[0]["ofport"]
if reflect.TypeOf(value).Kind() == reflect.Float64 {
//retry few more time. Due to asynchronous call between
//port creation and populating ovsdb entry for the interface
//may not be populated instantly.
if ofpPort := reflect.ValueOf(value).Float(); ofpPort != -1 {
return uint32(ofpPort), nil
}
}
}
time.Sleep(300 * time.Millisecond)
if retryNo == maxOfportRetry {
return 0, errors.New("ofPort not found")
}
retryNo++
}
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"GetOfpPortNo",
"(",
"intfName",
"string",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"retryNo",
":=",
"0",
"\n",
"condition",
":=",
"libovsdb",
".",
"NewCondition",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"intfName",
")",
"\n",
"selectOp",
":=",
"libovsdb",
".",
"Operation",
"{",
"Op",
":",
"\"",
"\"",
",",
"Table",
":",
"\"",
"\"",
",",
"Where",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"condition",
"}",
",",
"}",
"\n\n",
"for",
"{",
"row",
",",
"err",
":=",
"d",
".",
"ovs",
".",
"Transact",
"(",
"ovsDataBase",
",",
"selectOp",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"row",
")",
">",
"0",
"&&",
"len",
"(",
"row",
"[",
"0",
"]",
".",
"Rows",
")",
">",
"0",
"{",
"value",
":=",
"row",
"[",
"0",
"]",
".",
"Rows",
"[",
"0",
"]",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"reflect",
".",
"TypeOf",
"(",
"value",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Float64",
"{",
"//retry few more time. Due to asynchronous call between",
"//port creation and populating ovsdb entry for the interface",
"//may not be populated instantly.",
"if",
"ofpPort",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
".",
"Float",
"(",
")",
";",
"ofpPort",
"!=",
"-",
"1",
"{",
"return",
"uint32",
"(",
"ofpPort",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"300",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"if",
"retryNo",
"==",
"maxOfportRetry",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"retryNo",
"++",
"\n",
"}",
"\n",
"}"
]
| // GetOfpPortNo returns OFP port number for an interface | [
"GetOfpPortNo",
"returns",
"OFP",
"port",
"number",
"for",
"an",
"interface"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L828-L858 |
8,038 | contiv/netplugin | drivers/ovsd/ovsdbDriver.go | IsVtepPresent | func (d *OvsdbDriver) IsVtepPresent(remoteIP string) (bool, string) {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk the local cache
for tName, table := range d.cache {
if tName == "Interface" {
for _, row := range table {
options := row.Fields["options"]
switch optMap := options.(type) {
case libovsdb.OvsMap:
if optMap.GoMap["remote_ip"] == remoteIP {
value := row.Fields["name"]
switch t := value.(type) {
case string:
return true, t
default:
// return false, ""
}
}
default:
// return false, ""
}
}
}
}
// We could not find the interface name
return false, ""
} | go | func (d *OvsdbDriver) IsVtepPresent(remoteIP string) (bool, string) {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk the local cache
for tName, table := range d.cache {
if tName == "Interface" {
for _, row := range table {
options := row.Fields["options"]
switch optMap := options.(type) {
case libovsdb.OvsMap:
if optMap.GoMap["remote_ip"] == remoteIP {
value := row.Fields["name"]
switch t := value.(type) {
case string:
return true, t
default:
// return false, ""
}
}
default:
// return false, ""
}
}
}
}
// We could not find the interface name
return false, ""
} | [
"func",
"(",
"d",
"*",
"OvsdbDriver",
")",
"IsVtepPresent",
"(",
"remoteIP",
"string",
")",
"(",
"bool",
",",
"string",
")",
"{",
"d",
".",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"// walk the local cache",
"for",
"tName",
",",
"table",
":=",
"range",
"d",
".",
"cache",
"{",
"if",
"tName",
"==",
"\"",
"\"",
"{",
"for",
"_",
",",
"row",
":=",
"range",
"table",
"{",
"options",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"switch",
"optMap",
":=",
"options",
".",
"(",
"type",
")",
"{",
"case",
"libovsdb",
".",
"OvsMap",
":",
"if",
"optMap",
".",
"GoMap",
"[",
"\"",
"\"",
"]",
"==",
"remoteIP",
"{",
"value",
":=",
"row",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"switch",
"t",
":=",
"value",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"true",
",",
"t",
"\n",
"default",
":",
"// return false, \"\"",
"}",
"\n",
"}",
"\n",
"default",
":",
"// return false, \"\"",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// We could not find the interface name",
"return",
"false",
",",
"\"",
"\"",
"\n",
"}"
]
| // IsVtepPresent checks if VTEP already exists | [
"IsVtepPresent",
"checks",
"if",
"VTEP",
"already",
"exists"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdbDriver.go#L861-L890 |
8,039 | contiv/netplugin | netmaster/master/netmaster.go | SetClusterMode | func SetClusterMode(cm string) error {
switch cm {
case core.Docker, core.Kubernetes, core.SwarmMode:
case core.Test: // internal mode used for integration testing
break
default:
return core.Errorf("%s not a valid cluster mode {%s | %s | %s}",
cm, core.Docker, core.Kubernetes, core.SwarmMode)
}
masterRTCfg.clusterMode = cm
return nil
} | go | func SetClusterMode(cm string) error {
switch cm {
case core.Docker, core.Kubernetes, core.SwarmMode:
case core.Test: // internal mode used for integration testing
break
default:
return core.Errorf("%s not a valid cluster mode {%s | %s | %s}",
cm, core.Docker, core.Kubernetes, core.SwarmMode)
}
masterRTCfg.clusterMode = cm
return nil
} | [
"func",
"SetClusterMode",
"(",
"cm",
"string",
")",
"error",
"{",
"switch",
"cm",
"{",
"case",
"core",
".",
"Docker",
",",
"core",
".",
"Kubernetes",
",",
"core",
".",
"SwarmMode",
":",
"case",
"core",
".",
"Test",
":",
"// internal mode used for integration testing",
"break",
"\n",
"default",
":",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cm",
",",
"core",
".",
"Docker",
",",
"core",
".",
"Kubernetes",
",",
"core",
".",
"SwarmMode",
")",
"\n",
"}",
"\n\n",
"masterRTCfg",
".",
"clusterMode",
"=",
"cm",
"\n",
"return",
"nil",
"\n",
"}"
]
| // SetClusterMode sets the cluster mode for the contiv plugin | [
"SetClusterMode",
"sets",
"the",
"cluster",
"mode",
"for",
"the",
"contiv",
"plugin"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/netmaster.go#L44-L56 |
8,040 | contiv/netplugin | netmaster/master/netmaster.go | CreateGlobal | func CreateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
log.Infof("Received global create with intent {%v}", gc)
var err error
gcfgUpdateList := []string{}
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
masterGc.Read("global")
gstate.GlobalMutex.Lock()
defer gstate.GlobalMutex.Unlock()
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
gCfg.Read("global")
// check for valid values
if gc.NwInfraType != "" {
switch gc.NwInfraType {
case "default", "aci", "aci-opflex":
// These values are acceptable.
default:
return errors.New("invalid fabric mode")
}
masterGc.NwInfraType = gc.NwInfraType
}
if gc.VLANs != "" {
_, err := netutils.ParseTagRanges(gc.VLANs, "vlan")
if err != nil {
return err
}
gCfg.Auto.VLANs = gc.VLANs
gcfgUpdateList = append(gcfgUpdateList, "vlan")
}
if gc.VXLANs != "" {
_, err = netutils.ParseTagRanges(gc.VXLANs, "vxlan")
if err != nil {
return err
}
gCfg.Auto.VXLANs = gc.VXLANs
gcfgUpdateList = append(gcfgUpdateList, "vxlan")
}
if gc.FwdMode != "" {
masterGc.FwdMode = gc.FwdMode
}
if gc.ArpMode != "" {
masterGc.ArpMode = gc.ArpMode
}
if gc.PvtSubnet != "" {
masterGc.PvtSubnet = gc.PvtSubnet
}
if len(gcfgUpdateList) > 0 {
// Delete old state
gOper := &gstate.Oper{}
gOper.StateDriver = stateDriver
err = gOper.Read("")
if err == nil {
for _, res := range gcfgUpdateList {
err = gCfg.UpdateResources(res)
if err != nil {
return err
}
}
} else {
for _, res := range gcfgUpdateList {
// setup resources
err = gCfg.Process(res)
if err != nil {
log.Errorf("Error updating the config %+v. Error: %s", gCfg, err)
return err
}
}
}
err = gCfg.Write()
if err != nil {
log.Errorf("error updating global config.Error: %s", err)
return err
}
}
return masterGc.Write()
} | go | func CreateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
log.Infof("Received global create with intent {%v}", gc)
var err error
gcfgUpdateList := []string{}
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
masterGc.Read("global")
gstate.GlobalMutex.Lock()
defer gstate.GlobalMutex.Unlock()
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
gCfg.Read("global")
// check for valid values
if gc.NwInfraType != "" {
switch gc.NwInfraType {
case "default", "aci", "aci-opflex":
// These values are acceptable.
default:
return errors.New("invalid fabric mode")
}
masterGc.NwInfraType = gc.NwInfraType
}
if gc.VLANs != "" {
_, err := netutils.ParseTagRanges(gc.VLANs, "vlan")
if err != nil {
return err
}
gCfg.Auto.VLANs = gc.VLANs
gcfgUpdateList = append(gcfgUpdateList, "vlan")
}
if gc.VXLANs != "" {
_, err = netutils.ParseTagRanges(gc.VXLANs, "vxlan")
if err != nil {
return err
}
gCfg.Auto.VXLANs = gc.VXLANs
gcfgUpdateList = append(gcfgUpdateList, "vxlan")
}
if gc.FwdMode != "" {
masterGc.FwdMode = gc.FwdMode
}
if gc.ArpMode != "" {
masterGc.ArpMode = gc.ArpMode
}
if gc.PvtSubnet != "" {
masterGc.PvtSubnet = gc.PvtSubnet
}
if len(gcfgUpdateList) > 0 {
// Delete old state
gOper := &gstate.Oper{}
gOper.StateDriver = stateDriver
err = gOper.Read("")
if err == nil {
for _, res := range gcfgUpdateList {
err = gCfg.UpdateResources(res)
if err != nil {
return err
}
}
} else {
for _, res := range gcfgUpdateList {
// setup resources
err = gCfg.Process(res)
if err != nil {
log.Errorf("Error updating the config %+v. Error: %s", gCfg, err)
return err
}
}
}
err = gCfg.Write()
if err != nil {
log.Errorf("error updating global config.Error: %s", err)
return err
}
}
return masterGc.Write()
} | [
"func",
"CreateGlobal",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"gc",
"*",
"intent",
".",
"ConfigGlobal",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"gc",
")",
"\n",
"var",
"err",
"error",
"\n",
"gcfgUpdateList",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"masterGc",
":=",
"&",
"mastercfg",
".",
"GlobConfig",
"{",
"}",
"\n",
"masterGc",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"masterGc",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n\n",
"gstate",
".",
"GlobalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"gstate",
".",
"GlobalMutex",
".",
"Unlock",
"(",
")",
"\n",
"gCfg",
":=",
"&",
"gstate",
".",
"Cfg",
"{",
"}",
"\n",
"gCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"gCfg",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n\n",
"// check for valid values",
"if",
"gc",
".",
"NwInfraType",
"!=",
"\"",
"\"",
"{",
"switch",
"gc",
".",
"NwInfraType",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"// These values are acceptable.",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"masterGc",
".",
"NwInfraType",
"=",
"gc",
".",
"NwInfraType",
"\n",
"}",
"\n",
"if",
"gc",
".",
"VLANs",
"!=",
"\"",
"\"",
"{",
"_",
",",
"err",
":=",
"netutils",
".",
"ParseTagRanges",
"(",
"gc",
".",
"VLANs",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"gCfg",
".",
"Auto",
".",
"VLANs",
"=",
"gc",
".",
"VLANs",
"\n",
"gcfgUpdateList",
"=",
"append",
"(",
"gcfgUpdateList",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"gc",
".",
"VXLANs",
"!=",
"\"",
"\"",
"{",
"_",
",",
"err",
"=",
"netutils",
".",
"ParseTagRanges",
"(",
"gc",
".",
"VXLANs",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"gCfg",
".",
"Auto",
".",
"VXLANs",
"=",
"gc",
".",
"VXLANs",
"\n",
"gcfgUpdateList",
"=",
"append",
"(",
"gcfgUpdateList",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"gc",
".",
"FwdMode",
"!=",
"\"",
"\"",
"{",
"masterGc",
".",
"FwdMode",
"=",
"gc",
".",
"FwdMode",
"\n",
"}",
"\n\n",
"if",
"gc",
".",
"ArpMode",
"!=",
"\"",
"\"",
"{",
"masterGc",
".",
"ArpMode",
"=",
"gc",
".",
"ArpMode",
"\n",
"}",
"\n\n",
"if",
"gc",
".",
"PvtSubnet",
"!=",
"\"",
"\"",
"{",
"masterGc",
".",
"PvtSubnet",
"=",
"gc",
".",
"PvtSubnet",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"gcfgUpdateList",
")",
">",
"0",
"{",
"// Delete old state",
"gOper",
":=",
"&",
"gstate",
".",
"Oper",
"{",
"}",
"\n",
"gOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"gOper",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"res",
":=",
"range",
"gcfgUpdateList",
"{",
"err",
"=",
"gCfg",
".",
"UpdateResources",
"(",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"_",
",",
"res",
":=",
"range",
"gcfgUpdateList",
"{",
"// setup resources",
"err",
"=",
"gCfg",
".",
"Process",
"(",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gCfg",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
"=",
"gCfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"masterGc",
".",
"Write",
"(",
")",
"\n",
"}"
]
| // CreateGlobal sets the global state | [
"CreateGlobal",
"sets",
"the",
"global",
"state"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/netmaster.go#L94-L181 |
8,041 | contiv/netplugin | netmaster/master/netmaster.go | DeleteGlobal | func DeleteGlobal(stateDriver core.StateDriver) error {
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
err := masterGc.Read("")
if err == nil {
err = masterGc.Clear()
if err != nil {
return err
}
}
// Setup global state
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err = gCfg.Read("")
if err == nil {
err = gCfg.DeleteResources("vlan")
if err != nil {
return err
}
err = gCfg.DeleteResources("vxlan")
if err != nil {
return err
}
err = gCfg.Clear()
if err != nil {
return err
}
}
// Delete old state
gOper := &gstate.Oper{}
gOper.StateDriver = stateDriver
err = gOper.Read("")
if err == nil {
err = gOper.Clear()
if err != nil {
return err
}
}
return nil
} | go | func DeleteGlobal(stateDriver core.StateDriver) error {
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
err := masterGc.Read("")
if err == nil {
err = masterGc.Clear()
if err != nil {
return err
}
}
// Setup global state
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err = gCfg.Read("")
if err == nil {
err = gCfg.DeleteResources("vlan")
if err != nil {
return err
}
err = gCfg.DeleteResources("vxlan")
if err != nil {
return err
}
err = gCfg.Clear()
if err != nil {
return err
}
}
// Delete old state
gOper := &gstate.Oper{}
gOper.StateDriver = stateDriver
err = gOper.Read("")
if err == nil {
err = gOper.Clear()
if err != nil {
return err
}
}
return nil
} | [
"func",
"DeleteGlobal",
"(",
"stateDriver",
"core",
".",
"StateDriver",
")",
"error",
"{",
"masterGc",
":=",
"&",
"mastercfg",
".",
"GlobConfig",
"{",
"}",
"\n",
"masterGc",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"masterGc",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"masterGc",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Setup global state",
"gCfg",
":=",
"&",
"gstate",
".",
"Cfg",
"{",
"}",
"\n",
"gCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"gCfg",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"gCfg",
".",
"DeleteResources",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"gCfg",
".",
"DeleteResources",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"gCfg",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Delete old state",
"gOper",
":=",
"&",
"gstate",
".",
"Oper",
"{",
"}",
"\n",
"gOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"gOper",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"gOper",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // DeleteGlobal delete global state | [
"DeleteGlobal",
"delete",
"global",
"state"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/netmaster.go#L277-L320 |
8,042 | contiv/netplugin | netmaster/master/netmaster.go | DeleteTenant | func DeleteTenant(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
return validateTenantConfig(tenant)
} | go | func DeleteTenant(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
return validateTenantConfig(tenant)
} | [
"func",
"DeleteTenant",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"tenant",
"*",
"intent",
".",
"ConfigTenant",
")",
"error",
"{",
"return",
"validateTenantConfig",
"(",
"tenant",
")",
"\n",
"}"
]
| // DeleteTenant deletes a tenant from the state store based on its ConfigTenant. | [
"DeleteTenant",
"deletes",
"a",
"tenant",
"from",
"the",
"state",
"store",
"based",
"on",
"its",
"ConfigTenant",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/netmaster.go#L328-L330 |
8,043 | contiv/netplugin | netmaster/master/netmaster.go | IsAciConfigured | func IsAciConfigured() (res bool, err error) {
// Get the state driver
stateDriver, uErr := utils.GetStateDriver()
if uErr != nil {
log.Warnf("Couldn't read global config %v", uErr)
return false, uErr
}
// read global config
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
uErr = masterGc.Read("config")
if core.ErrIfKeyExists(uErr) != nil {
log.Errorf("Couldn't read global config %v", uErr)
return false, uErr
}
if uErr != nil {
log.Warnf("Couldn't read global config %v", uErr)
return false, nil
}
if masterGc.NwInfraType != "aci" {
log.Debugf("NwInfra type is %v, no ACI", masterGc.NwInfraType)
return false, nil
}
return true, nil
} | go | func IsAciConfigured() (res bool, err error) {
// Get the state driver
stateDriver, uErr := utils.GetStateDriver()
if uErr != nil {
log.Warnf("Couldn't read global config %v", uErr)
return false, uErr
}
// read global config
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
uErr = masterGc.Read("config")
if core.ErrIfKeyExists(uErr) != nil {
log.Errorf("Couldn't read global config %v", uErr)
return false, uErr
}
if uErr != nil {
log.Warnf("Couldn't read global config %v", uErr)
return false, nil
}
if masterGc.NwInfraType != "aci" {
log.Debugf("NwInfra type is %v, no ACI", masterGc.NwInfraType)
return false, nil
}
return true, nil
} | [
"func",
"IsAciConfigured",
"(",
")",
"(",
"res",
"bool",
",",
"err",
"error",
")",
"{",
"// Get the state driver",
"stateDriver",
",",
"uErr",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"uErr",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"uErr",
")",
"\n",
"return",
"false",
",",
"uErr",
"\n",
"}",
"\n\n",
"// read global config",
"masterGc",
":=",
"&",
"mastercfg",
".",
"GlobConfig",
"{",
"}",
"\n",
"masterGc",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"uErr",
"=",
"masterGc",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"core",
".",
"ErrIfKeyExists",
"(",
"uErr",
")",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"uErr",
")",
"\n",
"return",
"false",
",",
"uErr",
"\n",
"}",
"\n\n",
"if",
"uErr",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"uErr",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"masterGc",
".",
"NwInfraType",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"masterGc",
".",
"NwInfraType",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
]
| // IsAciConfigured returns true if aci is configured on netmaster. | [
"IsAciConfigured",
"returns",
"true",
"if",
"aci",
"is",
"configured",
"on",
"netmaster",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/netmaster.go#L333-L361 |
8,044 | contiv/netplugin | netmaster/daemon/utils.go | getVersion | func getVersion(w http.ResponseWriter, r *http.Request) {
ver := version.Get()
resp, err := json.Marshal(ver)
if err != nil {
http.Error(w,
core.Errorf("marshaling json failed. Error: %s", err).Error(),
http.StatusInternalServerError)
return
}
w.Write(resp)
return
} | go | func getVersion(w http.ResponseWriter, r *http.Request) {
ver := version.Get()
resp, err := json.Marshal(ver)
if err != nil {
http.Error(w,
core.Errorf("marshaling json failed. Error: %s", err).Error(),
http.StatusInternalServerError)
return
}
w.Write(resp)
return
} | [
"func",
"getVersion",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"ver",
":=",
"version",
".",
"Get",
"(",
")",
"\n\n",
"resp",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"ver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"w",
".",
"Write",
"(",
"resp",
")",
"\n",
"return",
"\n",
"}"
]
| // get current version | [
"get",
"current",
"version"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/utils.go#L36-L48 |
8,045 | contiv/netplugin | netmaster/daemon/utils.go | slaveProxyHandler | func slaveProxyHandler(w http.ResponseWriter, r *http.Request) {
log.Infof("proxy handler for %q ", r.URL.Path)
localIP, err := netutils.GetDefaultAddr()
if err != nil {
log.Fatalf("Error getting local IP address. Err: %v", err)
}
// get current holder of master lock
masterNode := leaderLock.GetHolder()
if masterNode == "" {
http.Error(w, "Leader not found", http.StatusInternalServerError)
return
}
// If we are the master, return
if localIP == masterNode {
http.Error(w, "Self proxying error", http.StatusInternalServerError)
return
}
// build the proxy url
url, _ := url.Parse(fmt.Sprintf("http://%s", masterNode))
// Create a proxy for the URL
proxy := httputil.NewSingleHostReverseProxy(url)
// modify the request url
newReq := *r
// newReq.URL = url
// Serve http
proxy.ServeHTTP(w, &newReq)
} | go | func slaveProxyHandler(w http.ResponseWriter, r *http.Request) {
log.Infof("proxy handler for %q ", r.URL.Path)
localIP, err := netutils.GetDefaultAddr()
if err != nil {
log.Fatalf("Error getting local IP address. Err: %v", err)
}
// get current holder of master lock
masterNode := leaderLock.GetHolder()
if masterNode == "" {
http.Error(w, "Leader not found", http.StatusInternalServerError)
return
}
// If we are the master, return
if localIP == masterNode {
http.Error(w, "Self proxying error", http.StatusInternalServerError)
return
}
// build the proxy url
url, _ := url.Parse(fmt.Sprintf("http://%s", masterNode))
// Create a proxy for the URL
proxy := httputil.NewSingleHostReverseProxy(url)
// modify the request url
newReq := *r
// newReq.URL = url
// Serve http
proxy.ServeHTTP(w, &newReq)
} | [
"func",
"slaveProxyHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"r",
".",
"URL",
".",
"Path",
")",
"\n\n",
"localIP",
",",
"err",
":=",
"netutils",
".",
"GetDefaultAddr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// get current holder of master lock",
"masterNode",
":=",
"leaderLock",
".",
"GetHolder",
"(",
")",
"\n",
"if",
"masterNode",
"==",
"\"",
"\"",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// If we are the master, return",
"if",
"localIP",
"==",
"masterNode",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// build the proxy url",
"url",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"masterNode",
")",
")",
"\n\n",
"// Create a proxy for the URL",
"proxy",
":=",
"httputil",
".",
"NewSingleHostReverseProxy",
"(",
"url",
")",
"\n\n",
"// modify the request url",
"newReq",
":=",
"*",
"r",
"\n",
"// newReq.URL = url",
"// Serve http",
"proxy",
".",
"ServeHTTP",
"(",
"w",
",",
"&",
"newReq",
")",
"\n",
"}"
]
| // slaveProxyHandler redirects to current master | [
"slaveProxyHandler",
"redirects",
"to",
"current",
"master"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/utils.go#L51-L84 |
8,046 | contiv/netplugin | netmaster/mastercfg/endpointstate.go | ReadAll | func (s *CfgEndpointState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(endpointConfigPathPrefix, s, json.Unmarshal)
} | go | func (s *CfgEndpointState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(endpointConfigPathPrefix, s, json.Unmarshal)
} | [
"func",
"(",
"s",
"*",
"CfgEndpointState",
")",
"ReadAll",
"(",
")",
"(",
"[",
"]",
"core",
".",
"State",
",",
"error",
")",
"{",
"return",
"s",
".",
"StateDriver",
".",
"ReadAllState",
"(",
"endpointConfigPathPrefix",
",",
"s",
",",
"json",
".",
"Unmarshal",
")",
"\n",
"}"
]
| // ReadAll reads all state objects for the endpoints. | [
"ReadAll",
"reads",
"all",
"state",
"objects",
"for",
"the",
"endpoints",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/endpointstate.go#L58-L60 |
8,047 | contiv/netplugin | netmaster/mastercfg/endpointstate.go | WatchAll | func (s *CfgEndpointState) WatchAll(rsps chan core.WatchState) error {
return s.StateDriver.WatchAllState(endpointConfigPathPrefix, s, json.Unmarshal,
rsps)
} | go | func (s *CfgEndpointState) WatchAll(rsps chan core.WatchState) error {
return s.StateDriver.WatchAllState(endpointConfigPathPrefix, s, json.Unmarshal,
rsps)
} | [
"func",
"(",
"s",
"*",
"CfgEndpointState",
")",
"WatchAll",
"(",
"rsps",
"chan",
"core",
".",
"WatchState",
")",
"error",
"{",
"return",
"s",
".",
"StateDriver",
".",
"WatchAllState",
"(",
"endpointConfigPathPrefix",
",",
"s",
",",
"json",
".",
"Unmarshal",
",",
"rsps",
")",
"\n",
"}"
]
| // WatchAll fills a channel on each state event related to endpoints. | [
"WatchAll",
"fills",
"a",
"channel",
"on",
"each",
"state",
"event",
"related",
"to",
"endpoints",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/endpointstate.go#L63-L66 |
8,048 | contiv/netplugin | netmaster/daemon/daemon.go | Init | func (d *MasterDaemon) Init() {
// set cluster mode
err := master.SetClusterMode(d.ClusterMode)
if err != nil {
log.Fatalf("Failed to set cluster-mode %q. Error: %s", d.ClusterMode, err)
}
// initialize state driver
d.stateDriver, err = utils.NewStateDriver(d.ClusterStoreDriver, &core.InstanceInfo{DbURL: d.ClusterStoreURL})
if err != nil {
log.Fatalf("Failed to init state-store: driver %q, URLs %q. Error: %s", d.ClusterStoreDriver, d.ClusterStoreURL, err)
}
// Initialize resource manager
d.resmgr, err = resources.NewStateResourceManager(d.stateDriver)
if err != nil {
log.Fatalf("Failed to init resource manager. Error: %s", err)
}
// Create an objdb client
d.objdbClient, err = objdb.InitClient(d.ClusterStoreDriver, []string{d.ClusterStoreURL})
if err != nil {
log.Fatalf("Error connecting to state store: driver %q, URLs %q. Err: %v", d.ClusterStoreDriver, d.ClusterStoreURL, err)
}
} | go | func (d *MasterDaemon) Init() {
// set cluster mode
err := master.SetClusterMode(d.ClusterMode)
if err != nil {
log.Fatalf("Failed to set cluster-mode %q. Error: %s", d.ClusterMode, err)
}
// initialize state driver
d.stateDriver, err = utils.NewStateDriver(d.ClusterStoreDriver, &core.InstanceInfo{DbURL: d.ClusterStoreURL})
if err != nil {
log.Fatalf("Failed to init state-store: driver %q, URLs %q. Error: %s", d.ClusterStoreDriver, d.ClusterStoreURL, err)
}
// Initialize resource manager
d.resmgr, err = resources.NewStateResourceManager(d.stateDriver)
if err != nil {
log.Fatalf("Failed to init resource manager. Error: %s", err)
}
// Create an objdb client
d.objdbClient, err = objdb.InitClient(d.ClusterStoreDriver, []string{d.ClusterStoreURL})
if err != nil {
log.Fatalf("Error connecting to state store: driver %q, URLs %q. Err: %v", d.ClusterStoreDriver, d.ClusterStoreURL, err)
}
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"Init",
"(",
")",
"{",
"// set cluster mode",
"err",
":=",
"master",
".",
"SetClusterMode",
"(",
"d",
".",
"ClusterMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"ClusterMode",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// initialize state driver",
"d",
".",
"stateDriver",
",",
"err",
"=",
"utils",
".",
"NewStateDriver",
"(",
"d",
".",
"ClusterStoreDriver",
",",
"&",
"core",
".",
"InstanceInfo",
"{",
"DbURL",
":",
"d",
".",
"ClusterStoreURL",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"ClusterStoreDriver",
",",
"d",
".",
"ClusterStoreURL",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Initialize resource manager",
"d",
".",
"resmgr",
",",
"err",
"=",
"resources",
".",
"NewStateResourceManager",
"(",
"d",
".",
"stateDriver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Create an objdb client",
"d",
".",
"objdbClient",
",",
"err",
"=",
"objdb",
".",
"InitClient",
"(",
"d",
".",
"ClusterStoreDriver",
",",
"[",
"]",
"string",
"{",
"d",
".",
"ClusterStoreURL",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"ClusterStoreDriver",
",",
"d",
".",
"ClusterStoreURL",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // Init initializes the master daemon | [
"Init",
"initializes",
"the",
"master",
"daemon"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L74-L98 |
8,049 | contiv/netplugin | netmaster/daemon/daemon.go | agentDiscoveryLoop | func (d *MasterDaemon) agentDiscoveryLoop() {
// Create channels for watch thread
agentEventCh := make(chan objdb.WatchServiceEvent, 1)
watchStopCh := make(chan bool, 1)
// Start a watch on netplugin service
err := d.objdbClient.WatchService("netplugin", agentEventCh, watchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netplugin service. Err: %v", err)
}
for {
agentEv := <-agentEventCh
log.Debugf("Received netplugin watch event: %+v", agentEv)
// build host info
nodeInfo := ofnet.OfnetNode{
HostAddr: agentEv.ServiceInfo.HostAddr,
HostPort: uint16(agentEv.ServiceInfo.Port),
}
if agentEv.EventType == objdb.WatchServiceEventAdd {
err = d.ofnetMaster.AddNode(nodeInfo)
if err != nil {
log.Errorf("Error adding node %v. Err: %v", nodeInfo, err)
}
} else if agentEv.EventType == objdb.WatchServiceEventDel {
var res bool
log.Infof("Unregister node %+v", nodeInfo)
d.ofnetMaster.UnRegisterNode(&nodeInfo, &res)
go d.startDeferredCleanup(nodeInfo, agentEv.ServiceInfo.Hostname)
}
// Dont process next peer event for another 100ms
time.Sleep(100 * time.Millisecond)
}
} | go | func (d *MasterDaemon) agentDiscoveryLoop() {
// Create channels for watch thread
agentEventCh := make(chan objdb.WatchServiceEvent, 1)
watchStopCh := make(chan bool, 1)
// Start a watch on netplugin service
err := d.objdbClient.WatchService("netplugin", agentEventCh, watchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netplugin service. Err: %v", err)
}
for {
agentEv := <-agentEventCh
log.Debugf("Received netplugin watch event: %+v", agentEv)
// build host info
nodeInfo := ofnet.OfnetNode{
HostAddr: agentEv.ServiceInfo.HostAddr,
HostPort: uint16(agentEv.ServiceInfo.Port),
}
if agentEv.EventType == objdb.WatchServiceEventAdd {
err = d.ofnetMaster.AddNode(nodeInfo)
if err != nil {
log.Errorf("Error adding node %v. Err: %v", nodeInfo, err)
}
} else if agentEv.EventType == objdb.WatchServiceEventDel {
var res bool
log.Infof("Unregister node %+v", nodeInfo)
d.ofnetMaster.UnRegisterNode(&nodeInfo, &res)
go d.startDeferredCleanup(nodeInfo, agentEv.ServiceInfo.Hostname)
}
// Dont process next peer event for another 100ms
time.Sleep(100 * time.Millisecond)
}
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"agentDiscoveryLoop",
"(",
")",
"{",
"// Create channels for watch thread",
"agentEventCh",
":=",
"make",
"(",
"chan",
"objdb",
".",
"WatchServiceEvent",
",",
"1",
")",
"\n",
"watchStopCh",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n\n",
"// Start a watch on netplugin service",
"err",
":=",
"d",
".",
"objdbClient",
".",
"WatchService",
"(",
"\"",
"\"",
",",
"agentEventCh",
",",
"watchStopCh",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"{",
"agentEv",
":=",
"<-",
"agentEventCh",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"agentEv",
")",
"\n",
"// build host info",
"nodeInfo",
":=",
"ofnet",
".",
"OfnetNode",
"{",
"HostAddr",
":",
"agentEv",
".",
"ServiceInfo",
".",
"HostAddr",
",",
"HostPort",
":",
"uint16",
"(",
"agentEv",
".",
"ServiceInfo",
".",
"Port",
")",
",",
"}",
"\n\n",
"if",
"agentEv",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventAdd",
"{",
"err",
"=",
"d",
".",
"ofnetMaster",
".",
"AddNode",
"(",
"nodeInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeInfo",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"agentEv",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventDel",
"{",
"var",
"res",
"bool",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeInfo",
")",
"\n",
"d",
".",
"ofnetMaster",
".",
"UnRegisterNode",
"(",
"&",
"nodeInfo",
",",
"&",
"res",
")",
"\n\n",
"go",
"d",
".",
"startDeferredCleanup",
"(",
"nodeInfo",
",",
"agentEv",
".",
"ServiceInfo",
".",
"Hostname",
")",
"\n",
"}",
"\n\n",
"// Dont process next peer event for another 100ms",
"time",
".",
"Sleep",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n",
"}"
]
| // Find all netplugin nodes and add them to ofnet master | [
"Find",
"all",
"netplugin",
"nodes",
"and",
"add",
"them",
"to",
"ofnet",
"master"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L141-L178 |
8,050 | contiv/netplugin | netmaster/daemon/daemon.go | getPluginAddress | func (d *MasterDaemon) getPluginAddress(hostName string) (string, error) {
srvList, err := d.objdbClient.GetService("netplugin.vtep")
if err != nil {
log.Errorf("Error getting netplugin nodes. Err: %v", err)
return "", err
}
for _, srv := range srvList {
if srv.Hostname == hostName {
return srv.HostAddr, nil
}
}
return "", fmt.Errorf("Could not find plugin instance with name: %s", hostName)
} | go | func (d *MasterDaemon) getPluginAddress(hostName string) (string, error) {
srvList, err := d.objdbClient.GetService("netplugin.vtep")
if err != nil {
log.Errorf("Error getting netplugin nodes. Err: %v", err)
return "", err
}
for _, srv := range srvList {
if srv.Hostname == hostName {
return srv.HostAddr, nil
}
}
return "", fmt.Errorf("Could not find plugin instance with name: %s", hostName)
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"getPluginAddress",
"(",
"hostName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"srvList",
",",
"err",
":=",
"d",
".",
"objdbClient",
".",
"GetService",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"srv",
":=",
"range",
"srvList",
"{",
"if",
"srv",
".",
"Hostname",
"==",
"hostName",
"{",
"return",
"srv",
".",
"HostAddr",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostName",
")",
"\n",
"}"
]
| // getPluginAddress gets the adrress of the netplugin agent given the host name | [
"getPluginAddress",
"gets",
"the",
"adrress",
"of",
"the",
"netplugin",
"agent",
"given",
"the",
"host",
"name"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L215-L229 |
8,051 | contiv/netplugin | netmaster/daemon/daemon.go | ClearEndpoints | func (d *MasterDaemon) ClearEndpoints(stateDriver core.StateDriver, epCfgs *[]core.State, id, matchField string) error {
for _, epCfg := range *epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
if (matchField == "net" && ep.NetID == id) ||
(matchField == "group" && ep.ServiceName == id) ||
(matchField == "ep" && strings.Contains(ep.EndpointID, id)) {
// Delete the endpoint state from netmaster
_, err := master.DeleteEndpointID(stateDriver, ep.ID)
if err != nil {
return fmt.Errorf("Cannot cleanup EP: %s. Err: %+v", ep.EndpointID, err)
}
pluginAddress, err := d.getPluginAddress(ep.HomingHost)
if err != nil {
return err
}
epDelURL := "http://" + pluginAddress + ":9090/debug/reclaimEndpoint/" + ep.ID
err = utils.HTTPDel(epDelURL)
if err != nil {
return fmt.Errorf("Error sending HTTP delete request to %s. Err: %+v", pluginAddress, err)
}
}
}
return nil
} | go | func (d *MasterDaemon) ClearEndpoints(stateDriver core.StateDriver, epCfgs *[]core.State, id, matchField string) error {
for _, epCfg := range *epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
if (matchField == "net" && ep.NetID == id) ||
(matchField == "group" && ep.ServiceName == id) ||
(matchField == "ep" && strings.Contains(ep.EndpointID, id)) {
// Delete the endpoint state from netmaster
_, err := master.DeleteEndpointID(stateDriver, ep.ID)
if err != nil {
return fmt.Errorf("Cannot cleanup EP: %s. Err: %+v", ep.EndpointID, err)
}
pluginAddress, err := d.getPluginAddress(ep.HomingHost)
if err != nil {
return err
}
epDelURL := "http://" + pluginAddress + ":9090/debug/reclaimEndpoint/" + ep.ID
err = utils.HTTPDel(epDelURL)
if err != nil {
return fmt.Errorf("Error sending HTTP delete request to %s. Err: %+v", pluginAddress, err)
}
}
}
return nil
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"ClearEndpoints",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"epCfgs",
"*",
"[",
"]",
"core",
".",
"State",
",",
"id",
",",
"matchField",
"string",
")",
"error",
"{",
"for",
"_",
",",
"epCfg",
":=",
"range",
"*",
"epCfgs",
"{",
"ep",
":=",
"epCfg",
".",
"(",
"*",
"mastercfg",
".",
"CfgEndpointState",
")",
"\n",
"if",
"(",
"matchField",
"==",
"\"",
"\"",
"&&",
"ep",
".",
"NetID",
"==",
"id",
")",
"||",
"(",
"matchField",
"==",
"\"",
"\"",
"&&",
"ep",
".",
"ServiceName",
"==",
"id",
")",
"||",
"(",
"matchField",
"==",
"\"",
"\"",
"&&",
"strings",
".",
"Contains",
"(",
"ep",
".",
"EndpointID",
",",
"id",
")",
")",
"{",
"// Delete the endpoint state from netmaster",
"_",
",",
"err",
":=",
"master",
".",
"DeleteEndpointID",
"(",
"stateDriver",
",",
"ep",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
".",
"EndpointID",
",",
"err",
")",
"\n",
"}",
"\n\n",
"pluginAddress",
",",
"err",
":=",
"d",
".",
"getPluginAddress",
"(",
"ep",
".",
"HomingHost",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"epDelURL",
":=",
"\"",
"\"",
"+",
"pluginAddress",
"+",
"\"",
"\"",
"+",
"ep",
".",
"ID",
"\n",
"err",
"=",
"utils",
".",
"HTTPDel",
"(",
"epDelURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pluginAddress",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // ClearEndpoints clears all the endpoints | [
"ClearEndpoints",
"clears",
"all",
"the",
"endpoints"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L232-L258 |
8,052 | contiv/netplugin | netmaster/daemon/daemon.go | runLeader | func (d *MasterDaemon) runLeader() {
router := mux.NewRouter()
// Create a new api controller
apiConfig := &objApi.APIControllerConfig{
NetForwardMode: d.NetForwardMode,
NetInfraType: d.NetInfraType,
}
d.apiController = objApi.NewAPIController(router, d.objdbClient, apiConfig)
//Restore state from clusterStore
d.restoreCache()
// Register netmaster service
d.registerService()
// initialize policy manager
mastercfg.InitPolicyMgr(d.stateDriver, d.ofnetMaster)
// setup HTTP routes
d.registerRoutes(router)
d.startListeners(router, d.stopLeaderChan)
log.Infof("Exiting Leader mode")
} | go | func (d *MasterDaemon) runLeader() {
router := mux.NewRouter()
// Create a new api controller
apiConfig := &objApi.APIControllerConfig{
NetForwardMode: d.NetForwardMode,
NetInfraType: d.NetInfraType,
}
d.apiController = objApi.NewAPIController(router, d.objdbClient, apiConfig)
//Restore state from clusterStore
d.restoreCache()
// Register netmaster service
d.registerService()
// initialize policy manager
mastercfg.InitPolicyMgr(d.stateDriver, d.ofnetMaster)
// setup HTTP routes
d.registerRoutes(router)
d.startListeners(router, d.stopLeaderChan)
log.Infof("Exiting Leader mode")
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"runLeader",
"(",
")",
"{",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n\n",
"// Create a new api controller",
"apiConfig",
":=",
"&",
"objApi",
".",
"APIControllerConfig",
"{",
"NetForwardMode",
":",
"d",
".",
"NetForwardMode",
",",
"NetInfraType",
":",
"d",
".",
"NetInfraType",
",",
"}",
"\n",
"d",
".",
"apiController",
"=",
"objApi",
".",
"NewAPIController",
"(",
"router",
",",
"d",
".",
"objdbClient",
",",
"apiConfig",
")",
"\n\n",
"//Restore state from clusterStore",
"d",
".",
"restoreCache",
"(",
")",
"\n\n",
"// Register netmaster service",
"d",
".",
"registerService",
"(",
")",
"\n\n",
"// initialize policy manager",
"mastercfg",
".",
"InitPolicyMgr",
"(",
"d",
".",
"stateDriver",
",",
"d",
".",
"ofnetMaster",
")",
"\n\n",
"// setup HTTP routes",
"d",
".",
"registerRoutes",
"(",
"router",
")",
"\n\n",
"d",
".",
"startListeners",
"(",
"router",
",",
"d",
".",
"stopLeaderChan",
")",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // runLeader runs leader loop | [
"runLeader",
"runs",
"leader",
"loop"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L408-L433 |
8,053 | contiv/netplugin | netmaster/daemon/daemon.go | runFollower | func (d *MasterDaemon) runFollower() {
router := mux.NewRouter()
router.PathPrefix("/").HandlerFunc(slaveProxyHandler)
// Register netmaster service
d.registerService()
// just wait on stop channel
log.Infof("Listening in follower mode")
d.startListeners(router, d.stopFollowerChan)
log.Info("Exiting follower mode")
} | go | func (d *MasterDaemon) runFollower() {
router := mux.NewRouter()
router.PathPrefix("/").HandlerFunc(slaveProxyHandler)
// Register netmaster service
d.registerService()
// just wait on stop channel
log.Infof("Listening in follower mode")
d.startListeners(router, d.stopFollowerChan)
log.Info("Exiting follower mode")
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"runFollower",
"(",
")",
"{",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n",
"router",
".",
"PathPrefix",
"(",
"\"",
"\"",
")",
".",
"HandlerFunc",
"(",
"slaveProxyHandler",
")",
"\n\n",
"// Register netmaster service",
"d",
".",
"registerService",
"(",
")",
"\n\n",
"// just wait on stop channel",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"d",
".",
"startListeners",
"(",
"router",
",",
"d",
".",
"stopFollowerChan",
")",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // runFollower runs the follower FSM loop | [
"runFollower",
"runs",
"the",
"follower",
"FSM",
"loop"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L436-L448 |
8,054 | contiv/netplugin | netmaster/daemon/daemon.go | becomeLeader | func (d *MasterDaemon) becomeLeader() {
// ask listener to stop
d.stopFollowerChan <- true
// set current state
d.currState = "leader"
// Run the HTTP listener
go d.runLeader()
} | go | func (d *MasterDaemon) becomeLeader() {
// ask listener to stop
d.stopFollowerChan <- true
// set current state
d.currState = "leader"
// Run the HTTP listener
go d.runLeader()
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"becomeLeader",
"(",
")",
"{",
"// ask listener to stop",
"d",
".",
"stopFollowerChan",
"<-",
"true",
"\n\n",
"// set current state",
"d",
".",
"currState",
"=",
"\"",
"\"",
"\n\n",
"// Run the HTTP listener",
"go",
"d",
".",
"runLeader",
"(",
")",
"\n",
"}"
]
| // becomeLeader changes daemon FSM state to master | [
"becomeLeader",
"changes",
"daemon",
"FSM",
"state",
"to",
"master"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L496-L505 |
8,055 | contiv/netplugin | netmaster/daemon/daemon.go | becomeFollower | func (d *MasterDaemon) becomeFollower() {
// ask listener to stop
d.stopLeaderChan <- true
time.Sleep(time.Second)
// set current state
d.currState = "follower"
// run follower loop
go d.runFollower()
} | go | func (d *MasterDaemon) becomeFollower() {
// ask listener to stop
d.stopLeaderChan <- true
time.Sleep(time.Second)
// set current state
d.currState = "follower"
// run follower loop
go d.runFollower()
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"becomeFollower",
"(",
")",
"{",
"// ask listener to stop",
"d",
".",
"stopLeaderChan",
"<-",
"true",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n\n",
"// set current state",
"d",
".",
"currState",
"=",
"\"",
"\"",
"\n\n",
"// run follower loop",
"go",
"d",
".",
"runFollower",
"(",
")",
"\n",
"}"
]
| // becomeFollower changes FSM state to follower | [
"becomeFollower",
"changes",
"FSM",
"state",
"to",
"follower"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L508-L518 |
8,056 | contiv/netplugin | netmaster/daemon/daemon.go | InitServices | func (d *MasterDaemon) InitServices() {
if d.ClusterMode == "kubernetes" {
isLeader := func() bool {
return d.currState == "leader"
}
networkpolicy.InitK8SServiceWatch(d.ControlURL, isLeader)
}
} | go | func (d *MasterDaemon) InitServices() {
if d.ClusterMode == "kubernetes" {
isLeader := func() bool {
return d.currState == "leader"
}
networkpolicy.InitK8SServiceWatch(d.ControlURL, isLeader)
}
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"InitServices",
"(",
")",
"{",
"if",
"d",
".",
"ClusterMode",
"==",
"\"",
"\"",
"{",
"isLeader",
":=",
"func",
"(",
")",
"bool",
"{",
"return",
"d",
".",
"currState",
"==",
"\"",
"\"",
"\n",
"}",
"\n",
"networkpolicy",
".",
"InitK8SServiceWatch",
"(",
"d",
".",
"ControlURL",
",",
"isLeader",
")",
"\n",
"}",
"\n",
"}"
]
| // InitServices init watch services | [
"InitServices",
"init",
"watch",
"services"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L521-L528 |
8,057 | contiv/netplugin | netmaster/daemon/daemon.go | RunMasterFsm | func (d *MasterDaemon) RunMasterFsm() {
var err error
masterURL := strings.Split(d.ControlURL, ":")
masterIP, masterPort := masterURL[0], masterURL[1]
if len(masterURL) != 2 {
log.Fatalf("Invalid netmaster URL")
}
// create new ofnet master
d.ofnetMaster = ofnet.NewOfnetMaster(masterIP, ofnet.OFNET_MASTER_PORT)
if d.ofnetMaster == nil {
log.Fatalf("Error creating ofnet master")
}
// Register all existing netplugins in the background
go d.agentDiscoveryLoop()
// Create the lock
leaderLock, err = d.objdbClient.NewLock("netmaster/leader", masterIP+":"+masterPort, leaderLockTTL)
if err != nil {
log.Fatalf("Could not create leader lock. Err: %v", err)
}
// Try to acquire the lock
err = leaderLock.Acquire(0)
if err != nil {
// We dont expect any error during acquire.
log.Fatalf("Error while acquiring lock. Err: %v", err)
}
// Initialize the stop channel
d.stopLeaderChan = make(chan bool, 1)
d.stopFollowerChan = make(chan bool, 1)
// set current state
d.currState = "follower"
// Start off being a follower
go d.runFollower()
// Main run loop waiting on leader lock
for {
// Wait for lock events
select {
case event := <-leaderLock.EventChan():
if event.EventType == objdb.LockAcquired {
log.Infof("Leader lock acquired")
d.becomeLeader()
} else if event.EventType == objdb.LockLost {
log.Infof("Leader lock lost. Becoming follower")
d.becomeFollower()
}
}
}
} | go | func (d *MasterDaemon) RunMasterFsm() {
var err error
masterURL := strings.Split(d.ControlURL, ":")
masterIP, masterPort := masterURL[0], masterURL[1]
if len(masterURL) != 2 {
log.Fatalf("Invalid netmaster URL")
}
// create new ofnet master
d.ofnetMaster = ofnet.NewOfnetMaster(masterIP, ofnet.OFNET_MASTER_PORT)
if d.ofnetMaster == nil {
log.Fatalf("Error creating ofnet master")
}
// Register all existing netplugins in the background
go d.agentDiscoveryLoop()
// Create the lock
leaderLock, err = d.objdbClient.NewLock("netmaster/leader", masterIP+":"+masterPort, leaderLockTTL)
if err != nil {
log.Fatalf("Could not create leader lock. Err: %v", err)
}
// Try to acquire the lock
err = leaderLock.Acquire(0)
if err != nil {
// We dont expect any error during acquire.
log.Fatalf("Error while acquiring lock. Err: %v", err)
}
// Initialize the stop channel
d.stopLeaderChan = make(chan bool, 1)
d.stopFollowerChan = make(chan bool, 1)
// set current state
d.currState = "follower"
// Start off being a follower
go d.runFollower()
// Main run loop waiting on leader lock
for {
// Wait for lock events
select {
case event := <-leaderLock.EventChan():
if event.EventType == objdb.LockAcquired {
log.Infof("Leader lock acquired")
d.becomeLeader()
} else if event.EventType == objdb.LockLost {
log.Infof("Leader lock lost. Becoming follower")
d.becomeFollower()
}
}
}
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"RunMasterFsm",
"(",
")",
"{",
"var",
"err",
"error",
"\n\n",
"masterURL",
":=",
"strings",
".",
"Split",
"(",
"d",
".",
"ControlURL",
",",
"\"",
"\"",
")",
"\n",
"masterIP",
",",
"masterPort",
":=",
"masterURL",
"[",
"0",
"]",
",",
"masterURL",
"[",
"1",
"]",
"\n",
"if",
"len",
"(",
"masterURL",
")",
"!=",
"2",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// create new ofnet master",
"d",
".",
"ofnetMaster",
"=",
"ofnet",
".",
"NewOfnetMaster",
"(",
"masterIP",
",",
"ofnet",
".",
"OFNET_MASTER_PORT",
")",
"\n",
"if",
"d",
".",
"ofnetMaster",
"==",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Register all existing netplugins in the background",
"go",
"d",
".",
"agentDiscoveryLoop",
"(",
")",
"\n\n",
"// Create the lock",
"leaderLock",
",",
"err",
"=",
"d",
".",
"objdbClient",
".",
"NewLock",
"(",
"\"",
"\"",
",",
"masterIP",
"+",
"\"",
"\"",
"+",
"masterPort",
",",
"leaderLockTTL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Try to acquire the lock",
"err",
"=",
"leaderLock",
".",
"Acquire",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// We dont expect any error during acquire.",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Initialize the stop channel",
"d",
".",
"stopLeaderChan",
"=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"d",
".",
"stopFollowerChan",
"=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n\n",
"// set current state",
"d",
".",
"currState",
"=",
"\"",
"\"",
"\n\n",
"// Start off being a follower",
"go",
"d",
".",
"runFollower",
"(",
")",
"\n\n",
"// Main run loop waiting on leader lock",
"for",
"{",
"// Wait for lock events",
"select",
"{",
"case",
"event",
":=",
"<-",
"leaderLock",
".",
"EventChan",
"(",
")",
":",
"if",
"event",
".",
"EventType",
"==",
"objdb",
".",
"LockAcquired",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"d",
".",
"becomeLeader",
"(",
")",
"\n",
"}",
"else",
"if",
"event",
".",
"EventType",
"==",
"objdb",
".",
"LockLost",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"d",
".",
"becomeFollower",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // RunMasterFsm runs netmaster FSM | [
"RunMasterFsm",
"runs",
"netmaster",
"FSM"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L531-L588 |
8,058 | contiv/netplugin | netmaster/daemon/daemon.go | getMasterInfo | func (d *MasterDaemon) getMasterInfo() (map[string]interface{}, error) {
info := make(map[string]interface{})
// get local ip
localIP, err := netutils.GetDefaultAddr()
if err != nil {
return nil, errors.New("error getting local IP address")
}
// get current holder of master lock
leader := leaderLock.GetHolder()
if leader == "" {
return nil, errors.New("leader not found")
}
// Get all netplugin services
srvList, err := d.objdbClient.GetService("netplugin")
if err != nil {
log.Errorf("Error getting netplugin nodes. Err: %v", err)
return nil, err
}
// Add each node
pluginNodes := []string{}
for _, srv := range srvList {
pluginNodes = append(pluginNodes, srv.HostAddr)
}
// Get all netmaster services
srvList, err = d.objdbClient.GetService("netmaster")
if err != nil {
log.Errorf("Error getting netmaster nodes. Err: %v", err)
return nil, err
}
// Add each node
masterNodes := []string{}
for _, srv := range srvList {
masterNodes = append(masterNodes, srv.HostAddr)
}
// setup info map
info["local-ip"] = localIP
info["leader-ip"] = leader
info["current-state"] = d.currState
info["netplugin-nodes"] = pluginNodes
info["netmaster-nodes"] = masterNodes
return info, nil
} | go | func (d *MasterDaemon) getMasterInfo() (map[string]interface{}, error) {
info := make(map[string]interface{})
// get local ip
localIP, err := netutils.GetDefaultAddr()
if err != nil {
return nil, errors.New("error getting local IP address")
}
// get current holder of master lock
leader := leaderLock.GetHolder()
if leader == "" {
return nil, errors.New("leader not found")
}
// Get all netplugin services
srvList, err := d.objdbClient.GetService("netplugin")
if err != nil {
log.Errorf("Error getting netplugin nodes. Err: %v", err)
return nil, err
}
// Add each node
pluginNodes := []string{}
for _, srv := range srvList {
pluginNodes = append(pluginNodes, srv.HostAddr)
}
// Get all netmaster services
srvList, err = d.objdbClient.GetService("netmaster")
if err != nil {
log.Errorf("Error getting netmaster nodes. Err: %v", err)
return nil, err
}
// Add each node
masterNodes := []string{}
for _, srv := range srvList {
masterNodes = append(masterNodes, srv.HostAddr)
}
// setup info map
info["local-ip"] = localIP
info["leader-ip"] = leader
info["current-state"] = d.currState
info["netplugin-nodes"] = pluginNodes
info["netmaster-nodes"] = masterNodes
return info, nil
} | [
"func",
"(",
"d",
"*",
"MasterDaemon",
")",
"getMasterInfo",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"info",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"// get local ip",
"localIP",
",",
"err",
":=",
"netutils",
".",
"GetDefaultAddr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// get current holder of master lock",
"leader",
":=",
"leaderLock",
".",
"GetHolder",
"(",
")",
"\n",
"if",
"leader",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Get all netplugin services",
"srvList",
",",
"err",
":=",
"d",
".",
"objdbClient",
".",
"GetService",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add each node",
"pluginNodes",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"srv",
":=",
"range",
"srvList",
"{",
"pluginNodes",
"=",
"append",
"(",
"pluginNodes",
",",
"srv",
".",
"HostAddr",
")",
"\n",
"}",
"\n\n",
"// Get all netmaster services",
"srvList",
",",
"err",
"=",
"d",
".",
"objdbClient",
".",
"GetService",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add each node",
"masterNodes",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"srv",
":=",
"range",
"srvList",
"{",
"masterNodes",
"=",
"append",
"(",
"masterNodes",
",",
"srv",
".",
"HostAddr",
")",
"\n",
"}",
"\n\n",
"// setup info map",
"info",
"[",
"\"",
"\"",
"]",
"=",
"localIP",
"\n",
"info",
"[",
"\"",
"\"",
"]",
"=",
"leader",
"\n",
"info",
"[",
"\"",
"\"",
"]",
"=",
"d",
".",
"currState",
"\n",
"info",
"[",
"\"",
"\"",
"]",
"=",
"pluginNodes",
"\n",
"info",
"[",
"\"",
"\"",
"]",
"=",
"masterNodes",
"\n\n",
"return",
"info",
",",
"nil",
"\n",
"}"
]
| // getMasterInfo returns information about cluster | [
"getMasterInfo",
"returns",
"information",
"about",
"cluster"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/daemon/daemon.go#L598-L647 |
8,059 | contiv/netplugin | netmaster/master/policy.go | PolicyAttach | func PolicyAttach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// See if it already exists
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp != nil {
log.Errorf("EPG policy %s already exists", epgpKey)
return EpgPolicyExists
}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Could not get StateDriver while attaching policy %+v", policy)
return err
}
epgID, err := mastercfg.GetEndpointGroupID(stateDriver, epg.GroupName, epg.TenantName)
if err != nil {
log.Errorf("Error getting epgID for %s. Err: %v", epgpKey, err)
return err
}
// Create the epg policy
gp, err = mastercfg.NewEpgPolicy(epgpKey, epgID, policy)
if err != nil {
log.Errorf("Error creating EPG policy. Err: %v", err)
return err
}
return nil
} | go | func PolicyAttach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// See if it already exists
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp != nil {
log.Errorf("EPG policy %s already exists", epgpKey)
return EpgPolicyExists
}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Could not get StateDriver while attaching policy %+v", policy)
return err
}
epgID, err := mastercfg.GetEndpointGroupID(stateDriver, epg.GroupName, epg.TenantName)
if err != nil {
log.Errorf("Error getting epgID for %s. Err: %v", epgpKey, err)
return err
}
// Create the epg policy
gp, err = mastercfg.NewEpgPolicy(epgpKey, epgID, policy)
if err != nil {
log.Errorf("Error creating EPG policy. Err: %v", err)
return err
}
return nil
} | [
"func",
"PolicyAttach",
"(",
"epg",
"*",
"contivModel",
".",
"EndpointGroup",
",",
"policy",
"*",
"contivModel",
".",
"Policy",
")",
"error",
"{",
"// Dont install policies in ACI mode",
"if",
"!",
"isPolicyEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"epgpKey",
":=",
"epg",
".",
"Key",
"+",
"\"",
"\"",
"+",
"policy",
".",
"Key",
"\n\n",
"// See if it already exists",
"gp",
":=",
"mastercfg",
".",
"FindEpgPolicy",
"(",
"epgpKey",
")",
"\n",
"if",
"gp",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgpKey",
")",
"\n",
"return",
"EpgPolicyExists",
"\n",
"}",
"\n\n",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"policy",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"epgID",
",",
"err",
":=",
"mastercfg",
".",
"GetEndpointGroupID",
"(",
"stateDriver",
",",
"epg",
".",
"GroupName",
",",
"epg",
".",
"TenantName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgpKey",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Create the epg policy",
"gp",
",",
"err",
"=",
"mastercfg",
".",
"NewEpgPolicy",
"(",
"epgpKey",
",",
"epgID",
",",
"policy",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // PolicyAttach attaches a policy to an endpoint and adds associated rules to policyDB | [
"PolicyAttach",
"attaches",
"a",
"policy",
"to",
"an",
"endpoint",
"and",
"adds",
"associated",
"rules",
"to",
"policyDB"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/policy.go#L42-L77 |
8,060 | contiv/netplugin | netmaster/master/policy.go | PolicyDetach | func PolicyDetach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// find the policy
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp == nil {
log.Errorf("Epg policy %s does not exist", epgpKey)
return core.Errorf("epg policy does not exist")
}
// Delete all rules within the policy
for ruleKey := range policy.LinkSets.Rules {
// find the rule
rule := contivModel.FindRule(ruleKey)
if rule == nil {
log.Errorf("Error finding the rule %s", ruleKey)
continue
}
log.Infof("Deleting Rule %s from epgp policy %s", ruleKey, epgpKey)
// Add the rule to epg Policy
err := gp.DelRule(rule)
if err != nil {
log.Errorf("Error deleting rule %s from epg polict %s. Err: %v", ruleKey, epgpKey, err)
}
}
// delete it
return gp.Delete()
} | go | func PolicyDetach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// find the policy
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp == nil {
log.Errorf("Epg policy %s does not exist", epgpKey)
return core.Errorf("epg policy does not exist")
}
// Delete all rules within the policy
for ruleKey := range policy.LinkSets.Rules {
// find the rule
rule := contivModel.FindRule(ruleKey)
if rule == nil {
log.Errorf("Error finding the rule %s", ruleKey)
continue
}
log.Infof("Deleting Rule %s from epgp policy %s", ruleKey, epgpKey)
// Add the rule to epg Policy
err := gp.DelRule(rule)
if err != nil {
log.Errorf("Error deleting rule %s from epg polict %s. Err: %v", ruleKey, epgpKey, err)
}
}
// delete it
return gp.Delete()
} | [
"func",
"PolicyDetach",
"(",
"epg",
"*",
"contivModel",
".",
"EndpointGroup",
",",
"policy",
"*",
"contivModel",
".",
"Policy",
")",
"error",
"{",
"// Dont install policies in ACI mode",
"if",
"!",
"isPolicyEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"epgpKey",
":=",
"epg",
".",
"Key",
"+",
"\"",
"\"",
"+",
"policy",
".",
"Key",
"\n\n",
"// find the policy",
"gp",
":=",
"mastercfg",
".",
"FindEpgPolicy",
"(",
"epgpKey",
")",
"\n",
"if",
"gp",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgpKey",
")",
"\n",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Delete all rules within the policy",
"for",
"ruleKey",
":=",
"range",
"policy",
".",
"LinkSets",
".",
"Rules",
"{",
"// find the rule",
"rule",
":=",
"contivModel",
".",
"FindRule",
"(",
"ruleKey",
")",
"\n",
"if",
"rule",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ruleKey",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"epgpKey",
")",
"\n\n",
"// Add the rule to epg Policy",
"err",
":=",
"gp",
".",
"DelRule",
"(",
"rule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"epgpKey",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// delete it",
"return",
"gp",
".",
"Delete",
"(",
")",
"\n",
"}"
]
| // PolicyDetach detaches policy from an endpoint and removes associated rules from policyDB | [
"PolicyDetach",
"detaches",
"policy",
"from",
"an",
"endpoint",
"and",
"removes",
"associated",
"rules",
"from",
"policyDB"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/policy.go#L80-L115 |
8,061 | contiv/netplugin | netmaster/master/policy.go | PolicyAddRule | func PolicyAddRule(policy *contivModel.Policy, rule *contivModel.Rule) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
// Walk all associated endpoint groups
for epgKey := range policy.LinkSets.EndpointGroups {
gpKey := epgKey + ":" + policy.Key
// Find the epg policy
gp := mastercfg.FindEpgPolicy(gpKey)
if gp == nil {
log.Errorf("Failed to find the epg policy %s", gpKey)
return core.Errorf("epg policy not found")
}
// Add the Rule
err := gp.AddRule(rule)
if err != nil {
log.Errorf("Error adding the rule %s to epg policy %s. Err: %v", rule.Key, gpKey, err)
return err
}
// Save the policy state
err = gp.Write()
if err != nil {
return err
}
}
return nil
} | go | func PolicyAddRule(policy *contivModel.Policy, rule *contivModel.Rule) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
// Walk all associated endpoint groups
for epgKey := range policy.LinkSets.EndpointGroups {
gpKey := epgKey + ":" + policy.Key
// Find the epg policy
gp := mastercfg.FindEpgPolicy(gpKey)
if gp == nil {
log.Errorf("Failed to find the epg policy %s", gpKey)
return core.Errorf("epg policy not found")
}
// Add the Rule
err := gp.AddRule(rule)
if err != nil {
log.Errorf("Error adding the rule %s to epg policy %s. Err: %v", rule.Key, gpKey, err)
return err
}
// Save the policy state
err = gp.Write()
if err != nil {
return err
}
}
return nil
} | [
"func",
"PolicyAddRule",
"(",
"policy",
"*",
"contivModel",
".",
"Policy",
",",
"rule",
"*",
"contivModel",
".",
"Rule",
")",
"error",
"{",
"// Dont install policies in ACI mode",
"if",
"!",
"isPolicyEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Walk all associated endpoint groups",
"for",
"epgKey",
":=",
"range",
"policy",
".",
"LinkSets",
".",
"EndpointGroups",
"{",
"gpKey",
":=",
"epgKey",
"+",
"\"",
"\"",
"+",
"policy",
".",
"Key",
"\n\n",
"// Find the epg policy",
"gp",
":=",
"mastercfg",
".",
"FindEpgPolicy",
"(",
"gpKey",
")",
"\n",
"if",
"gp",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gpKey",
")",
"\n",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Add the Rule",
"err",
":=",
"gp",
".",
"AddRule",
"(",
"rule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rule",
".",
"Key",
",",
"gpKey",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Save the policy state",
"err",
"=",
"gp",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // PolicyAddRule adds a rule to existing policy | [
"PolicyAddRule",
"adds",
"a",
"rule",
"to",
"existing",
"policy"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/policy.go#L118-L150 |
8,062 | contiv/netplugin | state/cfgtool/cfgtool.go | initStateDriver | func initStateDriver(clusterStore string) (core.StateDriver, error) {
// parse the state store URL
parts := strings.Split(clusterStore, "://")
if len(parts) < 2 {
return nil, core.Errorf("Invalid state-store URL %q", clusterStore)
}
stateStore := parts[0]
// Make sure we support the statestore type
switch stateStore {
case utils.EtcdNameStr:
case utils.ConsulNameStr:
default:
return nil, core.Errorf("Unsupported state-store %q", stateStore)
}
// Setup instance info
instInfo := core.InstanceInfo{
DbURL: clusterStore,
}
return utils.NewStateDriver(stateStore, &instInfo)
} | go | func initStateDriver(clusterStore string) (core.StateDriver, error) {
// parse the state store URL
parts := strings.Split(clusterStore, "://")
if len(parts) < 2 {
return nil, core.Errorf("Invalid state-store URL %q", clusterStore)
}
stateStore := parts[0]
// Make sure we support the statestore type
switch stateStore {
case utils.EtcdNameStr:
case utils.ConsulNameStr:
default:
return nil, core.Errorf("Unsupported state-store %q", stateStore)
}
// Setup instance info
instInfo := core.InstanceInfo{
DbURL: clusterStore,
}
return utils.NewStateDriver(stateStore, &instInfo)
} | [
"func",
"initStateDriver",
"(",
"clusterStore",
"string",
")",
"(",
"core",
".",
"StateDriver",
",",
"error",
")",
"{",
"// parse the state store URL",
"parts",
":=",
"strings",
".",
"Split",
"(",
"clusterStore",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"clusterStore",
")",
"\n",
"}",
"\n",
"stateStore",
":=",
"parts",
"[",
"0",
"]",
"\n\n",
"// Make sure we support the statestore type",
"switch",
"stateStore",
"{",
"case",
"utils",
".",
"EtcdNameStr",
":",
"case",
"utils",
".",
"ConsulNameStr",
":",
"default",
":",
"return",
"nil",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stateStore",
")",
"\n",
"}",
"\n\n",
"// Setup instance info",
"instInfo",
":=",
"core",
".",
"InstanceInfo",
"{",
"DbURL",
":",
"clusterStore",
",",
"}",
"\n\n",
"return",
"utils",
".",
"NewStateDriver",
"(",
"stateStore",
",",
"&",
"instInfo",
")",
"\n",
"}"
]
| // initStateDriver creates a state driver based on the cluster store URL | [
"initStateDriver",
"creates",
"a",
"state",
"driver",
"based",
"on",
"the",
"cluster",
"store",
"URL"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/cfgtool/cfgtool.go#L38-L60 |
8,063 | contiv/netplugin | state/cfgtool/cfgtool.go | parseRange | func parseRange(rangeStr string) ([]uint, error) {
var values []uint
if rangeStr == "" {
return []uint{}, nil
}
// split ranges based on "," char
rangeList := strings.Split(rangeStr, ",")
for _, subrange := range rangeList {
minMax := strings.Split(strings.TrimSpace(subrange), "-")
if len(minMax) == 2 {
min, err := strconv.Atoi(minMax[0])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
max, err := strconv.Atoi(minMax[1])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
// some error checking
if min > max || min < 0 || max < 0 {
log.Errorf("Invalid range values: %v", subrange)
return nil, fmt.Errorf("invalid range values")
}
for i := min; i <= max; i++ {
values = append(values, uint(i))
}
} else if len(minMax) == 1 {
val, err := strconv.Atoi(minMax[0])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
values = append(values, uint(val))
} else {
log.Errorf("Invalid range: %v", subrange)
return nil, fmt.Errorf("invalid range format")
}
}
return values, nil
} | go | func parseRange(rangeStr string) ([]uint, error) {
var values []uint
if rangeStr == "" {
return []uint{}, nil
}
// split ranges based on "," char
rangeList := strings.Split(rangeStr, ",")
for _, subrange := range rangeList {
minMax := strings.Split(strings.TrimSpace(subrange), "-")
if len(minMax) == 2 {
min, err := strconv.Atoi(minMax[0])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
max, err := strconv.Atoi(minMax[1])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
// some error checking
if min > max || min < 0 || max < 0 {
log.Errorf("Invalid range values: %v", subrange)
return nil, fmt.Errorf("invalid range values")
}
for i := min; i <= max; i++ {
values = append(values, uint(i))
}
} else if len(minMax) == 1 {
val, err := strconv.Atoi(minMax[0])
if err != nil {
log.Errorf("Invalid range: %v", subrange)
return nil, err
}
values = append(values, uint(val))
} else {
log.Errorf("Invalid range: %v", subrange)
return nil, fmt.Errorf("invalid range format")
}
}
return values, nil
} | [
"func",
"parseRange",
"(",
"rangeStr",
"string",
")",
"(",
"[",
"]",
"uint",
",",
"error",
")",
"{",
"var",
"values",
"[",
"]",
"uint",
"\n",
"if",
"rangeStr",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"uint",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"// split ranges based on \",\" char",
"rangeList",
":=",
"strings",
".",
"Split",
"(",
"rangeStr",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"subrange",
":=",
"range",
"rangeList",
"{",
"minMax",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"subrange",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"minMax",
")",
"==",
"2",
"{",
"min",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"minMax",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subrange",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"max",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"minMax",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subrange",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// some error checking",
"if",
"min",
">",
"max",
"||",
"min",
"<",
"0",
"||",
"max",
"<",
"0",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subrange",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"min",
";",
"i",
"<=",
"max",
";",
"i",
"++",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"uint",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"minMax",
")",
"==",
"1",
"{",
"val",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"minMax",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subrange",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"values",
"=",
"append",
"(",
"values",
",",
"uint",
"(",
"val",
")",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subrange",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"values",
",",
"nil",
"\n",
"}"
]
| // parseRange parses a string in "1,2-3,4-10" format and returns an array of values | [
"parseRange",
"parses",
"a",
"string",
"in",
"1",
"2",
"-",
"3",
"4",
"-",
"10",
"format",
"and",
"returns",
"an",
"array",
"of",
"values"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/cfgtool/cfgtool.go#L63-L110 |
8,064 | contiv/netplugin | state/cfgtool/cfgtool.go | processResource | func processResource(stateDriver core.StateDriver, rsrcName, rsrcVal string) error {
// Read global config
gCfg := gstate.Cfg{}
gCfg.StateDriver = stateDriver
err := gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant cfg state. Error: %s", err)
return err
}
// process resource based on name
if rsrcName == "vlan" {
numVlans, vlansInUse := gCfg.GetVlansInUse()
fmt.Printf("Num Vlans: %d\n Current Vlans in Use: %s\n", numVlans, vlansInUse)
// see if we need to set the resource
if rsrcVal != "" {
values, err := parseRange(rsrcVal)
if err != nil {
log.Errorf("Error parsing range: %v", err)
return err
}
log.Infof("Setting vlan values: %v", values)
// set vlan values
for _, val := range values {
_, err = gCfg.AllocVLAN(val)
if err != nil {
log.Errorf("Error setting vlan: %d. Err: %v", val, err)
}
}
log.Infof("Finished setting VLANs")
}
} else if rsrcName == "vxlan" {
numVxlans, vxlansInUse := gCfg.GetVxlansInUse()
fmt.Printf("Num Vxlans: %d\n Current Vxlans in Use: %s\n", numVxlans, vxlansInUse)
// see if we need to set the resource
if rsrcVal != "" {
values, err := parseRange(rsrcVal)
if err != nil {
log.Errorf("Error parsing range: %v", err)
return err
}
log.Infof("Setting vxlan values: %v", values)
// set vlan values
for _, val := range values {
_, _, err = gCfg.AllocVXLAN(val)
if err != nil {
log.Errorf("Error setting vxlan: %d. Err: %v", val, err)
}
}
log.Infof("Finished setting VXLANs")
}
} else {
log.Errorf("Unknown resource: %v", rsrcName)
return fmt.Errorf("unknown resource")
}
return nil
} | go | func processResource(stateDriver core.StateDriver, rsrcName, rsrcVal string) error {
// Read global config
gCfg := gstate.Cfg{}
gCfg.StateDriver = stateDriver
err := gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant cfg state. Error: %s", err)
return err
}
// process resource based on name
if rsrcName == "vlan" {
numVlans, vlansInUse := gCfg.GetVlansInUse()
fmt.Printf("Num Vlans: %d\n Current Vlans in Use: %s\n", numVlans, vlansInUse)
// see if we need to set the resource
if rsrcVal != "" {
values, err := parseRange(rsrcVal)
if err != nil {
log.Errorf("Error parsing range: %v", err)
return err
}
log.Infof("Setting vlan values: %v", values)
// set vlan values
for _, val := range values {
_, err = gCfg.AllocVLAN(val)
if err != nil {
log.Errorf("Error setting vlan: %d. Err: %v", val, err)
}
}
log.Infof("Finished setting VLANs")
}
} else if rsrcName == "vxlan" {
numVxlans, vxlansInUse := gCfg.GetVxlansInUse()
fmt.Printf("Num Vxlans: %d\n Current Vxlans in Use: %s\n", numVxlans, vxlansInUse)
// see if we need to set the resource
if rsrcVal != "" {
values, err := parseRange(rsrcVal)
if err != nil {
log.Errorf("Error parsing range: %v", err)
return err
}
log.Infof("Setting vxlan values: %v", values)
// set vlan values
for _, val := range values {
_, _, err = gCfg.AllocVXLAN(val)
if err != nil {
log.Errorf("Error setting vxlan: %d. Err: %v", val, err)
}
}
log.Infof("Finished setting VXLANs")
}
} else {
log.Errorf("Unknown resource: %v", rsrcName)
return fmt.Errorf("unknown resource")
}
return nil
} | [
"func",
"processResource",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"rsrcName",
",",
"rsrcVal",
"string",
")",
"error",
"{",
"// Read global config",
"gCfg",
":=",
"gstate",
".",
"Cfg",
"{",
"}",
"\n",
"gCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"gCfg",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// process resource based on name",
"if",
"rsrcName",
"==",
"\"",
"\"",
"{",
"numVlans",
",",
"vlansInUse",
":=",
"gCfg",
".",
"GetVlansInUse",
"(",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"numVlans",
",",
"vlansInUse",
")",
"\n\n",
"// see if we need to set the resource",
"if",
"rsrcVal",
"!=",
"\"",
"\"",
"{",
"values",
",",
"err",
":=",
"parseRange",
"(",
"rsrcVal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"values",
")",
"\n\n",
"// set vlan values",
"for",
"_",
",",
"val",
":=",
"range",
"values",
"{",
"_",
",",
"err",
"=",
"gCfg",
".",
"AllocVLAN",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"rsrcName",
"==",
"\"",
"\"",
"{",
"numVxlans",
",",
"vxlansInUse",
":=",
"gCfg",
".",
"GetVxlansInUse",
"(",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"numVxlans",
",",
"vxlansInUse",
")",
"\n\n",
"// see if we need to set the resource",
"if",
"rsrcVal",
"!=",
"\"",
"\"",
"{",
"values",
",",
"err",
":=",
"parseRange",
"(",
"rsrcVal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"values",
")",
"\n\n",
"// set vlan values",
"for",
"_",
",",
"val",
":=",
"range",
"values",
"{",
"_",
",",
"_",
",",
"err",
"=",
"gCfg",
".",
"AllocVXLAN",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rsrcName",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // processResource handles resource commands | [
"processResource",
"handles",
"resource",
"commands"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/state/cfgtool/cfgtool.go#L113-L176 |
8,065 | contiv/netplugin | mgmtfn/mesosplugin/cnidriver.go | ipnsExecute | func (cniReq *cniServer) ipnsExecute(namespace string, args []string) ([]byte, error) {
ipCmd := "ip"
ipArgs := []string{"netns", "exec", namespace}
ipArgs = append(ipArgs, args...)
cniLog.Infof("processing cmd: %v", ipArgs)
return exec.Command(ipCmd, ipArgs...).CombinedOutput()
} | go | func (cniReq *cniServer) ipnsExecute(namespace string, args []string) ([]byte, error) {
ipCmd := "ip"
ipArgs := []string{"netns", "exec", namespace}
ipArgs = append(ipArgs, args...)
cniLog.Infof("processing cmd: %v", ipArgs)
return exec.Command(ipCmd, ipArgs...).CombinedOutput()
} | [
"func",
"(",
"cniReq",
"*",
"cniServer",
")",
"ipnsExecute",
"(",
"namespace",
"string",
",",
"args",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ipCmd",
":=",
"\"",
"\"",
"\n",
"ipArgs",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"namespace",
"}",
"\n\n",
"ipArgs",
"=",
"append",
"(",
"ipArgs",
",",
"args",
"...",
")",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ipArgs",
")",
"\n",
"return",
"exec",
".",
"Command",
"(",
"ipCmd",
",",
"ipArgs",
"...",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"}"
]
| // execute name space commands | [
"execute",
"name",
"space",
"commands"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/cnidriver.go#L43-L50 |
8,066 | contiv/netplugin | mgmtfn/mesosplugin/cnidriver.go | ipnsBatchExecute | func (cniReq *cniServer) ipnsBatchExecute(namespace string, args [][]string) ([]byte, error) {
for idx, arg1 := range args {
if out, err := cniReq.ipnsExecute(namespace, arg1); err != nil {
cniLog.Errorf("failed to execute [%d] %v %s, %s", idx, err, arg1, string(out))
return out, err
}
}
return nil, nil
} | go | func (cniReq *cniServer) ipnsBatchExecute(namespace string, args [][]string) ([]byte, error) {
for idx, arg1 := range args {
if out, err := cniReq.ipnsExecute(namespace, arg1); err != nil {
cniLog.Errorf("failed to execute [%d] %v %s, %s", idx, err, arg1, string(out))
return out, err
}
}
return nil, nil
} | [
"func",
"(",
"cniReq",
"*",
"cniServer",
")",
"ipnsBatchExecute",
"(",
"namespace",
"string",
",",
"args",
"[",
"]",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"for",
"idx",
",",
"arg1",
":=",
"range",
"args",
"{",
"if",
"out",
",",
"err",
":=",
"cniReq",
".",
"ipnsExecute",
"(",
"namespace",
",",
"arg1",
")",
";",
"err",
"!=",
"nil",
"{",
"cniLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"idx",
",",
"err",
",",
"arg1",
",",
"string",
"(",
"out",
")",
")",
"\n",
"return",
"out",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
]
| // execute a batch of namespace commands | [
"execute",
"a",
"batch",
"of",
"namespace",
"commands"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/cnidriver.go#L53-L63 |
8,067 | contiv/netplugin | mgmtfn/k8splugin/cniserver.go | setUpAPIClient | func setUpAPIClient() *APIClient {
// Read config
err := k8sutils.GetK8SConfig(&contivK8Config)
if err != nil {
log.Errorf("Failed: %v", err)
return nil
}
return NewAPIClient(contivK8Config.K8sAPIServer, contivK8Config.K8sCa,
contivK8Config.K8sKey, contivK8Config.K8sCert, contivK8Config.K8sToken)
} | go | func setUpAPIClient() *APIClient {
// Read config
err := k8sutils.GetK8SConfig(&contivK8Config)
if err != nil {
log.Errorf("Failed: %v", err)
return nil
}
return NewAPIClient(contivK8Config.K8sAPIServer, contivK8Config.K8sCa,
contivK8Config.K8sKey, contivK8Config.K8sCert, contivK8Config.K8sToken)
} | [
"func",
"setUpAPIClient",
"(",
")",
"*",
"APIClient",
"{",
"// Read config",
"err",
":=",
"k8sutils",
".",
"GetK8SConfig",
"(",
"&",
"contivK8Config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"NewAPIClient",
"(",
"contivK8Config",
".",
"K8sAPIServer",
",",
"contivK8Config",
".",
"K8sCa",
",",
"contivK8Config",
".",
"K8sKey",
",",
"contivK8Config",
".",
"K8sCert",
",",
"contivK8Config",
".",
"K8sToken",
")",
"\n\n",
"}"
]
| // setUpAPIClient sets up an instance of the k8s api server | [
"setUpAPIClient",
"sets",
"up",
"an",
"instance",
"of",
"the",
"k8s",
"api",
"server"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/cniserver.go#L42-L53 |
8,068 | contiv/netplugin | mgmtfn/k8splugin/cniserver.go | InitKubServiceWatch | func InitKubServiceWatch(np *plugin.NetPlugin) {
watchClient := setUpAPIClient()
if watchClient == nil {
log.Fatalf("Could not init kubernetes API client")
}
svcCh := make(chan SvcWatchResp, 1)
epCh := make(chan EpWatchResp, 1)
go func() {
for {
select {
case svcEvent := <-svcCh:
switch svcEvent.opcode {
case "WARN":
log.Debugf("svcWatch : %s", svcEvent.errStr)
break
case "FATAL":
log.Errorf("svcWatch : %s", svcEvent.errStr)
break
case "ERROR":
log.Warnf("svcWatch : %s", svcEvent.errStr)
watchClient.WatchServices(svcCh)
break
case "DELETED":
np.DelSvcSpec(svcEvent.svcName, &svcEvent.svcSpec)
break
default:
np.AddSvcSpec(svcEvent.svcName, &svcEvent.svcSpec)
}
case epEvent := <-epCh:
switch epEvent.opcode {
case "WARN":
log.Debugf("epWatch : %s", epEvent.errStr)
break
case "FATAL":
log.Errorf("epWatch : %s", epEvent.errStr)
break
case "ERROR":
log.Warnf("epWatch : %s", epEvent.errStr)
watchClient.WatchSvcEps(epCh)
break
default:
np.SvcProviderUpdate(epEvent.svcName, epEvent.providers)
}
}
}
}()
watchClient.WatchServices(svcCh)
watchClient.WatchSvcEps(epCh)
} | go | func InitKubServiceWatch(np *plugin.NetPlugin) {
watchClient := setUpAPIClient()
if watchClient == nil {
log.Fatalf("Could not init kubernetes API client")
}
svcCh := make(chan SvcWatchResp, 1)
epCh := make(chan EpWatchResp, 1)
go func() {
for {
select {
case svcEvent := <-svcCh:
switch svcEvent.opcode {
case "WARN":
log.Debugf("svcWatch : %s", svcEvent.errStr)
break
case "FATAL":
log.Errorf("svcWatch : %s", svcEvent.errStr)
break
case "ERROR":
log.Warnf("svcWatch : %s", svcEvent.errStr)
watchClient.WatchServices(svcCh)
break
case "DELETED":
np.DelSvcSpec(svcEvent.svcName, &svcEvent.svcSpec)
break
default:
np.AddSvcSpec(svcEvent.svcName, &svcEvent.svcSpec)
}
case epEvent := <-epCh:
switch epEvent.opcode {
case "WARN":
log.Debugf("epWatch : %s", epEvent.errStr)
break
case "FATAL":
log.Errorf("epWatch : %s", epEvent.errStr)
break
case "ERROR":
log.Warnf("epWatch : %s", epEvent.errStr)
watchClient.WatchSvcEps(epCh)
break
default:
np.SvcProviderUpdate(epEvent.svcName, epEvent.providers)
}
}
}
}()
watchClient.WatchServices(svcCh)
watchClient.WatchSvcEps(epCh)
} | [
"func",
"InitKubServiceWatch",
"(",
"np",
"*",
"plugin",
".",
"NetPlugin",
")",
"{",
"watchClient",
":=",
"setUpAPIClient",
"(",
")",
"\n",
"if",
"watchClient",
"==",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"svcCh",
":=",
"make",
"(",
"chan",
"SvcWatchResp",
",",
"1",
")",
"\n",
"epCh",
":=",
"make",
"(",
"chan",
"EpWatchResp",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"svcEvent",
":=",
"<-",
"svcCh",
":",
"switch",
"svcEvent",
".",
"opcode",
"{",
"case",
"\"",
"\"",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"svcEvent",
".",
"errStr",
")",
"\n",
"break",
"\n",
"case",
"\"",
"\"",
":",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"svcEvent",
".",
"errStr",
")",
"\n",
"break",
"\n",
"case",
"\"",
"\"",
":",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"svcEvent",
".",
"errStr",
")",
"\n",
"watchClient",
".",
"WatchServices",
"(",
"svcCh",
")",
"\n",
"break",
"\n\n",
"case",
"\"",
"\"",
":",
"np",
".",
"DelSvcSpec",
"(",
"svcEvent",
".",
"svcName",
",",
"&",
"svcEvent",
".",
"svcSpec",
")",
"\n",
"break",
"\n",
"default",
":",
"np",
".",
"AddSvcSpec",
"(",
"svcEvent",
".",
"svcName",
",",
"&",
"svcEvent",
".",
"svcSpec",
")",
"\n",
"}",
"\n",
"case",
"epEvent",
":=",
"<-",
"epCh",
":",
"switch",
"epEvent",
".",
"opcode",
"{",
"case",
"\"",
"\"",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"epEvent",
".",
"errStr",
")",
"\n",
"break",
"\n",
"case",
"\"",
"\"",
":",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epEvent",
".",
"errStr",
")",
"\n",
"break",
"\n",
"case",
"\"",
"\"",
":",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"epEvent",
".",
"errStr",
")",
"\n",
"watchClient",
".",
"WatchSvcEps",
"(",
"epCh",
")",
"\n",
"break",
"\n\n",
"default",
":",
"np",
".",
"SvcProviderUpdate",
"(",
"epEvent",
".",
"svcName",
",",
"epEvent",
".",
"providers",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"watchClient",
".",
"WatchServices",
"(",
"svcCh",
")",
"\n",
"watchClient",
".",
"WatchSvcEps",
"(",
"epCh",
")",
"\n",
"}"
]
| // InitKubServiceWatch initializes the k8s service watch | [
"InitKubServiceWatch",
"initializes",
"the",
"k8s",
"service",
"watch"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/cniserver.go#L56-L109 |
8,069 | contiv/netplugin | mgmtfn/k8splugin/cniserver.go | InitCNIServer | func InitCNIServer(netplugin *plugin.NetPlugin) error {
netPlugin = netplugin
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not retrieve hostname: %v", err)
}
pluginHost = hostname
// Set up the api client instance
kubeAPIClient = setUpAPIClient()
if kubeAPIClient == nil {
log.Fatalf("Could not init kubernetes API client")
}
log.Debugf("Configuring router")
router := mux.NewRouter()
// register handlers for cni
t := router.Headers("Content-Type", "application/json").Methods("POST").Subrouter()
t.HandleFunc(cniapi.EPAddURL, utils.MakeHTTPHandler(addPod))
t.HandleFunc(cniapi.EPDelURL, utils.MakeHTTPHandler(deletePod))
t.HandleFunc("/ContivCNI.{*}", utils.UnknownAction)
driverPath := cniapi.ContivCniSocket
os.Remove(driverPath)
os.MkdirAll(cniapi.PluginPath, 0700)
go func() {
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: driverPath, Net: "unix"})
if err != nil {
panic(err)
}
log.Infof("k8s plugin listening on %s", driverPath)
http.Serve(l, router)
l.Close()
log.Infof("k8s plugin closing %s", driverPath)
}()
//InitKubServiceWatch(netplugin)
return nil
} | go | func InitCNIServer(netplugin *plugin.NetPlugin) error {
netPlugin = netplugin
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not retrieve hostname: %v", err)
}
pluginHost = hostname
// Set up the api client instance
kubeAPIClient = setUpAPIClient()
if kubeAPIClient == nil {
log.Fatalf("Could not init kubernetes API client")
}
log.Debugf("Configuring router")
router := mux.NewRouter()
// register handlers for cni
t := router.Headers("Content-Type", "application/json").Methods("POST").Subrouter()
t.HandleFunc(cniapi.EPAddURL, utils.MakeHTTPHandler(addPod))
t.HandleFunc(cniapi.EPDelURL, utils.MakeHTTPHandler(deletePod))
t.HandleFunc("/ContivCNI.{*}", utils.UnknownAction)
driverPath := cniapi.ContivCniSocket
os.Remove(driverPath)
os.MkdirAll(cniapi.PluginPath, 0700)
go func() {
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: driverPath, Net: "unix"})
if err != nil {
panic(err)
}
log.Infof("k8s plugin listening on %s", driverPath)
http.Serve(l, router)
l.Close()
log.Infof("k8s plugin closing %s", driverPath)
}()
//InitKubServiceWatch(netplugin)
return nil
} | [
"func",
"InitCNIServer",
"(",
"netplugin",
"*",
"plugin",
".",
"NetPlugin",
")",
"error",
"{",
"netPlugin",
"=",
"netplugin",
"\n",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"pluginHost",
"=",
"hostname",
"\n\n",
"// Set up the api client instance",
"kubeAPIClient",
"=",
"setUpAPIClient",
"(",
")",
"\n",
"if",
"kubeAPIClient",
"==",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n\n",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n\n",
"// register handlers for cni",
"t",
":=",
"router",
".",
"Headers",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Methods",
"(",
"\"",
"\"",
")",
".",
"Subrouter",
"(",
")",
"\n",
"t",
".",
"HandleFunc",
"(",
"cniapi",
".",
"EPAddURL",
",",
"utils",
".",
"MakeHTTPHandler",
"(",
"addPod",
")",
")",
"\n",
"t",
".",
"HandleFunc",
"(",
"cniapi",
".",
"EPDelURL",
",",
"utils",
".",
"MakeHTTPHandler",
"(",
"deletePod",
")",
")",
"\n",
"t",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"utils",
".",
"UnknownAction",
")",
"\n\n",
"driverPath",
":=",
"cniapi",
".",
"ContivCniSocket",
"\n",
"os",
".",
"Remove",
"(",
"driverPath",
")",
"\n",
"os",
".",
"MkdirAll",
"(",
"cniapi",
".",
"PluginPath",
",",
"0700",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"l",
",",
"err",
":=",
"net",
".",
"ListenUnix",
"(",
"\"",
"\"",
",",
"&",
"net",
".",
"UnixAddr",
"{",
"Name",
":",
"driverPath",
",",
"Net",
":",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"driverPath",
")",
"\n",
"http",
".",
"Serve",
"(",
"l",
",",
"router",
")",
"\n",
"l",
".",
"Close",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"driverPath",
")",
"\n",
"}",
"(",
")",
"\n\n",
"//InitKubServiceWatch(netplugin)",
"return",
"nil",
"\n",
"}"
]
| // InitCNIServer initializes the k8s cni server | [
"InitCNIServer",
"initializes",
"the",
"k8s",
"cni",
"server"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/cniserver.go#L112-L156 |
8,070 | contiv/netplugin | mgmtfn/k8splugin/driver.go | epCleanUp | func epCleanUp(req *epSpec) error {
// first delete from netplugin
// ignore any errors as this is best effort
netID := req.Network + "." + req.Tenant
pluginErr := netPlugin.DeleteEndpoint(netID + "-" + req.EndpointID)
// now delete from master
delReq := master.DeleteEndpointRequest{
TenantName: req.Tenant,
NetworkName: req.Network,
ServiceName: req.Group,
EndpointID: req.EndpointID,
}
var delResp master.DeleteEndpointResponse
masterErr := cluster.MasterPostReq("/plugin/deleteEndpoint", &delReq, &delResp)
if pluginErr != nil {
log.Errorf("failed to delete endpoint: %s from netplugin %s",
netID+"-"+req.EndpointID, pluginErr)
return pluginErr
}
if masterErr != nil {
log.Errorf("failed to delete endpoint %+v from netmaster, %s", delReq, masterErr)
}
return masterErr
} | go | func epCleanUp(req *epSpec) error {
// first delete from netplugin
// ignore any errors as this is best effort
netID := req.Network + "." + req.Tenant
pluginErr := netPlugin.DeleteEndpoint(netID + "-" + req.EndpointID)
// now delete from master
delReq := master.DeleteEndpointRequest{
TenantName: req.Tenant,
NetworkName: req.Network,
ServiceName: req.Group,
EndpointID: req.EndpointID,
}
var delResp master.DeleteEndpointResponse
masterErr := cluster.MasterPostReq("/plugin/deleteEndpoint", &delReq, &delResp)
if pluginErr != nil {
log.Errorf("failed to delete endpoint: %s from netplugin %s",
netID+"-"+req.EndpointID, pluginErr)
return pluginErr
}
if masterErr != nil {
log.Errorf("failed to delete endpoint %+v from netmaster, %s", delReq, masterErr)
}
return masterErr
} | [
"func",
"epCleanUp",
"(",
"req",
"*",
"epSpec",
")",
"error",
"{",
"// first delete from netplugin",
"// ignore any errors as this is best effort",
"netID",
":=",
"req",
".",
"Network",
"+",
"\"",
"\"",
"+",
"req",
".",
"Tenant",
"\n",
"pluginErr",
":=",
"netPlugin",
".",
"DeleteEndpoint",
"(",
"netID",
"+",
"\"",
"\"",
"+",
"req",
".",
"EndpointID",
")",
"\n\n",
"// now delete from master",
"delReq",
":=",
"master",
".",
"DeleteEndpointRequest",
"{",
"TenantName",
":",
"req",
".",
"Tenant",
",",
"NetworkName",
":",
"req",
".",
"Network",
",",
"ServiceName",
":",
"req",
".",
"Group",
",",
"EndpointID",
":",
"req",
".",
"EndpointID",
",",
"}",
"\n\n",
"var",
"delResp",
"master",
".",
"DeleteEndpointResponse",
"\n",
"masterErr",
":=",
"cluster",
".",
"MasterPostReq",
"(",
"\"",
"\"",
",",
"&",
"delReq",
",",
"&",
"delResp",
")",
"\n\n",
"if",
"pluginErr",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"netID",
"+",
"\"",
"\"",
"+",
"req",
".",
"EndpointID",
",",
"pluginErr",
")",
"\n",
"return",
"pluginErr",
"\n",
"}",
"\n\n",
"if",
"masterErr",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"delReq",
",",
"masterErr",
")",
"\n",
"}",
"\n\n",
"return",
"masterErr",
"\n",
"}"
]
| // epCleanUp deletes the ep from netplugin and netmaster | [
"epCleanUp",
"deletes",
"the",
"ep",
"from",
"netplugin",
"and",
"netmaster"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L57-L85 |
8,071 | contiv/netplugin | mgmtfn/k8splugin/driver.go | createEP | func createEP(req *epSpec) (*epAttr, error) {
// if the ep already exists, treat as error for now.
netID := req.Network + "." + req.Tenant
ep, err := utils.GetEndpoint(netID + "-" + req.EndpointID)
if err == nil {
return nil, fmt.Errorf("the EP %s already exists", req.EndpointID)
}
// Build endpoint request
mreq := master.CreateEndpointRequest{
TenantName: req.Tenant,
NetworkName: req.Network,
ServiceName: req.Group,
EndpointID: req.EndpointID,
EPCommonName: req.Name,
ConfigEP: intent.ConfigEP{
Container: req.EndpointID,
Host: pluginHost,
ServiceName: req.Group,
},
}
var mresp master.CreateEndpointResponse
err = cluster.MasterPostReq("/plugin/createEndpoint", &mreq, &mresp)
if err != nil {
epCleanUp(req)
return nil, err
}
// this response should contain IPv6 if the underlying network is configured with IPv6
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Ask netplugin to create the endpoint
err = netPlugin.CreateEndpoint(netID + "-" + req.EndpointID)
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
epCleanUp(req)
return nil, err
}
ep, err = utils.GetEndpoint(netID + "-" + req.EndpointID)
if err != nil {
epCleanUp(req)
return nil, err
}
log.Debug(ep)
// need to get the subnetlen from nw state.
nw, err := utils.GetNetwork(netID)
if err != nil {
epCleanUp(req)
return nil, err
}
epResponse := epAttr{}
epResponse.PortName = ep.PortName
epResponse.IPAddress = ep.IPAddress + "/" + strconv.Itoa(int(nw.SubnetLen))
epResponse.Gateway = nw.Gateway
if ep.IPv6Address != "" {
epResponse.IPv6Address = ep.IPv6Address + "/" + strconv.Itoa(int(nw.IPv6SubnetLen))
epResponse.IPv6Gateway = nw.IPv6Gateway
}
return &epResponse, nil
} | go | func createEP(req *epSpec) (*epAttr, error) {
// if the ep already exists, treat as error for now.
netID := req.Network + "." + req.Tenant
ep, err := utils.GetEndpoint(netID + "-" + req.EndpointID)
if err == nil {
return nil, fmt.Errorf("the EP %s already exists", req.EndpointID)
}
// Build endpoint request
mreq := master.CreateEndpointRequest{
TenantName: req.Tenant,
NetworkName: req.Network,
ServiceName: req.Group,
EndpointID: req.EndpointID,
EPCommonName: req.Name,
ConfigEP: intent.ConfigEP{
Container: req.EndpointID,
Host: pluginHost,
ServiceName: req.Group,
},
}
var mresp master.CreateEndpointResponse
err = cluster.MasterPostReq("/plugin/createEndpoint", &mreq, &mresp)
if err != nil {
epCleanUp(req)
return nil, err
}
// this response should contain IPv6 if the underlying network is configured with IPv6
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Ask netplugin to create the endpoint
err = netPlugin.CreateEndpoint(netID + "-" + req.EndpointID)
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
epCleanUp(req)
return nil, err
}
ep, err = utils.GetEndpoint(netID + "-" + req.EndpointID)
if err != nil {
epCleanUp(req)
return nil, err
}
log.Debug(ep)
// need to get the subnetlen from nw state.
nw, err := utils.GetNetwork(netID)
if err != nil {
epCleanUp(req)
return nil, err
}
epResponse := epAttr{}
epResponse.PortName = ep.PortName
epResponse.IPAddress = ep.IPAddress + "/" + strconv.Itoa(int(nw.SubnetLen))
epResponse.Gateway = nw.Gateway
if ep.IPv6Address != "" {
epResponse.IPv6Address = ep.IPv6Address + "/" + strconv.Itoa(int(nw.IPv6SubnetLen))
epResponse.IPv6Gateway = nw.IPv6Gateway
}
return &epResponse, nil
} | [
"func",
"createEP",
"(",
"req",
"*",
"epSpec",
")",
"(",
"*",
"epAttr",
",",
"error",
")",
"{",
"// if the ep already exists, treat as error for now.",
"netID",
":=",
"req",
".",
"Network",
"+",
"\"",
"\"",
"+",
"req",
".",
"Tenant",
"\n",
"ep",
",",
"err",
":=",
"utils",
".",
"GetEndpoint",
"(",
"netID",
"+",
"\"",
"\"",
"+",
"req",
".",
"EndpointID",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"req",
".",
"EndpointID",
")",
"\n",
"}",
"\n\n",
"// Build endpoint request",
"mreq",
":=",
"master",
".",
"CreateEndpointRequest",
"{",
"TenantName",
":",
"req",
".",
"Tenant",
",",
"NetworkName",
":",
"req",
".",
"Network",
",",
"ServiceName",
":",
"req",
".",
"Group",
",",
"EndpointID",
":",
"req",
".",
"EndpointID",
",",
"EPCommonName",
":",
"req",
".",
"Name",
",",
"ConfigEP",
":",
"intent",
".",
"ConfigEP",
"{",
"Container",
":",
"req",
".",
"EndpointID",
",",
"Host",
":",
"pluginHost",
",",
"ServiceName",
":",
"req",
".",
"Group",
",",
"}",
",",
"}",
"\n\n",
"var",
"mresp",
"master",
".",
"CreateEndpointResponse",
"\n",
"err",
"=",
"cluster",
".",
"MasterPostReq",
"(",
"\"",
"\"",
",",
"&",
"mreq",
",",
"&",
"mresp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"epCleanUp",
"(",
"req",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// this response should contain IPv6 if the underlying network is configured with IPv6",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"mresp",
")",
"\n\n",
"// Ask netplugin to create the endpoint",
"err",
"=",
"netPlugin",
".",
"CreateEndpoint",
"(",
"netID",
"+",
"\"",
"\"",
"+",
"req",
".",
"EndpointID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"epCleanUp",
"(",
"req",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ep",
",",
"err",
"=",
"utils",
".",
"GetEndpoint",
"(",
"netID",
"+",
"\"",
"\"",
"+",
"req",
".",
"EndpointID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"epCleanUp",
"(",
"req",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"ep",
")",
"\n",
"// need to get the subnetlen from nw state.",
"nw",
",",
"err",
":=",
"utils",
".",
"GetNetwork",
"(",
"netID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"epCleanUp",
"(",
"req",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"epResponse",
":=",
"epAttr",
"{",
"}",
"\n",
"epResponse",
".",
"PortName",
"=",
"ep",
".",
"PortName",
"\n",
"epResponse",
".",
"IPAddress",
"=",
"ep",
".",
"IPAddress",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"nw",
".",
"SubnetLen",
")",
")",
"\n",
"epResponse",
".",
"Gateway",
"=",
"nw",
".",
"Gateway",
"\n\n",
"if",
"ep",
".",
"IPv6Address",
"!=",
"\"",
"\"",
"{",
"epResponse",
".",
"IPv6Address",
"=",
"ep",
".",
"IPv6Address",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"nw",
".",
"IPv6SubnetLen",
")",
")",
"\n",
"epResponse",
".",
"IPv6Gateway",
"=",
"nw",
".",
"IPv6Gateway",
"\n",
"}",
"\n\n",
"return",
"&",
"epResponse",
",",
"nil",
"\n",
"}"
]
| // createEP creates the specified EP in contiv | [
"createEP",
"creates",
"the",
"specified",
"EP",
"in",
"contiv"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L88-L154 |
8,072 | contiv/netplugin | mgmtfn/k8splugin/driver.go | getLink | func getLink(ifname string) (netlink.Link, error) {
// find the link
link, err := netlink.LinkByName(ifname)
if err != nil {
if !strings.Contains(err.Error(), "Link not found") {
log.Errorf("unable to find link %q. Error: %q", ifname, err)
return link, err
}
// try once more as sometimes (somehow) link creation is taking
// sometime, causing link not found error
time.Sleep(1 * time.Second)
link, err = netlink.LinkByName(ifname)
if err != nil {
log.Errorf("unable to find link %q. Error %q", ifname, err)
}
return link, err
}
return link, err
} | go | func getLink(ifname string) (netlink.Link, error) {
// find the link
link, err := netlink.LinkByName(ifname)
if err != nil {
if !strings.Contains(err.Error(), "Link not found") {
log.Errorf("unable to find link %q. Error: %q", ifname, err)
return link, err
}
// try once more as sometimes (somehow) link creation is taking
// sometime, causing link not found error
time.Sleep(1 * time.Second)
link, err = netlink.LinkByName(ifname)
if err != nil {
log.Errorf("unable to find link %q. Error %q", ifname, err)
}
return link, err
}
return link, err
} | [
"func",
"getLink",
"(",
"ifname",
"string",
")",
"(",
"netlink",
".",
"Link",
",",
"error",
")",
"{",
"// find the link",
"link",
",",
"err",
":=",
"netlink",
".",
"LinkByName",
"(",
"ifname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifname",
",",
"err",
")",
"\n",
"return",
"link",
",",
"err",
"\n",
"}",
"\n",
"// try once more as sometimes (somehow) link creation is taking",
"// sometime, causing link not found error",
"time",
".",
"Sleep",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"link",
",",
"err",
"=",
"netlink",
".",
"LinkByName",
"(",
"ifname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifname",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"link",
",",
"err",
"\n",
"}",
"\n",
"return",
"link",
",",
"err",
"\n",
"}"
]
| // getLink is a wrapper that fetches the netlink corresponding to the ifname | [
"getLink",
"is",
"a",
"wrapper",
"that",
"fetches",
"the",
"netlink",
"corresponding",
"to",
"the",
"ifname"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L157-L175 |
8,073 | contiv/netplugin | mgmtfn/k8splugin/driver.go | nsToPID | func nsToPID(ns string) (int, error) {
// Make sure ns is well formed
ok := strings.HasPrefix(ns, "/proc/")
if !ok {
return -1, fmt.Errorf("invalid nw name space: %v", ns)
}
elements := strings.Split(ns, "/")
return strconv.Atoi(elements[2])
} | go | func nsToPID(ns string) (int, error) {
// Make sure ns is well formed
ok := strings.HasPrefix(ns, "/proc/")
if !ok {
return -1, fmt.Errorf("invalid nw name space: %v", ns)
}
elements := strings.Split(ns, "/")
return strconv.Atoi(elements[2])
} | [
"func",
"nsToPID",
"(",
"ns",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Make sure ns is well formed",
"ok",
":=",
"strings",
".",
"HasPrefix",
"(",
"ns",
",",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ns",
")",
"\n",
"}",
"\n\n",
"elements",
":=",
"strings",
".",
"Split",
"(",
"ns",
",",
"\"",
"\"",
")",
"\n",
"return",
"strconv",
".",
"Atoi",
"(",
"elements",
"[",
"2",
"]",
")",
"\n",
"}"
]
| // nsToPID is a utility that extracts the PID from the netns | [
"nsToPID",
"is",
"a",
"utility",
"that",
"extracts",
"the",
"PID",
"from",
"the",
"netns"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L178-L187 |
8,074 | contiv/netplugin | mgmtfn/k8splugin/driver.go | setIfAttrs | func setIfAttrs(pid int, ifname, cidr, cidr6, newname string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
ipPath, err := osexec.LookPath("ip")
if err != nil {
return err
}
// find the link
link, err := getLink(ifname)
if err != nil {
log.Errorf("unable to find link %q. Error %q", ifname, err)
return err
}
// move to the desired netns
err = netlink.LinkSetNsPid(link, pid)
if err != nil {
log.Errorf("unable to move interface %s to pid %d. Error: %s",
ifname, pid, err)
return err
}
// rename to the desired ifname
nsPid := fmt.Sprintf("%d", pid)
rename, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath, "link",
"set", "dev", ifname, "name", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to rename interface %s to %s. Error: %s",
ifname, newname, err)
return nil
}
log.Infof("Output from rename: %v", rename)
// set the ip address
assignIP, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"address", "add", cidr, "dev", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to assign ip %s to %s. Error: %s",
cidr, newname, err)
return nil
}
log.Infof("Output from ip assign: %v", assignIP)
if cidr6 != "" {
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"-6", "address", "add", cidr6, "dev", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to assign IPv6 %s to %s. Error: %s",
cidr6, newname, err)
return nil
}
log.Infof("Output of IPv6 assign: %v", out)
}
// Finally, mark the link up
bringUp, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"link", "set", "dev", newname, "up").CombinedOutput()
if err != nil {
log.Errorf("unable to assign ip %s to %s. Error: %s",
cidr, newname, err)
return nil
}
log.Debugf("Output from ip assign: %v", bringUp)
return nil
} | go | func setIfAttrs(pid int, ifname, cidr, cidr6, newname string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
ipPath, err := osexec.LookPath("ip")
if err != nil {
return err
}
// find the link
link, err := getLink(ifname)
if err != nil {
log.Errorf("unable to find link %q. Error %q", ifname, err)
return err
}
// move to the desired netns
err = netlink.LinkSetNsPid(link, pid)
if err != nil {
log.Errorf("unable to move interface %s to pid %d. Error: %s",
ifname, pid, err)
return err
}
// rename to the desired ifname
nsPid := fmt.Sprintf("%d", pid)
rename, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath, "link",
"set", "dev", ifname, "name", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to rename interface %s to %s. Error: %s",
ifname, newname, err)
return nil
}
log.Infof("Output from rename: %v", rename)
// set the ip address
assignIP, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"address", "add", cidr, "dev", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to assign ip %s to %s. Error: %s",
cidr, newname, err)
return nil
}
log.Infof("Output from ip assign: %v", assignIP)
if cidr6 != "" {
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"-6", "address", "add", cidr6, "dev", newname).CombinedOutput()
if err != nil {
log.Errorf("unable to assign IPv6 %s to %s. Error: %s",
cidr6, newname, err)
return nil
}
log.Infof("Output of IPv6 assign: %v", out)
}
// Finally, mark the link up
bringUp, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", ipPath,
"link", "set", "dev", newname, "up").CombinedOutput()
if err != nil {
log.Errorf("unable to assign ip %s to %s. Error: %s",
cidr, newname, err)
return nil
}
log.Debugf("Output from ip assign: %v", bringUp)
return nil
} | [
"func",
"setIfAttrs",
"(",
"pid",
"int",
",",
"ifname",
",",
"cidr",
",",
"cidr6",
",",
"newname",
"string",
")",
"error",
"{",
"nsenterPath",
",",
"err",
":=",
"osexec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ipPath",
",",
"err",
":=",
"osexec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// find the link",
"link",
",",
"err",
":=",
"getLink",
"(",
"ifname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifname",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// move to the desired netns",
"err",
"=",
"netlink",
".",
"LinkSetNsPid",
"(",
"link",
",",
"pid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifname",
",",
"pid",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// rename to the desired ifname",
"nsPid",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"rename",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ipPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ifname",
",",
"\"",
"\"",
",",
"newname",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifname",
",",
"newname",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"rename",
")",
"\n\n",
"// set the ip address",
"assignIP",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ipPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cidr",
",",
"\"",
"\"",
",",
"newname",
")",
".",
"CombinedOutput",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cidr",
",",
"newname",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"assignIP",
")",
"\n\n",
"if",
"cidr6",
"!=",
"\"",
"\"",
"{",
"out",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ipPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cidr6",
",",
"\"",
"\"",
",",
"newname",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cidr6",
",",
"newname",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"out",
")",
"\n",
"}",
"\n\n",
"// Finally, mark the link up",
"bringUp",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ipPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newname",
",",
"\"",
"\"",
")",
".",
"CombinedOutput",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cidr",
",",
"newname",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"bringUp",
")",
"\n",
"return",
"nil",
"\n\n",
"}"
]
| // setIfAttrs sets the required attributes for the container interface | [
"setIfAttrs",
"sets",
"the",
"required",
"attributes",
"for",
"the",
"container",
"interface"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L209-L279 |
8,075 | contiv/netplugin | mgmtfn/k8splugin/driver.go | setDefGw | func setDefGw(pid int, gw, gw6, intfName string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
routePath, err := osexec.LookPath("route")
if err != nil {
return err
}
// set default gw
nsPid := fmt.Sprintf("%d", pid)
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", routePath, "add",
"default", "gw", gw, intfName).CombinedOutput()
if err != nil {
log.Errorf("unable to set default gw %s. Error: %s - %s", gw, err, out)
return nil
}
if gw6 != "" {
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", routePath,
"-6", "add", "default", "gw", gw6, intfName).CombinedOutput()
if err != nil {
log.Errorf("unable to set default IPv6 gateway %s. Error: %s - %s", gw6, err, out)
return nil
}
}
return nil
} | go | func setDefGw(pid int, gw, gw6, intfName string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
routePath, err := osexec.LookPath("route")
if err != nil {
return err
}
// set default gw
nsPid := fmt.Sprintf("%d", pid)
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", routePath, "add",
"default", "gw", gw, intfName).CombinedOutput()
if err != nil {
log.Errorf("unable to set default gw %s. Error: %s - %s", gw, err, out)
return nil
}
if gw6 != "" {
out, err := osexec.Command(nsenterPath, "-t", nsPid, "-n", "-F", "--", routePath,
"-6", "add", "default", "gw", gw6, intfName).CombinedOutput()
if err != nil {
log.Errorf("unable to set default IPv6 gateway %s. Error: %s - %s", gw6, err, out)
return nil
}
}
return nil
} | [
"func",
"setDefGw",
"(",
"pid",
"int",
",",
"gw",
",",
"gw6",
",",
"intfName",
"string",
")",
"error",
"{",
"nsenterPath",
",",
"err",
":=",
"osexec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"routePath",
",",
"err",
":=",
"osexec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// set default gw",
"nsPid",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"out",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"routePath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"gw",
",",
"intfName",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gw",
",",
"err",
",",
"out",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"gw6",
"!=",
"\"",
"\"",
"{",
"out",
",",
"err",
":=",
"osexec",
".",
"Command",
"(",
"nsenterPath",
",",
"\"",
"\"",
",",
"nsPid",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"routePath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"gw6",
",",
"intfName",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gw6",
",",
"err",
",",
"out",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // setDefGw sets the default gateway for the container namespace | [
"setDefGw",
"sets",
"the",
"default",
"gateway",
"for",
"the",
"container",
"namespace"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L306-L334 |
8,076 | contiv/netplugin | mgmtfn/k8splugin/driver.go | getEPSpec | func getEPSpec(pInfo *cniapi.CNIPodAttr) (*epSpec, error) {
resp := epSpec{}
// Get labels from the kube api server
epg, err := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.net-group")
if err != nil {
log.Errorf("Error getting epg. Err: %v", err)
return &resp, err
}
// Safe to ignore the error return for subsequent invocations of GetPodLabel
netw, _ := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.network")
tenant, _ := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.tenant")
log.Infof("labels is %s/%s/%s for pod %s\n", tenant, netw, epg, pInfo.Name)
resp.Tenant = tenant
resp.Network = netw
resp.Group = epg
resp.EndpointID = pInfo.InfraContainerID
resp.Name = pInfo.Name
return &resp, nil
} | go | func getEPSpec(pInfo *cniapi.CNIPodAttr) (*epSpec, error) {
resp := epSpec{}
// Get labels from the kube api server
epg, err := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.net-group")
if err != nil {
log.Errorf("Error getting epg. Err: %v", err)
return &resp, err
}
// Safe to ignore the error return for subsequent invocations of GetPodLabel
netw, _ := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.network")
tenant, _ := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.tenant")
log.Infof("labels is %s/%s/%s for pod %s\n", tenant, netw, epg, pInfo.Name)
resp.Tenant = tenant
resp.Network = netw
resp.Group = epg
resp.EndpointID = pInfo.InfraContainerID
resp.Name = pInfo.Name
return &resp, nil
} | [
"func",
"getEPSpec",
"(",
"pInfo",
"*",
"cniapi",
".",
"CNIPodAttr",
")",
"(",
"*",
"epSpec",
",",
"error",
")",
"{",
"resp",
":=",
"epSpec",
"{",
"}",
"\n\n",
"// Get labels from the kube api server",
"epg",
",",
"err",
":=",
"kubeAPIClient",
".",
"GetPodLabel",
"(",
"pInfo",
".",
"K8sNameSpace",
",",
"pInfo",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"&",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"// Safe to ignore the error return for subsequent invocations of GetPodLabel",
"netw",
",",
"_",
":=",
"kubeAPIClient",
".",
"GetPodLabel",
"(",
"pInfo",
".",
"K8sNameSpace",
",",
"pInfo",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"tenant",
",",
"_",
":=",
"kubeAPIClient",
".",
"GetPodLabel",
"(",
"pInfo",
".",
"K8sNameSpace",
",",
"pInfo",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\\n",
"\"",
",",
"tenant",
",",
"netw",
",",
"epg",
",",
"pInfo",
".",
"Name",
")",
"\n",
"resp",
".",
"Tenant",
"=",
"tenant",
"\n",
"resp",
".",
"Network",
"=",
"netw",
"\n",
"resp",
".",
"Group",
"=",
"epg",
"\n",
"resp",
".",
"EndpointID",
"=",
"pInfo",
".",
"InfraContainerID",
"\n",
"resp",
".",
"Name",
"=",
"pInfo",
".",
"Name",
"\n\n",
"return",
"&",
"resp",
",",
"nil",
"\n",
"}"
]
| // getEPSpec gets the EP spec using the pod attributes | [
"getEPSpec",
"gets",
"the",
"EP",
"spec",
"using",
"the",
"pod",
"attributes"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L337-L361 |
8,077 | contiv/netplugin | mgmtfn/k8splugin/driver.go | deletePod | func deletePod(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
resp := cniapi.RspAddPod{}
logEvent("del pod")
content, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Errorf("Failed to read request: %v", err)
return resp, err
}
pInfo := cniapi.CNIPodAttr{}
if err := json.Unmarshal(content, &pInfo); err != nil {
return resp, err
}
// Get labels from the kube api server
epReq, err := getEPSpec(&pInfo)
if err != nil {
log.Errorf("Error getting labels. Err: %v", err)
setErrorResp(&resp, "Error getting labels", err)
return resp, err
}
netPlugin.DeleteHostAccPort(epReq.EndpointID)
if err = epCleanUp(epReq); err != nil {
log.Errorf("failed to delete pod, error: %s", err)
}
resp.Result = 0
resp.EndpointID = pInfo.InfraContainerID
return resp, nil
} | go | func deletePod(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
resp := cniapi.RspAddPod{}
logEvent("del pod")
content, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Errorf("Failed to read request: %v", err)
return resp, err
}
pInfo := cniapi.CNIPodAttr{}
if err := json.Unmarshal(content, &pInfo); err != nil {
return resp, err
}
// Get labels from the kube api server
epReq, err := getEPSpec(&pInfo)
if err != nil {
log.Errorf("Error getting labels. Err: %v", err)
setErrorResp(&resp, "Error getting labels", err)
return resp, err
}
netPlugin.DeleteHostAccPort(epReq.EndpointID)
if err = epCleanUp(epReq); err != nil {
log.Errorf("failed to delete pod, error: %s", err)
}
resp.Result = 0
resp.EndpointID = pInfo.InfraContainerID
return resp, nil
} | [
"func",
"deletePod",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"resp",
":=",
"cniapi",
".",
"RspAddPod",
"{",
"}",
"\n\n",
"logEvent",
"(",
"\"",
"\"",
")",
"\n\n",
"content",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"pInfo",
":=",
"cniapi",
".",
"CNIPodAttr",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"content",
",",
"&",
"pInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"// Get labels from the kube api server",
"epReq",
",",
"err",
":=",
"getEPSpec",
"(",
"&",
"pInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"setErrorResp",
"(",
"&",
"resp",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"netPlugin",
".",
"DeleteHostAccPort",
"(",
"epReq",
".",
"EndpointID",
")",
"\n",
"if",
"err",
"=",
"epCleanUp",
"(",
"epReq",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"resp",
".",
"Result",
"=",
"0",
"\n",
"resp",
".",
"EndpointID",
"=",
"pInfo",
".",
"InfraContainerID",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
]
| // deletePod is the handler for pod deletes | [
"deletePod",
"is",
"the",
"handler",
"for",
"pod",
"deletes"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/driver.go#L477-L509 |
8,078 | contiv/netplugin | netmaster/master/endpoint.go | freeAddrOnErr | func freeAddrOnErr(nwCfg *mastercfg.CfgNetworkState, epgCfg *mastercfg.EndpointGroupState,
ipAddress string, pErr *error) {
if *pErr != nil {
log.Infof("Freeing %s on error", ipAddress)
networkReleaseAddress(nwCfg, epgCfg, ipAddress)
}
} | go | func freeAddrOnErr(nwCfg *mastercfg.CfgNetworkState, epgCfg *mastercfg.EndpointGroupState,
ipAddress string, pErr *error) {
if *pErr != nil {
log.Infof("Freeing %s on error", ipAddress)
networkReleaseAddress(nwCfg, epgCfg, ipAddress)
}
} | [
"func",
"freeAddrOnErr",
"(",
"nwCfg",
"*",
"mastercfg",
".",
"CfgNetworkState",
",",
"epgCfg",
"*",
"mastercfg",
".",
"EndpointGroupState",
",",
"ipAddress",
"string",
",",
"pErr",
"*",
"error",
")",
"{",
"if",
"*",
"pErr",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ipAddress",
")",
"\n",
"networkReleaseAddress",
"(",
"nwCfg",
",",
"epgCfg",
",",
"ipAddress",
")",
"\n",
"}",
"\n",
"}"
]
| // freeAddrOnErr deferred function that cleans up on error | [
"freeAddrOnErr",
"deferred",
"function",
"that",
"cleans",
"up",
"on",
"error"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpoint.go#L93-L99 |
8,079 | contiv/netplugin | netmaster/master/endpoint.go | CreateEndpoints | func CreateEndpoints(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
err := validateEndpointConfig(stateDriver, tenant)
if err != nil {
log.Errorf("error validating endpoint config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := network.Name + "." + tenant.Name
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("error reading oper network %s. Error: %s", network.Name, err)
return err
}
for _, ep := range network.Endpoints {
epReq := CreateEndpointRequest{}
epReq.ConfigEP = ep
_, err = CreateEndpoint(stateDriver, nwCfg, &epReq)
if err != nil {
log.Errorf("Error creating endpoint %+v. Err: %v", ep, err)
return err
}
}
err = nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
}
return err
} | go | func CreateEndpoints(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
err := validateEndpointConfig(stateDriver, tenant)
if err != nil {
log.Errorf("error validating endpoint config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := network.Name + "." + tenant.Name
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("error reading oper network %s. Error: %s", network.Name, err)
return err
}
for _, ep := range network.Endpoints {
epReq := CreateEndpointRequest{}
epReq.ConfigEP = ep
_, err = CreateEndpoint(stateDriver, nwCfg, &epReq)
if err != nil {
log.Errorf("Error creating endpoint %+v. Err: %v", ep, err)
return err
}
}
err = nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
}
return err
} | [
"func",
"CreateEndpoints",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"tenant",
"*",
"intent",
".",
"ConfigTenant",
")",
"error",
"{",
"err",
":=",
"validateEndpointConfig",
"(",
"stateDriver",
",",
"tenant",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"network",
":=",
"range",
"tenant",
".",
"Networks",
"{",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"networkID",
":=",
"network",
".",
"Name",
"+",
"\"",
"\"",
"+",
"tenant",
".",
"Name",
"\n",
"err",
"=",
"nwCfg",
".",
"Read",
"(",
"networkID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"network",
".",
"Name",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ep",
":=",
"range",
"network",
".",
"Endpoints",
"{",
"epReq",
":=",
"CreateEndpointRequest",
"{",
"}",
"\n",
"epReq",
".",
"ConfigEP",
"=",
"ep",
"\n",
"_",
",",
"err",
"=",
"CreateEndpoint",
"(",
"stateDriver",
",",
"nwCfg",
",",
"&",
"epReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
"=",
"nwCfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // CreateEndpoints creates the endpoints for a given tenant. | [
"CreateEndpoints",
"creates",
"the",
"endpoints",
"for",
"a",
"given",
"tenant",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpoint.go#L195-L230 |
8,080 | contiv/netplugin | netmaster/master/endpoint.go | DeleteEndpoints | func DeleteEndpoints(hostAddr string) error {
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
readEp := &mastercfg.CfgEndpointState{}
readEp.StateDriver = stateDriver
epCfgs, err := readEp.ReadAll()
if err != nil {
return err
}
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(ep.NetID)
if err != nil {
log.Errorf("Network not found for NetID: %+v", ep.NetID)
continue
}
netID := nwCfg.NetworkName + "." + nwCfg.Tenant
epID := getEpName(netID, &intent.ConfigEP{Container: ep.EndpointID})
if ep.HomingHost == hostAddr {
log.Infof("Sending DeleteEndpoint for %+v", ep)
_, err = DeleteEndpointID(stateDriver, epID)
if err != nil {
log.Errorf("Error delete endpoint: %+v. Err: %+v", ep, err)
}
epOper := &drivers.OperEndpointState{}
epOper.StateDriver = stateDriver
err := epOper.Read(epID)
if err != nil {
log.Errorf("Failed to read epOper: %+v", epOper)
return err
}
err = epOper.Clear()
if err != nil {
log.Errorf("Error deleting oper state for %+v", epOper)
} else {
log.Infof("Deleted EP oper: %+v", epOper)
}
} else {
log.Infof("EP not on host: %+v", hostAddr)
}
}
return err
} | go | func DeleteEndpoints(hostAddr string) error {
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
readEp := &mastercfg.CfgEndpointState{}
readEp.StateDriver = stateDriver
epCfgs, err := readEp.ReadAll()
if err != nil {
return err
}
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(ep.NetID)
if err != nil {
log.Errorf("Network not found for NetID: %+v", ep.NetID)
continue
}
netID := nwCfg.NetworkName + "." + nwCfg.Tenant
epID := getEpName(netID, &intent.ConfigEP{Container: ep.EndpointID})
if ep.HomingHost == hostAddr {
log.Infof("Sending DeleteEndpoint for %+v", ep)
_, err = DeleteEndpointID(stateDriver, epID)
if err != nil {
log.Errorf("Error delete endpoint: %+v. Err: %+v", ep, err)
}
epOper := &drivers.OperEndpointState{}
epOper.StateDriver = stateDriver
err := epOper.Read(epID)
if err != nil {
log.Errorf("Failed to read epOper: %+v", epOper)
return err
}
err = epOper.Clear()
if err != nil {
log.Errorf("Error deleting oper state for %+v", epOper)
} else {
log.Infof("Deleted EP oper: %+v", epOper)
}
} else {
log.Infof("EP not on host: %+v", hostAddr)
}
}
return err
} | [
"func",
"DeleteEndpoints",
"(",
"hostAddr",
"string",
")",
"error",
"{",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"readEp",
":=",
"&",
"mastercfg",
".",
"CfgEndpointState",
"{",
"}",
"\n",
"readEp",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"epCfgs",
",",
"err",
":=",
"readEp",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"epCfg",
":=",
"range",
"epCfgs",
"{",
"ep",
":=",
"epCfg",
".",
"(",
"*",
"mastercfg",
".",
"CfgEndpointState",
")",
"\n",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"nwCfg",
".",
"Read",
"(",
"ep",
".",
"NetID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
".",
"NetID",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"netID",
":=",
"nwCfg",
".",
"NetworkName",
"+",
"\"",
"\"",
"+",
"nwCfg",
".",
"Tenant",
"\n",
"epID",
":=",
"getEpName",
"(",
"netID",
",",
"&",
"intent",
".",
"ConfigEP",
"{",
"Container",
":",
"ep",
".",
"EndpointID",
"}",
")",
"\n",
"if",
"ep",
".",
"HomingHost",
"==",
"hostAddr",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ep",
")",
"\n",
"_",
",",
"err",
"=",
"DeleteEndpointID",
"(",
"stateDriver",
",",
"epID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
",",
"err",
")",
"\n",
"}",
"\n",
"epOper",
":=",
"&",
"drivers",
".",
"OperEndpointState",
"{",
"}",
"\n",
"epOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"epOper",
".",
"Read",
"(",
"epID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epOper",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"epOper",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epOper",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"epOper",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"hostAddr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // DeleteEndpoints deletes the endpoints on a give host | [
"DeleteEndpoints",
"deletes",
"the",
"endpoints",
"on",
"a",
"give",
"host"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpoint.go#L233-L284 |
8,081 | contiv/netplugin | netmaster/master/endpoint.go | DeleteEndpointID | func DeleteEndpointID(stateDriver core.StateDriver, epID string) (*mastercfg.CfgEndpointState, error) {
epCfg := &mastercfg.CfgEndpointState{}
var epgCfg *mastercfg.EndpointGroupState
epCfg.StateDriver = stateDriver
err := epCfg.Read(epID)
if err != nil {
return nil, err
}
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(epCfg.NetID)
// Network may already be deleted if infra nw
// If network present, free up nw resources
if err == nil && epCfg.IPAddress != "" {
if len(epCfg.ServiceName) > 0 {
epgCfg = &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
if err := epgCfg.Read(epCfg.ServiceName + ":" + nwCfg.Tenant); err != nil {
log.Errorf("failed to read endpoint group %s, error %s",
epCfg.ServiceName+":"+epgCfg.TenantName, err)
return nil, err
}
}
err = networkReleaseAddress(nwCfg, epgCfg, epCfg.IPAddress)
if err != nil {
log.Errorf("Error releasing endpoint state for: %s. Err: %v", epCfg.IPAddress, err)
}
if epCfg.EndpointGroupKey != "" {
epgCfg := &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
err = epgCfg.Read(epCfg.EndpointGroupKey)
if err != nil {
log.Errorf("Error reading EPG for endpoint: %+v", epCfg)
}
epgCfg.EpCount--
// write updated epg state
err = epgCfg.Write()
if err != nil {
log.Errorf("error writing epg config. Error: %s", err)
}
}
// decrement ep count
nwCfg.EpCount--
// write modified nw state
err = nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
}
}
// Even if network not present (already deleted), cleanup ep cfg
err = epCfg.Clear()
if err != nil {
log.Errorf("error writing ep config. Error: %s", err)
return nil, err
}
return epCfg, err
} | go | func DeleteEndpointID(stateDriver core.StateDriver, epID string) (*mastercfg.CfgEndpointState, error) {
epCfg := &mastercfg.CfgEndpointState{}
var epgCfg *mastercfg.EndpointGroupState
epCfg.StateDriver = stateDriver
err := epCfg.Read(epID)
if err != nil {
return nil, err
}
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(epCfg.NetID)
// Network may already be deleted if infra nw
// If network present, free up nw resources
if err == nil && epCfg.IPAddress != "" {
if len(epCfg.ServiceName) > 0 {
epgCfg = &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
if err := epgCfg.Read(epCfg.ServiceName + ":" + nwCfg.Tenant); err != nil {
log.Errorf("failed to read endpoint group %s, error %s",
epCfg.ServiceName+":"+epgCfg.TenantName, err)
return nil, err
}
}
err = networkReleaseAddress(nwCfg, epgCfg, epCfg.IPAddress)
if err != nil {
log.Errorf("Error releasing endpoint state for: %s. Err: %v", epCfg.IPAddress, err)
}
if epCfg.EndpointGroupKey != "" {
epgCfg := &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
err = epgCfg.Read(epCfg.EndpointGroupKey)
if err != nil {
log.Errorf("Error reading EPG for endpoint: %+v", epCfg)
}
epgCfg.EpCount--
// write updated epg state
err = epgCfg.Write()
if err != nil {
log.Errorf("error writing epg config. Error: %s", err)
}
}
// decrement ep count
nwCfg.EpCount--
// write modified nw state
err = nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
}
}
// Even if network not present (already deleted), cleanup ep cfg
err = epCfg.Clear()
if err != nil {
log.Errorf("error writing ep config. Error: %s", err)
return nil, err
}
return epCfg, err
} | [
"func",
"DeleteEndpointID",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"epID",
"string",
")",
"(",
"*",
"mastercfg",
".",
"CfgEndpointState",
",",
"error",
")",
"{",
"epCfg",
":=",
"&",
"mastercfg",
".",
"CfgEndpointState",
"{",
"}",
"\n",
"var",
"epgCfg",
"*",
"mastercfg",
".",
"EndpointGroupState",
"\n\n",
"epCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"epCfg",
".",
"Read",
"(",
"epID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"nwCfg",
".",
"Read",
"(",
"epCfg",
".",
"NetID",
")",
"\n\n",
"// Network may already be deleted if infra nw",
"// If network present, free up nw resources",
"if",
"err",
"==",
"nil",
"&&",
"epCfg",
".",
"IPAddress",
"!=",
"\"",
"\"",
"{",
"if",
"len",
"(",
"epCfg",
".",
"ServiceName",
")",
">",
"0",
"{",
"epgCfg",
"=",
"&",
"mastercfg",
".",
"EndpointGroupState",
"{",
"}",
"\n",
"epgCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"if",
"err",
":=",
"epgCfg",
".",
"Read",
"(",
"epCfg",
".",
"ServiceName",
"+",
"\"",
"\"",
"+",
"nwCfg",
".",
"Tenant",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epCfg",
".",
"ServiceName",
"+",
"\"",
"\"",
"+",
"epgCfg",
".",
"TenantName",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
"=",
"networkReleaseAddress",
"(",
"nwCfg",
",",
"epgCfg",
",",
"epCfg",
".",
"IPAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epCfg",
".",
"IPAddress",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"epCfg",
".",
"EndpointGroupKey",
"!=",
"\"",
"\"",
"{",
"epgCfg",
":=",
"&",
"mastercfg",
".",
"EndpointGroupState",
"{",
"}",
"\n",
"epgCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"epgCfg",
".",
"Read",
"(",
"epCfg",
".",
"EndpointGroupKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epCfg",
")",
"\n",
"}",
"\n\n",
"epgCfg",
".",
"EpCount",
"--",
"\n\n",
"// write updated epg state",
"err",
"=",
"epgCfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// decrement ep count",
"nwCfg",
".",
"EpCount",
"--",
"\n\n",
"// write modified nw state",
"err",
"=",
"nwCfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Even if network not present (already deleted), cleanup ep cfg",
"err",
"=",
"epCfg",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"epCfg",
",",
"err",
"\n",
"}"
]
| // DeleteEndpointID deletes an endpoint by ID. | [
"DeleteEndpointID",
"deletes",
"an",
"endpoint",
"by",
"ID",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpoint.go#L287-L354 |
8,082 | contiv/netplugin | netmaster/master/endpoint.go | CreateEpBindings | func CreateEpBindings(epBindings *[]intent.ConfigEP) error {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
err = validateEpBindings(epBindings)
if err != nil {
log.Errorf("error validating the ep bindings. Error: %s", err)
return err
}
readEp := &mastercfg.CfgEndpointState{}
readEp.StateDriver = stateDriver
epCfgs, err := readEp.ReadAll()
if err != nil {
log.Errorf("error fetching eps. Error: %s", err)
return err
}
for _, ep := range *epBindings {
log.Infof("creating binding between container '%s' and host '%s'",
ep.Container, ep.Host)
for _, epCfg := range epCfgs {
cfg := epCfg.(*mastercfg.CfgEndpointState)
if cfg.EndpointID != ep.Container {
continue
}
cfg.HomingHost = ep.Host
err = cfg.Write()
if err != nil {
log.Errorf("error updating epCfg. Error: %s", err)
return err
}
}
}
return nil
} | go | func CreateEpBindings(epBindings *[]intent.ConfigEP) error {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
err = validateEpBindings(epBindings)
if err != nil {
log.Errorf("error validating the ep bindings. Error: %s", err)
return err
}
readEp := &mastercfg.CfgEndpointState{}
readEp.StateDriver = stateDriver
epCfgs, err := readEp.ReadAll()
if err != nil {
log.Errorf("error fetching eps. Error: %s", err)
return err
}
for _, ep := range *epBindings {
log.Infof("creating binding between container '%s' and host '%s'",
ep.Container, ep.Host)
for _, epCfg := range epCfgs {
cfg := epCfg.(*mastercfg.CfgEndpointState)
if cfg.EndpointID != ep.Container {
continue
}
cfg.HomingHost = ep.Host
err = cfg.Write()
if err != nil {
log.Errorf("error updating epCfg. Error: %s", err)
return err
}
}
}
return nil
} | [
"func",
"CreateEpBindings",
"(",
"epBindings",
"*",
"[",
"]",
"intent",
".",
"ConfigEP",
")",
"error",
"{",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"validateEpBindings",
"(",
"epBindings",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"readEp",
":=",
"&",
"mastercfg",
".",
"CfgEndpointState",
"{",
"}",
"\n",
"readEp",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"epCfgs",
",",
"err",
":=",
"readEp",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"ep",
":=",
"range",
"*",
"epBindings",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ep",
".",
"Container",
",",
"ep",
".",
"Host",
")",
"\n\n",
"for",
"_",
",",
"epCfg",
":=",
"range",
"epCfgs",
"{",
"cfg",
":=",
"epCfg",
".",
"(",
"*",
"mastercfg",
".",
"CfgEndpointState",
")",
"\n",
"if",
"cfg",
".",
"EndpointID",
"!=",
"ep",
".",
"Container",
"{",
"continue",
"\n",
"}",
"\n",
"cfg",
".",
"HomingHost",
"=",
"ep",
".",
"Host",
"\n",
"err",
"=",
"cfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // CreateEpBindings binds an endpoint to a host by updating host-label info
// in driver's endpoint configuration. | [
"CreateEpBindings",
"binds",
"an",
"endpoint",
"to",
"a",
"host",
"by",
"updating",
"host",
"-",
"label",
"info",
"in",
"driver",
"s",
"endpoint",
"configuration",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpoint.go#L371-L409 |
8,083 | contiv/netplugin | netmaster/objApi/extContracts.go | cleanupExternalContracts | func cleanupExternalContracts(endpointGroup *contivModel.EndpointGroup) error {
tenant := endpointGroup.TenantName
for _, contractsGrp := range endpointGroup.ExtContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj := contivModel.FindExtContractsGroup(contractsGrpKey)
if contractsGrpObj != nil {
// Break any linkeage we might have set.
modeldb.RemoveLinkSet(&contractsGrpObj.LinkSets.EndpointGroups, endpointGroup)
modeldb.RemoveLinkSet(&endpointGroup.LinkSets.ExtContractsGrps, contractsGrpObj)
// Links broken, update the contracts group object.
err := contractsGrpObj.Write()
if err != nil {
return err
}
} else {
log.Errorf("Error cleaning up consumed ext contract %s", contractsGrp)
continue
}
}
return nil
} | go | func cleanupExternalContracts(endpointGroup *contivModel.EndpointGroup) error {
tenant := endpointGroup.TenantName
for _, contractsGrp := range endpointGroup.ExtContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj := contivModel.FindExtContractsGroup(contractsGrpKey)
if contractsGrpObj != nil {
// Break any linkeage we might have set.
modeldb.RemoveLinkSet(&contractsGrpObj.LinkSets.EndpointGroups, endpointGroup)
modeldb.RemoveLinkSet(&endpointGroup.LinkSets.ExtContractsGrps, contractsGrpObj)
// Links broken, update the contracts group object.
err := contractsGrpObj.Write()
if err != nil {
return err
}
} else {
log.Errorf("Error cleaning up consumed ext contract %s", contractsGrp)
continue
}
}
return nil
} | [
"func",
"cleanupExternalContracts",
"(",
"endpointGroup",
"*",
"contivModel",
".",
"EndpointGroup",
")",
"error",
"{",
"tenant",
":=",
"endpointGroup",
".",
"TenantName",
"\n",
"for",
"_",
",",
"contractsGrp",
":=",
"range",
"endpointGroup",
".",
"ExtContractsGrps",
"{",
"contractsGrpKey",
":=",
"tenant",
"+",
"\"",
"\"",
"+",
"contractsGrp",
"\n",
"contractsGrpObj",
":=",
"contivModel",
".",
"FindExtContractsGroup",
"(",
"contractsGrpKey",
")",
"\n\n",
"if",
"contractsGrpObj",
"!=",
"nil",
"{",
"// Break any linkeage we might have set.",
"modeldb",
".",
"RemoveLinkSet",
"(",
"&",
"contractsGrpObj",
".",
"LinkSets",
".",
"EndpointGroups",
",",
"endpointGroup",
")",
"\n",
"modeldb",
".",
"RemoveLinkSet",
"(",
"&",
"endpointGroup",
".",
"LinkSets",
".",
"ExtContractsGrps",
",",
"contractsGrpObj",
")",
"\n\n",
"// Links broken, update the contracts group object.",
"err",
":=",
"contractsGrpObj",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"contractsGrp",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Some utility functions to work with the external contracts
// Cleanup external contracts from an epg. | [
"Some",
"utility",
"functions",
"to",
"work",
"with",
"the",
"external",
"contracts",
"Cleanup",
"external",
"contracts",
"from",
"an",
"epg",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/extContracts.go#L29-L52 |
8,084 | contiv/netplugin | netmaster/objApi/extContracts.go | setupExternalContracts | func setupExternalContracts(endpointGroup *contivModel.EndpointGroup, extContractsGrps []string) error {
// Validate presence and register consumed external contracts
tenant := endpointGroup.TenantName
for _, contractsGrp := range extContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj := contivModel.FindExtContractsGroup(contractsGrpKey)
if contractsGrpObj == nil {
errStr := fmt.Sprintf("External contracts group %s not found", contractsGrp)
log.Errorf(errStr)
return core.Errorf(errStr)
}
// Establish the necessary links.
modeldb.AddLinkSet(&contractsGrpObj.LinkSets.EndpointGroups, endpointGroup)
modeldb.AddLinkSet(&endpointGroup.LinkSets.ExtContractsGrps, contractsGrpObj)
// Links made, write the policy set object.
err := contractsGrpObj.Write()
if err != nil {
return err
}
}
return nil
} | go | func setupExternalContracts(endpointGroup *contivModel.EndpointGroup, extContractsGrps []string) error {
// Validate presence and register consumed external contracts
tenant := endpointGroup.TenantName
for _, contractsGrp := range extContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj := contivModel.FindExtContractsGroup(contractsGrpKey)
if contractsGrpObj == nil {
errStr := fmt.Sprintf("External contracts group %s not found", contractsGrp)
log.Errorf(errStr)
return core.Errorf(errStr)
}
// Establish the necessary links.
modeldb.AddLinkSet(&contractsGrpObj.LinkSets.EndpointGroups, endpointGroup)
modeldb.AddLinkSet(&endpointGroup.LinkSets.ExtContractsGrps, contractsGrpObj)
// Links made, write the policy set object.
err := contractsGrpObj.Write()
if err != nil {
return err
}
}
return nil
} | [
"func",
"setupExternalContracts",
"(",
"endpointGroup",
"*",
"contivModel",
".",
"EndpointGroup",
",",
"extContractsGrps",
"[",
"]",
"string",
")",
"error",
"{",
"// Validate presence and register consumed external contracts",
"tenant",
":=",
"endpointGroup",
".",
"TenantName",
"\n",
"for",
"_",
",",
"contractsGrp",
":=",
"range",
"extContractsGrps",
"{",
"contractsGrpKey",
":=",
"tenant",
"+",
"\"",
"\"",
"+",
"contractsGrp",
"\n",
"contractsGrpObj",
":=",
"contivModel",
".",
"FindExtContractsGroup",
"(",
"contractsGrpKey",
")",
"\n\n",
"if",
"contractsGrpObj",
"==",
"nil",
"{",
"errStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"contractsGrp",
")",
"\n",
"log",
".",
"Errorf",
"(",
"errStr",
")",
"\n",
"return",
"core",
".",
"Errorf",
"(",
"errStr",
")",
"\n",
"}",
"\n\n",
"// Establish the necessary links.",
"modeldb",
".",
"AddLinkSet",
"(",
"&",
"contractsGrpObj",
".",
"LinkSets",
".",
"EndpointGroups",
",",
"endpointGroup",
")",
"\n",
"modeldb",
".",
"AddLinkSet",
"(",
"&",
"endpointGroup",
".",
"LinkSets",
".",
"ExtContractsGrps",
",",
"contractsGrpObj",
")",
"\n\n",
"// Links made, write the policy set object.",
"err",
":=",
"contractsGrpObj",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Setup external contracts for an epg. | [
"Setup",
"external",
"contracts",
"for",
"an",
"epg",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/extContracts.go#L55-L80 |
8,085 | contiv/netplugin | netmaster/objApi/extContracts.go | ExtContractsGroupCreate | func (ac *APIController) ExtContractsGroupCreate(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupCreate: %+v", contractsGroup)
// Validate contracts type
if contractsGroup.ContractsType != "provided" && contractsGroup.ContractsType != "consumed" {
return core.Errorf("Contracts group need to be either 'provided' or 'consumed'")
}
// Make sure the tenant exists
tenant := contivModel.FindTenant(contractsGroup.TenantName)
if tenant == nil {
return core.Errorf("Tenant %s not found", contractsGroup.TenantName)
}
// NOTE: Nothing more needs to be done here. This object
// need not be created in the masterCfg.
return nil
} | go | func (ac *APIController) ExtContractsGroupCreate(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupCreate: %+v", contractsGroup)
// Validate contracts type
if contractsGroup.ContractsType != "provided" && contractsGroup.ContractsType != "consumed" {
return core.Errorf("Contracts group need to be either 'provided' or 'consumed'")
}
// Make sure the tenant exists
tenant := contivModel.FindTenant(contractsGroup.TenantName)
if tenant == nil {
return core.Errorf("Tenant %s not found", contractsGroup.TenantName)
}
// NOTE: Nothing more needs to be done here. This object
// need not be created in the masterCfg.
return nil
} | [
"func",
"(",
"ac",
"*",
"APIController",
")",
"ExtContractsGroupCreate",
"(",
"contractsGroup",
"*",
"contivModel",
".",
"ExtContractsGroup",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"contractsGroup",
")",
"\n\n",
"// Validate contracts type",
"if",
"contractsGroup",
".",
"ContractsType",
"!=",
"\"",
"\"",
"&&",
"contractsGroup",
".",
"ContractsType",
"!=",
"\"",
"\"",
"{",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Make sure the tenant exists",
"tenant",
":=",
"contivModel",
".",
"FindTenant",
"(",
"contractsGroup",
".",
"TenantName",
")",
"\n",
"if",
"tenant",
"==",
"nil",
"{",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"contractsGroup",
".",
"TenantName",
")",
"\n",
"}",
"\n\n",
"// NOTE: Nothing more needs to be done here. This object",
"// need not be created in the masterCfg.",
"return",
"nil",
"\n",
"}"
]
| // ExtContractsGroupCreate creates a new group of external contracts | [
"ExtContractsGroupCreate",
"creates",
"a",
"new",
"group",
"of",
"external",
"contracts"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/extContracts.go#L88-L105 |
8,086 | contiv/netplugin | netmaster/objApi/extContracts.go | ExtContractsGroupUpdate | func (ac *APIController) ExtContractsGroupUpdate(contractsGroup, params *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupUpdate: %+v, params: %+v", contractsGroup, params)
log.Errorf("Error: external contracts update not supported: %s", contractsGroup.ContractsGroupName)
return core.Errorf("external contracts update not supported")
} | go | func (ac *APIController) ExtContractsGroupUpdate(contractsGroup, params *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupUpdate: %+v, params: %+v", contractsGroup, params)
log.Errorf("Error: external contracts update not supported: %s", contractsGroup.ContractsGroupName)
return core.Errorf("external contracts update not supported")
} | [
"func",
"(",
"ac",
"*",
"APIController",
")",
"ExtContractsGroupUpdate",
"(",
"contractsGroup",
",",
"params",
"*",
"contivModel",
".",
"ExtContractsGroup",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"contractsGroup",
",",
"params",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"contractsGroup",
".",
"ContractsGroupName",
")",
"\n\n",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // ExtContractsGroupUpdate updates an existing group of contract sets | [
"ExtContractsGroupUpdate",
"updates",
"an",
"existing",
"group",
"of",
"contract",
"sets"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/extContracts.go#L108-L113 |
8,087 | contiv/netplugin | netmaster/objApi/extContracts.go | ExtContractsGroupDelete | func (ac *APIController) ExtContractsGroupDelete(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupDelete: %+v", contractsGroup)
// At this moment, we let the external contracts to be deleted only
// if there are no consumers of this external contracts group
if isExtContractsGroupUsed(contractsGroup) == true {
log.Errorf("Error: External contracts groups is being used: %s", contractsGroup.ContractsGroupName)
return core.Errorf("External contracts group is in-use")
}
return nil
} | go | func (ac *APIController) ExtContractsGroupDelete(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupDelete: %+v", contractsGroup)
// At this moment, we let the external contracts to be deleted only
// if there are no consumers of this external contracts group
if isExtContractsGroupUsed(contractsGroup) == true {
log.Errorf("Error: External contracts groups is being used: %s", contractsGroup.ContractsGroupName)
return core.Errorf("External contracts group is in-use")
}
return nil
} | [
"func",
"(",
"ac",
"*",
"APIController",
")",
"ExtContractsGroupDelete",
"(",
"contractsGroup",
"*",
"contivModel",
".",
"ExtContractsGroup",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"contractsGroup",
")",
"\n\n",
"// At this moment, we let the external contracts to be deleted only",
"// if there are no consumers of this external contracts group",
"if",
"isExtContractsGroupUsed",
"(",
"contractsGroup",
")",
"==",
"true",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"contractsGroup",
".",
"ContractsGroupName",
")",
"\n",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // ExtContractsGroupDelete deletes an existing external contracts group | [
"ExtContractsGroupDelete",
"deletes",
"an",
"existing",
"external",
"contracts",
"group"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/extContracts.go#L116-L127 |
8,088 | contiv/netplugin | utils/httputils.go | MakeHTTPHandler | func MakeHTTPHandler(handlerFunc httpAPIFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
if resp == nil {
// Send HTTP response
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
// Send HTTP response as Json
content, err := json.Marshal(resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusInternalServerError)
w.Write(content)
}
} else {
// Send HTTP response as Json
err = writeJSON(w, http.StatusOK, resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
} | go | func MakeHTTPHandler(handlerFunc httpAPIFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
if resp == nil {
// Send HTTP response
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
// Send HTTP response as Json
content, err := json.Marshal(resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusInternalServerError)
w.Write(content)
}
} else {
// Send HTTP response as Json
err = writeJSON(w, http.StatusOK, resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
} | [
"func",
"MakeHTTPHandler",
"(",
"handlerFunc",
"httpAPIFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"// Create a closure and return an anonymous function",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Call the handler",
"resp",
",",
"err",
":=",
"handlerFunc",
"(",
"w",
",",
"r",
",",
"mux",
".",
"Vars",
"(",
"r",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Log error",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Method",
",",
"r",
".",
"URL",
",",
"err",
")",
"\n\n",
"if",
"resp",
"==",
"nil",
"{",
"// Send HTTP response",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"else",
"{",
"// Send HTTP response as Json",
"content",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"w",
".",
"Write",
"(",
"content",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Send HTTP response as Json",
"err",
"=",
"writeJSON",
"(",
"w",
",",
"http",
".",
"StatusOK",
",",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // MakeHTTPHandler is a simple Wrapper for http handlers | [
"MakeHTTPHandler",
"is",
"a",
"simple",
"Wrapper",
"for",
"http",
"handlers"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/httputils.go#L33-L65 |
8,089 | contiv/netplugin | utils/httputils.go | UnknownAction | func UnknownAction(w http.ResponseWriter, r *http.Request) {
log.Infof("Unknown action at %q", r.URL.Path)
content, _ := ioutil.ReadAll(r.Body)
log.Infof("Body content: %s", string(content))
http.NotFound(w, r)
} | go | func UnknownAction(w http.ResponseWriter, r *http.Request) {
log.Infof("Unknown action at %q", r.URL.Path)
content, _ := ioutil.ReadAll(r.Body)
log.Infof("Body content: %s", string(content))
http.NotFound(w, r)
} | [
"func",
"UnknownAction",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"r",
".",
"URL",
".",
"Path",
")",
"\n",
"content",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"string",
"(",
"content",
")",
")",
"\n",
"http",
".",
"NotFound",
"(",
"w",
",",
"r",
")",
"\n",
"}"
]
| // UnknownAction is a catchall handler for additional driver functions | [
"UnknownAction",
"is",
"a",
"catchall",
"handler",
"for",
"additional",
"driver",
"functions"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/httputils.go#L81-L86 |
8,090 | contiv/netplugin | utils/httputils.go | HTTPPost | func HTTPPost(url string, req interface{}, resp interface{}) error {
// Convert the req to json
jsonStr, err := json.Marshal(req)
if err != nil {
log.Errorf("Error converting request data(%#v) to Json. Err: %v", req, err)
return err
}
// Perform HTTP POST operation
res, err := http.Post(url, "application/json", strings.NewReader(string(jsonStr)))
if err != nil {
log.Errorf("Error during http POST. Err: %v", err)
return err
}
defer res.Body.Close()
// Check the response code
if res.StatusCode == http.StatusInternalServerError {
eBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return errors.New("HTTP StatusInternalServerError" + err.Error())
}
return errors.New(string(eBody))
}
if res.StatusCode != http.StatusOK {
log.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
return fmt.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
}
// Read the entire response
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Errorf("Error during ioutil readall. Err: %v", err)
return err
}
// Convert response json to struct
err = json.Unmarshal(body, resp)
if err != nil {
log.Errorf("Error during json unmarshall. Err: %v", err)
return err
}
log.Debugf("Results for (%s): %+v\n", url, resp)
return nil
} | go | func HTTPPost(url string, req interface{}, resp interface{}) error {
// Convert the req to json
jsonStr, err := json.Marshal(req)
if err != nil {
log.Errorf("Error converting request data(%#v) to Json. Err: %v", req, err)
return err
}
// Perform HTTP POST operation
res, err := http.Post(url, "application/json", strings.NewReader(string(jsonStr)))
if err != nil {
log.Errorf("Error during http POST. Err: %v", err)
return err
}
defer res.Body.Close()
// Check the response code
if res.StatusCode == http.StatusInternalServerError {
eBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return errors.New("HTTP StatusInternalServerError" + err.Error())
}
return errors.New(string(eBody))
}
if res.StatusCode != http.StatusOK {
log.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
return fmt.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
}
// Read the entire response
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Errorf("Error during ioutil readall. Err: %v", err)
return err
}
// Convert response json to struct
err = json.Unmarshal(body, resp)
if err != nil {
log.Errorf("Error during json unmarshall. Err: %v", err)
return err
}
log.Debugf("Results for (%s): %+v\n", url, resp)
return nil
} | [
"func",
"HTTPPost",
"(",
"url",
"string",
",",
"req",
"interface",
"{",
"}",
",",
"resp",
"interface",
"{",
"}",
")",
"error",
"{",
"// Convert the req to json",
"jsonStr",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"req",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Perform HTTP POST operation",
"res",
",",
"err",
":=",
"http",
".",
"Post",
"(",
"url",
",",
"\"",
"\"",
",",
"strings",
".",
"NewReader",
"(",
"string",
"(",
"jsonStr",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Check the response code",
"if",
"res",
".",
"StatusCode",
"==",
"http",
".",
"StatusInternalServerError",
"{",
"eBody",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"res",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",
"string",
"(",
"eBody",
")",
")",
"\n",
"}",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Status",
",",
"res",
".",
"StatusCode",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Status",
",",
"res",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"// Read the entire response",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"res",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Convert response json to struct",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"url",
",",
"resp",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // HTTPPost performs http POST operation | [
"HTTPPost",
"performs",
"http",
"POST",
"operation"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/httputils.go#L89-L137 |
8,091 | contiv/netplugin | utils/httputils.go | HTTPDel | func HTTPDel(url string) error {
req, err := http.NewRequest("DELETE", url, nil)
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
// Check the response code
if res.StatusCode == http.StatusInternalServerError {
eBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return errors.New("HTTP StatusInternalServerError " + err.Error())
}
return errors.New(string(eBody))
}
if res.StatusCode != http.StatusOK {
log.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
return fmt.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
}
log.Debugf("Results for (%s): %+v\n", url, res)
return nil
} | go | func HTTPDel(url string) error {
req, err := http.NewRequest("DELETE", url, nil)
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
// Check the response code
if res.StatusCode == http.StatusInternalServerError {
eBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return errors.New("HTTP StatusInternalServerError " + err.Error())
}
return errors.New(string(eBody))
}
if res.StatusCode != http.StatusOK {
log.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
return fmt.Errorf("HTTP error response. Status: %s, StatusCode: %d", res.Status, res.StatusCode)
}
log.Debugf("Results for (%s): %+v\n", url, res)
return nil
} | [
"func",
"HTTPDel",
"(",
"url",
"string",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
")",
"\n\n",
"res",
",",
"err",
":=",
"http",
".",
"DefaultClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Check the response code",
"if",
"res",
".",
"StatusCode",
"==",
"http",
".",
"StatusInternalServerError",
"{",
"eBody",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"res",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",
"string",
"(",
"eBody",
")",
")",
"\n",
"}",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Status",
",",
"res",
".",
"StatusCode",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Status",
",",
"res",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"url",
",",
"res",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // HTTPDel performs http DELETE operation | [
"HTTPDel",
"performs",
"http",
"DELETE",
"operation"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/httputils.go#L140-L165 |
8,092 | contiv/netplugin | contivmodel/client/contivModelClient.go | NewContivClient | func NewContivClient(baseURL string) (*ContivClient, error) {
ok, err := regexp.Match(`^https?://`, []byte(baseURL))
if !ok {
return nil, errors.New("invalid URL: must begin with http:// or https://")
} else if err != nil {
return nil, err
}
client := ContivClient{
baseURL: baseURL,
customRequestHeaders: [][2]string{},
httpClient: &http.Client{},
}
return &client, nil
} | go | func NewContivClient(baseURL string) (*ContivClient, error) {
ok, err := regexp.Match(`^https?://`, []byte(baseURL))
if !ok {
return nil, errors.New("invalid URL: must begin with http:// or https://")
} else if err != nil {
return nil, err
}
client := ContivClient{
baseURL: baseURL,
customRequestHeaders: [][2]string{},
httpClient: &http.Client{},
}
return &client, nil
} | [
"func",
"NewContivClient",
"(",
"baseURL",
"string",
")",
"(",
"*",
"ContivClient",
",",
"error",
")",
"{",
"ok",
",",
"err",
":=",
"regexp",
".",
"Match",
"(",
"`^https?://`",
",",
"[",
"]",
"byte",
"(",
"baseURL",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"client",
":=",
"ContivClient",
"{",
"baseURL",
":",
"baseURL",
",",
"customRequestHeaders",
":",
"[",
"]",
"[",
"2",
"]",
"string",
"{",
"}",
",",
"httpClient",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"}",
"\n\n",
"return",
"&",
"client",
",",
"nil",
"\n",
"}"
]
| // NewContivClient creates a new client instance | [
"NewContivClient",
"creates",
"a",
"new",
"client",
"instance"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L233-L248 |
8,093 | contiv/netplugin | contivmodel/client/contivModelClient.go | SetAuthToken | func (c *ContivClient) SetAuthToken(token string) error {
// setting an auth token is only allowed on secure requests.
// if we didn't enforce this, the client could potentially send auth
// tokens in plain text across the network.
if !c.isHTTPS() {
return errors.New("setting auth token requires a https auth_proxy URL")
}
// having multiple auth token headers is confusing and makes no sense and
// which one is actually used depends on the implementation of the server.
// therefore, we will raise an error if there's already an auth token set.
for _, pair := range c.customRequestHeaders {
if pair[0] == authTokenHeader {
return errors.New("an auth token has already been set")
}
}
c.addCustomRequestHeader(authTokenHeader, token)
return nil
} | go | func (c *ContivClient) SetAuthToken(token string) error {
// setting an auth token is only allowed on secure requests.
// if we didn't enforce this, the client could potentially send auth
// tokens in plain text across the network.
if !c.isHTTPS() {
return errors.New("setting auth token requires a https auth_proxy URL")
}
// having multiple auth token headers is confusing and makes no sense and
// which one is actually used depends on the implementation of the server.
// therefore, we will raise an error if there's already an auth token set.
for _, pair := range c.customRequestHeaders {
if pair[0] == authTokenHeader {
return errors.New("an auth token has already been set")
}
}
c.addCustomRequestHeader(authTokenHeader, token)
return nil
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"SetAuthToken",
"(",
"token",
"string",
")",
"error",
"{",
"// setting an auth token is only allowed on secure requests.",
"// if we didn't enforce this, the client could potentially send auth",
"// tokens in plain text across the network.",
"if",
"!",
"c",
".",
"isHTTPS",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// having multiple auth token headers is confusing and makes no sense and",
"// which one is actually used depends on the implementation of the server.",
"// therefore, we will raise an error if there's already an auth token set.",
"for",
"_",
",",
"pair",
":=",
"range",
"c",
".",
"customRequestHeaders",
"{",
"if",
"pair",
"[",
"0",
"]",
"==",
"authTokenHeader",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"addCustomRequestHeader",
"(",
"authTokenHeader",
",",
"token",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // SetAuthToken sets the token used to authenticate with auth_proxy | [
"SetAuthToken",
"sets",
"the",
"token",
"used",
"to",
"authenticate",
"with",
"auth_proxy"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L265-L286 |
8,094 | contiv/netplugin | contivmodel/client/contivModelClient.go | Login | func (c *ContivClient) Login(username, password string) (*http.Response, []byte, error) {
// login is only allowed over a secure channel
if !c.isHTTPS() {
return nil, nil, errors.New("login requires a https auth_proxy URL")
}
url := c.baseURL + LoginPath
// create the POST payload for login
lp := loginPayload{
Username: username,
Password: password,
}
payload, err := json.Marshal(lp)
if err != nil {
return nil, nil, err
}
// send the login POST request
resp, err := c.httpClient.Post(url, "application/json", bytes.NewBuffer(payload))
if err != nil {
return nil, nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, err
}
return resp, body, nil
} | go | func (c *ContivClient) Login(username, password string) (*http.Response, []byte, error) {
// login is only allowed over a secure channel
if !c.isHTTPS() {
return nil, nil, errors.New("login requires a https auth_proxy URL")
}
url := c.baseURL + LoginPath
// create the POST payload for login
lp := loginPayload{
Username: username,
Password: password,
}
payload, err := json.Marshal(lp)
if err != nil {
return nil, nil, err
}
// send the login POST request
resp, err := c.httpClient.Post(url, "application/json", bytes.NewBuffer(payload))
if err != nil {
return nil, nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, err
}
return resp, body, nil
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"Login",
"(",
"username",
",",
"password",
"string",
")",
"(",
"*",
"http",
".",
"Response",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// login is only allowed over a secure channel",
"if",
"!",
"c",
".",
"isHTTPS",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"url",
":=",
"c",
".",
"baseURL",
"+",
"LoginPath",
"\n\n",
"// create the POST payload for login",
"lp",
":=",
"loginPayload",
"{",
"Username",
":",
"username",
",",
"Password",
":",
"password",
",",
"}",
"\n\n",
"payload",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"lp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// send the login POST request",
"resp",
",",
"err",
":=",
"c",
".",
"httpClient",
".",
"Post",
"(",
"url",
",",
"\"",
"\"",
",",
"bytes",
".",
"NewBuffer",
"(",
"payload",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"body",
",",
"nil",
"\n",
"}"
]
| // Login performs a login to auth_proxy and returns the response and body | [
"Login",
"performs",
"a",
"login",
"to",
"auth_proxy",
"and",
"returns",
"the",
"response",
"and",
"body"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L301-L334 |
8,095 | contiv/netplugin | contivmodel/client/contivModelClient.go | addCustomRequestHeader | func (c *ContivClient) addCustomRequestHeader(name, value string) {
// lowercase the header name so we can easily check for duplicates in other places.
// there can legitimately be many headers with the same name, but in some cases
// (e.g., auth token) we want to enforce that there is only one.
// Go internally canonicalizes them when we call Header.Add() anyways.
name = strings.ToLower(name)
c.customRequestHeaders = append(c.customRequestHeaders, [2]string{name, value})
} | go | func (c *ContivClient) addCustomRequestHeader(name, value string) {
// lowercase the header name so we can easily check for duplicates in other places.
// there can legitimately be many headers with the same name, but in some cases
// (e.g., auth token) we want to enforce that there is only one.
// Go internally canonicalizes them when we call Header.Add() anyways.
name = strings.ToLower(name)
c.customRequestHeaders = append(c.customRequestHeaders, [2]string{name, value})
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"addCustomRequestHeader",
"(",
"name",
",",
"value",
"string",
")",
"{",
"// lowercase the header name so we can easily check for duplicates in other places.",
"// there can legitimately be many headers with the same name, but in some cases",
"// (e.g., auth token) we want to enforce that there is only one.",
"// Go internally canonicalizes them when we call Header.Add() anyways.",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n\n",
"c",
".",
"customRequestHeaders",
"=",
"append",
"(",
"c",
".",
"customRequestHeaders",
",",
"[",
"2",
"]",
"string",
"{",
"name",
",",
"value",
"}",
")",
"\n",
"}"
]
| // addCustomRequestHeader records a custom request header to be added to all outgoing requests | [
"addCustomRequestHeader",
"records",
"a",
"custom",
"request",
"header",
"to",
"be",
"added",
"to",
"all",
"outgoing",
"requests"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L337-L346 |
8,096 | contiv/netplugin | contivmodel/client/contivModelClient.go | processCustomHeaders | func (c *ContivClient) processCustomHeaders(req *http.Request) {
for _, pair := range c.customRequestHeaders {
req.Header.Add(pair[0], pair[1])
}
} | go | func (c *ContivClient) processCustomHeaders(req *http.Request) {
for _, pair := range c.customRequestHeaders {
req.Header.Add(pair[0], pair[1])
}
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"processCustomHeaders",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"for",
"_",
",",
"pair",
":=",
"range",
"c",
".",
"customRequestHeaders",
"{",
"req",
".",
"Header",
".",
"Add",
"(",
"pair",
"[",
"0",
"]",
",",
"pair",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"}"
]
| // processCustomHeaders adds all custom request headers to the target request.
// this function is called before a GET, POST, or DELETE is sent by the client. | [
"processCustomHeaders",
"adds",
"all",
"custom",
"request",
"headers",
"to",
"the",
"target",
"request",
".",
"this",
"function",
"is",
"called",
"before",
"a",
"GET",
"POST",
"or",
"DELETE",
"is",
"sent",
"by",
"the",
"client",
"."
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L350-L354 |
8,097 | contiv/netplugin | contivmodel/client/contivModelClient.go | AciGwPost | func (c *ContivClient) AciGwPost(obj *AciGw) error {
// build key and URL
keyStr := obj.Name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http post the object
err := c.httpPost(url, obj)
if err != nil {
log.Debugf("Error creating aciGw %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func (c *ContivClient) AciGwPost(obj *AciGw) error {
// build key and URL
keyStr := obj.Name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http post the object
err := c.httpPost(url, obj)
if err != nil {
log.Debugf("Error creating aciGw %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"AciGwPost",
"(",
"obj",
"*",
"AciGw",
")",
"error",
"{",
"// build key and URL",
"keyStr",
":=",
"obj",
".",
"Name",
"\n",
"url",
":=",
"c",
".",
"baseURL",
"+",
"\"",
"\"",
"+",
"keyStr",
"+",
"\"",
"\"",
"\n\n",
"// http post the object",
"err",
":=",
"c",
".",
"httpPost",
"(",
"url",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // AciGwPost posts the aciGw object | [
"AciGwPost",
"posts",
"the",
"aciGw",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L887-L900 |
8,098 | contiv/netplugin | contivmodel/client/contivModelClient.go | AciGwList | func (c *ContivClient) AciGwList() (*[]*AciGw, error) {
// build key and URL
url := c.baseURL + "/api/v1/aciGws/"
// http get the object
var objList []*AciGw
err := c.httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting aciGws. Err: %v", err)
return nil, err
}
return &objList, nil
} | go | func (c *ContivClient) AciGwList() (*[]*AciGw, error) {
// build key and URL
url := c.baseURL + "/api/v1/aciGws/"
// http get the object
var objList []*AciGw
err := c.httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting aciGws. Err: %v", err)
return nil, err
}
return &objList, nil
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"AciGwList",
"(",
")",
"(",
"*",
"[",
"]",
"*",
"AciGw",
",",
"error",
")",
"{",
"// build key and URL",
"url",
":=",
"c",
".",
"baseURL",
"+",
"\"",
"\"",
"\n\n",
"// http get the object",
"var",
"objList",
"[",
"]",
"*",
"AciGw",
"\n",
"err",
":=",
"c",
".",
"httpGet",
"(",
"url",
",",
"&",
"objList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"objList",
",",
"nil",
"\n",
"}"
]
| // AciGwList lists all aciGw objects | [
"AciGwList",
"lists",
"all",
"aciGw",
"objects"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L903-L916 |
8,099 | contiv/netplugin | contivmodel/client/contivModelClient.go | AciGwDelete | func (c *ContivClient) AciGwDelete(name string) error {
// build key and URL
keyStr := name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http get the object
err := c.httpDelete(url)
if err != nil {
log.Debugf("Error deleting aciGw %s. Err: %v", keyStr, err)
return err
}
return nil
} | go | func (c *ContivClient) AciGwDelete(name string) error {
// build key and URL
keyStr := name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http get the object
err := c.httpDelete(url)
if err != nil {
log.Debugf("Error deleting aciGw %s. Err: %v", keyStr, err)
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"ContivClient",
")",
"AciGwDelete",
"(",
"name",
"string",
")",
"error",
"{",
"// build key and URL",
"keyStr",
":=",
"name",
"\n",
"url",
":=",
"c",
".",
"baseURL",
"+",
"\"",
"\"",
"+",
"keyStr",
"+",
"\"",
"\"",
"\n\n",
"// http get the object",
"err",
":=",
"c",
".",
"httpDelete",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // AciGwDelete deletes the aciGw object | [
"AciGwDelete",
"deletes",
"the",
"aciGw",
"object"
]
| 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L936-L949 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.