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", ",...
// 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", "{", "endpo...
// 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", ",", "_", ",",...
// 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", ",", "_", ",", ...
// 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", ...
// 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", "(", ...
// 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", ",...
// 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", "=", "process...
// 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", ".",...
// 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", "[",...
// 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 l...
// 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", ",", ...
// 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", ",", ...
// 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", "{...
// 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", "==", "\"", "\"", "{", "ret...
// 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", ".", "CfgNetworkS...
// 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", ".", "R...
// 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", "(", "\"", "\"", ",", ...
//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", "(", "\"", "\"", ",", ...
//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", ",",...
// 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", ":", ...
// 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", "."...
// 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", "{", "re...
// 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", ".", ...
// 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", ":=", "tableUpdate...
// 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", "{", "{", "G...
// 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"...
// 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...
// 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",...
// 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", ...
// 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"...
//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", "{", ...
// 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", "[", "strin...
//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", ")", ...
// 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", "(", "\"", "\"", ",", "\"", "\"", ",", "...
// 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", ...
// 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...
// 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", ":=", "...
// 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", ...
// 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", "(",...
// 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", "...
// 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", "....
// 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", ".", "Unma...
// 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", ...
// 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", "(", "\"", "\"", ","...
// 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", ...
// 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", "...
// 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", ":=",...
// 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", ...
// 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 ...
// 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...
// 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", ".", "currStat...
// 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", ...
// 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", ":=", "masterU...
// 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 ...
// 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", "}", ...
// 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", "}", ...
// 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",...
// 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", "(",...
// 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", "}", ...
// 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"...
// 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", "{", ...
// 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"...
// 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...
// 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", "...
// 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"...
// 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", ":=", "netPlugi...
// 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"...
// 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", "!", "str...
// 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", ...
// 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", "{", "...
// 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"...
// 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", ".", "GetPodLa...
// 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", ...
// 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", ".", ...
// 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", "{...
// 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", ...
// 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", ...
// 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\...
// 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",...
// 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", ".", "TenantNa...
// 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",...
// 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", ")", "...
// 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 th...
// 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", ")", "{", ...
// 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", ".", "Read...
// 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", "...
// 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", ")...
// 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", ...
// 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.", ...
// 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", ".", ...
// 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",...
// 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", "[", ...
// 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", "+", "\"", "\"",...
// 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", ...
// 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", "// ht...
// AciGwDelete deletes the aciGw object
[ "AciGwDelete", "deletes", "the", "aciGw", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L936-L949