id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
7,900
contiv/netplugin
contivmodel/contivModel.go
CreatePolicy
func CreatePolicy(obj *Policy) error { // Validate parameters err := ValidatePolicy(obj) if err != nil { log.Errorf("ValidatePolicy retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.PolicyCb == nil { log.Errorf("No callback registered for policy object") return errors.New("Invalid object type") } saveObj := obj collections.policyMutex.Lock() key := collections.policys[obj.Key] collections.policyMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.PolicyCb.PolicyUpdate(collections.policys[obj.Key], obj) if err != nil { log.Errorf("PolicyUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.policyMutex.Lock() saveObj = collections.policys[obj.Key] collections.policyMutex.Unlock() } else { // save it in cache collections.policyMutex.Lock() collections.policys[obj.Key] = obj collections.policyMutex.Unlock() // Perform Create callback err = objCallbackHandler.PolicyCb.PolicyCreate(obj) if err != nil { log.Errorf("PolicyCreate retruned error for: %+v. Err: %v", obj, err) collections.policyMutex.Lock() delete(collections.policys, obj.Key) collections.policyMutex.Unlock() return err } } // Write it to modeldb collections.policyMutex.Lock() err = saveObj.Write() collections.policyMutex.Unlock() if err != nil { log.Errorf("Error saving policy %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreatePolicy(obj *Policy) error { // Validate parameters err := ValidatePolicy(obj) if err != nil { log.Errorf("ValidatePolicy retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.PolicyCb == nil { log.Errorf("No callback registered for policy object") return errors.New("Invalid object type") } saveObj := obj collections.policyMutex.Lock() key := collections.policys[obj.Key] collections.policyMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.PolicyCb.PolicyUpdate(collections.policys[obj.Key], obj) if err != nil { log.Errorf("PolicyUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.policyMutex.Lock() saveObj = collections.policys[obj.Key] collections.policyMutex.Unlock() } else { // save it in cache collections.policyMutex.Lock() collections.policys[obj.Key] = obj collections.policyMutex.Unlock() // Perform Create callback err = objCallbackHandler.PolicyCb.PolicyCreate(obj) if err != nil { log.Errorf("PolicyCreate retruned error for: %+v. Err: %v", obj, err) collections.policyMutex.Lock() delete(collections.policys, obj.Key) collections.policyMutex.Unlock() return err } } // Write it to modeldb collections.policyMutex.Lock() err = saveObj.Write() collections.policyMutex.Unlock() if err != nil { log.Errorf("Error saving policy %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreatePolicy", "(", "obj", "*", "Policy", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidatePolicy", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "PolicyCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "policys", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "PolicyCb", ".", "PolicyUpdate", "(", "collections", ".", "policys", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "policys", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "policys", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "PolicyCb", ".", "PolicyCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "policys", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a policy object
[ "Create", "a", "policy", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3971-L4031
7,901
contiv/netplugin
contivmodel/contivModel.go
FindPolicy
func FindPolicy(key string) *Policy { collections.policyMutex.Lock() defer collections.policyMutex.Unlock() obj := collections.policys[key] if obj == nil { return nil } return obj }
go
func FindPolicy(key string) *Policy { collections.policyMutex.Lock() defer collections.policyMutex.Unlock() obj := collections.policys[key] if obj == nil { return nil } return obj }
[ "func", "FindPolicy", "(", "key", "string", ")", "*", "Policy", "{", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "policys", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to policy from collection
[ "Return", "a", "pointer", "to", "policy", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4034-L4044
7,902
contiv/netplugin
contivmodel/contivModel.go
DeletePolicy
func DeletePolicy(key string) error { collections.policyMutex.Lock() obj := collections.policys[key] collections.policyMutex.Unlock() if obj == nil { log.Errorf("policy %s not found", key) return errors.New("policy not found") } // Check if we handle this object if objCallbackHandler.PolicyCb == nil { log.Errorf("No callback registered for policy object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.PolicyCb.PolicyDelete(obj) if err != nil { log.Errorf("PolicyDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.policyMutex.Lock() err = obj.Delete() collections.policyMutex.Unlock() if err != nil { log.Errorf("Error deleting policy %s. Err: %v", obj.Key, err) } // delete it from cache collections.policyMutex.Lock() delete(collections.policys, key) collections.policyMutex.Unlock() return nil }
go
func DeletePolicy(key string) error { collections.policyMutex.Lock() obj := collections.policys[key] collections.policyMutex.Unlock() if obj == nil { log.Errorf("policy %s not found", key) return errors.New("policy not found") } // Check if we handle this object if objCallbackHandler.PolicyCb == nil { log.Errorf("No callback registered for policy object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.PolicyCb.PolicyDelete(obj) if err != nil { log.Errorf("PolicyDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.policyMutex.Lock() err = obj.Delete() collections.policyMutex.Unlock() if err != nil { log.Errorf("Error deleting policy %s. Err: %v", obj.Key, err) } // delete it from cache collections.policyMutex.Lock() delete(collections.policys, key) collections.policyMutex.Unlock() return nil }
[ "func", "DeletePolicy", "(", "key", "string", ")", "error", "{", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "policys", "[", "key", "]", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "PolicyCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "PolicyCb", ".", "PolicyDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "policys", ",", "key", ")", "\n", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a policy object
[ "Delete", "a", "policy", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4047-L4083
7,903
contiv/netplugin
contivmodel/contivModel.go
ValidatePolicy
func ValidatePolicy(obj *Policy) error { collections.policyMutex.Lock() defer collections.policyMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.PolicyName if obj.Key != keyStr { log.Errorf("Expecting Policy Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.PolicyName) > 64 { return errors.New("policyName string too long") } policyNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if policyNameMatch.MatchString(obj.PolicyName) == false { return errors.New("policyName string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
go
func ValidatePolicy(obj *Policy) error { collections.policyMutex.Lock() defer collections.policyMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.PolicyName if obj.Key != keyStr { log.Errorf("Expecting Policy Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.PolicyName) > 64 { return errors.New("policyName string too long") } policyNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if policyNameMatch.MatchString(obj.PolicyName) == false { return errors.New("policyName string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
[ "func", "ValidatePolicy", "(", "obj", "*", "Policy", ")", "error", "{", "collections", ".", "policyMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "policyMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "PolicyName", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "if", "len", "(", "obj", ".", "PolicyName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "policyNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "policyNameMatch", ".", "MatchString", "(", "obj", ".", "PolicyName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "TenantName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenantNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "tenantNameMatch", ".", "MatchString", "(", "obj", ".", "TenantName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate a policy object
[ "Validate", "a", "policy", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4146-L4178
7,904
contiv/netplugin
contivmodel/contivModel.go
CreateRule
func CreateRule(obj *Rule) error { // Validate parameters err := ValidateRule(obj) if err != nil { log.Errorf("ValidateRule retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.RuleCb == nil { log.Errorf("No callback registered for rule object") return errors.New("Invalid object type") } saveObj := obj collections.ruleMutex.Lock() key := collections.rules[obj.Key] collections.ruleMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.RuleCb.RuleUpdate(collections.rules[obj.Key], obj) if err != nil { log.Errorf("RuleUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.ruleMutex.Lock() saveObj = collections.rules[obj.Key] collections.ruleMutex.Unlock() } else { // save it in cache collections.ruleMutex.Lock() collections.rules[obj.Key] = obj collections.ruleMutex.Unlock() // Perform Create callback err = objCallbackHandler.RuleCb.RuleCreate(obj) if err != nil { log.Errorf("RuleCreate retruned error for: %+v. Err: %v", obj, err) collections.ruleMutex.Lock() delete(collections.rules, obj.Key) collections.ruleMutex.Unlock() return err } } // Write it to modeldb collections.ruleMutex.Lock() err = saveObj.Write() collections.ruleMutex.Unlock() if err != nil { log.Errorf("Error saving rule %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreateRule(obj *Rule) error { // Validate parameters err := ValidateRule(obj) if err != nil { log.Errorf("ValidateRule retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.RuleCb == nil { log.Errorf("No callback registered for rule object") return errors.New("Invalid object type") } saveObj := obj collections.ruleMutex.Lock() key := collections.rules[obj.Key] collections.ruleMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.RuleCb.RuleUpdate(collections.rules[obj.Key], obj) if err != nil { log.Errorf("RuleUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.ruleMutex.Lock() saveObj = collections.rules[obj.Key] collections.ruleMutex.Unlock() } else { // save it in cache collections.ruleMutex.Lock() collections.rules[obj.Key] = obj collections.ruleMutex.Unlock() // Perform Create callback err = objCallbackHandler.RuleCb.RuleCreate(obj) if err != nil { log.Errorf("RuleCreate retruned error for: %+v. Err: %v", obj, err) collections.ruleMutex.Lock() delete(collections.rules, obj.Key) collections.ruleMutex.Unlock() return err } } // Write it to modeldb collections.ruleMutex.Lock() err = saveObj.Write() collections.ruleMutex.Unlock() if err != nil { log.Errorf("Error saving rule %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreateRule", "(", "obj", "*", "Rule", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidateRule", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "RuleCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "rules", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "RuleCb", ".", "RuleUpdate", "(", "collections", ".", "rules", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "rules", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "rules", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "RuleCb", ".", "RuleCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "rules", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a rule object
[ "Create", "a", "rule", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4279-L4339
7,905
contiv/netplugin
contivmodel/contivModel.go
FindRule
func FindRule(key string) *Rule { collections.ruleMutex.Lock() defer collections.ruleMutex.Unlock() obj := collections.rules[key] if obj == nil { return nil } return obj }
go
func FindRule(key string) *Rule { collections.ruleMutex.Lock() defer collections.ruleMutex.Unlock() obj := collections.rules[key] if obj == nil { return nil } return obj }
[ "func", "FindRule", "(", "key", "string", ")", "*", "Rule", "{", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "rules", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to rule from collection
[ "Return", "a", "pointer", "to", "rule", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4342-L4352
7,906
contiv/netplugin
contivmodel/contivModel.go
DeleteRule
func DeleteRule(key string) error { collections.ruleMutex.Lock() obj := collections.rules[key] collections.ruleMutex.Unlock() if obj == nil { log.Errorf("rule %s not found", key) return errors.New("rule not found") } // Check if we handle this object if objCallbackHandler.RuleCb == nil { log.Errorf("No callback registered for rule object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.RuleCb.RuleDelete(obj) if err != nil { log.Errorf("RuleDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.ruleMutex.Lock() err = obj.Delete() collections.ruleMutex.Unlock() if err != nil { log.Errorf("Error deleting rule %s. Err: %v", obj.Key, err) } // delete it from cache collections.ruleMutex.Lock() delete(collections.rules, key) collections.ruleMutex.Unlock() return nil }
go
func DeleteRule(key string) error { collections.ruleMutex.Lock() obj := collections.rules[key] collections.ruleMutex.Unlock() if obj == nil { log.Errorf("rule %s not found", key) return errors.New("rule not found") } // Check if we handle this object if objCallbackHandler.RuleCb == nil { log.Errorf("No callback registered for rule object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.RuleCb.RuleDelete(obj) if err != nil { log.Errorf("RuleDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.ruleMutex.Lock() err = obj.Delete() collections.ruleMutex.Unlock() if err != nil { log.Errorf("Error deleting rule %s. Err: %v", obj.Key, err) } // delete it from cache collections.ruleMutex.Lock() delete(collections.rules, key) collections.ruleMutex.Unlock() return nil }
[ "func", "DeleteRule", "(", "key", "string", ")", "error", "{", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "rules", "[", "key", "]", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "RuleCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "RuleCb", ".", "RuleDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "rules", ",", "key", ")", "\n", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a rule object
[ "Delete", "a", "rule", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4355-L4391
7,907
contiv/netplugin
contivmodel/contivModel.go
ValidateRule
func ValidateRule(obj *Rule) error { collections.ruleMutex.Lock() defer collections.ruleMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID if obj.Key != keyStr { log.Errorf("Expecting Rule Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field actionMatch := regexp.MustCompile("^(allow|deny)$") if actionMatch.MatchString(obj.Action) == false { return errors.New("action string invalid format") } directionMatch := regexp.MustCompile("^(in|out)$") if directionMatch.MatchString(obj.Direction) == false { return errors.New("direction string invalid format") } if len(obj.FromEndpointGroup) > 64 { return errors.New("fromEndpointGroup string too long") } fromEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if fromEndpointGroupMatch.MatchString(obj.FromEndpointGroup) == false { return errors.New("fromEndpointGroup string invalid format") } fromIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$") if fromIpAddressMatch.MatchString(obj.FromIpAddress) == false { return errors.New("fromIpAddress string invalid format") } if len(obj.FromNetwork) > 64 { return errors.New("fromNetwork string too long") } fromNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if fromNetworkMatch.MatchString(obj.FromNetwork) == false { return errors.New("fromNetwork string invalid format") } if len(obj.PolicyName) > 64 { return errors.New("policyName string too long") } policyNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if policyNameMatch.MatchString(obj.PolicyName) == false { return errors.New("policyName string invalid format") } if obj.Port > 65535 { return errors.New("port Value Out of bound") } if obj.Priority == 0 { obj.Priority = 1 } if obj.Priority < 1 { return errors.New("priority Value Out of bound") } if obj.Priority > 100 { return errors.New("priority Value Out of bound") } protocolMatch := regexp.MustCompile("^(tcp|udp|icmp||[0-9]{1,3}?)$") if protocolMatch.MatchString(obj.Protocol) == false { return errors.New("protocol string invalid format") } if len(obj.RuleID) > 64 { return errors.New("ruleId string too long") } ruleIdMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if ruleIdMatch.MatchString(obj.RuleID) == false { return errors.New("ruleId string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } if len(obj.ToEndpointGroup) > 64 { return errors.New("toEndpointGroup string too long") } toEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if toEndpointGroupMatch.MatchString(obj.ToEndpointGroup) == false { return errors.New("toEndpointGroup string invalid format") } toIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$") if toIpAddressMatch.MatchString(obj.ToIpAddress) == false { return errors.New("toIpAddress string invalid format") } if len(obj.ToNetwork) > 64 { return errors.New("toNetwork string too long") } toNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if toNetworkMatch.MatchString(obj.ToNetwork) == false { return errors.New("toNetwork string invalid format") } return nil }
go
func ValidateRule(obj *Rule) error { collections.ruleMutex.Lock() defer collections.ruleMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID if obj.Key != keyStr { log.Errorf("Expecting Rule Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field actionMatch := regexp.MustCompile("^(allow|deny)$") if actionMatch.MatchString(obj.Action) == false { return errors.New("action string invalid format") } directionMatch := regexp.MustCompile("^(in|out)$") if directionMatch.MatchString(obj.Direction) == false { return errors.New("direction string invalid format") } if len(obj.FromEndpointGroup) > 64 { return errors.New("fromEndpointGroup string too long") } fromEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if fromEndpointGroupMatch.MatchString(obj.FromEndpointGroup) == false { return errors.New("fromEndpointGroup string invalid format") } fromIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$") if fromIpAddressMatch.MatchString(obj.FromIpAddress) == false { return errors.New("fromIpAddress string invalid format") } if len(obj.FromNetwork) > 64 { return errors.New("fromNetwork string too long") } fromNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if fromNetworkMatch.MatchString(obj.FromNetwork) == false { return errors.New("fromNetwork string invalid format") } if len(obj.PolicyName) > 64 { return errors.New("policyName string too long") } policyNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if policyNameMatch.MatchString(obj.PolicyName) == false { return errors.New("policyName string invalid format") } if obj.Port > 65535 { return errors.New("port Value Out of bound") } if obj.Priority == 0 { obj.Priority = 1 } if obj.Priority < 1 { return errors.New("priority Value Out of bound") } if obj.Priority > 100 { return errors.New("priority Value Out of bound") } protocolMatch := regexp.MustCompile("^(tcp|udp|icmp||[0-9]{1,3}?)$") if protocolMatch.MatchString(obj.Protocol) == false { return errors.New("protocol string invalid format") } if len(obj.RuleID) > 64 { return errors.New("ruleId string too long") } ruleIdMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if ruleIdMatch.MatchString(obj.RuleID) == false { return errors.New("ruleId string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } if len(obj.ToEndpointGroup) > 64 { return errors.New("toEndpointGroup string too long") } toEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if toEndpointGroupMatch.MatchString(obj.ToEndpointGroup) == false { return errors.New("toEndpointGroup string invalid format") } toIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$") if toIpAddressMatch.MatchString(obj.ToIpAddress) == false { return errors.New("toIpAddress string invalid format") } if len(obj.ToNetwork) > 64 { return errors.New("toNetwork string too long") } toNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if toNetworkMatch.MatchString(obj.ToNetwork) == false { return errors.New("toNetwork string invalid format") } return nil }
[ "func", "ValidateRule", "(", "obj", "*", "Rule", ")", "error", "{", "collections", ".", "ruleMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "ruleMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "PolicyName", "+", "\"", "\"", "+", "obj", ".", "RuleID", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "actionMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n", "if", "actionMatch", ".", "MatchString", "(", "obj", ".", "Action", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "directionMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n", "if", "directionMatch", ".", "MatchString", "(", "obj", ".", "Direction", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "FromEndpointGroup", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "fromEndpointGroupMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "fromEndpointGroupMatch", ".", "MatchString", "(", "obj", ".", "FromEndpointGroup", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "fromIpAddressMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "if", "fromIpAddressMatch", ".", "MatchString", "(", "obj", ".", "FromIpAddress", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "FromNetwork", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "fromNetworkMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "fromNetworkMatch", ".", "MatchString", "(", "obj", ".", "FromNetwork", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "PolicyName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "policyNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "policyNameMatch", ".", "MatchString", "(", "obj", ".", "PolicyName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "obj", ".", "Port", ">", "65535", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "obj", ".", "Priority", "==", "0", "{", "obj", ".", "Priority", "=", "1", "\n", "}", "\n\n", "if", "obj", ".", "Priority", "<", "1", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "obj", ".", "Priority", ">", "100", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "protocolMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n", "if", "protocolMatch", ".", "MatchString", "(", "obj", ".", "Protocol", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "RuleID", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "ruleIdMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "ruleIdMatch", ".", "MatchString", "(", "obj", ".", "RuleID", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "TenantName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenantNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "tenantNameMatch", ".", "MatchString", "(", "obj", ".", "TenantName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "ToEndpointGroup", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "toEndpointGroupMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "toEndpointGroupMatch", ".", "MatchString", "(", "obj", ".", "ToEndpointGroup", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "toIpAddressMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "if", "toIpAddressMatch", ".", "MatchString", "(", "obj", ".", "ToIpAddress", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "ToNetwork", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "toNetworkMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "toNetworkMatch", ".", "MatchString", "(", "obj", ".", "ToNetwork", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate a rule object
[ "Validate", "a", "rule", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4454-L4572
7,908
contiv/netplugin
contivmodel/contivModel.go
GetOperServiceLB
func GetOperServiceLB(obj *ServiceLBInspect) error { // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.ServiceLBCb.ServiceLBGetOper(obj) if err != nil { log.Errorf("ServiceLBDelete retruned error for: %+v. Err: %v", obj, err) return err } return nil }
go
func GetOperServiceLB(obj *ServiceLBInspect) error { // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.ServiceLBCb.ServiceLBGetOper(obj) if err != nil { log.Errorf("ServiceLBDelete retruned error for: %+v. Err: %v", obj, err) return err } return nil }
[ "func", "GetOperServiceLB", "(", "obj", "*", "ServiceLBInspect", ")", "error", "{", "// Check if we handle this object", "if", "objCallbackHandler", ".", "ServiceLBCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "ServiceLBCb", ".", "ServiceLBGetOper", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Get a serviceLBOper object
[ "Get", "a", "serviceLBOper", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4600-L4615
7,909
contiv/netplugin
contivmodel/contivModel.go
CreateServiceLB
func CreateServiceLB(obj *ServiceLB) error { // Validate parameters err := ValidateServiceLB(obj) if err != nil { log.Errorf("ValidateServiceLB retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } saveObj := obj collections.serviceLBMutex.Lock() key := collections.serviceLBs[obj.Key] collections.serviceLBMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.ServiceLBCb.ServiceLBUpdate(collections.serviceLBs[obj.Key], obj) if err != nil { log.Errorf("ServiceLBUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.serviceLBMutex.Lock() saveObj = collections.serviceLBs[obj.Key] collections.serviceLBMutex.Unlock() } else { // save it in cache collections.serviceLBMutex.Lock() collections.serviceLBs[obj.Key] = obj collections.serviceLBMutex.Unlock() // Perform Create callback err = objCallbackHandler.ServiceLBCb.ServiceLBCreate(obj) if err != nil { log.Errorf("ServiceLBCreate retruned error for: %+v. Err: %v", obj, err) collections.serviceLBMutex.Lock() delete(collections.serviceLBs, obj.Key) collections.serviceLBMutex.Unlock() return err } } // Write it to modeldb collections.serviceLBMutex.Lock() err = saveObj.Write() collections.serviceLBMutex.Unlock() if err != nil { log.Errorf("Error saving serviceLB %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreateServiceLB(obj *ServiceLB) error { // Validate parameters err := ValidateServiceLB(obj) if err != nil { log.Errorf("ValidateServiceLB retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } saveObj := obj collections.serviceLBMutex.Lock() key := collections.serviceLBs[obj.Key] collections.serviceLBMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.ServiceLBCb.ServiceLBUpdate(collections.serviceLBs[obj.Key], obj) if err != nil { log.Errorf("ServiceLBUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.serviceLBMutex.Lock() saveObj = collections.serviceLBs[obj.Key] collections.serviceLBMutex.Unlock() } else { // save it in cache collections.serviceLBMutex.Lock() collections.serviceLBs[obj.Key] = obj collections.serviceLBMutex.Unlock() // Perform Create callback err = objCallbackHandler.ServiceLBCb.ServiceLBCreate(obj) if err != nil { log.Errorf("ServiceLBCreate retruned error for: %+v. Err: %v", obj, err) collections.serviceLBMutex.Lock() delete(collections.serviceLBs, obj.Key) collections.serviceLBMutex.Unlock() return err } } // Write it to modeldb collections.serviceLBMutex.Lock() err = saveObj.Write() collections.serviceLBMutex.Unlock() if err != nil { log.Errorf("Error saving serviceLB %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreateServiceLB", "(", "obj", "*", "ServiceLB", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidateServiceLB", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "ServiceLBCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "serviceLBs", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "ServiceLBCb", ".", "ServiceLBUpdate", "(", "collections", ".", "serviceLBs", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "serviceLBs", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "serviceLBs", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "ServiceLBCb", ".", "ServiceLBCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "serviceLBs", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a serviceLB object
[ "Create", "a", "serviceLB", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4696-L4756
7,910
contiv/netplugin
contivmodel/contivModel.go
FindServiceLB
func FindServiceLB(key string) *ServiceLB { collections.serviceLBMutex.Lock() defer collections.serviceLBMutex.Unlock() obj := collections.serviceLBs[key] if obj == nil { return nil } return obj }
go
func FindServiceLB(key string) *ServiceLB { collections.serviceLBMutex.Lock() defer collections.serviceLBMutex.Unlock() obj := collections.serviceLBs[key] if obj == nil { return nil } return obj }
[ "func", "FindServiceLB", "(", "key", "string", ")", "*", "ServiceLB", "{", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "serviceLBs", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to serviceLB from collection
[ "Return", "a", "pointer", "to", "serviceLB", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4759-L4769
7,911
contiv/netplugin
contivmodel/contivModel.go
DeleteServiceLB
func DeleteServiceLB(key string) error { collections.serviceLBMutex.Lock() obj := collections.serviceLBs[key] collections.serviceLBMutex.Unlock() if obj == nil { log.Errorf("serviceLB %s not found", key) return errors.New("serviceLB not found") } // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.ServiceLBCb.ServiceLBDelete(obj) if err != nil { log.Errorf("ServiceLBDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.serviceLBMutex.Lock() err = obj.Delete() collections.serviceLBMutex.Unlock() if err != nil { log.Errorf("Error deleting serviceLB %s. Err: %v", obj.Key, err) } // delete it from cache collections.serviceLBMutex.Lock() delete(collections.serviceLBs, key) collections.serviceLBMutex.Unlock() return nil }
go
func DeleteServiceLB(key string) error { collections.serviceLBMutex.Lock() obj := collections.serviceLBs[key] collections.serviceLBMutex.Unlock() if obj == nil { log.Errorf("serviceLB %s not found", key) return errors.New("serviceLB not found") } // Check if we handle this object if objCallbackHandler.ServiceLBCb == nil { log.Errorf("No callback registered for serviceLB object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.ServiceLBCb.ServiceLBDelete(obj) if err != nil { log.Errorf("ServiceLBDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.serviceLBMutex.Lock() err = obj.Delete() collections.serviceLBMutex.Unlock() if err != nil { log.Errorf("Error deleting serviceLB %s. Err: %v", obj.Key, err) } // delete it from cache collections.serviceLBMutex.Lock() delete(collections.serviceLBs, key) collections.serviceLBMutex.Unlock() return nil }
[ "func", "DeleteServiceLB", "(", "key", "string", ")", "error", "{", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "serviceLBs", "[", "key", "]", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "ServiceLBCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "ServiceLBCb", ".", "ServiceLBDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "serviceLBs", ",", "key", ")", "\n", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a serviceLB object
[ "Delete", "a", "serviceLB", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4772-L4808
7,912
contiv/netplugin
contivmodel/contivModel.go
ValidateServiceLB
func ValidateServiceLB(obj *ServiceLB) error { collections.serviceLBMutex.Lock() defer collections.serviceLBMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.ServiceName if obj.Key != keyStr { log.Errorf("Expecting ServiceLB Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.IpAddress) > 15 { return errors.New("ipAddress string too long") } ipAddressMatch := regexp.MustCompile("^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})?$") if ipAddressMatch.MatchString(obj.IpAddress) == false { return errors.New("ipAddress string invalid format") } if len(obj.NetworkName) > 64 { return errors.New("networkName string too long") } networkNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if networkNameMatch.MatchString(obj.NetworkName) == false { return errors.New("networkName string invalid format") } if len(obj.ServiceName) > 256 { return errors.New("serviceName string too long") } serviceNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if serviceNameMatch.MatchString(obj.ServiceName) == false { return errors.New("serviceName string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
go
func ValidateServiceLB(obj *ServiceLB) error { collections.serviceLBMutex.Lock() defer collections.serviceLBMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.ServiceName if obj.Key != keyStr { log.Errorf("Expecting ServiceLB Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.IpAddress) > 15 { return errors.New("ipAddress string too long") } ipAddressMatch := regexp.MustCompile("^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})?$") if ipAddressMatch.MatchString(obj.IpAddress) == false { return errors.New("ipAddress string invalid format") } if len(obj.NetworkName) > 64 { return errors.New("networkName string too long") } networkNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if networkNameMatch.MatchString(obj.NetworkName) == false { return errors.New("networkName string invalid format") } if len(obj.ServiceName) > 256 { return errors.New("serviceName string too long") } serviceNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if serviceNameMatch.MatchString(obj.ServiceName) == false { return errors.New("serviceName string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
[ "func", "ValidateServiceLB", "(", "obj", "*", "ServiceLB", ")", "error", "{", "collections", ".", "serviceLBMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "serviceLBMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "ServiceName", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "if", "len", "(", "obj", ".", "IpAddress", ")", ">", "15", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "ipAddressMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\"", ")", "\n", "if", "ipAddressMatch", ".", "MatchString", "(", "obj", ".", "IpAddress", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "NetworkName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "networkNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "networkNameMatch", ".", "MatchString", "(", "obj", ".", "NetworkName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "ServiceName", ")", ">", "256", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "serviceNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "serviceNameMatch", ".", "MatchString", "(", "obj", ".", "ServiceName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "TenantName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenantNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "tenantNameMatch", ".", "MatchString", "(", "obj", ".", "TenantName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate a serviceLB object
[ "Validate", "a", "serviceLB", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4871-L4921
7,913
contiv/netplugin
contivmodel/contivModel.go
GetOperTenant
func GetOperTenant(obj *TenantInspect) error { // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.TenantCb.TenantGetOper(obj) if err != nil { log.Errorf("TenantDelete retruned error for: %+v. Err: %v", obj, err) return err } return nil }
go
func GetOperTenant(obj *TenantInspect) error { // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.TenantCb.TenantGetOper(obj) if err != nil { log.Errorf("TenantDelete retruned error for: %+v. Err: %v", obj, err) return err } return nil }
[ "func", "GetOperTenant", "(", "obj", "*", "TenantInspect", ")", "error", "{", "// Check if we handle this object", "if", "objCallbackHandler", ".", "TenantCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "TenantCb", ".", "TenantGetOper", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Get a tenantOper object
[ "Get", "a", "tenantOper", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L4949-L4964
7,914
contiv/netplugin
contivmodel/contivModel.go
CreateTenant
func CreateTenant(obj *Tenant) error { // Validate parameters err := ValidateTenant(obj) if err != nil { log.Errorf("ValidateTenant retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } saveObj := obj collections.tenantMutex.Lock() key := collections.tenants[obj.Key] collections.tenantMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.TenantCb.TenantUpdate(collections.tenants[obj.Key], obj) if err != nil { log.Errorf("TenantUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.tenantMutex.Lock() saveObj = collections.tenants[obj.Key] collections.tenantMutex.Unlock() } else { // save it in cache collections.tenantMutex.Lock() collections.tenants[obj.Key] = obj collections.tenantMutex.Unlock() // Perform Create callback err = objCallbackHandler.TenantCb.TenantCreate(obj) if err != nil { log.Errorf("TenantCreate retruned error for: %+v. Err: %v", obj, err) collections.tenantMutex.Lock() delete(collections.tenants, obj.Key) collections.tenantMutex.Unlock() return err } } // Write it to modeldb collections.tenantMutex.Lock() err = saveObj.Write() collections.tenantMutex.Unlock() if err != nil { log.Errorf("Error saving tenant %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreateTenant(obj *Tenant) error { // Validate parameters err := ValidateTenant(obj) if err != nil { log.Errorf("ValidateTenant retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } saveObj := obj collections.tenantMutex.Lock() key := collections.tenants[obj.Key] collections.tenantMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.TenantCb.TenantUpdate(collections.tenants[obj.Key], obj) if err != nil { log.Errorf("TenantUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.tenantMutex.Lock() saveObj = collections.tenants[obj.Key] collections.tenantMutex.Unlock() } else { // save it in cache collections.tenantMutex.Lock() collections.tenants[obj.Key] = obj collections.tenantMutex.Unlock() // Perform Create callback err = objCallbackHandler.TenantCb.TenantCreate(obj) if err != nil { log.Errorf("TenantCreate retruned error for: %+v. Err: %v", obj, err) collections.tenantMutex.Lock() delete(collections.tenants, obj.Key) collections.tenantMutex.Unlock() return err } } // Write it to modeldb collections.tenantMutex.Lock() err = saveObj.Write() collections.tenantMutex.Unlock() if err != nil { log.Errorf("Error saving tenant %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreateTenant", "(", "obj", "*", "Tenant", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidateTenant", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "TenantCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "tenants", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "TenantCb", ".", "TenantUpdate", "(", "collections", ".", "tenants", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "tenants", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "tenants", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "TenantCb", ".", "TenantCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "tenants", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a tenant object
[ "Create", "a", "tenant", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5045-L5105
7,915
contiv/netplugin
contivmodel/contivModel.go
FindTenant
func FindTenant(key string) *Tenant { collections.tenantMutex.Lock() defer collections.tenantMutex.Unlock() obj := collections.tenants[key] if obj == nil { return nil } return obj }
go
func FindTenant(key string) *Tenant { collections.tenantMutex.Lock() defer collections.tenantMutex.Unlock() obj := collections.tenants[key] if obj == nil { return nil } return obj }
[ "func", "FindTenant", "(", "key", "string", ")", "*", "Tenant", "{", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "tenants", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to tenant from collection
[ "Return", "a", "pointer", "to", "tenant", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5108-L5118
7,916
contiv/netplugin
contivmodel/contivModel.go
DeleteTenant
func DeleteTenant(key string) error { collections.tenantMutex.Lock() obj := collections.tenants[key] collections.tenantMutex.Unlock() if obj == nil { log.Errorf("tenant %s not found", key) return errors.New("tenant not found") } // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.TenantCb.TenantDelete(obj) if err != nil { log.Errorf("TenantDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.tenantMutex.Lock() err = obj.Delete() collections.tenantMutex.Unlock() if err != nil { log.Errorf("Error deleting tenant %s. Err: %v", obj.Key, err) } // delete it from cache collections.tenantMutex.Lock() delete(collections.tenants, key) collections.tenantMutex.Unlock() return nil }
go
func DeleteTenant(key string) error { collections.tenantMutex.Lock() obj := collections.tenants[key] collections.tenantMutex.Unlock() if obj == nil { log.Errorf("tenant %s not found", key) return errors.New("tenant not found") } // Check if we handle this object if objCallbackHandler.TenantCb == nil { log.Errorf("No callback registered for tenant object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.TenantCb.TenantDelete(obj) if err != nil { log.Errorf("TenantDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.tenantMutex.Lock() err = obj.Delete() collections.tenantMutex.Unlock() if err != nil { log.Errorf("Error deleting tenant %s. Err: %v", obj.Key, err) } // delete it from cache collections.tenantMutex.Lock() delete(collections.tenants, key) collections.tenantMutex.Unlock() return nil }
[ "func", "DeleteTenant", "(", "key", "string", ")", "error", "{", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "tenants", "[", "key", "]", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "TenantCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "TenantCb", ".", "TenantDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "tenants", ",", "key", ")", "\n", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a tenant object
[ "Delete", "a", "tenant", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5121-L5157
7,917
contiv/netplugin
contivmodel/contivModel.go
ValidateTenant
func ValidateTenant(obj *Tenant) error { collections.tenantMutex.Lock() defer collections.tenantMutex.Unlock() // Validate key is correct keyStr := obj.TenantName if obj.Key != keyStr { log.Errorf("Expecting Tenant Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.DefaultNetwork) > 64 { return errors.New("defaultNetwork string too long") } defaultNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if defaultNetworkMatch.MatchString(obj.DefaultNetwork) == false { return errors.New("defaultNetwork string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
go
func ValidateTenant(obj *Tenant) error { collections.tenantMutex.Lock() defer collections.tenantMutex.Unlock() // Validate key is correct keyStr := obj.TenantName if obj.Key != keyStr { log.Errorf("Expecting Tenant Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field if len(obj.DefaultNetwork) > 64 { return errors.New("defaultNetwork string too long") } defaultNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$") if defaultNetworkMatch.MatchString(obj.DefaultNetwork) == false { return errors.New("defaultNetwork string invalid format") } if len(obj.TenantName) > 64 { return errors.New("tenantName string too long") } tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") if tenantNameMatch.MatchString(obj.TenantName) == false { return errors.New("tenantName string invalid format") } return nil }
[ "func", "ValidateTenant", "(", "obj", "*", "Tenant", ")", "error", "{", "collections", ".", "tenantMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "tenantMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "if", "len", "(", "obj", ".", "DefaultNetwork", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "defaultNetworkMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "defaultNetworkMatch", ".", "MatchString", "(", "obj", ".", "DefaultNetwork", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "obj", ".", "TenantName", ")", ">", "64", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenantNameMatch", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\\\\", "\"", ")", "\n", "if", "tenantNameMatch", ".", "MatchString", "(", "obj", ".", "TenantName", ")", "==", "false", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate a tenant object
[ "Validate", "a", "tenant", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5220-L5252
7,918
contiv/netplugin
contivmodel/contivModel.go
CreateVolume
func CreateVolume(obj *Volume) error { // Validate parameters err := ValidateVolume(obj) if err != nil { log.Errorf("ValidateVolume retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.VolumeCb == nil { log.Errorf("No callback registered for volume object") return errors.New("Invalid object type") } saveObj := obj collections.volumeMutex.Lock() key := collections.volumes[obj.Key] collections.volumeMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.VolumeCb.VolumeUpdate(collections.volumes[obj.Key], obj) if err != nil { log.Errorf("VolumeUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.volumeMutex.Lock() saveObj = collections.volumes[obj.Key] collections.volumeMutex.Unlock() } else { // save it in cache collections.volumeMutex.Lock() collections.volumes[obj.Key] = obj collections.volumeMutex.Unlock() // Perform Create callback err = objCallbackHandler.VolumeCb.VolumeCreate(obj) if err != nil { log.Errorf("VolumeCreate retruned error for: %+v. Err: %v", obj, err) collections.volumeMutex.Lock() delete(collections.volumes, obj.Key) collections.volumeMutex.Unlock() return err } } // Write it to modeldb collections.volumeMutex.Lock() err = saveObj.Write() collections.volumeMutex.Unlock() if err != nil { log.Errorf("Error saving volume %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreateVolume(obj *Volume) error { // Validate parameters err := ValidateVolume(obj) if err != nil { log.Errorf("ValidateVolume retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.VolumeCb == nil { log.Errorf("No callback registered for volume object") return errors.New("Invalid object type") } saveObj := obj collections.volumeMutex.Lock() key := collections.volumes[obj.Key] collections.volumeMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.VolumeCb.VolumeUpdate(collections.volumes[obj.Key], obj) if err != nil { log.Errorf("VolumeUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.volumeMutex.Lock() saveObj = collections.volumes[obj.Key] collections.volumeMutex.Unlock() } else { // save it in cache collections.volumeMutex.Lock() collections.volumes[obj.Key] = obj collections.volumeMutex.Unlock() // Perform Create callback err = objCallbackHandler.VolumeCb.VolumeCreate(obj) if err != nil { log.Errorf("VolumeCreate retruned error for: %+v. Err: %v", obj, err) collections.volumeMutex.Lock() delete(collections.volumes, obj.Key) collections.volumeMutex.Unlock() return err } } // Write it to modeldb collections.volumeMutex.Lock() err = saveObj.Write() collections.volumeMutex.Unlock() if err != nil { log.Errorf("Error saving volume %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreateVolume", "(", "obj", "*", "Volume", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidateVolume", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "VolumeCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "volumes", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "VolumeCb", ".", "VolumeUpdate", "(", "collections", ".", "volumes", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "volumes", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "volumes", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "VolumeCb", ".", "VolumeCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "volumes", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a volume object
[ "Create", "a", "volume", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5353-L5413
7,919
contiv/netplugin
contivmodel/contivModel.go
FindVolume
func FindVolume(key string) *Volume { collections.volumeMutex.Lock() defer collections.volumeMutex.Unlock() obj := collections.volumes[key] if obj == nil { return nil } return obj }
go
func FindVolume(key string) *Volume { collections.volumeMutex.Lock() defer collections.volumeMutex.Unlock() obj := collections.volumes[key] if obj == nil { return nil } return obj }
[ "func", "FindVolume", "(", "key", "string", ")", "*", "Volume", "{", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "volumes", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to volume from collection
[ "Return", "a", "pointer", "to", "volume", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5416-L5426
7,920
contiv/netplugin
contivmodel/contivModel.go
DeleteVolume
func DeleteVolume(key string) error { collections.volumeMutex.Lock() obj := collections.volumes[key] collections.volumeMutex.Unlock() if obj == nil { log.Errorf("volume %s not found", key) return errors.New("volume not found") } // Check if we handle this object if objCallbackHandler.VolumeCb == nil { log.Errorf("No callback registered for volume object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.VolumeCb.VolumeDelete(obj) if err != nil { log.Errorf("VolumeDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.volumeMutex.Lock() err = obj.Delete() collections.volumeMutex.Unlock() if err != nil { log.Errorf("Error deleting volume %s. Err: %v", obj.Key, err) } // delete it from cache collections.volumeMutex.Lock() delete(collections.volumes, key) collections.volumeMutex.Unlock() return nil }
go
func DeleteVolume(key string) error { collections.volumeMutex.Lock() obj := collections.volumes[key] collections.volumeMutex.Unlock() if obj == nil { log.Errorf("volume %s not found", key) return errors.New("volume not found") } // Check if we handle this object if objCallbackHandler.VolumeCb == nil { log.Errorf("No callback registered for volume object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.VolumeCb.VolumeDelete(obj) if err != nil { log.Errorf("VolumeDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.volumeMutex.Lock() err = obj.Delete() collections.volumeMutex.Unlock() if err != nil { log.Errorf("Error deleting volume %s. Err: %v", obj.Key, err) } // delete it from cache collections.volumeMutex.Lock() delete(collections.volumes, key) collections.volumeMutex.Unlock() return nil }
[ "func", "DeleteVolume", "(", "key", "string", ")", "error", "{", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "volumes", "[", "key", "]", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "VolumeCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "VolumeCb", ".", "VolumeDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "volumes", ",", "key", ")", "\n", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a volume object
[ "Delete", "a", "volume", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5429-L5465
7,921
contiv/netplugin
contivmodel/contivModel.go
ValidateVolume
func ValidateVolume(obj *Volume) error { collections.volumeMutex.Lock() defer collections.volumeMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.VolumeName if obj.Key != keyStr { log.Errorf("Expecting Volume Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field return nil }
go
func ValidateVolume(obj *Volume) error { collections.volumeMutex.Lock() defer collections.volumeMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.VolumeName if obj.Key != keyStr { log.Errorf("Expecting Volume Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field return nil }
[ "func", "ValidateVolume", "(", "obj", "*", "Volume", ")", "error", "{", "collections", ".", "volumeMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "volumeMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "VolumeName", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "return", "nil", "\n", "}" ]
// Validate a volume object
[ "Validate", "a", "volume", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5528-L5542
7,922
contiv/netplugin
contivmodel/contivModel.go
CreateVolumeProfile
func CreateVolumeProfile(obj *VolumeProfile) error { // Validate parameters err := ValidateVolumeProfile(obj) if err != nil { log.Errorf("ValidateVolumeProfile retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.VolumeProfileCb == nil { log.Errorf("No callback registered for volumeProfile object") return errors.New("Invalid object type") } saveObj := obj collections.volumeProfileMutex.Lock() key := collections.volumeProfiles[obj.Key] collections.volumeProfileMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.VolumeProfileCb.VolumeProfileUpdate(collections.volumeProfiles[obj.Key], obj) if err != nil { log.Errorf("VolumeProfileUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.volumeProfileMutex.Lock() saveObj = collections.volumeProfiles[obj.Key] collections.volumeProfileMutex.Unlock() } else { // save it in cache collections.volumeProfileMutex.Lock() collections.volumeProfiles[obj.Key] = obj collections.volumeProfileMutex.Unlock() // Perform Create callback err = objCallbackHandler.VolumeProfileCb.VolumeProfileCreate(obj) if err != nil { log.Errorf("VolumeProfileCreate retruned error for: %+v. Err: %v", obj, err) collections.volumeProfileMutex.Lock() delete(collections.volumeProfiles, obj.Key) collections.volumeProfileMutex.Unlock() return err } } // Write it to modeldb collections.volumeProfileMutex.Lock() err = saveObj.Write() collections.volumeProfileMutex.Unlock() if err != nil { log.Errorf("Error saving volumeProfile %s to db. Err: %v", saveObj.Key, err) return err } return nil }
go
func CreateVolumeProfile(obj *VolumeProfile) error { // Validate parameters err := ValidateVolumeProfile(obj) if err != nil { log.Errorf("ValidateVolumeProfile retruned error for: %+v. Err: %v", obj, err) return err } // Check if we handle this object if objCallbackHandler.VolumeProfileCb == nil { log.Errorf("No callback registered for volumeProfile object") return errors.New("Invalid object type") } saveObj := obj collections.volumeProfileMutex.Lock() key := collections.volumeProfiles[obj.Key] collections.volumeProfileMutex.Unlock() // Check if object already exists if key != nil { // Perform Update callback err = objCallbackHandler.VolumeProfileCb.VolumeProfileUpdate(collections.volumeProfiles[obj.Key], obj) if err != nil { log.Errorf("VolumeProfileUpdate retruned error for: %+v. Err: %v", obj, err) return err } // save the original object after update collections.volumeProfileMutex.Lock() saveObj = collections.volumeProfiles[obj.Key] collections.volumeProfileMutex.Unlock() } else { // save it in cache collections.volumeProfileMutex.Lock() collections.volumeProfiles[obj.Key] = obj collections.volumeProfileMutex.Unlock() // Perform Create callback err = objCallbackHandler.VolumeProfileCb.VolumeProfileCreate(obj) if err != nil { log.Errorf("VolumeProfileCreate retruned error for: %+v. Err: %v", obj, err) collections.volumeProfileMutex.Lock() delete(collections.volumeProfiles, obj.Key) collections.volumeProfileMutex.Unlock() return err } } // Write it to modeldb collections.volumeProfileMutex.Lock() err = saveObj.Write() collections.volumeProfileMutex.Unlock() if err != nil { log.Errorf("Error saving volumeProfile %s to db. Err: %v", saveObj.Key, err) return err } return nil }
[ "func", "CreateVolumeProfile", "(", "obj", "*", "VolumeProfile", ")", "error", "{", "// Validate parameters", "err", ":=", "ValidateVolumeProfile", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "VolumeProfileCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "saveObj", ":=", "obj", "\n\n", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "key", ":=", "collections", ".", "volumeProfiles", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n\n", "// Check if object already exists", "if", "key", "!=", "nil", "{", "// Perform Update callback", "err", "=", "objCallbackHandler", ".", "VolumeProfileCb", ".", "VolumeProfileUpdate", "(", "collections", ".", "volumeProfiles", "[", "obj", ".", "Key", "]", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// save the original object after update", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "saveObj", "=", "collections", ".", "volumeProfiles", "[", "obj", ".", "Key", "]", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n", "}", "else", "{", "// save it in cache", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "collections", ".", "volumeProfiles", "[", "obj", ".", "Key", "]", "=", "obj", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n\n", "// Perform Create callback", "err", "=", "objCallbackHandler", ".", "VolumeProfileCb", ".", "VolumeProfileCreate", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "volumeProfiles", ",", "obj", ".", "Key", ")", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Write it to modeldb", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "err", "=", "saveObj", ".", "Write", "(", ")", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "saveObj", ".", "Key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Create a volumeProfile object
[ "Create", "a", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5643-L5703
7,923
contiv/netplugin
contivmodel/contivModel.go
FindVolumeProfile
func FindVolumeProfile(key string) *VolumeProfile { collections.volumeProfileMutex.Lock() defer collections.volumeProfileMutex.Unlock() obj := collections.volumeProfiles[key] if obj == nil { return nil } return obj }
go
func FindVolumeProfile(key string) *VolumeProfile { collections.volumeProfileMutex.Lock() defer collections.volumeProfileMutex.Unlock() obj := collections.volumeProfiles[key] if obj == nil { return nil } return obj }
[ "func", "FindVolumeProfile", "(", "key", "string", ")", "*", "VolumeProfile", "{", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n\n", "obj", ":=", "collections", ".", "volumeProfiles", "[", "key", "]", "\n", "if", "obj", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "obj", "\n", "}" ]
// Return a pointer to volumeProfile from collection
[ "Return", "a", "pointer", "to", "volumeProfile", "from", "collection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5706-L5716
7,924
contiv/netplugin
contivmodel/contivModel.go
DeleteVolumeProfile
func DeleteVolumeProfile(key string) error { collections.volumeProfileMutex.Lock() obj := collections.volumeProfiles[key] collections.volumeProfileMutex.Unlock() if obj == nil { log.Errorf("volumeProfile %s not found", key) return errors.New("volumeProfile not found") } // Check if we handle this object if objCallbackHandler.VolumeProfileCb == nil { log.Errorf("No callback registered for volumeProfile object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.VolumeProfileCb.VolumeProfileDelete(obj) if err != nil { log.Errorf("VolumeProfileDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.volumeProfileMutex.Lock() err = obj.Delete() collections.volumeProfileMutex.Unlock() if err != nil { log.Errorf("Error deleting volumeProfile %s. Err: %v", obj.Key, err) } // delete it from cache collections.volumeProfileMutex.Lock() delete(collections.volumeProfiles, key) collections.volumeProfileMutex.Unlock() return nil }
go
func DeleteVolumeProfile(key string) error { collections.volumeProfileMutex.Lock() obj := collections.volumeProfiles[key] collections.volumeProfileMutex.Unlock() if obj == nil { log.Errorf("volumeProfile %s not found", key) return errors.New("volumeProfile not found") } // Check if we handle this object if objCallbackHandler.VolumeProfileCb == nil { log.Errorf("No callback registered for volumeProfile object") return errors.New("Invalid object type") } // Perform callback err := objCallbackHandler.VolumeProfileCb.VolumeProfileDelete(obj) if err != nil { log.Errorf("VolumeProfileDelete retruned error for: %+v. Err: %v", obj, err) return err } // delete it from modeldb collections.volumeProfileMutex.Lock() err = obj.Delete() collections.volumeProfileMutex.Unlock() if err != nil { log.Errorf("Error deleting volumeProfile %s. Err: %v", obj.Key, err) } // delete it from cache collections.volumeProfileMutex.Lock() delete(collections.volumeProfiles, key) collections.volumeProfileMutex.Unlock() return nil }
[ "func", "DeleteVolumeProfile", "(", "key", "string", ")", "error", "{", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "obj", ":=", "collections", ".", "volumeProfiles", "[", "key", "]", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if we handle this object", "if", "objCallbackHandler", ".", "VolumeProfileCb", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Perform callback", "err", ":=", "objCallbackHandler", ".", "VolumeProfileCb", ".", "VolumeProfileDelete", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// delete it from modeldb", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "err", "=", "obj", ".", "Delete", "(", ")", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "obj", ".", "Key", ",", "err", ")", "\n", "}", "\n\n", "// delete it from cache", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "collections", ".", "volumeProfiles", ",", "key", ")", "\n", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete a volumeProfile object
[ "Delete", "a", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5719-L5755
7,925
contiv/netplugin
contivmodel/contivModel.go
ValidateVolumeProfile
func ValidateVolumeProfile(obj *VolumeProfile) error { collections.volumeProfileMutex.Lock() defer collections.volumeProfileMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.VolumeProfileName if obj.Key != keyStr { log.Errorf("Expecting VolumeProfile Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field return nil }
go
func ValidateVolumeProfile(obj *VolumeProfile) error { collections.volumeProfileMutex.Lock() defer collections.volumeProfileMutex.Unlock() // Validate key is correct keyStr := obj.TenantName + ":" + obj.VolumeProfileName if obj.Key != keyStr { log.Errorf("Expecting VolumeProfile Key: %s. Got: %s", keyStr, obj.Key) return errors.New("Invalid Key") } // Validate each field return nil }
[ "func", "ValidateVolumeProfile", "(", "obj", "*", "VolumeProfile", ")", "error", "{", "collections", ".", "volumeProfileMutex", ".", "Lock", "(", ")", "\n", "defer", "collections", ".", "volumeProfileMutex", ".", "Unlock", "(", ")", "\n\n", "// Validate key is correct", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "VolumeProfileName", "\n", "if", "obj", ".", "Key", "!=", "keyStr", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyStr", ",", "obj", ".", "Key", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Validate each field", "return", "nil", "\n", "}" ]
// Validate a volumeProfile object
[ "Validate", "a", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L5818-L5832
7,926
contiv/netplugin
netplugin/agent/agent.go
NewAgent
func NewAgent(pluginConfig *plugin.Config) *Agent { opts := pluginConfig.Instance netPlugin := &plugin.NetPlugin{} // init cluster state err := cluster.Init(pluginConfig.Drivers.State, []string{opts.DbURL}) if err != nil { log.Fatalf("Error initializing cluster. Err: %v", err) } // Init the driver plugins.. err = netPlugin.Init(*pluginConfig) if err != nil { log.Fatalf("Failed to initialize the plugin. Error: %s", err) } // Initialize appropriate plugin switch opts.PluginMode { case core.SwarmMode: fallthrough case core.Docker: dockplugin.InitDockPlugin(netPlugin, opts.PluginMode) case core.Kubernetes: k8splugin.InitCNIServer(netPlugin) case core.Test: // nothing to do. internal mode for testing default: log.Fatalf("Unknown plugin mode -- should be %s | %s | %s", core.Docker, core.SwarmMode, core.Kubernetes) } // init mesos plugin mesosplugin.InitPlugin(netPlugin) // create a new agent agent := &Agent{ netPlugin: netPlugin, pluginConfig: pluginConfig, } return agent }
go
func NewAgent(pluginConfig *plugin.Config) *Agent { opts := pluginConfig.Instance netPlugin := &plugin.NetPlugin{} // init cluster state err := cluster.Init(pluginConfig.Drivers.State, []string{opts.DbURL}) if err != nil { log.Fatalf("Error initializing cluster. Err: %v", err) } // Init the driver plugins.. err = netPlugin.Init(*pluginConfig) if err != nil { log.Fatalf("Failed to initialize the plugin. Error: %s", err) } // Initialize appropriate plugin switch opts.PluginMode { case core.SwarmMode: fallthrough case core.Docker: dockplugin.InitDockPlugin(netPlugin, opts.PluginMode) case core.Kubernetes: k8splugin.InitCNIServer(netPlugin) case core.Test: // nothing to do. internal mode for testing default: log.Fatalf("Unknown plugin mode -- should be %s | %s | %s", core.Docker, core.SwarmMode, core.Kubernetes) } // init mesos plugin mesosplugin.InitPlugin(netPlugin) // create a new agent agent := &Agent{ netPlugin: netPlugin, pluginConfig: pluginConfig, } return agent }
[ "func", "NewAgent", "(", "pluginConfig", "*", "plugin", ".", "Config", ")", "*", "Agent", "{", "opts", ":=", "pluginConfig", ".", "Instance", "\n", "netPlugin", ":=", "&", "plugin", ".", "NetPlugin", "{", "}", "\n\n", "// init cluster state", "err", ":=", "cluster", ".", "Init", "(", "pluginConfig", ".", "Drivers", ".", "State", ",", "[", "]", "string", "{", "opts", ".", "DbURL", "}", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Init the driver plugins..", "err", "=", "netPlugin", ".", "Init", "(", "*", "pluginConfig", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Initialize appropriate plugin", "switch", "opts", ".", "PluginMode", "{", "case", "core", ".", "SwarmMode", ":", "fallthrough", "\n", "case", "core", ".", "Docker", ":", "dockplugin", ".", "InitDockPlugin", "(", "netPlugin", ",", "opts", ".", "PluginMode", ")", "\n\n", "case", "core", ".", "Kubernetes", ":", "k8splugin", ".", "InitCNIServer", "(", "netPlugin", ")", "\n\n", "case", "core", ".", "Test", ":", "// nothing to do. internal mode for testing", "default", ":", "log", ".", "Fatalf", "(", "\"", "\"", ",", "core", ".", "Docker", ",", "core", ".", "SwarmMode", ",", "core", ".", "Kubernetes", ")", "\n", "}", "\n", "// init mesos plugin", "mesosplugin", ".", "InitPlugin", "(", "netPlugin", ")", "\n\n", "// create a new agent", "agent", ":=", "&", "Agent", "{", "netPlugin", ":", "netPlugin", ",", "pluginConfig", ":", "pluginConfig", ",", "}", "\n\n", "return", "agent", "\n", "}" ]
// NewAgent creates a new netplugin agent
[ "NewAgent", "creates", "a", "new", "netplugin", "agent" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L48-L90
7,927
contiv/netplugin
netplugin/agent/agent.go
ProcessCurrentState
func (ag *Agent) ProcessCurrentState() error { opts := ag.pluginConfig.Instance readNet := &mastercfg.CfgNetworkState{} readNet.StateDriver = ag.netPlugin.StateDriver netCfgs, err := readNet.ReadAll() if err == nil { for idx, netCfg := range netCfgs { net := netCfg.(*mastercfg.CfgNetworkState) log.Debugf("read net key[%d] %s, populating state \n", idx, net.ID) processNetEvent(ag.netPlugin, net, false, opts) if net.NwType == "infra" { processInfraNwCreate(ag.netPlugin, net, opts) } } } readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = ag.netPlugin.StateDriver epCfgs, err := readEp.ReadAll() if err == nil { for idx, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) log.Debugf("read ep key[%d] %s, populating state \n", idx, ep.ID) processEpState(ag.netPlugin, opts, ep.ID) } } readBgp := &mastercfg.CfgBgpState{} readBgp.StateDriver = ag.netPlugin.StateDriver bgpCfgs, err := readBgp.ReadAll() if err == nil { for idx, bgpCfg := range bgpCfgs { bgp := bgpCfg.(*mastercfg.CfgBgpState) log.Debugf("read bgp key[%d] %s, populating state \n", idx, bgp.Hostname) processBgpEvent(ag.netPlugin, opts, bgp.Hostname, false) } } readEpg := mastercfg.EndpointGroupState{} readEpg.StateDriver = ag.netPlugin.StateDriver epgCfgs, err := readEpg.ReadAll() if err == nil { for idx, epgCfg := range epgCfgs { epg := epgCfg.(*mastercfg.EndpointGroupState) log.Infof("Read epg key[%d] %s, populating state \n", idx, epg.GroupName) processEpgEvent(ag.netPlugin, opts, epg.ID, false) } } readServiceLb := &mastercfg.CfgServiceLBState{} readServiceLb.StateDriver = ag.netPlugin.StateDriver serviceLbCfgs, err := readServiceLb.ReadAll() if err == nil { for idx, serviceLbCfg := range serviceLbCfgs { serviceLb := serviceLbCfg.(*mastercfg.CfgServiceLBState) log.Debugf("read svc key[%d] %s for tenant %s, populating state \n", idx, serviceLb.ServiceName, serviceLb.Tenant) processServiceLBEvent(ag.netPlugin, serviceLb, false) } } readSvcProviders := &mastercfg.SvcProvider{} readSvcProviders.StateDriver = ag.netPlugin.StateDriver svcProviders, err := readSvcProviders.ReadAll() if err == nil { for idx, providers := range svcProviders { svcProvider := providers.(*mastercfg.SvcProvider) log.Infof("read svc provider[%d] %s , populating state \n", idx, svcProvider.ServiceName) processSvcProviderUpdEvent(ag.netPlugin, svcProvider, false) } } return nil }
go
func (ag *Agent) ProcessCurrentState() error { opts := ag.pluginConfig.Instance readNet := &mastercfg.CfgNetworkState{} readNet.StateDriver = ag.netPlugin.StateDriver netCfgs, err := readNet.ReadAll() if err == nil { for idx, netCfg := range netCfgs { net := netCfg.(*mastercfg.CfgNetworkState) log.Debugf("read net key[%d] %s, populating state \n", idx, net.ID) processNetEvent(ag.netPlugin, net, false, opts) if net.NwType == "infra" { processInfraNwCreate(ag.netPlugin, net, opts) } } } readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = ag.netPlugin.StateDriver epCfgs, err := readEp.ReadAll() if err == nil { for idx, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) log.Debugf("read ep key[%d] %s, populating state \n", idx, ep.ID) processEpState(ag.netPlugin, opts, ep.ID) } } readBgp := &mastercfg.CfgBgpState{} readBgp.StateDriver = ag.netPlugin.StateDriver bgpCfgs, err := readBgp.ReadAll() if err == nil { for idx, bgpCfg := range bgpCfgs { bgp := bgpCfg.(*mastercfg.CfgBgpState) log.Debugf("read bgp key[%d] %s, populating state \n", idx, bgp.Hostname) processBgpEvent(ag.netPlugin, opts, bgp.Hostname, false) } } readEpg := mastercfg.EndpointGroupState{} readEpg.StateDriver = ag.netPlugin.StateDriver epgCfgs, err := readEpg.ReadAll() if err == nil { for idx, epgCfg := range epgCfgs { epg := epgCfg.(*mastercfg.EndpointGroupState) log.Infof("Read epg key[%d] %s, populating state \n", idx, epg.GroupName) processEpgEvent(ag.netPlugin, opts, epg.ID, false) } } readServiceLb := &mastercfg.CfgServiceLBState{} readServiceLb.StateDriver = ag.netPlugin.StateDriver serviceLbCfgs, err := readServiceLb.ReadAll() if err == nil { for idx, serviceLbCfg := range serviceLbCfgs { serviceLb := serviceLbCfg.(*mastercfg.CfgServiceLBState) log.Debugf("read svc key[%d] %s for tenant %s, populating state \n", idx, serviceLb.ServiceName, serviceLb.Tenant) processServiceLBEvent(ag.netPlugin, serviceLb, false) } } readSvcProviders := &mastercfg.SvcProvider{} readSvcProviders.StateDriver = ag.netPlugin.StateDriver svcProviders, err := readSvcProviders.ReadAll() if err == nil { for idx, providers := range svcProviders { svcProvider := providers.(*mastercfg.SvcProvider) log.Infof("read svc provider[%d] %s , populating state \n", idx, svcProvider.ServiceName) processSvcProviderUpdEvent(ag.netPlugin, svcProvider, false) } } return nil }
[ "func", "(", "ag", "*", "Agent", ")", "ProcessCurrentState", "(", ")", "error", "{", "opts", ":=", "ag", ".", "pluginConfig", ".", "Instance", "\n", "readNet", ":=", "&", "mastercfg", ".", "CfgNetworkState", "{", "}", "\n", "readNet", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "netCfgs", ",", "err", ":=", "readNet", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "netCfg", ":=", "range", "netCfgs", "{", "net", ":=", "netCfg", ".", "(", "*", "mastercfg", ".", "CfgNetworkState", ")", "\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "idx", ",", "net", ".", "ID", ")", "\n", "processNetEvent", "(", "ag", ".", "netPlugin", ",", "net", ",", "false", ",", "opts", ")", "\n", "if", "net", ".", "NwType", "==", "\"", "\"", "{", "processInfraNwCreate", "(", "ag", ".", "netPlugin", ",", "net", ",", "opts", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "readEp", ":=", "&", "mastercfg", ".", "CfgEndpointState", "{", "}", "\n", "readEp", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "epCfgs", ",", "err", ":=", "readEp", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "epCfg", ":=", "range", "epCfgs", "{", "ep", ":=", "epCfg", ".", "(", "*", "mastercfg", ".", "CfgEndpointState", ")", "\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "idx", ",", "ep", ".", "ID", ")", "\n", "processEpState", "(", "ag", ".", "netPlugin", ",", "opts", ",", "ep", ".", "ID", ")", "\n", "}", "\n", "}", "\n\n", "readBgp", ":=", "&", "mastercfg", ".", "CfgBgpState", "{", "}", "\n", "readBgp", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "bgpCfgs", ",", "err", ":=", "readBgp", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "bgpCfg", ":=", "range", "bgpCfgs", "{", "bgp", ":=", "bgpCfg", ".", "(", "*", "mastercfg", ".", "CfgBgpState", ")", "\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "idx", ",", "bgp", ".", "Hostname", ")", "\n", "processBgpEvent", "(", "ag", ".", "netPlugin", ",", "opts", ",", "bgp", ".", "Hostname", ",", "false", ")", "\n", "}", "\n", "}", "\n\n", "readEpg", ":=", "mastercfg", ".", "EndpointGroupState", "{", "}", "\n", "readEpg", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "epgCfgs", ",", "err", ":=", "readEpg", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "epgCfg", ":=", "range", "epgCfgs", "{", "epg", ":=", "epgCfg", ".", "(", "*", "mastercfg", ".", "EndpointGroupState", ")", "\n", "log", ".", "Infof", "(", "\"", "\\n", "\"", ",", "idx", ",", "epg", ".", "GroupName", ")", "\n", "processEpgEvent", "(", "ag", ".", "netPlugin", ",", "opts", ",", "epg", ".", "ID", ",", "false", ")", "\n", "}", "\n", "}", "\n\n", "readServiceLb", ":=", "&", "mastercfg", ".", "CfgServiceLBState", "{", "}", "\n", "readServiceLb", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "serviceLbCfgs", ",", "err", ":=", "readServiceLb", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "serviceLbCfg", ":=", "range", "serviceLbCfgs", "{", "serviceLb", ":=", "serviceLbCfg", ".", "(", "*", "mastercfg", ".", "CfgServiceLBState", ")", "\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "idx", ",", "serviceLb", ".", "ServiceName", ",", "serviceLb", ".", "Tenant", ")", "\n", "processServiceLBEvent", "(", "ag", ".", "netPlugin", ",", "serviceLb", ",", "false", ")", "\n", "}", "\n", "}", "\n\n", "readSvcProviders", ":=", "&", "mastercfg", ".", "SvcProvider", "{", "}", "\n", "readSvcProviders", ".", "StateDriver", "=", "ag", ".", "netPlugin", ".", "StateDriver", "\n", "svcProviders", ",", "err", ":=", "readSvcProviders", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "idx", ",", "providers", ":=", "range", "svcProviders", "{", "svcProvider", ":=", "providers", ".", "(", "*", "mastercfg", ".", "SvcProvider", ")", "\n", "log", ".", "Infof", "(", "\"", "\\n", "\"", ",", "idx", ",", "svcProvider", ".", "ServiceName", ")", "\n", "processSvcProviderUpdEvent", "(", "ag", ".", "netPlugin", ",", "svcProvider", ",", "false", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ProcessCurrentState processes current state as read from stateStore
[ "ProcessCurrentState", "processes", "current", "state", "as", "read", "from", "stateStore" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L98-L172
7,928
contiv/netplugin
netplugin/agent/agent.go
PostInit
func (ag *Agent) PostInit() error { opts := ag.pluginConfig.Instance // Initialize clustering err := cluster.RunLoop(ag.netPlugin, opts.CtrlIP, opts.VtepIP, opts.HostLabel) if err != nil { log.Errorf("Error starting cluster run loop") } // start service REST requests ag.serveRequests() return nil }
go
func (ag *Agent) PostInit() error { opts := ag.pluginConfig.Instance // Initialize clustering err := cluster.RunLoop(ag.netPlugin, opts.CtrlIP, opts.VtepIP, opts.HostLabel) if err != nil { log.Errorf("Error starting cluster run loop") } // start service REST requests ag.serveRequests() return nil }
[ "func", "(", "ag", "*", "Agent", ")", "PostInit", "(", ")", "error", "{", "opts", ":=", "ag", ".", "pluginConfig", ".", "Instance", "\n\n", "// Initialize clustering", "err", ":=", "cluster", ".", "RunLoop", "(", "ag", ".", "netPlugin", ",", "opts", ".", "CtrlIP", ",", "opts", ".", "VtepIP", ",", "opts", ".", "HostLabel", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// start service REST requests", "ag", ".", "serveRequests", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// PostInit post initialization
[ "PostInit", "post", "initialization" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L175-L188
7,929
contiv/netplugin
netplugin/agent/agent.go
HandleEvents
func (ag *Agent) HandleEvents() error { opts := ag.pluginConfig.Instance recvErr := make(chan error, 1) go handleNetworkEvents(ag.netPlugin, opts, recvErr) go handleBgpEvents(ag.netPlugin, opts, recvErr) go handleEndpointEvents(ag.netPlugin, opts, recvErr) go handleEpgEvents(ag.netPlugin, opts, recvErr) go handleServiceLBEvents(ag.netPlugin, opts, recvErr) go handleSvcProviderUpdEvents(ag.netPlugin, opts, recvErr) go handleGlobalCfgEvents(ag.netPlugin, opts, recvErr) go handlePolicyRuleEvents(ag.netPlugin, opts, recvErr) if ag.pluginConfig.Instance.PluginMode == core.Docker || ag.pluginConfig.Instance.PluginMode == core.SwarmMode { go ag.monitorDockerEvents(recvErr) } else if ag.pluginConfig.Instance.PluginMode == core.Kubernetes { // start watching kubernetes events k8splugin.InitKubServiceWatch(ag.netPlugin) } err := <-recvErr if err != nil { time.Sleep(1 * time.Second) log.Errorf("Failure occurred. Error: %s", err) return err } return nil }
go
func (ag *Agent) HandleEvents() error { opts := ag.pluginConfig.Instance recvErr := make(chan error, 1) go handleNetworkEvents(ag.netPlugin, opts, recvErr) go handleBgpEvents(ag.netPlugin, opts, recvErr) go handleEndpointEvents(ag.netPlugin, opts, recvErr) go handleEpgEvents(ag.netPlugin, opts, recvErr) go handleServiceLBEvents(ag.netPlugin, opts, recvErr) go handleSvcProviderUpdEvents(ag.netPlugin, opts, recvErr) go handleGlobalCfgEvents(ag.netPlugin, opts, recvErr) go handlePolicyRuleEvents(ag.netPlugin, opts, recvErr) if ag.pluginConfig.Instance.PluginMode == core.Docker || ag.pluginConfig.Instance.PluginMode == core.SwarmMode { go ag.monitorDockerEvents(recvErr) } else if ag.pluginConfig.Instance.PluginMode == core.Kubernetes { // start watching kubernetes events k8splugin.InitKubServiceWatch(ag.netPlugin) } err := <-recvErr if err != nil { time.Sleep(1 * time.Second) log.Errorf("Failure occurred. Error: %s", err) return err } return nil }
[ "func", "(", "ag", "*", "Agent", ")", "HandleEvents", "(", ")", "error", "{", "opts", ":=", "ag", ".", "pluginConfig", ".", "Instance", "\n", "recvErr", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n\n", "go", "handleNetworkEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleBgpEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleEndpointEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleEpgEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleServiceLBEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleSvcProviderUpdEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handleGlobalCfgEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "go", "handlePolicyRuleEvents", "(", "ag", ".", "netPlugin", ",", "opts", ",", "recvErr", ")", "\n\n", "if", "ag", ".", "pluginConfig", ".", "Instance", ".", "PluginMode", "==", "core", ".", "Docker", "||", "ag", ".", "pluginConfig", ".", "Instance", ".", "PluginMode", "==", "core", ".", "SwarmMode", "{", "go", "ag", ".", "monitorDockerEvents", "(", "recvErr", ")", "\n", "}", "else", "if", "ag", ".", "pluginConfig", ".", "Instance", ".", "PluginMode", "==", "core", ".", "Kubernetes", "{", "// start watching kubernetes events", "k8splugin", ".", "InitKubServiceWatch", "(", "ag", ".", "netPlugin", ")", "\n", "}", "\n", "err", ":=", "<-", "recvErr", "\n", "if", "err", "!=", "nil", "{", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Second", ")", "\n", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// HandleEvents handles events
[ "HandleEvents", "handles", "events" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L207-L242
7,930
contiv/netplugin
netplugin/agent/agent.go
serveRequests
func (ag *Agent) serveRequests() { listenURL := ":9090" router := mux.NewRouter() // Add REST routes s := router.Methods("GET").Subrouter() s.HandleFunc("/svcstats", func(w http.ResponseWriter, r *http.Request) { stats, err := ag.netPlugin.GetEndpointStats() if err != nil { log.Errorf("Error fetching stats from driver. Err: %v", err) http.Error(w, "Error fetching stats from driver", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.Write(stats) }) s.HandleFunc("/inspect/driver", func(w http.ResponseWriter, r *http.Request) { driverState, err := ag.netPlugin.InspectState() if err != nil { log.Errorf("Error fetching driver state. Err: %v", err) http.Error(w, "Error fetching driver state", http.StatusInternalServerError) return } w.Write(driverState) }) s.HandleFunc("/inspect/bgp", func(w http.ResponseWriter, r *http.Request) { bgpState, err := ag.netPlugin.InspectBgp() if err != nil { log.Errorf("Error fetching bgp. Err: %v", err) http.Error(w, "Error fetching bgp", http.StatusInternalServerError) return } w.Write(bgpState) }) s.HandleFunc("/inspect/nameserver", func(w http.ResponseWriter, r *http.Request) { ns, err := ag.netPlugin.NetworkDriver.InspectNameserver() if err != nil { log.Errorf("Error fetching nameserver state. Err: %v", err) http.Error(w, "Error fetching nameserver state", http.StatusInternalServerError) return } w.Write(ns) }) s = router.Methods("Delete").Subrouter() s.HandleFunc("/debug/reclaimEndpoint/{id}", utils.MakeHTTPHandler(ag.ReclaimEndpointHandler)) // Create HTTP server and listener server := &http.Server{Handler: router} listener, err := net.Listen("tcp", listenURL) if nil != err { log.Fatalln(err) } log.Infof("Netplugin listening on %s", listenURL) // start server go server.Serve(listener) }
go
func (ag *Agent) serveRequests() { listenURL := ":9090" router := mux.NewRouter() // Add REST routes s := router.Methods("GET").Subrouter() s.HandleFunc("/svcstats", func(w http.ResponseWriter, r *http.Request) { stats, err := ag.netPlugin.GetEndpointStats() if err != nil { log.Errorf("Error fetching stats from driver. Err: %v", err) http.Error(w, "Error fetching stats from driver", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.Write(stats) }) s.HandleFunc("/inspect/driver", func(w http.ResponseWriter, r *http.Request) { driverState, err := ag.netPlugin.InspectState() if err != nil { log.Errorf("Error fetching driver state. Err: %v", err) http.Error(w, "Error fetching driver state", http.StatusInternalServerError) return } w.Write(driverState) }) s.HandleFunc("/inspect/bgp", func(w http.ResponseWriter, r *http.Request) { bgpState, err := ag.netPlugin.InspectBgp() if err != nil { log.Errorf("Error fetching bgp. Err: %v", err) http.Error(w, "Error fetching bgp", http.StatusInternalServerError) return } w.Write(bgpState) }) s.HandleFunc("/inspect/nameserver", func(w http.ResponseWriter, r *http.Request) { ns, err := ag.netPlugin.NetworkDriver.InspectNameserver() if err != nil { log.Errorf("Error fetching nameserver state. Err: %v", err) http.Error(w, "Error fetching nameserver state", http.StatusInternalServerError) return } w.Write(ns) }) s = router.Methods("Delete").Subrouter() s.HandleFunc("/debug/reclaimEndpoint/{id}", utils.MakeHTTPHandler(ag.ReclaimEndpointHandler)) // Create HTTP server and listener server := &http.Server{Handler: router} listener, err := net.Listen("tcp", listenURL) if nil != err { log.Fatalln(err) } log.Infof("Netplugin listening on %s", listenURL) // start server go server.Serve(listener) }
[ "func", "(", "ag", "*", "Agent", ")", "serveRequests", "(", ")", "{", "listenURL", ":=", "\"", "\"", "\n", "router", ":=", "mux", ".", "NewRouter", "(", ")", "\n\n", "// Add REST routes", "s", ":=", "router", ".", "Methods", "(", "\"", "\"", ")", ".", "Subrouter", "(", ")", "\n", "s", ".", "HandleFunc", "(", "\"", "\"", ",", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "stats", ",", "err", ":=", "ag", ".", "netPlugin", ".", "GetEndpointStats", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "Write", "(", "stats", ")", "\n", "}", ")", "\n", "s", ".", "HandleFunc", "(", "\"", "\"", ",", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "driverState", ",", "err", ":=", "ag", ".", "netPlugin", ".", "InspectState", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Write", "(", "driverState", ")", "\n", "}", ")", "\n", "s", ".", "HandleFunc", "(", "\"", "\"", ",", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "bgpState", ",", "err", ":=", "ag", ".", "netPlugin", ".", "InspectBgp", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Write", "(", "bgpState", ")", "\n", "}", ")", "\n\n", "s", ".", "HandleFunc", "(", "\"", "\"", ",", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "ns", ",", "err", ":=", "ag", ".", "netPlugin", ".", "NetworkDriver", ".", "InspectNameserver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Write", "(", "ns", ")", "\n", "}", ")", "\n\n", "s", "=", "router", ".", "Methods", "(", "\"", "\"", ")", ".", "Subrouter", "(", ")", "\n", "s", ".", "HandleFunc", "(", "\"", "\"", ",", "utils", ".", "MakeHTTPHandler", "(", "ag", ".", "ReclaimEndpointHandler", ")", ")", "\n\n", "// Create HTTP server and listener", "server", ":=", "&", "http", ".", "Server", "{", "Handler", ":", "router", "}", "\n", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "listenURL", ")", "\n", "if", "nil", "!=", "err", "{", "log", ".", "Fatalln", "(", "err", ")", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "listenURL", ")", "\n\n", "// start server", "go", "server", ".", "Serve", "(", "listener", ")", "\n", "}" ]
// serveRequests serve REST api requests
[ "serveRequests", "serve", "REST", "api", "requests" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L245-L304
7,931
contiv/netplugin
netplugin/agent/agent.go
ReclaimEndpointHandler
func (ag *Agent) ReclaimEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) { epID := vars["id"] // delete the endpoint err := ag.netPlugin.DeleteEndpoint(epID) if err != nil { log.Errorf("Error deleting endpoint %v. Err: %v", epID, err) http.Error(w, fmt.Sprintf("failed to delete endpoint: %+v", epID), 0) return nil, err } return nil, nil }
go
func (ag *Agent) ReclaimEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) { epID := vars["id"] // delete the endpoint err := ag.netPlugin.DeleteEndpoint(epID) if err != nil { log.Errorf("Error deleting endpoint %v. Err: %v", epID, err) http.Error(w, fmt.Sprintf("failed to delete endpoint: %+v", epID), 0) return nil, err } return nil, nil }
[ "func", "(", "ag", "*", "Agent", ")", "ReclaimEndpointHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "epID", ":=", "vars", "[", "\"", "\"", "]", "\n", "// delete the endpoint", "err", ":=", "ag", ".", "netPlugin", ".", "DeleteEndpoint", "(", "epID", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epID", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "epID", ")", ",", "0", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "nil", ",", "nil", "\n", "}" ]
// ReclaimEndpointHandler reclaims endpoint
[ "ReclaimEndpointHandler", "reclaims", "endpoint" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/agent.go#L307-L318
7,932
contiv/netplugin
netctl/config.go
applyConfig
func applyConfig(cl *contivClient.ContivClient) error { data, err := ioutil.ReadFile(configPath()) if err != nil { return fmt.Errorf("failed to read config file: %v", err) } nc := Config{} if err := json.Unmarshal(data, &nc); err != nil { return fmt.Errorf("failed to unmarshal JSON: %v", err) } // add the token header we use to authenticate if err := cl.SetAuthToken(nc.Token); err != nil { return fmt.Errorf("failed to set auth token: %v", err) } return nil }
go
func applyConfig(cl *contivClient.ContivClient) error { data, err := ioutil.ReadFile(configPath()) if err != nil { return fmt.Errorf("failed to read config file: %v", err) } nc := Config{} if err := json.Unmarshal(data, &nc); err != nil { return fmt.Errorf("failed to unmarshal JSON: %v", err) } // add the token header we use to authenticate if err := cl.SetAuthToken(nc.Token); err != nil { return fmt.Errorf("failed to set auth token: %v", err) } return nil }
[ "func", "applyConfig", "(", "cl", "*", "contivClient", ".", "ContivClient", ")", "error", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "configPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "nc", ":=", "Config", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "nc", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// add the token header we use to authenticate", "if", "err", ":=", "cl", ".", "SetAuthToken", "(", "nc", ".", "Token", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// applyConfig applies the netctl config to the specified ContivClient
[ "applyConfig", "applies", "the", "netctl", "config", "to", "the", "specified", "ContivClient" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/config.go#L24-L41
7,933
contiv/netplugin
netctl/config.go
configPath
func configPath() string { var homeDir string // this fails for static binaries usr, err := user.Current() if err == nil { homeDir = usr.HomeDir } // this should work where we don't have static binaries if err != nil { homeDir = os.Getenv("HOME") } // panic if we've failed to retrieve the home directory if homeDir == "" { panic(errHomeDirectoryNotSet) } return usr.HomeDir + "/.netctl/config.json" }
go
func configPath() string { var homeDir string // this fails for static binaries usr, err := user.Current() if err == nil { homeDir = usr.HomeDir } // this should work where we don't have static binaries if err != nil { homeDir = os.Getenv("HOME") } // panic if we've failed to retrieve the home directory if homeDir == "" { panic(errHomeDirectoryNotSet) } return usr.HomeDir + "/.netctl/config.json" }
[ "func", "configPath", "(", ")", "string", "{", "var", "homeDir", "string", "\n", "// this fails for static binaries", "usr", ",", "err", ":=", "user", ".", "Current", "(", ")", "\n", "if", "err", "==", "nil", "{", "homeDir", "=", "usr", ".", "HomeDir", "\n", "}", "\n", "// this should work where we don't have static binaries", "if", "err", "!=", "nil", "{", "homeDir", "=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "}", "\n", "// panic if we've failed to retrieve the home directory", "if", "homeDir", "==", "\"", "\"", "{", "panic", "(", "errHomeDirectoryNotSet", ")", "\n", "}", "\n\n", "return", "usr", ".", "HomeDir", "+", "\"", "\"", "\n", "}" ]
// configPath returns the full path to the user's netctl config file
[ "configPath", "returns", "the", "full", "path", "to", "the", "user", "s", "netctl", "config", "file" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/config.go#L55-L72
7,934
contiv/netplugin
netctl/config.go
writeConfig
func writeConfig(ctx *cli.Context, data []byte) { dir := filepath.Dir(configPath()) // try to create the netctl config directory but ignore "already exists" errors. // only the user should be able to read the contents of this directory if err := os.Mkdir(dir, 0700); err != nil && !os.IsExist(err) { errExit(ctx, exitIO, err.Error(), false) } // only the user should be able to read the config file if err := ioutil.WriteFile(configPath(), data, 0600); err != nil { errExit(ctx, exitIO, err.Error(), false) } }
go
func writeConfig(ctx *cli.Context, data []byte) { dir := filepath.Dir(configPath()) // try to create the netctl config directory but ignore "already exists" errors. // only the user should be able to read the contents of this directory if err := os.Mkdir(dir, 0700); err != nil && !os.IsExist(err) { errExit(ctx, exitIO, err.Error(), false) } // only the user should be able to read the config file if err := ioutil.WriteFile(configPath(), data, 0600); err != nil { errExit(ctx, exitIO, err.Error(), false) } }
[ "func", "writeConfig", "(", "ctx", "*", "cli", ".", "Context", ",", "data", "[", "]", "byte", ")", "{", "dir", ":=", "filepath", ".", "Dir", "(", "configPath", "(", ")", ")", "\n\n", "// try to create the netctl config directory but ignore \"already exists\" errors.", "// only the user should be able to read the contents of this directory", "if", "err", ":=", "os", ".", "Mkdir", "(", "dir", ",", "0700", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsExist", "(", "err", ")", "{", "errExit", "(", "ctx", ",", "exitIO", ",", "err", ".", "Error", "(", ")", ",", "false", ")", "\n", "}", "\n\n", "// only the user should be able to read the config file", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "configPath", "(", ")", ",", "data", ",", "0600", ")", ";", "err", "!=", "nil", "{", "errExit", "(", "ctx", ",", "exitIO", ",", "err", ".", "Error", "(", ")", ",", "false", ")", "\n", "}", "\n", "}" ]
// writeConfig writes out the netctl config file, creating the directory and file as necessary
[ "writeConfig", "writes", "out", "the", "netctl", "config", "file", "creating", "the", "directory", "and", "file", "as", "necessary" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/config.go#L75-L88
7,935
contiv/netplugin
utils/dockerutils.go
getDockerHost
func getDockerHost() string { dockerHost := os.Getenv("DOCKER_HOST") if dockerHost == "" { if runtime.GOOS == "windows" { // If we do not have a host, default to TCP socket on Windows dockerHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort) } else { // If we do not have a host, default to unix socket dockerHost = fmt.Sprintf("unix://%s", DefaultUnixSocket) } } return dockerHost }
go
func getDockerHost() string { dockerHost := os.Getenv("DOCKER_HOST") if dockerHost == "" { if runtime.GOOS == "windows" { // If we do not have a host, default to TCP socket on Windows dockerHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort) } else { // If we do not have a host, default to unix socket dockerHost = fmt.Sprintf("unix://%s", DefaultUnixSocket) } } return dockerHost }
[ "func", "getDockerHost", "(", ")", "string", "{", "dockerHost", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "dockerHost", "==", "\"", "\"", "{", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "// If we do not have a host, default to TCP socket on Windows", "dockerHost", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "DefaultHTTPHost", ",", "DefaultHTTPPort", ")", "\n", "}", "else", "{", "// If we do not have a host, default to unix socket", "dockerHost", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "DefaultUnixSocket", ")", "\n", "}", "\n", "}", "\n", "return", "dockerHost", "\n", "}" ]
// getDockerHost returns the docker socket based on Environment settings
[ "getDockerHost", "returns", "the", "docker", "socket", "based", "on", "Environment", "settings" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/dockerutils.go#L21-L33
7,936
contiv/netplugin
netplugin/nameserver/nameserver.go
AddLbService
func (ens *NetpluginNameServer) AddLbService(tenant string, name string, v4name string) { if len(v4name) > 0 { dnsLog.Infof("add k8s service %s ip %s", name, v4name) if tenant == K8sDefaultTenant { ens.k8sService.Set(name, nameRecord{v4Record: net.ParseIP(v4name)}) } else { mc := mastercfg.CfgServiceLBState{ Tenant: tenant, ServiceName: name, IPAddress: v4name, } ens.addService(&mc) } } }
go
func (ens *NetpluginNameServer) AddLbService(tenant string, name string, v4name string) { if len(v4name) > 0 { dnsLog.Infof("add k8s service %s ip %s", name, v4name) if tenant == K8sDefaultTenant { ens.k8sService.Set(name, nameRecord{v4Record: net.ParseIP(v4name)}) } else { mc := mastercfg.CfgServiceLBState{ Tenant: tenant, ServiceName: name, IPAddress: v4name, } ens.addService(&mc) } } }
[ "func", "(", "ens", "*", "NetpluginNameServer", ")", "AddLbService", "(", "tenant", "string", ",", "name", "string", ",", "v4name", "string", ")", "{", "if", "len", "(", "v4name", ")", ">", "0", "{", "dnsLog", ".", "Infof", "(", "\"", "\"", ",", "name", ",", "v4name", ")", "\n", "if", "tenant", "==", "K8sDefaultTenant", "{", "ens", ".", "k8sService", ".", "Set", "(", "name", ",", "nameRecord", "{", "v4Record", ":", "net", ".", "ParseIP", "(", "v4name", ")", "}", ")", "\n", "}", "else", "{", "mc", ":=", "mastercfg", ".", "CfgServiceLBState", "{", "Tenant", ":", "tenant", ",", "ServiceName", ":", "name", ",", "IPAddress", ":", "v4name", ",", "}", "\n", "ens", ".", "addService", "(", "&", "mc", ")", "\n", "}", "\n", "}", "\n", "}" ]
// AddLbService adds a LB service in non-multi tenant record
[ "AddLbService", "adds", "a", "LB", "service", "in", "non", "-", "multi", "tenant", "record" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/nameserver/nameserver.go#L153-L167
7,937
contiv/netplugin
netplugin/nameserver/nameserver.go
DelLbService
func (ens *NetpluginNameServer) DelLbService(tenant string, name string) { dnsLog.Infof("delete k8s service %s ", name) if tenant == K8sDefaultTenant { ens.k8sService.Remove(name) } else { mc := mastercfg.CfgServiceLBState{ Tenant: tenant, ServiceName: name, } ens.delService(&mc) } }
go
func (ens *NetpluginNameServer) DelLbService(tenant string, name string) { dnsLog.Infof("delete k8s service %s ", name) if tenant == K8sDefaultTenant { ens.k8sService.Remove(name) } else { mc := mastercfg.CfgServiceLBState{ Tenant: tenant, ServiceName: name, } ens.delService(&mc) } }
[ "func", "(", "ens", "*", "NetpluginNameServer", ")", "DelLbService", "(", "tenant", "string", ",", "name", "string", ")", "{", "dnsLog", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "if", "tenant", "==", "K8sDefaultTenant", "{", "ens", ".", "k8sService", ".", "Remove", "(", "name", ")", "\n", "}", "else", "{", "mc", ":=", "mastercfg", ".", "CfgServiceLBState", "{", "Tenant", ":", "tenant", ",", "ServiceName", ":", "name", ",", "}", "\n", "ens", ".", "delService", "(", "&", "mc", ")", "\n", "}", "\n", "}" ]
// DelLbService deletes LB service from non-multi tenant record
[ "DelLbService", "deletes", "LB", "service", "from", "non", "-", "multi", "tenant", "record" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/nameserver/nameserver.go#L170-L182
7,938
contiv/netplugin
netplugin/nameserver/nameserver.go
InspectState
func (ens *NetpluginNameServer) InspectState() (interface{}, error) { s := struct { SvcChan int `json:"serviceQueue"` EpChan int `json:"endpointQueue"` Dtbl map[string]map[string]map[string][]string `json:"dnsRecords"` Stats map[string]map[string]uint64 `json:"stats"` }{SvcChan: len(ens.svcChan), EpChan: len(ens.epChan), Dtbl: ens.inspectNameRecord(), Stats: ens.inspectStats()} return &s, nil }
go
func (ens *NetpluginNameServer) InspectState() (interface{}, error) { s := struct { SvcChan int `json:"serviceQueue"` EpChan int `json:"endpointQueue"` Dtbl map[string]map[string]map[string][]string `json:"dnsRecords"` Stats map[string]map[string]uint64 `json:"stats"` }{SvcChan: len(ens.svcChan), EpChan: len(ens.epChan), Dtbl: ens.inspectNameRecord(), Stats: ens.inspectStats()} return &s, nil }
[ "func", "(", "ens", "*", "NetpluginNameServer", ")", "InspectState", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "s", ":=", "struct", "{", "SvcChan", "int", "`json:\"serviceQueue\"`", "\n", "EpChan", "int", "`json:\"endpointQueue\"`", "\n", "Dtbl", "map", "[", "string", "]", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "string", "`json:\"dnsRecords\"`", "\n", "Stats", "map", "[", "string", "]", "map", "[", "string", "]", "uint64", "`json:\"stats\"`", "\n", "}", "{", "SvcChan", ":", "len", "(", "ens", ".", "svcChan", ")", ",", "EpChan", ":", "len", "(", "ens", ".", "epChan", ")", ",", "Dtbl", ":", "ens", ".", "inspectNameRecord", "(", ")", ",", "Stats", ":", "ens", ".", "inspectStats", "(", ")", "}", "\n", "return", "&", "s", ",", "nil", "\n", "}" ]
// InspectState returns state
[ "InspectState", "returns", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/nameserver/nameserver.go#L572-L582
7,939
contiv/netplugin
netplugin/nameserver/nameserver.go
NsLookup
func (ens *NetpluginNameServer) NsLookup(nsq []byte, vrfPtr *string) ([]byte, error) { tenant := *vrfPtr req := new(dns.Msg) err := req.Unpack(nsq) if err != nil { ens.incTenantStats(tenant, "invalidQuery") return nil, err } // no fancy requests if req.Response { ens.incTenantStats(tenant, "invalidQuery") return nil, errors.New("") } if req.IsTsig() != nil { ens.incTenantStats(tenant, "invalidQuery") return nil, errors.New("") } d, err := ens.serveNameRecord(tenant, req) if err != nil { logrus.Infof("no name record: %s", err) ens.incTenantStats(tenant, "noNameRecord") return nil, err } ens.incTenantStats(tenant, "foundNameRecord") return d, err }
go
func (ens *NetpluginNameServer) NsLookup(nsq []byte, vrfPtr *string) ([]byte, error) { tenant := *vrfPtr req := new(dns.Msg) err := req.Unpack(nsq) if err != nil { ens.incTenantStats(tenant, "invalidQuery") return nil, err } // no fancy requests if req.Response { ens.incTenantStats(tenant, "invalidQuery") return nil, errors.New("") } if req.IsTsig() != nil { ens.incTenantStats(tenant, "invalidQuery") return nil, errors.New("") } d, err := ens.serveNameRecord(tenant, req) if err != nil { logrus.Infof("no name record: %s", err) ens.incTenantStats(tenant, "noNameRecord") return nil, err } ens.incTenantStats(tenant, "foundNameRecord") return d, err }
[ "func", "(", "ens", "*", "NetpluginNameServer", ")", "NsLookup", "(", "nsq", "[", "]", "byte", ",", "vrfPtr", "*", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "tenant", ":=", "*", "vrfPtr", "\n", "req", ":=", "new", "(", "dns", ".", "Msg", ")", "\n", "err", ":=", "req", ".", "Unpack", "(", "nsq", ")", "\n", "if", "err", "!=", "nil", "{", "ens", ".", "incTenantStats", "(", "tenant", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "// no fancy requests", "if", "req", ".", "Response", "{", "ens", ".", "incTenantStats", "(", "tenant", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "req", ".", "IsTsig", "(", ")", "!=", "nil", "{", "ens", ".", "incTenantStats", "(", "tenant", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "d", ",", "err", ":=", "ens", ".", "serveNameRecord", "(", "tenant", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Infof", "(", "\"", "\"", ",", "err", ")", "\n", "ens", ".", "incTenantStats", "(", "tenant", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "ens", ".", "incTenantStats", "(", "tenant", ",", "\"", "\"", ")", "\n", "return", "d", ",", "err", "\n\n", "}" ]
// NsLookup returns name record,called from ofnet agent
[ "NsLookup", "returns", "name", "record", "called", "from", "ofnet", "agent" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/nameserver/nameserver.go#L585-L615
7,940
contiv/netplugin
netplugin/nameserver/nameserver.go
Init
func (ens *NetpluginNameServer) Init(sd core.StateDriver) error { dnsLog = logrus.WithField("module", "nameserver") ens.bucketSize = 64 ens.stateDriver = sd // don't change buffering ens.epChan = make(chan core.WatchState, 64) ens.epErrChan = make(chan error) ens.svcChan = make(chan core.WatchState, 8) ens.svcErrChan = make(chan error) ens.buckets = make([]tenantBucket, ens.bucketSize) ens.k8sService = cmap.New() for i := uint(0); i < ens.bucketSize; i++ { ens.buckets[i].tenantTables = make(map[string]*dnsTables) ens.stats.tenantStats = make(map[string]map[string]uint64) } ens.epKeyPath = mastercfg.StateConfigPath + "eps/" ens.svcKeyPath = mastercfg.StateConfigPath + "serviceLB/" go ens.processStateEvent() go ens.startSvcWatch() go ens.startEndpointWatch() ens.readStateStore() dnsLog.Infof("nameserver started") return nil }
go
func (ens *NetpluginNameServer) Init(sd core.StateDriver) error { dnsLog = logrus.WithField("module", "nameserver") ens.bucketSize = 64 ens.stateDriver = sd // don't change buffering ens.epChan = make(chan core.WatchState, 64) ens.epErrChan = make(chan error) ens.svcChan = make(chan core.WatchState, 8) ens.svcErrChan = make(chan error) ens.buckets = make([]tenantBucket, ens.bucketSize) ens.k8sService = cmap.New() for i := uint(0); i < ens.bucketSize; i++ { ens.buckets[i].tenantTables = make(map[string]*dnsTables) ens.stats.tenantStats = make(map[string]map[string]uint64) } ens.epKeyPath = mastercfg.StateConfigPath + "eps/" ens.svcKeyPath = mastercfg.StateConfigPath + "serviceLB/" go ens.processStateEvent() go ens.startSvcWatch() go ens.startEndpointWatch() ens.readStateStore() dnsLog.Infof("nameserver started") return nil }
[ "func", "(", "ens", "*", "NetpluginNameServer", ")", "Init", "(", "sd", "core", ".", "StateDriver", ")", "error", "{", "dnsLog", "=", "logrus", ".", "WithField", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "ens", ".", "bucketSize", "=", "64", "\n", "ens", ".", "stateDriver", "=", "sd", "\n\n", "// don't change buffering", "ens", ".", "epChan", "=", "make", "(", "chan", "core", ".", "WatchState", ",", "64", ")", "\n", "ens", ".", "epErrChan", "=", "make", "(", "chan", "error", ")", "\n", "ens", ".", "svcChan", "=", "make", "(", "chan", "core", ".", "WatchState", ",", "8", ")", "\n", "ens", ".", "svcErrChan", "=", "make", "(", "chan", "error", ")", "\n", "ens", ".", "buckets", "=", "make", "(", "[", "]", "tenantBucket", ",", "ens", ".", "bucketSize", ")", "\n", "ens", ".", "k8sService", "=", "cmap", ".", "New", "(", ")", "\n\n", "for", "i", ":=", "uint", "(", "0", ")", ";", "i", "<", "ens", ".", "bucketSize", ";", "i", "++", "{", "ens", ".", "buckets", "[", "i", "]", ".", "tenantTables", "=", "make", "(", "map", "[", "string", "]", "*", "dnsTables", ")", "\n", "ens", ".", "stats", ".", "tenantStats", "=", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "uint64", ")", "\n", "}", "\n", "ens", ".", "epKeyPath", "=", "mastercfg", ".", "StateConfigPath", "+", "\"", "\"", "\n", "ens", ".", "svcKeyPath", "=", "mastercfg", ".", "StateConfigPath", "+", "\"", "\"", "\n", "go", "ens", ".", "processStateEvent", "(", ")", "\n", "go", "ens", ".", "startSvcWatch", "(", ")", "\n", "go", "ens", ".", "startEndpointWatch", "(", ")", "\n", "ens", ".", "readStateStore", "(", ")", "\n", "dnsLog", ".", "Infof", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// Init to start name server
[ "Init", "to", "start", "name", "server" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/nameserver/nameserver.go#L693-L718
7,941
contiv/netplugin
netmaster/master/bgp.go
AddBgp
func AddBgp(stateDriver core.StateDriver, bgpCfg *intent.ConfigBgp) error { log.Infof("Adding bgp neighbor {%v}", bgpCfg) aci, _ := IsAciConfigured() if aci { log.Errorf("Invalid configuration. Not supported in ACI fabric mode.") return errors.New("not supported in ACI fabric mode") } bgpState := &mastercfg.CfgBgpState{} bgpState.Hostname = bgpCfg.Hostname bgpState.RouterIP = bgpCfg.RouterIP bgpState.As = bgpCfg.As bgpState.NeighborAs = bgpCfg.NeighborAs bgpState.Neighbor = bgpCfg.Neighbor bgpState.StateDriver = stateDriver bgpState.ID = bgpCfg.Hostname return bgpState.Write() }
go
func AddBgp(stateDriver core.StateDriver, bgpCfg *intent.ConfigBgp) error { log.Infof("Adding bgp neighbor {%v}", bgpCfg) aci, _ := IsAciConfigured() if aci { log.Errorf("Invalid configuration. Not supported in ACI fabric mode.") return errors.New("not supported in ACI fabric mode") } bgpState := &mastercfg.CfgBgpState{} bgpState.Hostname = bgpCfg.Hostname bgpState.RouterIP = bgpCfg.RouterIP bgpState.As = bgpCfg.As bgpState.NeighborAs = bgpCfg.NeighborAs bgpState.Neighbor = bgpCfg.Neighbor bgpState.StateDriver = stateDriver bgpState.ID = bgpCfg.Hostname return bgpState.Write() }
[ "func", "AddBgp", "(", "stateDriver", "core", ".", "StateDriver", ",", "bgpCfg", "*", "intent", ".", "ConfigBgp", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "bgpCfg", ")", "\n", "aci", ",", "_", ":=", "IsAciConfigured", "(", ")", "\n", "if", "aci", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "bgpState", ":=", "&", "mastercfg", ".", "CfgBgpState", "{", "}", "\n", "bgpState", ".", "Hostname", "=", "bgpCfg", ".", "Hostname", "\n", "bgpState", ".", "RouterIP", "=", "bgpCfg", ".", "RouterIP", "\n", "bgpState", ".", "As", "=", "bgpCfg", ".", "As", "\n", "bgpState", ".", "NeighborAs", "=", "bgpCfg", ".", "NeighborAs", "\n", "bgpState", ".", "Neighbor", "=", "bgpCfg", ".", "Neighbor", "\n", "bgpState", ".", "StateDriver", "=", "stateDriver", "\n", "bgpState", ".", "ID", "=", "bgpCfg", ".", "Hostname", "\n", "return", "bgpState", ".", "Write", "(", ")", "\n", "}" ]
//AddBgp adds to the etcd state
[ "AddBgp", "adds", "to", "the", "etcd", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/bgp.go#L28-L45
7,942
contiv/netplugin
netmaster/master/bgp.go
DeleteBgp
func DeleteBgp(stateDriver core.StateDriver, hostname string) error { log.Infof("Deleting bgp neighbor for {%v}", hostname) bgpState := &mastercfg.CfgBgpState{} bgpState.StateDriver = stateDriver err := bgpState.Read(hostname) if err != nil { log.Errorf("Error reading bgp config for hostname %s", hostname) return err } err = bgpState.Clear() if err != nil { log.Errorf("Error deleing Bgp config for hostname %s", hostname) return err } return nil }
go
func DeleteBgp(stateDriver core.StateDriver, hostname string) error { log.Infof("Deleting bgp neighbor for {%v}", hostname) bgpState := &mastercfg.CfgBgpState{} bgpState.StateDriver = stateDriver err := bgpState.Read(hostname) if err != nil { log.Errorf("Error reading bgp config for hostname %s", hostname) return err } err = bgpState.Clear() if err != nil { log.Errorf("Error deleing Bgp config for hostname %s", hostname) return err } return nil }
[ "func", "DeleteBgp", "(", "stateDriver", "core", ".", "StateDriver", ",", "hostname", "string", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "hostname", ")", "\n", "bgpState", ":=", "&", "mastercfg", ".", "CfgBgpState", "{", "}", "\n", "bgpState", ".", "StateDriver", "=", "stateDriver", "\n", "err", ":=", "bgpState", ".", "Read", "(", "hostname", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "hostname", ")", "\n", "return", "err", "\n", "}", "\n", "err", "=", "bgpState", ".", "Clear", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "hostname", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n\n", "}" ]
//DeleteBgp deletes from etcd state
[ "DeleteBgp", "deletes", "from", "etcd", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/bgp.go#L48-L64
7,943
contiv/netplugin
objdb/etcdLock.go
NewLock
func (ep *EtcdClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error) { watchCtx, watchCancel := context.WithCancel(context.Background()) // Create a lock return &etcdLock{ name: name, myID: myID, ttl: time.Duration(ttl) * time.Second, kapi: ep.kapi, eventChan: make(chan LockEvent, 1), stopChan: make(chan bool, 1), watchCh: make(chan *client.Response, 1), watchCtx: watchCtx, watchCancel: watchCancel, mutex: new(sync.Mutex), }, nil }
go
func (ep *EtcdClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error) { watchCtx, watchCancel := context.WithCancel(context.Background()) // Create a lock return &etcdLock{ name: name, myID: myID, ttl: time.Duration(ttl) * time.Second, kapi: ep.kapi, eventChan: make(chan LockEvent, 1), stopChan: make(chan bool, 1), watchCh: make(chan *client.Response, 1), watchCtx: watchCtx, watchCancel: watchCancel, mutex: new(sync.Mutex), }, nil }
[ "func", "(", "ep", "*", "EtcdClient", ")", "NewLock", "(", "name", "string", ",", "myID", "string", ",", "ttl", "uint64", ")", "(", "LockInterface", ",", "error", ")", "{", "watchCtx", ",", "watchCancel", ":=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n", "// Create a lock", "return", "&", "etcdLock", "{", "name", ":", "name", ",", "myID", ":", "myID", ",", "ttl", ":", "time", ".", "Duration", "(", "ttl", ")", "*", "time", ".", "Second", ",", "kapi", ":", "ep", ".", "kapi", ",", "eventChan", ":", "make", "(", "chan", "LockEvent", ",", "1", ")", ",", "stopChan", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "watchCh", ":", "make", "(", "chan", "*", "client", ".", "Response", ",", "1", ")", ",", "watchCtx", ":", "watchCtx", ",", "watchCancel", ":", "watchCancel", ",", "mutex", ":", "new", "(", "sync", ".", "Mutex", ")", ",", "}", ",", "nil", "\n", "}" ]
// NewLock Create a new lock
[ "NewLock", "Create", "a", "new", "lock" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdLock.go#L33-L48
7,944
contiv/netplugin
objdb/etcdLock.go
waitForLock
func (lk *etcdLock) waitForLock() { // If timeout is not specified, set it to high value timeoutIntvl := time.Second * time.Duration(20000) if lk.timeout != 0 { timeoutIntvl = time.Second * time.Duration(lk.timeout) } log.Infof("Waiting to acquire lock (%s/%s)", lk.name, lk.myID) // Create a timer timer := time.NewTimer(timeoutIntvl) defer timer.Stop() // Wait for changes for { // wait on watch channel for holder to release the lock select { case <-timer.C: lk.mutex.Lock() if lk.timeout != 0 { lk.mutex.Unlock() log.Infof("Lock timeout on lock %s/%s", lk.name, lk.myID) lk.eventChan <- LockEvent{EventType: LockAcquireTimeout} log.Infof("Lock acquire timed out. Stopping lock") lk.watchCancel() // Release the lock lk.Release() return } lk.mutex.Unlock() case watchResp := <-lk.watchCh: if watchResp != nil { log.Debugf("Received watch notification(%s/%s): %+v", lk.name, lk.myID, watchResp) if watchResp.Action == "expire" || watchResp.Action == "delete" || watchResp.Action == "compareAndDelete" { log.Infof("Retrying to acquire lock") return } } case <-lk.stopChan: log.Infof("Stopping lock") lk.watchCancel() return } } }
go
func (lk *etcdLock) waitForLock() { // If timeout is not specified, set it to high value timeoutIntvl := time.Second * time.Duration(20000) if lk.timeout != 0 { timeoutIntvl = time.Second * time.Duration(lk.timeout) } log.Infof("Waiting to acquire lock (%s/%s)", lk.name, lk.myID) // Create a timer timer := time.NewTimer(timeoutIntvl) defer timer.Stop() // Wait for changes for { // wait on watch channel for holder to release the lock select { case <-timer.C: lk.mutex.Lock() if lk.timeout != 0 { lk.mutex.Unlock() log.Infof("Lock timeout on lock %s/%s", lk.name, lk.myID) lk.eventChan <- LockEvent{EventType: LockAcquireTimeout} log.Infof("Lock acquire timed out. Stopping lock") lk.watchCancel() // Release the lock lk.Release() return } lk.mutex.Unlock() case watchResp := <-lk.watchCh: if watchResp != nil { log.Debugf("Received watch notification(%s/%s): %+v", lk.name, lk.myID, watchResp) if watchResp.Action == "expire" || watchResp.Action == "delete" || watchResp.Action == "compareAndDelete" { log.Infof("Retrying to acquire lock") return } } case <-lk.stopChan: log.Infof("Stopping lock") lk.watchCancel() return } } }
[ "func", "(", "lk", "*", "etcdLock", ")", "waitForLock", "(", ")", "{", "// If timeout is not specified, set it to high value", "timeoutIntvl", ":=", "time", ".", "Second", "*", "time", ".", "Duration", "(", "20000", ")", "\n", "if", "lk", ".", "timeout", "!=", "0", "{", "timeoutIntvl", "=", "time", ".", "Second", "*", "time", ".", "Duration", "(", "lk", ".", "timeout", ")", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "lk", ".", "name", ",", "lk", ".", "myID", ")", "\n\n", "// Create a timer", "timer", ":=", "time", ".", "NewTimer", "(", "timeoutIntvl", ")", "\n", "defer", "timer", ".", "Stop", "(", ")", "\n\n", "// Wait for changes", "for", "{", "// wait on watch channel for holder to release the lock", "select", "{", "case", "<-", "timer", ".", "C", ":", "lk", ".", "mutex", ".", "Lock", "(", ")", "\n", "if", "lk", ".", "timeout", "!=", "0", "{", "lk", ".", "mutex", ".", "Unlock", "(", ")", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "lk", ".", "name", ",", "lk", ".", "myID", ")", "\n\n", "lk", ".", "eventChan", "<-", "LockEvent", "{", "EventType", ":", "LockAcquireTimeout", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ")", "\n\n", "lk", ".", "watchCancel", "(", ")", "\n\n", "// Release the lock", "lk", ".", "Release", "(", ")", "\n\n", "return", "\n", "}", "\n", "lk", ".", "mutex", ".", "Unlock", "(", ")", "\n", "case", "watchResp", ":=", "<-", "lk", ".", "watchCh", ":", "if", "watchResp", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "lk", ".", "name", ",", "lk", ".", "myID", ",", "watchResp", ")", "\n\n", "if", "watchResp", ".", "Action", "==", "\"", "\"", "||", "watchResp", ".", "Action", "==", "\"", "\"", "||", "watchResp", ".", "Action", "==", "\"", "\"", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "case", "<-", "lk", ".", "stopChan", ":", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "lk", ".", "watchCancel", "(", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// We couldnt acquire lock, Wait for changes on the lock
[ "We", "couldnt", "acquire", "lock", "Wait", "for", "changes", "on", "the", "lock" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdLock.go#L236-L287
7,945
contiv/netplugin
objdb/etcdLock.go
watchLock
func (lk *etcdLock) watchLock() { keyName := "/contiv.io/lock/" + lk.name watcher := lk.kapi.Watcher(keyName, nil) if watcher == nil { log.Errorf("Error creating the watcher") return } for { resp, err := watcher.Next(lk.watchCtx) if err != nil && (err.Error() == client.ErrClusterUnavailable.Error() || strings.Contains(err.Error(), "context canceled")) { log.Infof("Stopping watch on key %s", keyName) return } else if err != nil { log.Errorf("Error watching the key %s, Err %v.", keyName, err) } else { log.Debugf("Got Watch Resp: %+v", resp) // send the event to watch channel lk.watchCh <- resp } lk.mutex.Lock() // If the lock is released, we are done if lk.isReleased { lk.mutex.Unlock() return } lk.mutex.Unlock() } }
go
func (lk *etcdLock) watchLock() { keyName := "/contiv.io/lock/" + lk.name watcher := lk.kapi.Watcher(keyName, nil) if watcher == nil { log.Errorf("Error creating the watcher") return } for { resp, err := watcher.Next(lk.watchCtx) if err != nil && (err.Error() == client.ErrClusterUnavailable.Error() || strings.Contains(err.Error(), "context canceled")) { log.Infof("Stopping watch on key %s", keyName) return } else if err != nil { log.Errorf("Error watching the key %s, Err %v.", keyName, err) } else { log.Debugf("Got Watch Resp: %+v", resp) // send the event to watch channel lk.watchCh <- resp } lk.mutex.Lock() // If the lock is released, we are done if lk.isReleased { lk.mutex.Unlock() return } lk.mutex.Unlock() } }
[ "func", "(", "lk", "*", "etcdLock", ")", "watchLock", "(", ")", "{", "keyName", ":=", "\"", "\"", "+", "lk", ".", "name", "\n\n", "watcher", ":=", "lk", ".", "kapi", ".", "Watcher", "(", "keyName", ",", "nil", ")", "\n", "if", "watcher", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "for", "{", "resp", ",", "err", ":=", "watcher", ".", "Next", "(", "lk", ".", "watchCtx", ")", "\n", "if", "err", "!=", "nil", "&&", "(", "err", ".", "Error", "(", ")", "==", "client", ".", "ErrClusterUnavailable", ".", "Error", "(", ")", "||", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", ")", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "keyName", ")", "\n", "return", "\n", "}", "else", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyName", ",", "err", ")", "\n", "}", "else", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "resp", ")", "\n\n", "// send the event to watch channel", "lk", ".", "watchCh", "<-", "resp", "\n", "}", "\n\n", "lk", ".", "mutex", ".", "Lock", "(", ")", "\n", "// If the lock is released, we are done", "if", "lk", ".", "isReleased", "{", "lk", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n", "lk", ".", "mutex", ".", "Unlock", "(", ")", "\n", "}", "\n", "}" ]
// Watch for changes on the lock
[ "Watch", "for", "changes", "on", "the", "lock" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/etcdLock.go#L346-L377
7,946
contiv/netplugin
utils/driverfactory.go
initHelper
func initHelper(driverRegistry map[string]driverConfigTypes, driverName string) (core.Driver, error) { if _, ok := driverRegistry[driverName]; ok { driverType := driverRegistry[driverName].DriverType driver := reflect.New(driverType).Interface() return driver, nil } return nil, core.Errorf("Failed to find a registered driver for: %s", driverName) }
go
func initHelper(driverRegistry map[string]driverConfigTypes, driverName string) (core.Driver, error) { if _, ok := driverRegistry[driverName]; ok { driverType := driverRegistry[driverName].DriverType driver := reflect.New(driverType).Interface() return driver, nil } return nil, core.Errorf("Failed to find a registered driver for: %s", driverName) }
[ "func", "initHelper", "(", "driverRegistry", "map", "[", "string", "]", "driverConfigTypes", ",", "driverName", "string", ")", "(", "core", ".", "Driver", ",", "error", ")", "{", "if", "_", ",", "ok", ":=", "driverRegistry", "[", "driverName", "]", ";", "ok", "{", "driverType", ":=", "driverRegistry", "[", "driverName", "]", ".", "DriverType", "\n\n", "driver", ":=", "reflect", ".", "New", "(", "driverType", ")", ".", "Interface", "(", ")", "\n", "return", "driver", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ",", "driverName", ")", "\n", "}" ]
// initHelper initializes the NetPlugin by mapping driver names to // configuration, then it imports the configuration.
[ "initHelper", "initializes", "the", "NetPlugin", "by", "mapping", "driver", "names", "to", "configuration", "then", "it", "imports", "the", "configuration", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/driverfactory.go#L70-L79
7,947
contiv/netplugin
utils/driverfactory.go
NewStateDriver
func NewStateDriver(name string, instInfo *core.InstanceInfo) (core.StateDriver, error) { if name == "" || instInfo == nil { return nil, core.Errorf("invalid driver name or configuration passed.") } if gStateDriver != nil { return nil, core.Errorf("statedriver instance already exists.") } driver, err := initHelper(stateDriverRegistry, name) if err != nil { return nil, err } d := driver.(core.StateDriver) err = d.Init(instInfo) if err != nil { return nil, err } gStateDriver = d return d, nil }
go
func NewStateDriver(name string, instInfo *core.InstanceInfo) (core.StateDriver, error) { if name == "" || instInfo == nil { return nil, core.Errorf("invalid driver name or configuration passed.") } if gStateDriver != nil { return nil, core.Errorf("statedriver instance already exists.") } driver, err := initHelper(stateDriverRegistry, name) if err != nil { return nil, err } d := driver.(core.StateDriver) err = d.Init(instInfo) if err != nil { return nil, err } gStateDriver = d return d, nil }
[ "func", "NewStateDriver", "(", "name", "string", ",", "instInfo", "*", "core", ".", "InstanceInfo", ")", "(", "core", ".", "StateDriver", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "||", "instInfo", "==", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "gStateDriver", "!=", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "driver", ",", "err", ":=", "initHelper", "(", "stateDriverRegistry", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "d", ":=", "driver", ".", "(", "core", ".", "StateDriver", ")", "\n", "err", "=", "d", ".", "Init", "(", "instInfo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "gStateDriver", "=", "d", "\n", "return", "d", ",", "nil", "\n", "}" ]
// NewStateDriver instantiates a 'named' state-driver with specified configuration
[ "NewStateDriver", "instantiates", "a", "named", "state", "-", "driver", "with", "specified", "configuration" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/driverfactory.go#L82-L104
7,948
contiv/netplugin
utils/driverfactory.go
GetStateDriver
func GetStateDriver() (core.StateDriver, error) { if gStateDriver == nil { return nil, core.Errorf("statedriver has not been not created.") } return gStateDriver, nil }
go
func GetStateDriver() (core.StateDriver, error) { if gStateDriver == nil { return nil, core.Errorf("statedriver has not been not created.") } return gStateDriver, nil }
[ "func", "GetStateDriver", "(", ")", "(", "core", ".", "StateDriver", ",", "error", ")", "{", "if", "gStateDriver", "==", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "gStateDriver", ",", "nil", "\n", "}" ]
// GetStateDriver returns the singleton instance of the state-driver
[ "GetStateDriver", "returns", "the", "singleton", "instance", "of", "the", "state", "-", "driver" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/driverfactory.go#L107-L113
7,949
contiv/netplugin
utils/driverfactory.go
NewNetworkDriver
func NewNetworkDriver(name string, instInfo *core.InstanceInfo) (core.NetworkDriver, error) { if name == "" || instInfo == nil { return nil, core.Errorf("invalid driver name or configuration passed.") } driver, err := initHelper(networkDriverRegistry, name) if err != nil { return nil, err } d := driver.(core.NetworkDriver) err = d.Init(instInfo) if err != nil { return nil, err } return d, nil }
go
func NewNetworkDriver(name string, instInfo *core.InstanceInfo) (core.NetworkDriver, error) { if name == "" || instInfo == nil { return nil, core.Errorf("invalid driver name or configuration passed.") } driver, err := initHelper(networkDriverRegistry, name) if err != nil { return nil, err } d := driver.(core.NetworkDriver) err = d.Init(instInfo) if err != nil { return nil, err } return d, nil }
[ "func", "NewNetworkDriver", "(", "name", "string", ",", "instInfo", "*", "core", ".", "InstanceInfo", ")", "(", "core", ".", "NetworkDriver", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "||", "instInfo", "==", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "driver", ",", "err", ":=", "initHelper", "(", "networkDriverRegistry", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "d", ":=", "driver", ".", "(", "core", ".", "NetworkDriver", ")", "\n", "err", "=", "d", ".", "Init", "(", "instInfo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "d", ",", "nil", "\n", "}" ]
// NewNetworkDriver instantiates a 'named' network-driver with specified configuration
[ "NewNetworkDriver", "instantiates", "a", "named", "network", "-", "driver", "with", "specified", "configuration" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/driverfactory.go#L124-L141
7,950
contiv/netplugin
utils/configs.go
BuildNetworkFlags
func BuildNetworkFlags(binary string) []cli.Flag { binUpper := strings.ToUpper(binary) binLower := strings.ToLower(binary) return []cli.Flag{ cli.StringFlag{ Name: "mode, plugin-mode, cluster-mode", EnvVar: fmt.Sprintf("CONTIV_%s_MODE", binUpper), Usage: fmt.Sprintf("set %s mode, options: [docker, kubernetes, swarm-mode]", binLower), }, cli.StringFlag{ Name: "netmode, network-mode", EnvVar: fmt.Sprintf("CONTIV_%s_NET_MODE", binUpper), Usage: fmt.Sprintf("set %s network mode, options: [vlan, vxlan]", binLower), }, cli.StringFlag{ Name: "fwdmode, forward-mode", EnvVar: fmt.Sprintf("CONTIV_%s_FORWARD_MODE", binUpper), Usage: fmt.Sprintf("set %s forwarding network mode, options: [bridge, routing]", binLower), }, /* // only ovs is supported // TODO: turn it on when having more than one backend supported cli.StringFlag { Name: "driver, net-driver", Value: "ovs", EnvVar: "CONTIV_NETPLUGIN_DRIVER", Usage: "set netplugin key-value store url, options: [ovs, vpp]", } */ } }
go
func BuildNetworkFlags(binary string) []cli.Flag { binUpper := strings.ToUpper(binary) binLower := strings.ToLower(binary) return []cli.Flag{ cli.StringFlag{ Name: "mode, plugin-mode, cluster-mode", EnvVar: fmt.Sprintf("CONTIV_%s_MODE", binUpper), Usage: fmt.Sprintf("set %s mode, options: [docker, kubernetes, swarm-mode]", binLower), }, cli.StringFlag{ Name: "netmode, network-mode", EnvVar: fmt.Sprintf("CONTIV_%s_NET_MODE", binUpper), Usage: fmt.Sprintf("set %s network mode, options: [vlan, vxlan]", binLower), }, cli.StringFlag{ Name: "fwdmode, forward-mode", EnvVar: fmt.Sprintf("CONTIV_%s_FORWARD_MODE", binUpper), Usage: fmt.Sprintf("set %s forwarding network mode, options: [bridge, routing]", binLower), }, /* // only ovs is supported // TODO: turn it on when having more than one backend supported cli.StringFlag { Name: "driver, net-driver", Value: "ovs", EnvVar: "CONTIV_NETPLUGIN_DRIVER", Usage: "set netplugin key-value store url, options: [ovs, vpp]", } */ } }
[ "func", "BuildNetworkFlags", "(", "binary", "string", ")", "[", "]", "cli", ".", "Flag", "{", "binUpper", ":=", "strings", ".", "ToUpper", "(", "binary", ")", "\n", "binLower", ":=", "strings", ".", "ToLower", "(", "binary", ")", "\n", "return", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "/*\n\t\t\t// only ovs is supported\n\t\t\t// TODO: turn it on when having more than one backend supported\n\t\t\tcli.StringFlag {\n\t\t\t\tName: \"driver, net-driver\",\n\t\t\t\tValue: \"ovs\",\n\t\t\t\tEnvVar: \"CONTIV_NETPLUGIN_DRIVER\",\n\t\t\t\tUsage: \"set netplugin key-value store url, options: [ovs, vpp]\",\n\t\t\t}\n\t\t*/", "}", "\n", "}" ]
// BuildNetworkFlags CLI networking flags for given binary
[ "BuildNetworkFlags", "CLI", "networking", "flags", "for", "given", "binary" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L16-L46
7,951
contiv/netplugin
utils/configs.go
BuildLogFlags
func BuildLogFlags(binary string) []cli.Flag { binUpper := strings.ToUpper(binary) binLower := strings.ToLower(binary) return []cli.Flag{ cli.StringFlag{ Name: "log-level", Value: "INFO", EnvVar: fmt.Sprintf("CONTIV_%s_LOG_LEVEL", binUpper), Usage: fmt.Sprintf("set %s log level, options: [DEBUG, INFO, WARN, ERROR]", binLower), }, cli.BoolFlag{ Name: "use-json-log, json-log", EnvVar: fmt.Sprintf("CONTIV_%s_USE_JSON_LOG", binUpper), Usage: fmt.Sprintf("set %s log format to json if this flag is provided", binLower), }, cli.BoolFlag{ Name: "use-syslog, syslog", EnvVar: fmt.Sprintf("CONTIV_%s_USE_SYSLOG", binUpper), Usage: fmt.Sprintf("set %s send log to syslog if this flag is provided", binLower), }, cli.StringFlag{ Name: "syslog-url", Value: "udp://127.0.0.1:514", EnvVar: fmt.Sprintf("CONTIV_%s_SYSLOG_URL", binUpper), Usage: fmt.Sprintf("set %s syslog url in format protocol://ip:port", binLower), }, } }
go
func BuildLogFlags(binary string) []cli.Flag { binUpper := strings.ToUpper(binary) binLower := strings.ToLower(binary) return []cli.Flag{ cli.StringFlag{ Name: "log-level", Value: "INFO", EnvVar: fmt.Sprintf("CONTIV_%s_LOG_LEVEL", binUpper), Usage: fmt.Sprintf("set %s log level, options: [DEBUG, INFO, WARN, ERROR]", binLower), }, cli.BoolFlag{ Name: "use-json-log, json-log", EnvVar: fmt.Sprintf("CONTIV_%s_USE_JSON_LOG", binUpper), Usage: fmt.Sprintf("set %s log format to json if this flag is provided", binLower), }, cli.BoolFlag{ Name: "use-syslog, syslog", EnvVar: fmt.Sprintf("CONTIV_%s_USE_SYSLOG", binUpper), Usage: fmt.Sprintf("set %s send log to syslog if this flag is provided", binLower), }, cli.StringFlag{ Name: "syslog-url", Value: "udp://127.0.0.1:514", EnvVar: fmt.Sprintf("CONTIV_%s_SYSLOG_URL", binUpper), Usage: fmt.Sprintf("set %s syslog url in format protocol://ip:port", binLower), }, } }
[ "func", "BuildLogFlags", "(", "binary", "string", ")", "[", "]", "cli", ".", "Flag", "{", "binUpper", ":=", "strings", ".", "ToUpper", "(", "binary", ")", "\n", "binLower", ":=", "strings", ".", "ToLower", "(", "binary", ")", "\n", "return", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Value", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Value", ":", "\"", "\"", ",", "EnvVar", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binUpper", ")", ",", "Usage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "binLower", ")", ",", "}", ",", "}", "\n", "}" ]
// BuildLogFlags CLI logging flags for given binary
[ "BuildLogFlags", "CLI", "logging", "flags", "for", "given", "binary" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L80-L107
7,952
contiv/netplugin
utils/configs.go
InitLogging
func InitLogging(binary string, ctx *cli.Context) error { logLevel, err := logrus.ParseLevel(ctx.String("log-level")) if err != nil { return err } logrus.SetLevel(logLevel) logrus.Infof("Using %v log level: %v", binary, logLevel) if ctx.Bool("use-syslog") { syslogURL := ctx.String("syslog-url") if err := configureSyslog(binary, logLevel, syslogURL); err != nil { return err } logrus.Infof("Using %v syslog config: %v", binary, syslogURL) } else { logrus.Infof("Using %v syslog config: nil", binary) } if ctx.Bool("use-json-log") { logrus.SetFormatter(&logrus.JSONFormatter{}) logrus.Infof("Using %v log format: json", binary) } else { logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, TimestampFormat: time.StampNano}) logrus.Infof("Using %v log format: text", binary) } return nil }
go
func InitLogging(binary string, ctx *cli.Context) error { logLevel, err := logrus.ParseLevel(ctx.String("log-level")) if err != nil { return err } logrus.SetLevel(logLevel) logrus.Infof("Using %v log level: %v", binary, logLevel) if ctx.Bool("use-syslog") { syslogURL := ctx.String("syslog-url") if err := configureSyslog(binary, logLevel, syslogURL); err != nil { return err } logrus.Infof("Using %v syslog config: %v", binary, syslogURL) } else { logrus.Infof("Using %v syslog config: nil", binary) } if ctx.Bool("use-json-log") { logrus.SetFormatter(&logrus.JSONFormatter{}) logrus.Infof("Using %v log format: json", binary) } else { logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, TimestampFormat: time.StampNano}) logrus.Infof("Using %v log format: text", binary) } return nil }
[ "func", "InitLogging", "(", "binary", "string", ",", "ctx", "*", "cli", ".", "Context", ")", "error", "{", "logLevel", ",", "err", ":=", "logrus", ".", "ParseLevel", "(", "ctx", ".", "String", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "logrus", ".", "SetLevel", "(", "logLevel", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "logLevel", ")", "\n\n", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "syslogURL", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "configureSyslog", "(", "binary", ",", "logLevel", ",", "syslogURL", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "syslogURL", ")", "\n", "}", "else", "{", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ")", "\n", "}", "\n\n", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "logrus", ".", "SetFormatter", "(", "&", "logrus", ".", "JSONFormatter", "{", "}", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ")", "\n", "}", "else", "{", "logrus", ".", "SetFormatter", "(", "&", "logrus", ".", "TextFormatter", "{", "FullTimestamp", ":", "true", ",", "TimestampFormat", ":", "time", ".", "StampNano", "}", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// InitLogging initiates logging from CLI options
[ "InitLogging", "initiates", "logging", "from", "CLI", "options" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L149-L175
7,953
contiv/netplugin
utils/configs.go
ValidateDBOptions
func ValidateDBOptions(binary string, ctx *cli.Context) (*DBConfigs, error) { var storeDriver string var storeURL string var storeURLs string etcdURLs := ctx.String("etcd") consulURLs := ctx.String("consul") if etcdURLs != "" && consulURLs != "" { return nil, fmt.Errorf("ambiguous %s db endpoints, both etcd and consul specified: etcd: %s, consul: %s", binary, etcdURLs, consulURLs) } else if etcdURLs == "" && consulURLs == "" { // if neither etcd or consul is set, try etcd at http://127.0.0.1:2379 storeDriver = "etcd" storeURLs = "http://127.0.0.1:2379" } else if etcdURLs != "" { storeDriver = "etcd" storeURLs = etcdURLs } else { storeDriver = "consul" storeURLs = consulURLs } for _, endpoint := range FilterEmpty(strings.Split(storeURLs, ",")) { _, err := url.Parse(endpoint) if err != nil { return nil, fmt.Errorf("invalid %s %v endpoint: %v", binary, storeDriver, endpoint) } // TODO: support multi-endpoints storeURL = endpoint logrus.Infof("Using %s state db endpoints: %v: %v", binary, storeDriver, storeURL) break } if storeURL == "" { return nil, fmt.Errorf("invalid %s %s endpoints: empty", binary, storeDriver) } return &DBConfigs{ StoreDriver: storeDriver, StoreURL: storeURL, }, nil }
go
func ValidateDBOptions(binary string, ctx *cli.Context) (*DBConfigs, error) { var storeDriver string var storeURL string var storeURLs string etcdURLs := ctx.String("etcd") consulURLs := ctx.String("consul") if etcdURLs != "" && consulURLs != "" { return nil, fmt.Errorf("ambiguous %s db endpoints, both etcd and consul specified: etcd: %s, consul: %s", binary, etcdURLs, consulURLs) } else if etcdURLs == "" && consulURLs == "" { // if neither etcd or consul is set, try etcd at http://127.0.0.1:2379 storeDriver = "etcd" storeURLs = "http://127.0.0.1:2379" } else if etcdURLs != "" { storeDriver = "etcd" storeURLs = etcdURLs } else { storeDriver = "consul" storeURLs = consulURLs } for _, endpoint := range FilterEmpty(strings.Split(storeURLs, ",")) { _, err := url.Parse(endpoint) if err != nil { return nil, fmt.Errorf("invalid %s %v endpoint: %v", binary, storeDriver, endpoint) } // TODO: support multi-endpoints storeURL = endpoint logrus.Infof("Using %s state db endpoints: %v: %v", binary, storeDriver, storeURL) break } if storeURL == "" { return nil, fmt.Errorf("invalid %s %s endpoints: empty", binary, storeDriver) } return &DBConfigs{ StoreDriver: storeDriver, StoreURL: storeURL, }, nil }
[ "func", "ValidateDBOptions", "(", "binary", "string", ",", "ctx", "*", "cli", ".", "Context", ")", "(", "*", "DBConfigs", ",", "error", ")", "{", "var", "storeDriver", "string", "\n", "var", "storeURL", "string", "\n", "var", "storeURLs", "string", "\n", "etcdURLs", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "consulURLs", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n\n", "if", "etcdURLs", "!=", "\"", "\"", "&&", "consulURLs", "!=", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "etcdURLs", ",", "consulURLs", ")", "\n", "}", "else", "if", "etcdURLs", "==", "\"", "\"", "&&", "consulURLs", "==", "\"", "\"", "{", "// if neither etcd or consul is set, try etcd at http://127.0.0.1:2379", "storeDriver", "=", "\"", "\"", "\n", "storeURLs", "=", "\"", "\"", "\n", "}", "else", "if", "etcdURLs", "!=", "\"", "\"", "{", "storeDriver", "=", "\"", "\"", "\n", "storeURLs", "=", "etcdURLs", "\n", "}", "else", "{", "storeDriver", "=", "\"", "\"", "\n", "storeURLs", "=", "consulURLs", "\n", "}", "\n", "for", "_", ",", "endpoint", ":=", "range", "FilterEmpty", "(", "strings", ".", "Split", "(", "storeURLs", ",", "\"", "\"", ")", ")", "{", "_", ",", "err", ":=", "url", ".", "Parse", "(", "endpoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "storeDriver", ",", "endpoint", ")", "\n", "}", "\n", "// TODO: support multi-endpoints", "storeURL", "=", "endpoint", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "storeDriver", ",", "storeURL", ")", "\n", "break", "\n", "}", "\n\n", "if", "storeURL", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "storeDriver", ")", "\n", "}", "\n\n", "return", "&", "DBConfigs", "{", "StoreDriver", ":", "storeDriver", ",", "StoreURL", ":", "storeURL", ",", "}", ",", "nil", "\n", "}" ]
// ValidateDBOptions returns error if db options are not valid
[ "ValidateDBOptions", "returns", "error", "if", "db", "options", "are", "not", "valid" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L178-L217
7,954
contiv/netplugin
utils/configs.go
ValidateNetworkOptions
func ValidateNetworkOptions(binary string, ctx *cli.Context) (*NetworkConfigs, error) { // 1. validate and set plugin mode pluginMode := strings.ToLower(ctx.String("mode")) switch pluginMode { case core.Docker, core.Kubernetes, core.SwarmMode, core.Test: logrus.Infof("Using %s mode: %v", binary, pluginMode) case "": return nil, fmt.Errorf("%s mode is not set", binary) default: return nil, fmt.Errorf("unknown %s mode: %v", binary, pluginMode) } // 2. validate and set network mode networkMode := strings.ToLower(ctx.String("netmode")) switch networkMode { case "vlan", "vxlan": logrus.Infof("Using %s network mode: %v", binary, networkMode) case "": return nil, fmt.Errorf("%s network mode is not set", binary) default: return nil, fmt.Errorf("unknown %s network mode: %v", binary, networkMode) } // 3. validate forwarding mode forwardMode := strings.ToLower(ctx.String("fwdmode")) if forwardMode == "" { return nil, fmt.Errorf("unknown %s forwarding mode: %v", binary, forwardMode) } else if forwardMode != "bridge" && forwardMode != "routing" { return nil, fmt.Errorf("%s forwarding mode is not set", binary) } else if networkMode == "vxlan" && forwardMode == "bridge" { return nil, fmt.Errorf("invalid %s forwarding mode: %q (network mode: %q)", binary, forwardMode, networkMode) } // vxlan/vlan+routing, vlan+bridge are valid combinations logrus.Infof("Using %s forwarding mode: %v", binary, forwardMode) return &NetworkConfigs{ Mode: pluginMode, NetworkMode: networkMode, ForwardMode: forwardMode, }, nil }
go
func ValidateNetworkOptions(binary string, ctx *cli.Context) (*NetworkConfigs, error) { // 1. validate and set plugin mode pluginMode := strings.ToLower(ctx.String("mode")) switch pluginMode { case core.Docker, core.Kubernetes, core.SwarmMode, core.Test: logrus.Infof("Using %s mode: %v", binary, pluginMode) case "": return nil, fmt.Errorf("%s mode is not set", binary) default: return nil, fmt.Errorf("unknown %s mode: %v", binary, pluginMode) } // 2. validate and set network mode networkMode := strings.ToLower(ctx.String("netmode")) switch networkMode { case "vlan", "vxlan": logrus.Infof("Using %s network mode: %v", binary, networkMode) case "": return nil, fmt.Errorf("%s network mode is not set", binary) default: return nil, fmt.Errorf("unknown %s network mode: %v", binary, networkMode) } // 3. validate forwarding mode forwardMode := strings.ToLower(ctx.String("fwdmode")) if forwardMode == "" { return nil, fmt.Errorf("unknown %s forwarding mode: %v", binary, forwardMode) } else if forwardMode != "bridge" && forwardMode != "routing" { return nil, fmt.Errorf("%s forwarding mode is not set", binary) } else if networkMode == "vxlan" && forwardMode == "bridge" { return nil, fmt.Errorf("invalid %s forwarding mode: %q (network mode: %q)", binary, forwardMode, networkMode) } // vxlan/vlan+routing, vlan+bridge are valid combinations logrus.Infof("Using %s forwarding mode: %v", binary, forwardMode) return &NetworkConfigs{ Mode: pluginMode, NetworkMode: networkMode, ForwardMode: forwardMode, }, nil }
[ "func", "ValidateNetworkOptions", "(", "binary", "string", ",", "ctx", "*", "cli", ".", "Context", ")", "(", "*", "NetworkConfigs", ",", "error", ")", "{", "// 1. validate and set plugin mode", "pluginMode", ":=", "strings", ".", "ToLower", "(", "ctx", ".", "String", "(", "\"", "\"", ")", ")", "\n", "switch", "pluginMode", "{", "case", "core", ".", "Docker", ",", "core", ".", "Kubernetes", ",", "core", ".", "SwarmMode", ",", "core", ".", "Test", ":", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "pluginMode", ")", "\n", "case", "\"", "\"", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "pluginMode", ")", "\n", "}", "\n\n", "// 2. validate and set network mode", "networkMode", ":=", "strings", ".", "ToLower", "(", "ctx", ".", "String", "(", "\"", "\"", ")", ")", "\n", "switch", "networkMode", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "networkMode", ")", "\n", "case", "\"", "\"", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "networkMode", ")", "\n", "}", "\n\n", "// 3. validate forwarding mode", "forwardMode", ":=", "strings", ".", "ToLower", "(", "ctx", ".", "String", "(", "\"", "\"", ")", ")", "\n", "if", "forwardMode", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "forwardMode", ")", "\n", "}", "else", "if", "forwardMode", "!=", "\"", "\"", "&&", "forwardMode", "!=", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ")", "\n", "}", "else", "if", "networkMode", "==", "\"", "\"", "&&", "forwardMode", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "binary", ",", "forwardMode", ",", "networkMode", ")", "\n", "}", "\n", "// vxlan/vlan+routing, vlan+bridge are valid combinations", "logrus", ".", "Infof", "(", "\"", "\"", ",", "binary", ",", "forwardMode", ")", "\n", "return", "&", "NetworkConfigs", "{", "Mode", ":", "pluginMode", ",", "NetworkMode", ":", "networkMode", ",", "ForwardMode", ":", "forwardMode", ",", "}", ",", "nil", "\n", "}" ]
// ValidateNetworkOptions returns error if network options are not valid
[ "ValidateNetworkOptions", "returns", "error", "if", "network", "options", "are", "not", "valid" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L220-L259
7,955
contiv/netplugin
utils/configs.go
FlattenFlags
func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag { var flags []cli.Flag for _, slice := range flagSlices { flags = append(flags, slice...) } return flags }
go
func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag { var flags []cli.Flag for _, slice := range flagSlices { flags = append(flags, slice...) } return flags }
[ "func", "FlattenFlags", "(", "flagSlices", "...", "[", "]", "cli", ".", "Flag", ")", "[", "]", "cli", ".", "Flag", "{", "var", "flags", "[", "]", "cli", ".", "Flag", "\n", "for", "_", ",", "slice", ":=", "range", "flagSlices", "{", "flags", "=", "append", "(", "flags", ",", "slice", "...", ")", "\n", "}", "\n", "return", "flags", "\n", "}" ]
// FlattenFlags concatenate slices of flags into one slice
[ "FlattenFlags", "concatenate", "slices", "of", "flags", "into", "one", "slice" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L262-L268
7,956
contiv/netplugin
utils/configs.go
FilterEmpty
func FilterEmpty(stringSlice []string) []string { var result []string for _, str := range stringSlice { if str != "" { result = append(result, str) } } return result }
go
func FilterEmpty(stringSlice []string) []string { var result []string for _, str := range stringSlice { if str != "" { result = append(result, str) } } return result }
[ "func", "FilterEmpty", "(", "stringSlice", "[", "]", "string", ")", "[", "]", "string", "{", "var", "result", "[", "]", "string", "\n", "for", "_", ",", "str", ":=", "range", "stringSlice", "{", "if", "str", "!=", "\"", "\"", "{", "result", "=", "append", "(", "result", ",", "str", ")", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// FilterEmpty filters empty string from string slices
[ "FilterEmpty", "filters", "empty", "string", "from", "string", "slices" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/configs.go#L271-L279
7,957
contiv/netplugin
utils/sysutils.go
FetchSysAttrs
func FetchSysAttrs() error { output, err := ioutil.ReadFile("/etc/os-release") if err != nil { log.Errorf("Error reading the /etc/os-release Error: %s Output: \n%s\n", err, output) return err } strOutput := string(output) if strings.Contains(strOutput, "CentOS") { SysAttrs.OsType = "centos" } else if strings.Contains(strOutput, "Ubuntu") { SysAttrs.OsType = "ubuntu" } else { SysAttrs.OsType = "unsupported" } // fetch the system memory, disk, and other attributes return err }
go
func FetchSysAttrs() error { output, err := ioutil.ReadFile("/etc/os-release") if err != nil { log.Errorf("Error reading the /etc/os-release Error: %s Output: \n%s\n", err, output) return err } strOutput := string(output) if strings.Contains(strOutput, "CentOS") { SysAttrs.OsType = "centos" } else if strings.Contains(strOutput, "Ubuntu") { SysAttrs.OsType = "ubuntu" } else { SysAttrs.OsType = "unsupported" } // fetch the system memory, disk, and other attributes return err }
[ "func", "FetchSysAttrs", "(", ")", "error", "{", "output", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\\n", "\\n", "\"", ",", "err", ",", "output", ")", "\n", "return", "err", "\n", "}", "\n\n", "strOutput", ":=", "string", "(", "output", ")", "\n", "if", "strings", ".", "Contains", "(", "strOutput", ",", "\"", "\"", ")", "{", "SysAttrs", ".", "OsType", "=", "\"", "\"", "\n", "}", "else", "if", "strings", ".", "Contains", "(", "strOutput", ",", "\"", "\"", ")", "{", "SysAttrs", ".", "OsType", "=", "\"", "\"", "\n", "}", "else", "{", "SysAttrs", ".", "OsType", "=", "\"", "\"", "\n", "}", "\n\n", "// fetch the system memory, disk, and other attributes", "return", "err", "\n", "}" ]
// FetchSysAttrs would read the system attributes and store them in the // exported vars for the plugin to use; some of the attributes may need OS // spefici methods to fetch, thus the first attribute to fetch is the OS type
[ "FetchSysAttrs", "would", "read", "the", "system", "attributes", "and", "store", "them", "in", "the", "exported", "vars", "for", "the", "plugin", "to", "use", ";", "some", "of", "the", "attributes", "may", "need", "OS", "spefici", "methods", "to", "fetch", "thus", "the", "first", "attribute", "to", "fetch", "is", "the", "OS", "type" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/sysutils.go#L46-L64
7,958
contiv/netplugin
drivers/ovsd/nodeProxy.go
NewNodeProxy
func NewNodeProxy() (*NodeSvcProxy, error) { ipTablesPath, err := osexec.LookPath("iptables") if err != nil { return nil, err } // Install contiv chain and jump out, err := osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-N", contivNPChain).CombinedOutput() if err != nil { if !strings.Contains(string(out), "Chain already exists") { log.Errorf("Failed to setup contiv nodeport chain %v out: %s", err, out) return nil, err } } _, err = osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-C", "PREROUTING", "-m", "addrtype", "--dst-type", "LOCAL", "-j", contivNPChain).CombinedOutput() if err != nil { out, err = osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-I", "PREROUTING", "-m", "addrtype", "--dst-type", "LOCAL", "-j", contivNPChain).CombinedOutput() if err != nil { log.Errorf("Failed to setup contiv nodeport chain jump %v out: %s", err, out) return nil, err } } // Flush any old rules we might have added. They will get re-added // if the service is still active osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-F", contivNPChain).CombinedOutput() proxy := NodeSvcProxy{} proxy.SvcMap = make(map[string]core.ServiceSpec) proxy.ProvMap = make(map[string]Presence) proxy.LocalIP = make(map[string]string) proxy.ipTablesPath = ipTablesPath proxy.natRules = make(map[string][]string) return &proxy, nil }
go
func NewNodeProxy() (*NodeSvcProxy, error) { ipTablesPath, err := osexec.LookPath("iptables") if err != nil { return nil, err } // Install contiv chain and jump out, err := osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-N", contivNPChain).CombinedOutput() if err != nil { if !strings.Contains(string(out), "Chain already exists") { log.Errorf("Failed to setup contiv nodeport chain %v out: %s", err, out) return nil, err } } _, err = osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-C", "PREROUTING", "-m", "addrtype", "--dst-type", "LOCAL", "-j", contivNPChain).CombinedOutput() if err != nil { out, err = osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-I", "PREROUTING", "-m", "addrtype", "--dst-type", "LOCAL", "-j", contivNPChain).CombinedOutput() if err != nil { log.Errorf("Failed to setup contiv nodeport chain jump %v out: %s", err, out) return nil, err } } // Flush any old rules we might have added. They will get re-added // if the service is still active osexec.Command(ipTablesPath, "-w", iptablesWaitLock, "-t", "nat", "-F", contivNPChain).CombinedOutput() proxy := NodeSvcProxy{} proxy.SvcMap = make(map[string]core.ServiceSpec) proxy.ProvMap = make(map[string]Presence) proxy.LocalIP = make(map[string]string) proxy.ipTablesPath = ipTablesPath proxy.natRules = make(map[string][]string) return &proxy, nil }
[ "func", "NewNodeProxy", "(", ")", "(", "*", "NodeSvcProxy", ",", "error", ")", "{", "ipTablesPath", ",", "err", ":=", "osexec", ".", "LookPath", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Install contiv chain and jump", "out", ",", "err", ":=", "osexec", ".", "Command", "(", "ipTablesPath", ",", "\"", "\"", ",", "iptablesWaitLock", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "contivNPChain", ")", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "strings", ".", "Contains", "(", "string", "(", "out", ")", ",", "\"", "\"", ")", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "out", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "_", ",", "err", "=", "osexec", ".", "Command", "(", "ipTablesPath", ",", "\"", "\"", ",", "iptablesWaitLock", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "contivNPChain", ")", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "out", ",", "err", "=", "osexec", ".", "Command", "(", "ipTablesPath", ",", "\"", "\"", ",", "iptablesWaitLock", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "contivNPChain", ")", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "out", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "// Flush any old rules we might have added. They will get re-added", "// if the service is still active", "osexec", ".", "Command", "(", "ipTablesPath", ",", "\"", "\"", ",", "iptablesWaitLock", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "contivNPChain", ")", ".", "CombinedOutput", "(", ")", "\n\n", "proxy", ":=", "NodeSvcProxy", "{", "}", "\n", "proxy", ".", "SvcMap", "=", "make", "(", "map", "[", "string", "]", "core", ".", "ServiceSpec", ")", "\n", "proxy", ".", "ProvMap", "=", "make", "(", "map", "[", "string", "]", "Presence", ")", "\n", "proxy", ".", "LocalIP", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "proxy", ".", "ipTablesPath", "=", "ipTablesPath", "\n", "proxy", ".", "natRules", "=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "return", "&", "proxy", ",", "nil", "\n", "}" ]
// NewNodeProxy creates an instance of the node proxy
[ "NewNodeProxy", "creates", "an", "instance", "of", "the", "node", "proxy" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/nodeProxy.go#L49-L92
7,959
contiv/netplugin
drivers/ovsd/nodeProxy.go
DeleteLocalIP
func (p *NodeSvcProxy) DeleteLocalIP(globalIP string) { // strip cidr globalIP = strings.Split(globalIP, "/")[0] p.Mutex.Lock() defer p.Mutex.Unlock() delete(p.LocalIP, globalIP) }
go
func (p *NodeSvcProxy) DeleteLocalIP(globalIP string) { // strip cidr globalIP = strings.Split(globalIP, "/")[0] p.Mutex.Lock() defer p.Mutex.Unlock() delete(p.LocalIP, globalIP) }
[ "func", "(", "p", "*", "NodeSvcProxy", ")", "DeleteLocalIP", "(", "globalIP", "string", ")", "{", "// strip cidr", "globalIP", "=", "strings", ".", "Split", "(", "globalIP", ",", "\"", "\"", ")", "[", "0", "]", "\n", "p", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "delete", "(", "p", ".", "LocalIP", ",", "globalIP", ")", "\n", "}" ]
// DeleteLocalIP removes an entry from the localIP map
[ "DeleteLocalIP", "removes", "an", "entry", "from", "the", "localIP", "map" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/nodeProxy.go#L95-L101
7,960
contiv/netplugin
drivers/ovsd/nodeProxy.go
AddLocalIP
func (p *NodeSvcProxy) AddLocalIP(globalIP, localIP string) { // strip cidr globalIP = strings.Split(globalIP, "/")[0] localIP = strings.Split(localIP, "/")[0] p.Mutex.Lock() defer p.Mutex.Unlock() p.LocalIP[globalIP] = localIP }
go
func (p *NodeSvcProxy) AddLocalIP(globalIP, localIP string) { // strip cidr globalIP = strings.Split(globalIP, "/")[0] localIP = strings.Split(localIP, "/")[0] p.Mutex.Lock() defer p.Mutex.Unlock() p.LocalIP[globalIP] = localIP }
[ "func", "(", "p", "*", "NodeSvcProxy", ")", "AddLocalIP", "(", "globalIP", ",", "localIP", "string", ")", "{", "// strip cidr", "globalIP", "=", "strings", ".", "Split", "(", "globalIP", ",", "\"", "\"", ")", "[", "0", "]", "\n", "localIP", "=", "strings", ".", "Split", "(", "localIP", ",", "\"", "\"", ")", "[", "0", "]", "\n", "p", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "p", ".", "LocalIP", "[", "globalIP", "]", "=", "localIP", "\n", "}" ]
// AddLocalIP adds an entry to the localIP map
[ "AddLocalIP", "adds", "an", "entry", "to", "the", "localIP", "map" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/nodeProxy.go#L104-L111
7,961
contiv/netplugin
drivers/ovsd/nodeProxy.go
AddSvcSpec
func (p *NodeSvcProxy) AddSvcSpec(svcName string, spec *core.ServiceSpec) error { p.Mutex.Lock() defer p.Mutex.Unlock() log.Infof("Node proxy AddSvcSpec: %s", svcName) // Determine if this is a node service isNodeSvc := false for _, port := range spec.Ports { if port.NodePort != 0 && port.Protocol == "TCP" { isNodeSvc = true if p.detectClash(svcName, port.NodePort) { return nil } } } if !isNodeSvc { p.deleteSvc(svcName) // delete it if it exists return nil } p.SvcMap[svcName] = *spec p.syncSvc(svcName) return nil }
go
func (p *NodeSvcProxy) AddSvcSpec(svcName string, spec *core.ServiceSpec) error { p.Mutex.Lock() defer p.Mutex.Unlock() log.Infof("Node proxy AddSvcSpec: %s", svcName) // Determine if this is a node service isNodeSvc := false for _, port := range spec.Ports { if port.NodePort != 0 && port.Protocol == "TCP" { isNodeSvc = true if p.detectClash(svcName, port.NodePort) { return nil } } } if !isNodeSvc { p.deleteSvc(svcName) // delete it if it exists return nil } p.SvcMap[svcName] = *spec p.syncSvc(svcName) return nil }
[ "func", "(", "p", "*", "NodeSvcProxy", ")", "AddSvcSpec", "(", "svcName", "string", ",", "spec", "*", "core", ".", "ServiceSpec", ")", "error", "{", "p", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "svcName", ")", "\n", "// Determine if this is a node service", "isNodeSvc", ":=", "false", "\n", "for", "_", ",", "port", ":=", "range", "spec", ".", "Ports", "{", "if", "port", ".", "NodePort", "!=", "0", "&&", "port", ".", "Protocol", "==", "\"", "\"", "{", "isNodeSvc", "=", "true", "\n", "if", "p", ".", "detectClash", "(", "svcName", ",", "port", ".", "NodePort", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "!", "isNodeSvc", "{", "p", ".", "deleteSvc", "(", "svcName", ")", "// delete it if it exists", "\n", "return", "nil", "\n", "}", "\n\n", "p", ".", "SvcMap", "[", "svcName", "]", "=", "*", "spec", "\n", "p", ".", "syncSvc", "(", "svcName", ")", "\n", "return", "nil", "\n", "}" ]
// AddSvcSpec adds a service to the proxy
[ "AddSvcSpec", "adds", "a", "service", "to", "the", "proxy" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/nodeProxy.go#L133-L156
7,962
contiv/netplugin
drivers/ovsd/nodeProxy.go
DelSvcSpec
func (p *NodeSvcProxy) DelSvcSpec(svcName string, spec *core.ServiceSpec) error { p.Mutex.Lock() defer p.Mutex.Unlock() p.deleteSvc(svcName) // delete it if it exists return nil }
go
func (p *NodeSvcProxy) DelSvcSpec(svcName string, spec *core.ServiceSpec) error { p.Mutex.Lock() defer p.Mutex.Unlock() p.deleteSvc(svcName) // delete it if it exists return nil }
[ "func", "(", "p", "*", "NodeSvcProxy", ")", "DelSvcSpec", "(", "svcName", "string", ",", "spec", "*", "core", ".", "ServiceSpec", ")", "error", "{", "p", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "p", ".", "deleteSvc", "(", "svcName", ")", "// delete it if it exists", "\n", "return", "nil", "\n", "}" ]
// DelSvcSpec deletes a service from the proxy
[ "DelSvcSpec", "deletes", "a", "service", "from", "the", "proxy" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/nodeProxy.go#L159-L164
7,963
contiv/netplugin
netctl/netctl.go
readLoginCredentials
func readLoginCredentials(ctx *cli.Context) (string, string) { fmt.Print("Username: ") reader := bufio.NewReader(os.Stdin) username, err := reader.ReadString('\n') if err != nil { errExit(ctx, exitIO, err.Error(), false) } username = strings.TrimSpace(username) // ReadString includes the newline if len(username) == 0 { errExit(ctx, exitInvalid, "you must specify a username", false) } fmt.Print("Password: ") // use terminal.ReadPassword() so there's no echoing of what's typed bytePassword, err := terminal.ReadPassword(0) // fd 0 = stdin if err != nil { errExit(ctx, exitIO, err.Error(), false) } password := string(bytePassword) fmt.Println("") return username, password }
go
func readLoginCredentials(ctx *cli.Context) (string, string) { fmt.Print("Username: ") reader := bufio.NewReader(os.Stdin) username, err := reader.ReadString('\n') if err != nil { errExit(ctx, exitIO, err.Error(), false) } username = strings.TrimSpace(username) // ReadString includes the newline if len(username) == 0 { errExit(ctx, exitInvalid, "you must specify a username", false) } fmt.Print("Password: ") // use terminal.ReadPassword() so there's no echoing of what's typed bytePassword, err := terminal.ReadPassword(0) // fd 0 = stdin if err != nil { errExit(ctx, exitIO, err.Error(), false) } password := string(bytePassword) fmt.Println("") return username, password }
[ "func", "readLoginCredentials", "(", "ctx", "*", "cli", ".", "Context", ")", "(", "string", ",", "string", ")", "{", "fmt", ".", "Print", "(", "\"", "\"", ")", "\n\n", "reader", ":=", "bufio", ".", "NewReader", "(", "os", ".", "Stdin", ")", "\n", "username", ",", "err", ":=", "reader", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "errExit", "(", "ctx", ",", "exitIO", ",", "err", ".", "Error", "(", ")", ",", "false", ")", "\n", "}", "\n\n", "username", "=", "strings", ".", "TrimSpace", "(", "username", ")", "// ReadString includes the newline", "\n", "if", "len", "(", "username", ")", "==", "0", "{", "errExit", "(", "ctx", ",", "exitInvalid", ",", "\"", "\"", ",", "false", ")", "\n", "}", "\n\n", "fmt", ".", "Print", "(", "\"", "\"", ")", "\n\n", "// use terminal.ReadPassword() so there's no echoing of what's typed", "bytePassword", ",", "err", ":=", "terminal", ".", "ReadPassword", "(", "0", ")", "// fd 0 = stdin", "\n", "if", "err", "!=", "nil", "{", "errExit", "(", "ctx", ",", "exitIO", ",", "err", ".", "Error", "(", ")", ",", "false", ")", "\n", "}", "\n", "password", ":=", "string", "(", "bytePassword", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n\n", "return", "username", ",", "password", "\n", "}" ]
// readLoginCredentials prompts for a username and password and returns them. // password input is not echoed back to the user for security reasons.
[ "readLoginCredentials", "prompts", "for", "a", "username", "and", "password", "and", "returns", "them", ".", "password", "input", "is", "not", "echoed", "back", "to", "the", "user", "for", "security", "reasons", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L57-L82
7,964
contiv/netplugin
netctl/netctl.go
addBgp
func addBgp(ctx *cli.Context) { if len(ctx.Args()) < 1 { errExit(ctx, exitHelp, "Host name required", true) } hostname := ctx.Args()[0] routerip := ctx.String("router-ip") asid := ctx.String("as") neighboras := ctx.String("neighbor-as") neighbor := ctx.String("neighbor") //Error checks _, _, err := net.ParseCIDR(routerip) if err != nil { errExit(ctx, exitHelp, "Wrong CIDR format. Enter in x.x.x.x/len format", true) } ip := net.ParseIP(neighbor) if ip == nil { errExit(ctx, exitHelp, "Wrong IP format. Enter in x.x.x.x format", true) } if routerip == "" || asid == "" || neighbor == "" || neighboras == "" { errExit(ctx, exitHelp, "Missing attributes", true) } errCheck(ctx, getClient(ctx).BgpPost(&contivClient.Bgp{ As: asid, Hostname: hostname, Neighbor: neighbor, NeighborAs: neighboras, Routerip: routerip, })) }
go
func addBgp(ctx *cli.Context) { if len(ctx.Args()) < 1 { errExit(ctx, exitHelp, "Host name required", true) } hostname := ctx.Args()[0] routerip := ctx.String("router-ip") asid := ctx.String("as") neighboras := ctx.String("neighbor-as") neighbor := ctx.String("neighbor") //Error checks _, _, err := net.ParseCIDR(routerip) if err != nil { errExit(ctx, exitHelp, "Wrong CIDR format. Enter in x.x.x.x/len format", true) } ip := net.ParseIP(neighbor) if ip == nil { errExit(ctx, exitHelp, "Wrong IP format. Enter in x.x.x.x format", true) } if routerip == "" || asid == "" || neighbor == "" || neighboras == "" { errExit(ctx, exitHelp, "Missing attributes", true) } errCheck(ctx, getClient(ctx).BgpPost(&contivClient.Bgp{ As: asid, Hostname: hostname, Neighbor: neighbor, NeighborAs: neighboras, Routerip: routerip, })) }
[ "func", "addBgp", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "ctx", ".", "Args", "(", ")", ")", "<", "1", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "hostname", ":=", "ctx", ".", "Args", "(", ")", "[", "0", "]", "\n", "routerip", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "asid", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "neighboras", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "neighbor", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n\n", "//Error checks", "_", ",", "_", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "routerip", ")", "\n", "if", "err", "!=", "nil", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "ip", ":=", "net", ".", "ParseIP", "(", "neighbor", ")", "\n", "if", "ip", "==", "nil", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "if", "routerip", "==", "\"", "\"", "||", "asid", "==", "\"", "\"", "||", "neighbor", "==", "\"", "\"", "||", "neighboras", "==", "\"", "\"", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "errCheck", "(", "ctx", ",", "getClient", "(", "ctx", ")", ".", "BgpPost", "(", "&", "contivClient", ".", "Bgp", "{", "As", ":", "asid", ",", "Hostname", ":", "hostname", ",", "Neighbor", ":", "neighbor", ",", "NeighborAs", ":", "neighboras", ",", "Routerip", ":", "routerip", ",", "}", ")", ")", "\n\n", "}" ]
//addBgp is a netctl interface routine to add //bgp config
[ "addBgp", "is", "a", "netctl", "interface", "routine", "to", "add", "bgp", "config" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L850-L884
7,965
contiv/netplugin
netctl/netctl.go
deleteBgp
func deleteBgp(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Host name required", true) } hostname := ctx.Args()[0] fmt.Printf("Deleting Bgp router config: %s\n", hostname) errCheck(ctx, getClient(ctx).BgpDelete(hostname)) }
go
func deleteBgp(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Host name required", true) } hostname := ctx.Args()[0] fmt.Printf("Deleting Bgp router config: %s\n", hostname) errCheck(ctx, getClient(ctx).BgpDelete(hostname)) }
[ "func", "deleteBgp", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "ctx", ".", "Args", "(", ")", ")", "!=", "1", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "hostname", ":=", "ctx", ".", "Args", "(", ")", "[", "0", "]", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "hostname", ")", "\n\n", "errCheck", "(", "ctx", ",", "getClient", "(", "ctx", ")", ".", "BgpDelete", "(", "hostname", ")", ")", "\n", "}" ]
//deleteBgp is a netctl interface routine to delete //bgp config
[ "deleteBgp", "is", "a", "netctl", "interface", "routine", "to", "delete", "bgp", "config" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L888-L897
7,966
contiv/netplugin
netctl/netctl.go
listBgp
func listBgp(ctx *cli.Context) { if len(ctx.Args()) != 0 { errExit(ctx, exitHelp, "More arguments than required", true) } bgpList, err := getClient(ctx).BgpList() errCheck(ctx, err) if ctx.Bool("json") { dumpJSONList(ctx, bgpList) } else if ctx.Bool("quite") { bgpName := "" for _, bgp := range *bgpList { bgpName += bgp.Hostname + "\n" } os.Stdout.WriteString(bgpName) } else { writer := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0) defer writer.Flush() writer.Write([]byte("HostName\tRouterIP\tAS\tNeighbor\tNeighborAS\n")) writer.Write([]byte("---------\t--------\t-------\t--------\t-------\n")) for _, group := range *bgpList { writer.Write( []byte(fmt.Sprintf("%v\t%v\t%v\t%v\t%v\n", group.Hostname, group.Routerip, group.As, group.Neighbor, group.NeighborAs, ))) } } }
go
func listBgp(ctx *cli.Context) { if len(ctx.Args()) != 0 { errExit(ctx, exitHelp, "More arguments than required", true) } bgpList, err := getClient(ctx).BgpList() errCheck(ctx, err) if ctx.Bool("json") { dumpJSONList(ctx, bgpList) } else if ctx.Bool("quite") { bgpName := "" for _, bgp := range *bgpList { bgpName += bgp.Hostname + "\n" } os.Stdout.WriteString(bgpName) } else { writer := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0) defer writer.Flush() writer.Write([]byte("HostName\tRouterIP\tAS\tNeighbor\tNeighborAS\n")) writer.Write([]byte("---------\t--------\t-------\t--------\t-------\n")) for _, group := range *bgpList { writer.Write( []byte(fmt.Sprintf("%v\t%v\t%v\t%v\t%v\n", group.Hostname, group.Routerip, group.As, group.Neighbor, group.NeighborAs, ))) } } }
[ "func", "listBgp", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "ctx", ".", "Args", "(", ")", ")", "!=", "0", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "bgpList", ",", "err", ":=", "getClient", "(", "ctx", ")", ".", "BgpList", "(", ")", "\n", "errCheck", "(", "ctx", ",", "err", ")", "\n\n", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "dumpJSONList", "(", "ctx", ",", "bgpList", ")", "\n", "}", "else", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "bgpName", ":=", "\"", "\"", "\n", "for", "_", ",", "bgp", ":=", "range", "*", "bgpList", "{", "bgpName", "+=", "bgp", ".", "Hostname", "+", "\"", "\\n", "\"", "\n", "}", "\n", "os", ".", "Stdout", ".", "WriteString", "(", "bgpName", ")", "\n", "}", "else", "{", "writer", ":=", "tabwriter", ".", "NewWriter", "(", "os", ".", "Stdout", ",", "0", ",", "2", ",", "2", ",", "' '", ",", "0", ")", "\n", "defer", "writer", ".", "Flush", "(", ")", "\n", "writer", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\t", "\\t", "\\t", "\\t", "\\n", "\"", ")", ")", "\n", "writer", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\t", "\\t", "\\t", "\\t", "\\n", "\"", ")", ")", "\n", "for", "_", ",", "group", ":=", "range", "*", "bgpList", "{", "writer", ".", "Write", "(", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\t", "\\t", "\\t", "\\n", "\"", ",", "group", ".", "Hostname", ",", "group", ".", "Routerip", ",", "group", ".", "As", ",", "group", ".", "Neighbor", ",", "group", ".", "NeighborAs", ",", ")", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
//listBgpNeighbors is netctl interface routine to list //Bgp neighbor configs for a given host
[ "listBgpNeighbors", "is", "netctl", "interface", "routine", "to", "list", "Bgp", "neighbor", "configs", "for", "a", "given", "host" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L901-L933
7,967
contiv/netplugin
netctl/netctl.go
createServiceLB
func createServiceLB(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Service name required", true) } serviceName := ctx.Args()[0] serviceSubnet := ctx.String("network") tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } selectors := ctx.StringSlice("selector") ports := ctx.StringSlice("port") ipAddress := ctx.String("preferred-ip") service := &contivClient.ServiceLB{ ServiceName: serviceName, TenantName: tenantName, NetworkName: serviceSubnet, IpAddress: ipAddress, } service.Selectors = append(service.Selectors, selectors...) service.Ports = append(service.Ports, ports...) errCheck(ctx, getClient(ctx).ServiceLBPost(service)) fmt.Printf("Creating ServiceLB %s:%s\n", tenantName, serviceName) }
go
func createServiceLB(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Service name required", true) } serviceName := ctx.Args()[0] serviceSubnet := ctx.String("network") tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } selectors := ctx.StringSlice("selector") ports := ctx.StringSlice("port") ipAddress := ctx.String("preferred-ip") service := &contivClient.ServiceLB{ ServiceName: serviceName, TenantName: tenantName, NetworkName: serviceSubnet, IpAddress: ipAddress, } service.Selectors = append(service.Selectors, selectors...) service.Ports = append(service.Ports, ports...) errCheck(ctx, getClient(ctx).ServiceLBPost(service)) fmt.Printf("Creating ServiceLB %s:%s\n", tenantName, serviceName) }
[ "func", "createServiceLB", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "ctx", ".", "Args", "(", ")", ")", "!=", "1", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "serviceName", ":=", "ctx", ".", "Args", "(", ")", "[", "0", "]", "\n", "serviceSubnet", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "tenantName", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "if", "len", "(", "tenantName", ")", "==", "0", "{", "tenantName", "=", "\"", "\"", "\n", "}", "\n", "selectors", ":=", "ctx", ".", "StringSlice", "(", "\"", "\"", ")", "\n", "ports", ":=", "ctx", ".", "StringSlice", "(", "\"", "\"", ")", "\n", "ipAddress", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "service", ":=", "&", "contivClient", ".", "ServiceLB", "{", "ServiceName", ":", "serviceName", ",", "TenantName", ":", "tenantName", ",", "NetworkName", ":", "serviceSubnet", ",", "IpAddress", ":", "ipAddress", ",", "}", "\n", "service", ".", "Selectors", "=", "append", "(", "service", ".", "Selectors", ",", "selectors", "...", ")", "\n", "service", ".", "Ports", "=", "append", "(", "service", ".", "Ports", ",", "ports", "...", ")", "\n", "errCheck", "(", "ctx", ",", "getClient", "(", "ctx", ")", ".", "ServiceLBPost", "(", "service", ")", ")", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "tenantName", ",", "serviceName", ")", "\n", "}" ]
//createServiceLB is a netctl interface routine to delete //service object
[ "createServiceLB", "is", "a", "netctl", "interface", "routine", "to", "delete", "service", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L1254-L1279
7,968
contiv/netplugin
netctl/netctl.go
deleteServiceLB
func deleteServiceLB(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Service name required", true) } serviceName := ctx.Args()[0] tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } fmt.Printf("Deleting Service %s,%s\n", serviceName, tenantName) errCheck(ctx, getClient(ctx).ServiceLBDelete(tenantName, serviceName)) }
go
func deleteServiceLB(ctx *cli.Context) { if len(ctx.Args()) != 1 { errExit(ctx, exitHelp, "Service name required", true) } serviceName := ctx.Args()[0] tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } fmt.Printf("Deleting Service %s,%s\n", serviceName, tenantName) errCheck(ctx, getClient(ctx).ServiceLBDelete(tenantName, serviceName)) }
[ "func", "deleteServiceLB", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "ctx", ".", "Args", "(", ")", ")", "!=", "1", "{", "errExit", "(", "ctx", ",", "exitHelp", ",", "\"", "\"", ",", "true", ")", "\n", "}", "\n\n", "serviceName", ":=", "ctx", ".", "Args", "(", ")", "[", "0", "]", "\n", "tenantName", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "if", "len", "(", "tenantName", ")", "==", "0", "{", "tenantName", "=", "\"", "\"", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "serviceName", ",", "tenantName", ")", "\n\n", "errCheck", "(", "ctx", ",", "getClient", "(", "ctx", ")", ".", "ServiceLBDelete", "(", "tenantName", ",", "serviceName", ")", ")", "\n", "}" ]
//deleteServiceLB is a netctl interface routine to delete //service object
[ "deleteServiceLB", "is", "a", "netctl", "interface", "routine", "to", "delete", "service", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L1283-L1296
7,969
contiv/netplugin
netctl/netctl.go
listServiceLB
func listServiceLB(ctx *cli.Context) { tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } _, err := getClient(ctx).TenantGet(tenantName) errCheck(ctx, err) svcList, err := getClient(ctx).ServiceLBList() errCheck(ctx, err) filtered := []*contivClient.ServiceLB{} if ctx.Bool("all") { filtered = *svcList } else { for _, svc := range *svcList { if svc.TenantName == tenantName { filtered = append(filtered, svc) } } } if ctx.Bool("json") { dumpJSONList(ctx, filtered) } else if ctx.Bool("quiet") { services := "" for _, service := range filtered { services += service.ServiceName + "\n" } os.Stdout.WriteString(services) } else { writer := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0) defer writer.Flush() writer.Write([]byte("ServiceName\tTenant\tNetwork\tSelectors\n")) writer.Write([]byte("---------\t--------\t-------\t-------\n")) for _, group := range filtered { writer.Write( []byte(fmt.Sprintf("%v\t%v\t%v\t%v\t\n", group.ServiceName, group.TenantName, group.NetworkName, group.Selectors, ))) } } }
go
func listServiceLB(ctx *cli.Context) { tenantName := ctx.String("tenant") if len(tenantName) == 0 { tenantName = "default" } _, err := getClient(ctx).TenantGet(tenantName) errCheck(ctx, err) svcList, err := getClient(ctx).ServiceLBList() errCheck(ctx, err) filtered := []*contivClient.ServiceLB{} if ctx.Bool("all") { filtered = *svcList } else { for _, svc := range *svcList { if svc.TenantName == tenantName { filtered = append(filtered, svc) } } } if ctx.Bool("json") { dumpJSONList(ctx, filtered) } else if ctx.Bool("quiet") { services := "" for _, service := range filtered { services += service.ServiceName + "\n" } os.Stdout.WriteString(services) } else { writer := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0) defer writer.Flush() writer.Write([]byte("ServiceName\tTenant\tNetwork\tSelectors\n")) writer.Write([]byte("---------\t--------\t-------\t-------\n")) for _, group := range filtered { writer.Write( []byte(fmt.Sprintf("%v\t%v\t%v\t%v\t\n", group.ServiceName, group.TenantName, group.NetworkName, group.Selectors, ))) } } }
[ "func", "listServiceLB", "(", "ctx", "*", "cli", ".", "Context", ")", "{", "tenantName", ":=", "ctx", ".", "String", "(", "\"", "\"", ")", "\n", "if", "len", "(", "tenantName", ")", "==", "0", "{", "tenantName", "=", "\"", "\"", "\n", "}", "\n", "_", ",", "err", ":=", "getClient", "(", "ctx", ")", ".", "TenantGet", "(", "tenantName", ")", "\n", "errCheck", "(", "ctx", ",", "err", ")", "\n\n", "svcList", ",", "err", ":=", "getClient", "(", "ctx", ")", ".", "ServiceLBList", "(", ")", "\n", "errCheck", "(", "ctx", ",", "err", ")", "\n\n", "filtered", ":=", "[", "]", "*", "contivClient", ".", "ServiceLB", "{", "}", "\n\n", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "filtered", "=", "*", "svcList", "\n", "}", "else", "{", "for", "_", ",", "svc", ":=", "range", "*", "svcList", "{", "if", "svc", ".", "TenantName", "==", "tenantName", "{", "filtered", "=", "append", "(", "filtered", ",", "svc", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "dumpJSONList", "(", "ctx", ",", "filtered", ")", "\n", "}", "else", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "services", ":=", "\"", "\"", "\n", "for", "_", ",", "service", ":=", "range", "filtered", "{", "services", "+=", "service", ".", "ServiceName", "+", "\"", "\\n", "\"", "\n", "}", "\n", "os", ".", "Stdout", ".", "WriteString", "(", "services", ")", "\n", "}", "else", "{", "writer", ":=", "tabwriter", ".", "NewWriter", "(", "os", ".", "Stdout", ",", "0", ",", "2", ",", "2", ",", "' '", ",", "0", ")", "\n", "defer", "writer", ".", "Flush", "(", ")", "\n", "writer", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\t", "\\t", "\\t", "\\n", "\"", ")", ")", "\n", "writer", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\t", "\\t", "\\t", "\\n", "\"", ")", ")", "\n", "for", "_", ",", "group", ":=", "range", "filtered", "{", "writer", ".", "Write", "(", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\t", "\\t", "\\t", "\\n", "\"", ",", "group", ".", "ServiceName", ",", "group", ".", "TenantName", ",", "group", ".", "NetworkName", ",", "group", ".", "Selectors", ",", ")", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
//listServiceLB is a netctl interface routine to list //service object
[ "listServiceLB", "is", "a", "netctl", "interface", "routine", "to", "list", "service", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netctl/netctl.go#L1300-L1348
7,970
contiv/netplugin
objdb/consulService.go
GetService
func (cp *ConsulClient) GetService(srvName string) ([]ServiceInfo, error) { keyName := "contiv.io/service/" + srvName + "/" srvList, _, err := cp.getServiceInstances(keyName, 0) return srvList, err }
go
func (cp *ConsulClient) GetService(srvName string) ([]ServiceInfo, error) { keyName := "contiv.io/service/" + srvName + "/" srvList, _, err := cp.getServiceInstances(keyName, 0) return srvList, err }
[ "func", "(", "cp", "*", "ConsulClient", ")", "GetService", "(", "srvName", "string", ")", "(", "[", "]", "ServiceInfo", ",", "error", ")", "{", "keyName", ":=", "\"", "\"", "+", "srvName", "+", "\"", "\"", "\n", "srvList", ",", "_", ",", "err", ":=", "cp", ".", "getServiceInstances", "(", "keyName", ",", "0", ")", "\n\n", "return", "srvList", ",", "err", "\n", "}" ]
// GetService gets all instances of a service
[ "GetService", "gets", "all", "instances", "of", "a", "service" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulService.go#L137-L142
7,971
contiv/netplugin
objdb/consulService.go
WatchService
func (cp *ConsulClient) WatchService(srvName string, eventCh chan WatchServiceEvent, stopCh chan bool) error { keyName := "contiv.io/service/" + srvName + "/" // Run in background go func() { var currSrvMap = make(map[string]ServiceInfo) // Get current list of services srvList, lastIdx, err := cp.getServiceInstances(keyName, 0) if err != nil { log.Errorf("Error getting service instances for (%s): Err: %v", srvName, err) } else { // for each instance trigger an add event for _, srvInfo := range srvList { eventCh <- WatchServiceEvent{ EventType: WatchServiceEventAdd, ServiceInfo: srvInfo, } // Add the service to local cache srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) currSrvMap[srvKey] = srvInfo } } // Loop till asked to stop for { // Check if we should quit select { case <-stopCh: return default: // Read the service instances srvList, lastIdx, err = cp.getServiceInstances(keyName, lastIdx) if err != nil { if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") || strings.Contains(err.Error(), "connection refused") { log.Warnf("Consul service watch: server error: %v Retrying..", err) } else { log.Errorf("Error getting service instances for (%s): Err: %v. Exiting watch", srvName, err) } // Wait a little and continue time.Sleep(5 * time.Second) continue } else { log.Debugf("Got consul srv list: {%+v}. Curr: {%+v}", srvList, currSrvMap) var newSrvMap = make(map[string]ServiceInfo) // Check if there are any new services for _, srvInfo := range srvList { srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) // If the entry didnt exists previously, trigger add event if _, ok := currSrvMap[srvKey]; !ok { log.Debugf("Sending add event for srv: %v", srvInfo) eventCh <- WatchServiceEvent{ EventType: WatchServiceEventAdd, ServiceInfo: srvInfo, } } // create new service map newSrvMap[srvKey] = srvInfo } // for all entries in old service list, see if we need to delete any for _, srvInfo := range currSrvMap { srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) // if the entry does not exists in new list, delete it if _, ok := newSrvMap[srvKey]; !ok { log.Debugf("Sending delete event for srv: %v", srvInfo) eventCh <- WatchServiceEvent{ EventType: WatchServiceEventDel, ServiceInfo: srvInfo, } } } // set new srv map as the current currSrvMap = newSrvMap } } } }() return nil }
go
func (cp *ConsulClient) WatchService(srvName string, eventCh chan WatchServiceEvent, stopCh chan bool) error { keyName := "contiv.io/service/" + srvName + "/" // Run in background go func() { var currSrvMap = make(map[string]ServiceInfo) // Get current list of services srvList, lastIdx, err := cp.getServiceInstances(keyName, 0) if err != nil { log.Errorf("Error getting service instances for (%s): Err: %v", srvName, err) } else { // for each instance trigger an add event for _, srvInfo := range srvList { eventCh <- WatchServiceEvent{ EventType: WatchServiceEventAdd, ServiceInfo: srvInfo, } // Add the service to local cache srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) currSrvMap[srvKey] = srvInfo } } // Loop till asked to stop for { // Check if we should quit select { case <-stopCh: return default: // Read the service instances srvList, lastIdx, err = cp.getServiceInstances(keyName, lastIdx) if err != nil { if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") || strings.Contains(err.Error(), "connection refused") { log.Warnf("Consul service watch: server error: %v Retrying..", err) } else { log.Errorf("Error getting service instances for (%s): Err: %v. Exiting watch", srvName, err) } // Wait a little and continue time.Sleep(5 * time.Second) continue } else { log.Debugf("Got consul srv list: {%+v}. Curr: {%+v}", srvList, currSrvMap) var newSrvMap = make(map[string]ServiceInfo) // Check if there are any new services for _, srvInfo := range srvList { srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) // If the entry didnt exists previously, trigger add event if _, ok := currSrvMap[srvKey]; !ok { log.Debugf("Sending add event for srv: %v", srvInfo) eventCh <- WatchServiceEvent{ EventType: WatchServiceEventAdd, ServiceInfo: srvInfo, } } // create new service map newSrvMap[srvKey] = srvInfo } // for all entries in old service list, see if we need to delete any for _, srvInfo := range currSrvMap { srvKey := srvInfo.HostAddr + ":" + strconv.Itoa(srvInfo.Port) // if the entry does not exists in new list, delete it if _, ok := newSrvMap[srvKey]; !ok { log.Debugf("Sending delete event for srv: %v", srvInfo) eventCh <- WatchServiceEvent{ EventType: WatchServiceEventDel, ServiceInfo: srvInfo, } } } // set new srv map as the current currSrvMap = newSrvMap } } } }() return nil }
[ "func", "(", "cp", "*", "ConsulClient", ")", "WatchService", "(", "srvName", "string", ",", "eventCh", "chan", "WatchServiceEvent", ",", "stopCh", "chan", "bool", ")", "error", "{", "keyName", ":=", "\"", "\"", "+", "srvName", "+", "\"", "\"", "\n\n", "// Run in background", "go", "func", "(", ")", "{", "var", "currSrvMap", "=", "make", "(", "map", "[", "string", "]", "ServiceInfo", ")", "\n\n", "// Get current list of services", "srvList", ",", "lastIdx", ",", "err", ":=", "cp", ".", "getServiceInstances", "(", "keyName", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "srvName", ",", "err", ")", "\n", "}", "else", "{", "// for each instance trigger an add event", "for", "_", ",", "srvInfo", ":=", "range", "srvList", "{", "eventCh", "<-", "WatchServiceEvent", "{", "EventType", ":", "WatchServiceEventAdd", ",", "ServiceInfo", ":", "srvInfo", ",", "}", "\n\n", "// Add the service to local cache", "srvKey", ":=", "srvInfo", ".", "HostAddr", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "srvInfo", ".", "Port", ")", "\n", "currSrvMap", "[", "srvKey", "]", "=", "srvInfo", "\n", "}", "\n", "}", "\n\n", "// Loop till asked to stop", "for", "{", "// Check if we should quit", "select", "{", "case", "<-", "stopCh", ":", "return", "\n", "default", ":", "// Read the service instances", "srvList", ",", "lastIdx", ",", "err", "=", "cp", ".", "getServiceInstances", "(", "keyName", ",", "lastIdx", ")", "\n", "if", "err", "!=", "nil", "{", "if", "api", ".", "IsServerError", "(", "err", ")", "||", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "||", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "else", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "srvName", ",", "err", ")", "\n", "}", "\n\n", "// Wait a little and continue", "time", ".", "Sleep", "(", "5", "*", "time", ".", "Second", ")", "\n", "continue", "\n", "}", "else", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "srvList", ",", "currSrvMap", ")", "\n", "var", "newSrvMap", "=", "make", "(", "map", "[", "string", "]", "ServiceInfo", ")", "\n\n", "// Check if there are any new services", "for", "_", ",", "srvInfo", ":=", "range", "srvList", "{", "srvKey", ":=", "srvInfo", ".", "HostAddr", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "srvInfo", ".", "Port", ")", "\n\n", "// If the entry didnt exists previously, trigger add event", "if", "_", ",", "ok", ":=", "currSrvMap", "[", "srvKey", "]", ";", "!", "ok", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "srvInfo", ")", "\n", "eventCh", "<-", "WatchServiceEvent", "{", "EventType", ":", "WatchServiceEventAdd", ",", "ServiceInfo", ":", "srvInfo", ",", "}", "\n", "}", "\n\n", "// create new service map", "newSrvMap", "[", "srvKey", "]", "=", "srvInfo", "\n", "}", "\n\n", "// for all entries in old service list, see if we need to delete any", "for", "_", ",", "srvInfo", ":=", "range", "currSrvMap", "{", "srvKey", ":=", "srvInfo", ".", "HostAddr", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "srvInfo", ".", "Port", ")", "\n\n", "// if the entry does not exists in new list, delete it", "if", "_", ",", "ok", ":=", "newSrvMap", "[", "srvKey", "]", ";", "!", "ok", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "srvInfo", ")", "\n", "eventCh", "<-", "WatchServiceEvent", "{", "EventType", ":", "WatchServiceEventDel", ",", "ServiceInfo", ":", "srvInfo", ",", "}", "\n", "}", "\n", "}", "\n\n", "// set new srv map as the current", "currSrvMap", "=", "newSrvMap", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "return", "nil", "\n", "}" ]
// WatchService watches for service instance changes
[ "WatchService", "watches", "for", "service", "instance", "changes" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulService.go#L145-L231
7,972
contiv/netplugin
objdb/consulService.go
DeregisterService
func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error { keyName := "contiv.io/service/" + serviceInfo.ServiceName + "/" + serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port) // Find it in the database srvState := cp.serviceDb[keyName] if srvState == nil { log.Errorf("Could not find the service in db %s", keyName) return errors.New("Service not found") } log.Infof("Deregistering service key: %s, value: %+v", keyName, serviceInfo) // stop the refresh thread and delete service close(srvState.stopChan) delete(cp.serviceDb, keyName) // Delete the service instance _, err := cp.client.KV().Delete(keyName, nil) if err != nil { log.Errorf("Error deleting key %s. Err: %v", keyName, err) return err } return nil }
go
func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error { keyName := "contiv.io/service/" + serviceInfo.ServiceName + "/" + serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port) // Find it in the database srvState := cp.serviceDb[keyName] if srvState == nil { log.Errorf("Could not find the service in db %s", keyName) return errors.New("Service not found") } log.Infof("Deregistering service key: %s, value: %+v", keyName, serviceInfo) // stop the refresh thread and delete service close(srvState.stopChan) delete(cp.serviceDb, keyName) // Delete the service instance _, err := cp.client.KV().Delete(keyName, nil) if err != nil { log.Errorf("Error deleting key %s. Err: %v", keyName, err) return err } return nil }
[ "func", "(", "cp", "*", "ConsulClient", ")", "DeregisterService", "(", "serviceInfo", "ServiceInfo", ")", "error", "{", "keyName", ":=", "\"", "\"", "+", "serviceInfo", ".", "ServiceName", "+", "\"", "\"", "+", "serviceInfo", ".", "HostAddr", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "serviceInfo", ".", "Port", ")", "\n\n", "// Find it in the database", "srvState", ":=", "cp", ".", "serviceDb", "[", "keyName", "]", "\n", "if", "srvState", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyName", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "keyName", ",", "serviceInfo", ")", "\n\n", "// stop the refresh thread and delete service", "close", "(", "srvState", ".", "stopChan", ")", "\n", "delete", "(", "cp", ".", "serviceDb", ",", "keyName", ")", "\n\n", "// Delete the service instance", "_", ",", "err", ":=", "cp", ".", "client", ".", "KV", "(", ")", ".", "Delete", "(", "keyName", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "keyName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeregisterService deregisters a service instance
[ "DeregisterService", "deregisters", "a", "service", "instance" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulService.go#L234-L259
7,973
contiv/netplugin
objdb/consulService.go
getServiceInstances
func (cp *ConsulClient) getServiceInstances(key string, waitIdx uint64) ([]ServiceInfo, uint64, error) { var srvcList []ServiceInfo // Get the object from consul client kvs, meta, err := cp.client.KV().List(key, &api.QueryOptions{WaitIndex: waitIdx}) if err != nil { log.Errorf("Error getting key %s. Err: %v", key, err) return nil, 0, 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 []ServiceInfo{}, meta.LastIndex, nil } // Parse each node in the directory for _, kv := range kvs { var respSrvc ServiceInfo // Parse JSON response err = json.Unmarshal([]byte(kv.Value), &respSrvc) if err != nil { log.Errorf("Error parsing object %+v, Err %v", kv, err) return nil, 0, err } srvcList = append(srvcList, respSrvc) } return srvcList, meta.LastIndex, nil }
go
func (cp *ConsulClient) getServiceInstances(key string, waitIdx uint64) ([]ServiceInfo, uint64, error) { var srvcList []ServiceInfo // Get the object from consul client kvs, meta, err := cp.client.KV().List(key, &api.QueryOptions{WaitIndex: waitIdx}) if err != nil { log.Errorf("Error getting key %s. Err: %v", key, err) return nil, 0, 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 []ServiceInfo{}, meta.LastIndex, nil } // Parse each node in the directory for _, kv := range kvs { var respSrvc ServiceInfo // Parse JSON response err = json.Unmarshal([]byte(kv.Value), &respSrvc) if err != nil { log.Errorf("Error parsing object %+v, Err %v", kv, err) return nil, 0, err } srvcList = append(srvcList, respSrvc) } return srvcList, meta.LastIndex, nil }
[ "func", "(", "cp", "*", "ConsulClient", ")", "getServiceInstances", "(", "key", "string", ",", "waitIdx", "uint64", ")", "(", "[", "]", "ServiceInfo", ",", "uint64", ",", "error", ")", "{", "var", "srvcList", "[", "]", "ServiceInfo", "\n\n", "// Get the object from consul client", "kvs", ",", "meta", ",", "err", ":=", "cp", ".", "client", ".", "KV", "(", ")", ".", "List", "(", "key", ",", "&", "api", ".", "QueryOptions", "{", "WaitIndex", ":", "waitIdx", "}", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "err", ")", "\n", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "// Consul returns success and a nil kv when a key is not found,", "// translate it to 'Key not found' error", "if", "kvs", "==", "nil", "{", "return", "[", "]", "ServiceInfo", "{", "}", ",", "meta", ".", "LastIndex", ",", "nil", "\n", "}", "\n\n", "// Parse each node in the directory", "for", "_", ",", "kv", ":=", "range", "kvs", "{", "var", "respSrvc", "ServiceInfo", "\n", "// Parse JSON response", "err", "=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "kv", ".", "Value", ")", ",", "&", "respSrvc", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "kv", ",", "err", ")", "\n", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "srvcList", "=", "append", "(", "srvcList", ",", "respSrvc", ")", "\n", "}", "\n\n", "return", "srvcList", ",", "meta", ".", "LastIndex", ",", "nil", "\n", "}" ]
// getServiceInstances gets the current list of service instances
[ "getServiceInstances", "gets", "the", "current", "list", "of", "service", "instances" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/consulService.go#L303-L333
7,974
contiv/netplugin
netmaster/master/endpointGroup.go
DeleteEndpointGroup
func DeleteEndpointGroup(tenantName, groupName string) error { // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } epgKey := mastercfg.GetEndpointGroupKey(groupName, tenantName) epgCfg := &mastercfg.EndpointGroupState{} epgCfg.StateDriver = stateDriver err = epgCfg.Read(epgKey) if err != nil { log.Errorf("error reading EPG key %s. Error: %s", epgKey, err) return err } if epgCfg.EpCount != 0 { return core.Errorf("Error: EPG %s has active endpoints", groupName) } networkID := epgCfg.NetworkName + "." + epgCfg.TenantName nwCfg := &mastercfg.CfgNetworkState{} nwCfg.StateDriver = stateDriver err = nwCfg.Read(networkID) if err != nil { log.Errorf("Could not find network %s. Err: %v", networkID, err) return err } // Delete the endpoint group state gstate.GlobalMutex.Lock() defer gstate.GlobalMutex.Unlock() gCfg := gstate.Cfg{} gCfg.StateDriver = stateDriver err = gCfg.Read(epgCfg.TenantName) if err != nil { log.Errorf("error reading tenant cfg state. Error: %s", err) return err } // if aci mode we allocate per-epg vlan. free it here. aciMode, aErr := IsAciConfigured() if aErr != nil { return aErr } if aciMode { if epgCfg.PktTagType == "vlan" { err = gCfg.FreeVLAN(uint(epgCfg.PktTag)) if err != nil { return err } log.Debugf("Freed vlan %v\n", epgCfg.PktTag) } } // mark it as unused if len(epgCfg.IPPool) > 0 { netutils.ClearIPAddrRange(&nwCfg.IPAllocMap, epgCfg.IPPool, nwCfg.SubnetIP, nwCfg.SubnetLen) if err = nwCfg.Write(); err != nil { log.Errorf("error writing nw config after releasing subnet. Error: %v", err) return err } } // Delete endpoint group err = epgCfg.Clear() if err != nil { log.Errorf("error writing epGroup config. Error: %v", err) return err } if GetClusterMode() == core.Docker { return docknet.DeleteDockNet(epgCfg.TenantName, epgCfg.NetworkName, epgCfg.GroupName) } return nil }
go
func DeleteEndpointGroup(tenantName, groupName string) error { // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } epgKey := mastercfg.GetEndpointGroupKey(groupName, tenantName) epgCfg := &mastercfg.EndpointGroupState{} epgCfg.StateDriver = stateDriver err = epgCfg.Read(epgKey) if err != nil { log.Errorf("error reading EPG key %s. Error: %s", epgKey, err) return err } if epgCfg.EpCount != 0 { return core.Errorf("Error: EPG %s has active endpoints", groupName) } networkID := epgCfg.NetworkName + "." + epgCfg.TenantName nwCfg := &mastercfg.CfgNetworkState{} nwCfg.StateDriver = stateDriver err = nwCfg.Read(networkID) if err != nil { log.Errorf("Could not find network %s. Err: %v", networkID, err) return err } // Delete the endpoint group state gstate.GlobalMutex.Lock() defer gstate.GlobalMutex.Unlock() gCfg := gstate.Cfg{} gCfg.StateDriver = stateDriver err = gCfg.Read(epgCfg.TenantName) if err != nil { log.Errorf("error reading tenant cfg state. Error: %s", err) return err } // if aci mode we allocate per-epg vlan. free it here. aciMode, aErr := IsAciConfigured() if aErr != nil { return aErr } if aciMode { if epgCfg.PktTagType == "vlan" { err = gCfg.FreeVLAN(uint(epgCfg.PktTag)) if err != nil { return err } log.Debugf("Freed vlan %v\n", epgCfg.PktTag) } } // mark it as unused if len(epgCfg.IPPool) > 0 { netutils.ClearIPAddrRange(&nwCfg.IPAllocMap, epgCfg.IPPool, nwCfg.SubnetIP, nwCfg.SubnetLen) if err = nwCfg.Write(); err != nil { log.Errorf("error writing nw config after releasing subnet. Error: %v", err) return err } } // Delete endpoint group err = epgCfg.Clear() if err != nil { log.Errorf("error writing epGroup config. Error: %v", err) return err } if GetClusterMode() == core.Docker { return docknet.DeleteDockNet(epgCfg.TenantName, epgCfg.NetworkName, epgCfg.GroupName) } return nil }
[ "func", "DeleteEndpointGroup", "(", "tenantName", ",", "groupName", "string", ")", "error", "{", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "epgKey", ":=", "mastercfg", ".", "GetEndpointGroupKey", "(", "groupName", ",", "tenantName", ")", "\n", "epgCfg", ":=", "&", "mastercfg", ".", "EndpointGroupState", "{", "}", "\n", "epgCfg", ".", "StateDriver", "=", "stateDriver", "\n", "err", "=", "epgCfg", ".", "Read", "(", "epgKey", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgKey", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "epgCfg", ".", "EpCount", "!=", "0", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "groupName", ")", "\n", "}", "\n\n", "networkID", ":=", "epgCfg", ".", "NetworkName", "+", "\"", "\"", "+", "epgCfg", ".", "TenantName", "\n", "nwCfg", ":=", "&", "mastercfg", ".", "CfgNetworkState", "{", "}", "\n", "nwCfg", ".", "StateDriver", "=", "stateDriver", "\n", "err", "=", "nwCfg", ".", "Read", "(", "networkID", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "networkID", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Delete the endpoint group state", "gstate", ".", "GlobalMutex", ".", "Lock", "(", ")", "\n", "defer", "gstate", ".", "GlobalMutex", ".", "Unlock", "(", ")", "\n", "gCfg", ":=", "gstate", ".", "Cfg", "{", "}", "\n", "gCfg", ".", "StateDriver", "=", "stateDriver", "\n", "err", "=", "gCfg", ".", "Read", "(", "epgCfg", ".", "TenantName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// if aci mode we allocate per-epg vlan. free it here.", "aciMode", ",", "aErr", ":=", "IsAciConfigured", "(", ")", "\n", "if", "aErr", "!=", "nil", "{", "return", "aErr", "\n", "}", "\n\n", "if", "aciMode", "{", "if", "epgCfg", ".", "PktTagType", "==", "\"", "\"", "{", "err", "=", "gCfg", ".", "FreeVLAN", "(", "uint", "(", "epgCfg", ".", "PktTag", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "epgCfg", ".", "PktTag", ")", "\n", "}", "\n", "}", "\n\n", "// mark it as unused", "if", "len", "(", "epgCfg", ".", "IPPool", ")", ">", "0", "{", "netutils", ".", "ClearIPAddrRange", "(", "&", "nwCfg", ".", "IPAllocMap", ",", "epgCfg", ".", "IPPool", ",", "nwCfg", ".", "SubnetIP", ",", "nwCfg", ".", "SubnetLen", ")", "\n", "if", "err", "=", "nwCfg", ".", "Write", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Delete endpoint group", "err", "=", "epgCfg", ".", "Clear", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "GetClusterMode", "(", ")", "==", "core", ".", "Docker", "{", "return", "docknet", ".", "DeleteDockNet", "(", "epgCfg", ".", "TenantName", ",", "epgCfg", ".", "NetworkName", ",", "epgCfg", ".", "GroupName", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteEndpointGroup handles endpoint group deletes
[ "DeleteEndpointGroup", "handles", "endpoint", "group", "deletes" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpointGroup.go#L180-L256
7,975
contiv/netplugin
netmaster/master/endpointGroup.go
UpdateEndpointGroup
func UpdateEndpointGroup(bandwidth, groupName, tenantName string, Dscp, burst int) error { // Get the state driver - get the etcd driver state stateDriver, err := utils.GetStateDriver() if err != nil { return err } key := mastercfg.GetEndpointGroupKey(groupName, tenantName) if key == "" { return errors.New("error finding endpointGroup key ") } // Read etcd driver epCfg := mastercfg.EndpointGroupState{} epCfg.StateDriver = stateDriver err = epCfg.Read(key) if err != nil { log.Errorf("Error finding endpointgroup %s. Err: %v", key, err) return err } //update the epGroup state epCfg.DSCP = Dscp epCfg.Bandwidth = bandwidth epCfg.Burst = burst //Write to etcd return epCfg.Write() }
go
func UpdateEndpointGroup(bandwidth, groupName, tenantName string, Dscp, burst int) error { // Get the state driver - get the etcd driver state stateDriver, err := utils.GetStateDriver() if err != nil { return err } key := mastercfg.GetEndpointGroupKey(groupName, tenantName) if key == "" { return errors.New("error finding endpointGroup key ") } // Read etcd driver epCfg := mastercfg.EndpointGroupState{} epCfg.StateDriver = stateDriver err = epCfg.Read(key) if err != nil { log.Errorf("Error finding endpointgroup %s. Err: %v", key, err) return err } //update the epGroup state epCfg.DSCP = Dscp epCfg.Bandwidth = bandwidth epCfg.Burst = burst //Write to etcd return epCfg.Write() }
[ "func", "UpdateEndpointGroup", "(", "bandwidth", ",", "groupName", ",", "tenantName", "string", ",", "Dscp", ",", "burst", "int", ")", "error", "{", "// Get the state driver - get the etcd driver state", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "key", ":=", "mastercfg", ".", "GetEndpointGroupKey", "(", "groupName", ",", "tenantName", ")", "\n", "if", "key", "==", "\"", "\"", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Read etcd driver", "epCfg", ":=", "mastercfg", ".", "EndpointGroupState", "{", "}", "\n", "epCfg", ".", "StateDriver", "=", "stateDriver", "\n\n", "err", "=", "epCfg", ".", "Read", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "//update the epGroup state", "epCfg", ".", "DSCP", "=", "Dscp", "\n", "epCfg", ".", "Bandwidth", "=", "bandwidth", "\n", "epCfg", ".", "Burst", "=", "burst", "\n\n", "//Write to etcd", "return", "epCfg", ".", "Write", "(", ")", "\n", "}" ]
//UpdateEndpointGroup updates the endpointgroups
[ "UpdateEndpointGroup", "updates", "the", "endpointgroups" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/endpointGroup.go#L259-L289
7,976
contiv/netplugin
netmaster/master/provider.go
SvcProviderUpdate
func SvcProviderUpdate(serviceID string, isDelete bool) error { providerList := []string{} stateDriver, err := utils.GetStateDriver() if err != nil { return err } svcProvider := &mastercfg.SvcProvider{} svcProvider.StateDriver = stateDriver if _, present := mastercfg.ServiceLBDb[serviceID]; !present { svcProvider.ID = serviceID return svcProvider.Clear() } for _, provider := range mastercfg.ServiceLBDb[serviceID].Providers { providerList = append(providerList, provider.IPAddress) } //empty the current provider list svcProvider.Providers = nil //update to the latest provider list svcProvider.Providers = append(svcProvider.Providers, providerList...) svcProvider.ServiceName = serviceID svcProvider.ID = serviceID log.Infof("Updating service providers with {%v} on service %s", svcProvider.Providers, serviceID) return svcProvider.Write() }
go
func SvcProviderUpdate(serviceID string, isDelete bool) error { providerList := []string{} stateDriver, err := utils.GetStateDriver() if err != nil { return err } svcProvider := &mastercfg.SvcProvider{} svcProvider.StateDriver = stateDriver if _, present := mastercfg.ServiceLBDb[serviceID]; !present { svcProvider.ID = serviceID return svcProvider.Clear() } for _, provider := range mastercfg.ServiceLBDb[serviceID].Providers { providerList = append(providerList, provider.IPAddress) } //empty the current provider list svcProvider.Providers = nil //update to the latest provider list svcProvider.Providers = append(svcProvider.Providers, providerList...) svcProvider.ServiceName = serviceID svcProvider.ID = serviceID log.Infof("Updating service providers with {%v} on service %s", svcProvider.Providers, serviceID) return svcProvider.Write() }
[ "func", "SvcProviderUpdate", "(", "serviceID", "string", ",", "isDelete", "bool", ")", "error", "{", "providerList", ":=", "[", "]", "string", "{", "}", "\n\n", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "svcProvider", ":=", "&", "mastercfg", ".", "SvcProvider", "{", "}", "\n", "svcProvider", ".", "StateDriver", "=", "stateDriver", "\n\n", "if", "_", ",", "present", ":=", "mastercfg", ".", "ServiceLBDb", "[", "serviceID", "]", ";", "!", "present", "{", "svcProvider", ".", "ID", "=", "serviceID", "\n", "return", "svcProvider", ".", "Clear", "(", ")", "\n", "}", "\n\n", "for", "_", ",", "provider", ":=", "range", "mastercfg", ".", "ServiceLBDb", "[", "serviceID", "]", ".", "Providers", "{", "providerList", "=", "append", "(", "providerList", ",", "provider", ".", "IPAddress", ")", "\n", "}", "\n\n", "//empty the current provider list", "svcProvider", ".", "Providers", "=", "nil", "\n", "//update to the latest provider list", "svcProvider", ".", "Providers", "=", "append", "(", "svcProvider", ".", "Providers", ",", "providerList", "...", ")", "\n", "svcProvider", ".", "ServiceName", "=", "serviceID", "\n", "svcProvider", ".", "ID", "=", "serviceID", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "svcProvider", ".", "Providers", ",", "serviceID", ")", "\n\n", "return", "svcProvider", ".", "Write", "(", ")", "\n", "}" ]
//SvcProviderUpdate propagates service provider updates to netplugins
[ "SvcProviderUpdate", "propagates", "service", "provider", "updates", "to", "netplugins" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/provider.go#L25-L55
7,977
contiv/netplugin
core/error.go
ErrIfKeyExists
func ErrIfKeyExists(err error) error { if err == nil || strings.Contains(err.Error(), "key not found") { return nil } return err }
go
func ErrIfKeyExists(err error) error { if err == nil || strings.Contains(err.Error(), "key not found") { return nil } return err }
[ "func", "ErrIfKeyExists", "(", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "||", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// ErrIfKeyExists checks if the error message contains "key not found".
[ "ErrIfKeyExists", "checks", "if", "the", "error", "message", "contains", "key", "not", "found", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/core/error.go#L81-L87
7,978
contiv/netplugin
netmaster/resources/vlanresource.go
ReadAll
func (r *AutoVLANCfgResource) ReadAll() ([]core.State, error) { return r.StateDriver.ReadAllState(vLANResourceConfigPathPrefix, r, json.Unmarshal) }
go
func (r *AutoVLANCfgResource) ReadAll() ([]core.State, error) { return r.StateDriver.ReadAllState(vLANResourceConfigPathPrefix, r, json.Unmarshal) }
[ "func", "(", "r", "*", "AutoVLANCfgResource", ")", "ReadAll", "(", ")", "(", "[", "]", "core", ".", "State", ",", "error", ")", "{", "return", "r", ".", "StateDriver", ".", "ReadAllState", "(", "vLANResourceConfigPathPrefix", ",", "r", ",", "json", ".", "Unmarshal", ")", "\n", "}" ]
// ReadAll the state for this resource.
[ "ReadAll", "the", "state", "for", "this", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vlanresource.go#L69-L72
7,979
contiv/netplugin
netmaster/resources/vlanresource.go
Allocate
func (r *AutoVLANCfgResource) Allocate(reqVal interface{}) (interface{}, error) { oper := &AutoVLANOperResource{} oper.StateDriver = r.StateDriver err := oper.Read(r.ID) if err != nil { return nil, err } var vlan uint if (reqVal != nil) && (reqVal.(uint) != 0) { vlan = reqVal.(uint) if !oper.FreeVLANs.Test(vlan) { return nil, fmt.Errorf("requested vlan not available - vlan:%d", vlan) } } else { ok := false vlan, ok = oper.FreeVLANs.NextSet(0) if !ok { return nil, errors.New("no vlans available") } } oper.FreeVLANs.Clear(vlan) err = oper.Write() if err != nil { return nil, err } return vlan, nil }
go
func (r *AutoVLANCfgResource) Allocate(reqVal interface{}) (interface{}, error) { oper := &AutoVLANOperResource{} oper.StateDriver = r.StateDriver err := oper.Read(r.ID) if err != nil { return nil, err } var vlan uint if (reqVal != nil) && (reqVal.(uint) != 0) { vlan = reqVal.(uint) if !oper.FreeVLANs.Test(vlan) { return nil, fmt.Errorf("requested vlan not available - vlan:%d", vlan) } } else { ok := false vlan, ok = oper.FreeVLANs.NextSet(0) if !ok { return nil, errors.New("no vlans available") } } oper.FreeVLANs.Clear(vlan) err = oper.Write() if err != nil { return nil, err } return vlan, nil }
[ "func", "(", "r", "*", "AutoVLANCfgResource", ")", "Allocate", "(", "reqVal", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "oper", ":=", "&", "AutoVLANOperResource", "{", "}", "\n", "oper", ".", "StateDriver", "=", "r", ".", "StateDriver", "\n", "err", ":=", "oper", ".", "Read", "(", "r", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "vlan", "uint", "\n", "if", "(", "reqVal", "!=", "nil", ")", "&&", "(", "reqVal", ".", "(", "uint", ")", "!=", "0", ")", "{", "vlan", "=", "reqVal", ".", "(", "uint", ")", "\n", "if", "!", "oper", ".", "FreeVLANs", ".", "Test", "(", "vlan", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vlan", ")", "\n", "}", "\n", "}", "else", "{", "ok", ":=", "false", "\n", "vlan", ",", "ok", "=", "oper", ".", "FreeVLANs", ".", "NextSet", "(", "0", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "oper", ".", "FreeVLANs", ".", "Clear", "(", "vlan", ")", "\n\n", "err", "=", "oper", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "vlan", ",", "nil", "\n", "}" ]
// Allocate a resource.
[ "Allocate", "a", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vlanresource.go#L213-L241
7,980
contiv/netplugin
netmaster/resources/vlanresource.go
Deallocate
func (r *AutoVLANCfgResource) Deallocate(value interface{}) error { oper := &AutoVLANOperResource{} oper.StateDriver = r.StateDriver err := oper.Read(r.ID) if err != nil { return err } vlan, ok := value.(uint) if !ok { return core.Errorf("Invalid type for vlan value") } if oper.FreeVLANs.Test(vlan) { return nil } oper.FreeVLANs.Set(vlan) return oper.Write() }
go
func (r *AutoVLANCfgResource) Deallocate(value interface{}) error { oper := &AutoVLANOperResource{} oper.StateDriver = r.StateDriver err := oper.Read(r.ID) if err != nil { return err } vlan, ok := value.(uint) if !ok { return core.Errorf("Invalid type for vlan value") } if oper.FreeVLANs.Test(vlan) { return nil } oper.FreeVLANs.Set(vlan) return oper.Write() }
[ "func", "(", "r", "*", "AutoVLANCfgResource", ")", "Deallocate", "(", "value", "interface", "{", "}", ")", "error", "{", "oper", ":=", "&", "AutoVLANOperResource", "{", "}", "\n", "oper", ".", "StateDriver", "=", "r", ".", "StateDriver", "\n", "err", ":=", "oper", ".", "Read", "(", "r", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "vlan", ",", "ok", ":=", "value", ".", "(", "uint", ")", "\n", "if", "!", "ok", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "oper", ".", "FreeVLANs", ".", "Test", "(", "vlan", ")", "{", "return", "nil", "\n", "}", "\n", "oper", ".", "FreeVLANs", ".", "Set", "(", "vlan", ")", "\n\n", "return", "oper", ".", "Write", "(", ")", "\n", "}" ]
// Deallocate the resource.
[ "Deallocate", "the", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vlanresource.go#L244-L262
7,981
contiv/netplugin
netmaster/resources/vlanresource.go
ReadAll
func (r *AutoVLANOperResource) ReadAll() ([]core.State, error) { return r.StateDriver.ReadAllState(vLANResourceOperPathPrefix, r, json.Unmarshal) }
go
func (r *AutoVLANOperResource) ReadAll() ([]core.State, error) { return r.StateDriver.ReadAllState(vLANResourceOperPathPrefix, r, json.Unmarshal) }
[ "func", "(", "r", "*", "AutoVLANOperResource", ")", "ReadAll", "(", ")", "(", "[", "]", "core", ".", "State", ",", "error", ")", "{", "return", "r", ".", "StateDriver", ".", "ReadAllState", "(", "vLANResourceOperPathPrefix", ",", "r", ",", "json", ".", "Unmarshal", ")", "\n", "}" ]
// ReadAll state for this path.
[ "ReadAll", "state", "for", "this", "path", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/vlanresource.go#L283-L286
7,982
contiv/netplugin
drivers/ovsd/ovsdriver.go
DeleteHostAccPort
func (d *OvsDriver) DeleteHostAccPort(id string) error { sw, found := d.switchDb["host"] if found { operEp := &drivers.OperEndpointState{} operEp.StateDriver = d.oper.StateDriver err := operEp.Read(id) if err != nil { return err } d.HostProxy.DeleteLocalIP(operEp.IPAddress) portName := operEp.PortName intfName := netutils.GetHostIntfName(portName) return sw.DelHostPort(intfName, false) } return errors.New("host bridge not found") }
go
func (d *OvsDriver) DeleteHostAccPort(id string) error { sw, found := d.switchDb["host"] if found { operEp := &drivers.OperEndpointState{} operEp.StateDriver = d.oper.StateDriver err := operEp.Read(id) if err != nil { return err } d.HostProxy.DeleteLocalIP(operEp.IPAddress) portName := operEp.PortName intfName := netutils.GetHostIntfName(portName) return sw.DelHostPort(intfName, false) } return errors.New("host bridge not found") }
[ "func", "(", "d", "*", "OvsDriver", ")", "DeleteHostAccPort", "(", "id", "string", ")", "error", "{", "sw", ",", "found", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "if", "found", "{", "operEp", ":=", "&", "drivers", ".", "OperEndpointState", "{", "}", "\n", "operEp", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", ":=", "operEp", ".", "Read", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "d", ".", "HostProxy", ".", "DeleteLocalIP", "(", "operEp", ".", "IPAddress", ")", "\n", "portName", ":=", "operEp", ".", "PortName", "\n", "intfName", ":=", "netutils", ".", "GetHostIntfName", "(", "portName", ")", "\n", "return", "sw", ".", "DelHostPort", "(", "intfName", ",", "false", ")", "\n", "}", "\n\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
//DeleteHostAccPort deletes the access port
[ "DeleteHostAccPort", "deletes", "the", "access", "port" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L221-L237
7,983
contiv/netplugin
drivers/ovsd/ovsdriver.go
CreateHostAccPort
func (d *OvsDriver) CreateHostAccPort(portName, globalIP string, net int) (string, error) { sw, found := d.switchDb["host"] if found { num := strings.Replace(portName, "hport", "", 1) intfNum, err := strconv.Atoi(num) if err != nil { return "", err } hostIP, err := sw.AddHostPort(portName, intfNum, net, false) if err == nil { d.HostProxy.AddLocalIP(globalIP, hostIP) return hostIP, nil } } return "", errors.New("host bridge not found") }
go
func (d *OvsDriver) CreateHostAccPort(portName, globalIP string, net int) (string, error) { sw, found := d.switchDb["host"] if found { num := strings.Replace(portName, "hport", "", 1) intfNum, err := strconv.Atoi(num) if err != nil { return "", err } hostIP, err := sw.AddHostPort(portName, intfNum, net, false) if err == nil { d.HostProxy.AddLocalIP(globalIP, hostIP) return hostIP, nil } } return "", errors.New("host bridge not found") }
[ "func", "(", "d", "*", "OvsDriver", ")", "CreateHostAccPort", "(", "portName", ",", "globalIP", "string", ",", "net", "int", ")", "(", "string", ",", "error", ")", "{", "sw", ",", "found", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "if", "found", "{", "num", ":=", "strings", ".", "Replace", "(", "portName", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "intfNum", ",", "err", ":=", "strconv", ".", "Atoi", "(", "num", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "hostIP", ",", "err", ":=", "sw", ".", "AddHostPort", "(", "portName", ",", "intfNum", ",", "net", ",", "false", ")", "\n", "if", "err", "==", "nil", "{", "d", ".", "HostProxy", ".", "AddLocalIP", "(", "globalIP", ",", "hostIP", ")", "\n", "return", "hostIP", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// CreateHostAccPort creates an access port
[ "CreateHostAccPort", "creates", "an", "access", "port" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L240-L257
7,984
contiv/netplugin
drivers/ovsd/ovsdriver.go
Deinit
func (d *OvsDriver) Deinit() { log.Infof("Cleaning up ovsdriver") // cleanup both vlan and vxlan OVS instances if d.switchDb["vlan"] != nil { d.switchDb["vlan"].RemoveUplinks() d.switchDb["vlan"].Delete() } if d.switchDb["vxlan"] != nil { d.switchDb["vxlan"].DelHostPort(hostPortName, true) d.switchDb["vxlan"].Delete() } }
go
func (d *OvsDriver) Deinit() { log.Infof("Cleaning up ovsdriver") // cleanup both vlan and vxlan OVS instances if d.switchDb["vlan"] != nil { d.switchDb["vlan"].RemoveUplinks() d.switchDb["vlan"].Delete() } if d.switchDb["vxlan"] != nil { d.switchDb["vxlan"].DelHostPort(hostPortName, true) d.switchDb["vxlan"].Delete() } }
[ "func", "(", "d", "*", "OvsDriver", ")", "Deinit", "(", ")", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n\n", "// cleanup both vlan and vxlan OVS instances", "if", "d", ".", "switchDb", "[", "\"", "\"", "]", "!=", "nil", "{", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "RemoveUplinks", "(", ")", "\n", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "Delete", "(", ")", "\n", "}", "\n", "if", "d", ".", "switchDb", "[", "\"", "\"", "]", "!=", "nil", "{", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "DelHostPort", "(", "hostPortName", ",", "true", ")", "\n", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "Delete", "(", ")", "\n", "}", "\n", "}" ]
// Deinit performs cleanup prior to destruction of the OvsDriver
[ "Deinit", "performs", "cleanup", "prior", "to", "destruction", "of", "the", "OvsDriver" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L260-L272
7,985
contiv/netplugin
drivers/ovsd/ovsdriver.go
CreateNetwork
func (d *OvsDriver) CreateNetwork(id string) error { cfgNw := mastercfg.CfgNetworkState{} cfgNw.StateDriver = d.oper.StateDriver err := cfgNw.Read(id) if err != nil { log.Errorf("Failed to read net %s \n", cfgNw.ID) return err } log.Infof("create net %+v \n", cfgNw) // Find the switch based on network type var sw *OvsSwitch if cfgNw.PktTagType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } return sw.CreateNetwork(uint16(cfgNw.PktTag), uint32(cfgNw.ExtPktTag), cfgNw.Gateway, cfgNw.Tenant) }
go
func (d *OvsDriver) CreateNetwork(id string) error { cfgNw := mastercfg.CfgNetworkState{} cfgNw.StateDriver = d.oper.StateDriver err := cfgNw.Read(id) if err != nil { log.Errorf("Failed to read net %s \n", cfgNw.ID) return err } log.Infof("create net %+v \n", cfgNw) // Find the switch based on network type var sw *OvsSwitch if cfgNw.PktTagType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } return sw.CreateNetwork(uint16(cfgNw.PktTag), uint32(cfgNw.ExtPktTag), cfgNw.Gateway, cfgNw.Tenant) }
[ "func", "(", "d", "*", "OvsDriver", ")", "CreateNetwork", "(", "id", "string", ")", "error", "{", "cfgNw", ":=", "mastercfg", ".", "CfgNetworkState", "{", "}", "\n", "cfgNw", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", ":=", "cfgNw", ".", "Read", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "cfgNw", ".", "ID", ")", "\n", "return", "err", "\n", "}", "\n", "log", ".", "Infof", "(", "\"", "\\n", "\"", ",", "cfgNw", ")", "\n\n", "// Find the switch based on network type", "var", "sw", "*", "OvsSwitch", "\n", "if", "cfgNw", ".", "PktTagType", "==", "\"", "\"", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "else", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "\n\n", "return", "sw", ".", "CreateNetwork", "(", "uint16", "(", "cfgNw", ".", "PktTag", ")", ",", "uint32", "(", "cfgNw", ".", "ExtPktTag", ")", ",", "cfgNw", ".", "Gateway", ",", "cfgNw", ".", "Tenant", ")", "\n", "}" ]
// CreateNetwork creates a network by named identifier
[ "CreateNetwork", "creates", "a", "network", "by", "named", "identifier" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L275-L294
7,986
contiv/netplugin
drivers/ovsd/ovsdriver.go
DeleteNetwork
func (d *OvsDriver) DeleteNetwork(id, subnet, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error { log.Infof("delete net %s, nwType %s, encap %s, tags: %d/%d", id, nwType, encap, pktTag, extPktTag) // Find the switch based on network type var sw *OvsSwitch if encap == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } // Delete infra nw endpoint if present if nwType == "infra" { hostName, _ := os.Hostname() epID := id + "-" + hostName epOper := drivers.OperEndpointState{} epOper.StateDriver = d.oper.StateDriver err := epOper.Read(epID) if err == nil { err = sw.DeletePort(&epOper, true) if err != nil { log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err) } epOper.Clear() } } return sw.DeleteNetwork(uint16(pktTag), uint32(extPktTag), gateway, tenant) }
go
func (d *OvsDriver) DeleteNetwork(id, subnet, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error { log.Infof("delete net %s, nwType %s, encap %s, tags: %d/%d", id, nwType, encap, pktTag, extPktTag) // Find the switch based on network type var sw *OvsSwitch if encap == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } // Delete infra nw endpoint if present if nwType == "infra" { hostName, _ := os.Hostname() epID := id + "-" + hostName epOper := drivers.OperEndpointState{} epOper.StateDriver = d.oper.StateDriver err := epOper.Read(epID) if err == nil { err = sw.DeletePort(&epOper, true) if err != nil { log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err) } epOper.Clear() } } return sw.DeleteNetwork(uint16(pktTag), uint32(extPktTag), gateway, tenant) }
[ "func", "(", "d", "*", "OvsDriver", ")", "DeleteNetwork", "(", "id", ",", "subnet", ",", "nwType", ",", "encap", "string", ",", "pktTag", ",", "extPktTag", "int", ",", "gateway", "string", ",", "tenant", "string", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "id", ",", "nwType", ",", "encap", ",", "pktTag", ",", "extPktTag", ")", "\n\n", "// Find the switch based on network type", "var", "sw", "*", "OvsSwitch", "\n", "if", "encap", "==", "\"", "\"", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "else", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "\n\n", "// Delete infra nw endpoint if present", "if", "nwType", "==", "\"", "\"", "{", "hostName", ",", "_", ":=", "os", ".", "Hostname", "(", ")", "\n", "epID", ":=", "id", "+", "\"", "\"", "+", "hostName", "\n\n", "epOper", ":=", "drivers", ".", "OperEndpointState", "{", "}", "\n", "epOper", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", ":=", "epOper", ".", "Read", "(", "epID", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "sw", ".", "DeletePort", "(", "&", "epOper", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epOper", ",", "err", ")", "\n", "}", "\n", "epOper", ".", "Clear", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "sw", ".", "DeleteNetwork", "(", "uint16", "(", "pktTag", ")", ",", "uint32", "(", "extPktTag", ")", ",", "gateway", ",", "tenant", ")", "\n", "}" ]
// DeleteNetwork deletes a network by named identifier
[ "DeleteNetwork", "deletes", "a", "network", "by", "named", "identifier" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L297-L326
7,987
contiv/netplugin
drivers/ovsd/ovsdriver.go
UpdateEndpointGroup
func (d *OvsDriver) UpdateEndpointGroup(id string) error { log.Infof("Received endpoint group update for %s", id) var ( err error epgBandwidth int64 sw *OvsSwitch ) //gets the EndpointGroupState object cfgEpGroup := &mastercfg.EndpointGroupState{} cfgEpGroup.StateDriver = d.oper.StateDriver err = cfgEpGroup.Read(id) if err != nil { return err } if cfgEpGroup.ID != "" { if cfgEpGroup.Bandwidth != "" { epgBandwidth = netutils.ConvertBandwidth(cfgEpGroup.Bandwidth) } d.oper.localEpInfoMutex.Lock() defer d.oper.localEpInfoMutex.Unlock() for _, epInfo := range d.oper.LocalEpInfo { if epInfo.EpgKey == id { log.Debugf("Applying bandwidth: %s on: %s ", cfgEpGroup.Bandwidth, epInfo.Ovsportname) // Find the switch based on network type if epInfo.BridgeType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } // update the endpoint in ovs switch err = sw.UpdateEndpoint(epInfo.Ovsportname, cfgEpGroup.Burst, cfgEpGroup.DSCP, epgBandwidth) if err != nil { log.Errorf("Error adding bandwidth %v , err: %+v", epgBandwidth, err) return err } } } } return err }
go
func (d *OvsDriver) UpdateEndpointGroup(id string) error { log.Infof("Received endpoint group update for %s", id) var ( err error epgBandwidth int64 sw *OvsSwitch ) //gets the EndpointGroupState object cfgEpGroup := &mastercfg.EndpointGroupState{} cfgEpGroup.StateDriver = d.oper.StateDriver err = cfgEpGroup.Read(id) if err != nil { return err } if cfgEpGroup.ID != "" { if cfgEpGroup.Bandwidth != "" { epgBandwidth = netutils.ConvertBandwidth(cfgEpGroup.Bandwidth) } d.oper.localEpInfoMutex.Lock() defer d.oper.localEpInfoMutex.Unlock() for _, epInfo := range d.oper.LocalEpInfo { if epInfo.EpgKey == id { log.Debugf("Applying bandwidth: %s on: %s ", cfgEpGroup.Bandwidth, epInfo.Ovsportname) // Find the switch based on network type if epInfo.BridgeType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } // update the endpoint in ovs switch err = sw.UpdateEndpoint(epInfo.Ovsportname, cfgEpGroup.Burst, cfgEpGroup.DSCP, epgBandwidth) if err != nil { log.Errorf("Error adding bandwidth %v , err: %+v", epgBandwidth, err) return err } } } } return err }
[ "func", "(", "d", "*", "OvsDriver", ")", "UpdateEndpointGroup", "(", "id", "string", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "id", ")", "\n", "var", "(", "err", "error", "\n", "epgBandwidth", "int64", "\n", "sw", "*", "OvsSwitch", "\n", ")", "\n", "//gets the EndpointGroupState object", "cfgEpGroup", ":=", "&", "mastercfg", ".", "EndpointGroupState", "{", "}", "\n", "cfgEpGroup", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", "=", "cfgEpGroup", ".", "Read", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "cfgEpGroup", ".", "ID", "!=", "\"", "\"", "{", "if", "cfgEpGroup", ".", "Bandwidth", "!=", "\"", "\"", "{", "epgBandwidth", "=", "netutils", ".", "ConvertBandwidth", "(", "cfgEpGroup", ".", "Bandwidth", ")", "\n", "}", "\n\n", "d", ".", "oper", ".", "localEpInfoMutex", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "oper", ".", "localEpInfoMutex", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "epInfo", ":=", "range", "d", ".", "oper", ".", "LocalEpInfo", "{", "if", "epInfo", ".", "EpgKey", "==", "id", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "cfgEpGroup", ".", "Bandwidth", ",", "epInfo", ".", "Ovsportname", ")", "\n", "// Find the switch based on network type", "if", "epInfo", ".", "BridgeType", "==", "\"", "\"", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "else", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "\n\n", "// update the endpoint in ovs switch", "err", "=", "sw", ".", "UpdateEndpoint", "(", "epInfo", ".", "Ovsportname", ",", "cfgEpGroup", ".", "Burst", ",", "cfgEpGroup", ".", "DSCP", ",", "epgBandwidth", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgBandwidth", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
//UpdateEndpointGroup updates the epg
[ "UpdateEndpointGroup", "updates", "the", "epg" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L476-L518
7,988
contiv/netplugin
drivers/ovsd/ovsdriver.go
DeleteEndpoint
func (d *OvsDriver) DeleteEndpoint(id string) error { epOper := drivers.OperEndpointState{} epOper.StateDriver = d.oper.StateDriver err := epOper.Read(id) if err != nil { return err } defer func() { epOper.Clear() }() // Get the network state cfgNw := mastercfg.CfgNetworkState{} cfgNw.StateDriver = d.oper.StateDriver err = cfgNw.Read(epOper.NetID) if err != nil { return err } // Find the switch based on network type var sw *OvsSwitch if cfgNw.PktTagType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } skipVethPair := (cfgNw.NwType == "infra") err = sw.DeletePort(&epOper, skipVethPair) if err != nil { log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err) } d.oper.localEpInfoMutex.Lock() delete(d.oper.LocalEpInfo, id) d.oper.localEpInfoMutex.Unlock() err = d.oper.Write() if err != nil { return err } return nil }
go
func (d *OvsDriver) DeleteEndpoint(id string) error { epOper := drivers.OperEndpointState{} epOper.StateDriver = d.oper.StateDriver err := epOper.Read(id) if err != nil { return err } defer func() { epOper.Clear() }() // Get the network state cfgNw := mastercfg.CfgNetworkState{} cfgNw.StateDriver = d.oper.StateDriver err = cfgNw.Read(epOper.NetID) if err != nil { return err } // Find the switch based on network type var sw *OvsSwitch if cfgNw.PktTagType == "vxlan" { sw = d.switchDb["vxlan"] } else { sw = d.switchDb["vlan"] } skipVethPair := (cfgNw.NwType == "infra") err = sw.DeletePort(&epOper, skipVethPair) if err != nil { log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err) } d.oper.localEpInfoMutex.Lock() delete(d.oper.LocalEpInfo, id) d.oper.localEpInfoMutex.Unlock() err = d.oper.Write() if err != nil { return err } return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "DeleteEndpoint", "(", "id", "string", ")", "error", "{", "epOper", ":=", "drivers", ".", "OperEndpointState", "{", "}", "\n", "epOper", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", ":=", "epOper", ".", "Read", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "epOper", ".", "Clear", "(", ")", "\n", "}", "(", ")", "\n\n", "// Get the network state", "cfgNw", ":=", "mastercfg", ".", "CfgNetworkState", "{", "}", "\n", "cfgNw", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", "=", "cfgNw", ".", "Read", "(", "epOper", ".", "NetID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Find the switch based on network type", "var", "sw", "*", "OvsSwitch", "\n", "if", "cfgNw", ".", "PktTagType", "==", "\"", "\"", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "else", "{", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "}", "\n\n", "skipVethPair", ":=", "(", "cfgNw", ".", "NwType", "==", "\"", "\"", ")", "\n", "err", "=", "sw", ".", "DeletePort", "(", "&", "epOper", ",", "skipVethPair", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epOper", ",", "err", ")", "\n", "}", "\n\n", "d", ".", "oper", ".", "localEpInfoMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "d", ".", "oper", ".", "LocalEpInfo", ",", "id", ")", "\n", "d", ".", "oper", ".", "localEpInfoMutex", ".", "Unlock", "(", ")", "\n", "err", "=", "d", ".", "oper", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteEndpoint deletes an endpoint by named identifier.
[ "DeleteEndpoint", "deletes", "an", "endpoint", "by", "named", "identifier", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L521-L563
7,989
contiv/netplugin
drivers/ovsd/ovsdriver.go
AddPeerHost
func (d *OvsDriver) AddPeerHost(node core.ServiceInfo) error { // Nothing to do if this is our own IP if node.HostAddr == d.localIP { return nil } log.Infof("CreatePeerHost for %+v", node) // Add the VTEP for the peer in vxlan switch. err := d.switchDb["vxlan"].CreateVtep(node.HostAddr) if err != nil { log.Errorf("Error adding the VTEP %s. Err: %s", node.HostAddr, err) return err } return nil }
go
func (d *OvsDriver) AddPeerHost(node core.ServiceInfo) error { // Nothing to do if this is our own IP if node.HostAddr == d.localIP { return nil } log.Infof("CreatePeerHost for %+v", node) // Add the VTEP for the peer in vxlan switch. err := d.switchDb["vxlan"].CreateVtep(node.HostAddr) if err != nil { log.Errorf("Error adding the VTEP %s. Err: %s", node.HostAddr, err) return err } return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "AddPeerHost", "(", "node", "core", ".", "ServiceInfo", ")", "error", "{", "// Nothing to do if this is our own IP", "if", "node", ".", "HostAddr", "==", "d", ".", "localIP", "{", "return", "nil", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "node", ")", "\n\n", "// Add the VTEP for the peer in vxlan switch.", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "CreateVtep", "(", "node", ".", "HostAddr", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "node", ".", "HostAddr", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddPeerHost adds VTEPs if necessary
[ "AddPeerHost", "adds", "VTEPs", "if", "necessary" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L579-L595
7,990
contiv/netplugin
drivers/ovsd/ovsdriver.go
DeletePeerHost
func (d *OvsDriver) DeletePeerHost(node core.ServiceInfo) error { // Nothing to do if this is our own IP if node.HostAddr == d.localIP { return nil } log.Infof("DeletePeerHost for %+v", node) // Remove the VTEP for the peer in vxlan switch. err := d.switchDb["vxlan"].DeleteVtep(node.HostAddr) if err != nil { log.Errorf("Error deleting the VTEP %s. Err: %s", node.HostAddr, err) return err } return nil }
go
func (d *OvsDriver) DeletePeerHost(node core.ServiceInfo) error { // Nothing to do if this is our own IP if node.HostAddr == d.localIP { return nil } log.Infof("DeletePeerHost for %+v", node) // Remove the VTEP for the peer in vxlan switch. err := d.switchDb["vxlan"].DeleteVtep(node.HostAddr) if err != nil { log.Errorf("Error deleting the VTEP %s. Err: %s", node.HostAddr, err) return err } return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "DeletePeerHost", "(", "node", "core", ".", "ServiceInfo", ")", "error", "{", "// Nothing to do if this is our own IP", "if", "node", ".", "HostAddr", "==", "d", ".", "localIP", "{", "return", "nil", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "node", ")", "\n\n", "// Remove the VTEP for the peer in vxlan switch.", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "DeleteVtep", "(", "node", ".", "HostAddr", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "node", ".", "HostAddr", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeletePeerHost deletes associated VTEP
[ "DeletePeerHost", "deletes", "associated", "VTEP" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L598-L614
7,991
contiv/netplugin
drivers/ovsd/ovsdriver.go
AddBgp
func (d *OvsDriver) AddBgp(id string) error { var sw *OvsSwitch cfg := mastercfg.CfgBgpState{} cfg.StateDriver = d.oper.StateDriver err := cfg.Read(id) if err != nil { log.Errorf("Failed to read router state %s \n", cfg.Hostname) return err } log.Infof("Create Bgp :%+v", cfg) // Find the switch based on network type sw = d.switchDb["vlan"] return sw.AddBgp(cfg.Hostname, cfg.RouterIP, cfg.As, cfg.NeighborAs, cfg.Neighbor) }
go
func (d *OvsDriver) AddBgp(id string) error { var sw *OvsSwitch cfg := mastercfg.CfgBgpState{} cfg.StateDriver = d.oper.StateDriver err := cfg.Read(id) if err != nil { log.Errorf("Failed to read router state %s \n", cfg.Hostname) return err } log.Infof("Create Bgp :%+v", cfg) // Find the switch based on network type sw = d.switchDb["vlan"] return sw.AddBgp(cfg.Hostname, cfg.RouterIP, cfg.As, cfg.NeighborAs, cfg.Neighbor) }
[ "func", "(", "d", "*", "OvsDriver", ")", "AddBgp", "(", "id", "string", ")", "error", "{", "var", "sw", "*", "OvsSwitch", "\n\n", "cfg", ":=", "mastercfg", ".", "CfgBgpState", "{", "}", "\n", "cfg", ".", "StateDriver", "=", "d", ".", "oper", ".", "StateDriver", "\n", "err", ":=", "cfg", ".", "Read", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "cfg", ".", "Hostname", ")", "\n", "return", "err", "\n", "}", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "cfg", ")", "\n\n", "// Find the switch based on network type", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n\n", "return", "sw", ".", "AddBgp", "(", "cfg", ".", "Hostname", ",", "cfg", ".", "RouterIP", ",", "cfg", ".", "As", ",", "cfg", ".", "NeighborAs", ",", "cfg", ".", "Neighbor", ")", "\n", "}" ]
// AddBgp adds bgp config by named identifier
[ "AddBgp", "adds", "bgp", "config", "by", "named", "identifier" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L641-L657
7,992
contiv/netplugin
drivers/ovsd/ovsdriver.go
DeleteBgp
func (d *OvsDriver) DeleteBgp(id string) error { log.Infof("Delete Bgp Neighbor %s \n", id) //FixME: We are not maintaining oper state for Bgp //Need to Revisit again // Find the switch based on network type var sw *OvsSwitch sw = d.switchDb["vlan"] return sw.DeleteBgp() }
go
func (d *OvsDriver) DeleteBgp(id string) error { log.Infof("Delete Bgp Neighbor %s \n", id) //FixME: We are not maintaining oper state for Bgp //Need to Revisit again // Find the switch based on network type var sw *OvsSwitch sw = d.switchDb["vlan"] return sw.DeleteBgp() }
[ "func", "(", "d", "*", "OvsDriver", ")", "DeleteBgp", "(", "id", "string", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\\n", "\"", ",", "id", ")", "\n", "//FixME: We are not maintaining oper state for Bgp", "//Need to Revisit again", "// Find the switch based on network type", "var", "sw", "*", "OvsSwitch", "\n", "sw", "=", "d", ".", "switchDb", "[", "\"", "\"", "]", "\n", "return", "sw", ".", "DeleteBgp", "(", ")", "\n\n", "}" ]
// DeleteBgp deletes bgp config by named identifier
[ "DeleteBgp", "deletes", "bgp", "config", "by", "named", "identifier" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L660-L669
7,993
contiv/netplugin
drivers/ovsd/ovsdriver.go
convSvcSpec
func convSvcSpec(spec *core.ServiceSpec) *ofnet.ServiceSpec { pSpec := make([]ofnet.PortSpec, len(spec.Ports)) for ix, p := range spec.Ports { pSpec[ix].Protocol = p.Protocol pSpec[ix].SvcPort = p.SvcPort pSpec[ix].ProvPort = p.ProvPort } ofnetSS := ofnet.ServiceSpec{ IpAddress: spec.IPAddress, Ports: pSpec, } return &ofnetSS }
go
func convSvcSpec(spec *core.ServiceSpec) *ofnet.ServiceSpec { pSpec := make([]ofnet.PortSpec, len(spec.Ports)) for ix, p := range spec.Ports { pSpec[ix].Protocol = p.Protocol pSpec[ix].SvcPort = p.SvcPort pSpec[ix].ProvPort = p.ProvPort } ofnetSS := ofnet.ServiceSpec{ IpAddress: spec.IPAddress, Ports: pSpec, } return &ofnetSS }
[ "func", "convSvcSpec", "(", "spec", "*", "core", ".", "ServiceSpec", ")", "*", "ofnet", ".", "ServiceSpec", "{", "pSpec", ":=", "make", "(", "[", "]", "ofnet", ".", "PortSpec", ",", "len", "(", "spec", ".", "Ports", ")", ")", "\n", "for", "ix", ",", "p", ":=", "range", "spec", ".", "Ports", "{", "pSpec", "[", "ix", "]", ".", "Protocol", "=", "p", ".", "Protocol", "\n", "pSpec", "[", "ix", "]", ".", "SvcPort", "=", "p", ".", "SvcPort", "\n", "pSpec", "[", "ix", "]", ".", "ProvPort", "=", "p", ".", "ProvPort", "\n", "}", "\n\n", "ofnetSS", ":=", "ofnet", ".", "ServiceSpec", "{", "IpAddress", ":", "spec", ".", "IPAddress", ",", "Ports", ":", "pSpec", ",", "}", "\n", "return", "&", "ofnetSS", "\n", "}" ]
// convSvcSpec converts core.ServiceSpec to ofnet.ServiceSpec
[ "convSvcSpec", "converts", "core", ".", "ServiceSpec", "to", "ofnet", ".", "ServiceSpec" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L672-L685
7,994
contiv/netplugin
drivers/ovsd/ovsdriver.go
AddSvcSpec
func (d *OvsDriver) AddSvcSpec(svcName string, spec *core.ServiceSpec) error { log.Infof("AddSvcSpec: %s", svcName) ss := convSvcSpec(spec) errs := "" for _, sw := range d.switchDb { log.Infof("sw AddSvcSpec: %s", svcName) err := sw.AddSvcSpec(svcName, ss) if err != nil { errs += err.Error() } } err := d.HostProxy.AddSvcSpec(svcName, spec) if err != nil { errs += err.Error() } if errs != "" { return errors.New(errs) } d.nameServer.AddLbService(nameserver.K8sDefaultTenant, svcName, spec.IPAddress) return nil }
go
func (d *OvsDriver) AddSvcSpec(svcName string, spec *core.ServiceSpec) error { log.Infof("AddSvcSpec: %s", svcName) ss := convSvcSpec(spec) errs := "" for _, sw := range d.switchDb { log.Infof("sw AddSvcSpec: %s", svcName) err := sw.AddSvcSpec(svcName, ss) if err != nil { errs += err.Error() } } err := d.HostProxy.AddSvcSpec(svcName, spec) if err != nil { errs += err.Error() } if errs != "" { return errors.New(errs) } d.nameServer.AddLbService(nameserver.K8sDefaultTenant, svcName, spec.IPAddress) return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "AddSvcSpec", "(", "svcName", "string", ",", "spec", "*", "core", ".", "ServiceSpec", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "svcName", ")", "\n", "ss", ":=", "convSvcSpec", "(", "spec", ")", "\n", "errs", ":=", "\"", "\"", "\n", "for", "_", ",", "sw", ":=", "range", "d", ".", "switchDb", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "svcName", ")", "\n", "err", ":=", "sw", ".", "AddSvcSpec", "(", "svcName", ",", "ss", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "+=", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}", "\n\n", "err", ":=", "d", ".", "HostProxy", ".", "AddSvcSpec", "(", "svcName", ",", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "+=", "err", ".", "Error", "(", ")", "\n", "}", "\n\n", "if", "errs", "!=", "\"", "\"", "{", "return", "errors", ".", "New", "(", "errs", ")", "\n", "}", "\n\n", "d", ".", "nameServer", ".", "AddLbService", "(", "nameserver", ".", "K8sDefaultTenant", ",", "svcName", ",", "spec", ".", "IPAddress", ")", "\n\n", "return", "nil", "\n", "}" ]
// AddSvcSpec invokes switch api
[ "AddSvcSpec", "invokes", "switch", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L688-L712
7,995
contiv/netplugin
drivers/ovsd/ovsdriver.go
DelSvcSpec
func (d *OvsDriver) DelSvcSpec(svcName string, spec *core.ServiceSpec) error { ss := convSvcSpec(spec) errs := "" for _, sw := range d.switchDb { err := sw.DelSvcSpec(svcName, ss) if err != nil { errs += err.Error() } } err := d.HostProxy.DelSvcSpec(svcName, spec) if err != nil { errs += err.Error() } if errs != "" { return errors.New(errs) } d.nameServer.DelLbService(nameserver.K8sDefaultTenant, svcName) return nil }
go
func (d *OvsDriver) DelSvcSpec(svcName string, spec *core.ServiceSpec) error { ss := convSvcSpec(spec) errs := "" for _, sw := range d.switchDb { err := sw.DelSvcSpec(svcName, ss) if err != nil { errs += err.Error() } } err := d.HostProxy.DelSvcSpec(svcName, spec) if err != nil { errs += err.Error() } if errs != "" { return errors.New(errs) } d.nameServer.DelLbService(nameserver.K8sDefaultTenant, svcName) return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "DelSvcSpec", "(", "svcName", "string", ",", "spec", "*", "core", ".", "ServiceSpec", ")", "error", "{", "ss", ":=", "convSvcSpec", "(", "spec", ")", "\n", "errs", ":=", "\"", "\"", "\n", "for", "_", ",", "sw", ":=", "range", "d", ".", "switchDb", "{", "err", ":=", "sw", ".", "DelSvcSpec", "(", "svcName", ",", "ss", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "+=", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}", "\n\n", "err", ":=", "d", ".", "HostProxy", ".", "DelSvcSpec", "(", "svcName", ",", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "+=", "err", ".", "Error", "(", ")", "\n", "}", "\n\n", "if", "errs", "!=", "\"", "\"", "{", "return", "errors", ".", "New", "(", "errs", ")", "\n", "}", "\n\n", "d", ".", "nameServer", ".", "DelLbService", "(", "nameserver", ".", "K8sDefaultTenant", ",", "svcName", ")", "\n\n", "return", "nil", "\n", "}" ]
// DelSvcSpec invokes switch api
[ "DelSvcSpec", "invokes", "switch", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L715-L737
7,996
contiv/netplugin
drivers/ovsd/ovsdriver.go
GetEndpointStats
func (d *OvsDriver) GetEndpointStats() ([]byte, error) { vxlanStats, err := d.switchDb["vxlan"].GetEndpointStats() if err != nil { log.Errorf("Error getting vxlan stats. Err: %v", err) return []byte{}, err } vlanStats, err := d.switchDb["vlan"].GetEndpointStats() if err != nil { log.Errorf("Error getting vlan stats. Err: %v", err) return []byte{}, err } // combine the maps for key, val := range vxlanStats { vlanStats[key] = val } jsonStats, err := json.Marshal(vlanStats) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return jsonStats, err } return jsonStats, nil }
go
func (d *OvsDriver) GetEndpointStats() ([]byte, error) { vxlanStats, err := d.switchDb["vxlan"].GetEndpointStats() if err != nil { log.Errorf("Error getting vxlan stats. Err: %v", err) return []byte{}, err } vlanStats, err := d.switchDb["vlan"].GetEndpointStats() if err != nil { log.Errorf("Error getting vlan stats. Err: %v", err) return []byte{}, err } // combine the maps for key, val := range vxlanStats { vlanStats[key] = val } jsonStats, err := json.Marshal(vlanStats) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return jsonStats, err } return jsonStats, nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "GetEndpointStats", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "vxlanStats", ",", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "GetEndpointStats", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "vlanStats", ",", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "GetEndpointStats", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "// combine the maps", "for", "key", ",", "val", ":=", "range", "vxlanStats", "{", "vlanStats", "[", "key", "]", "=", "val", "\n", "}", "\n\n", "jsonStats", ",", "err", ":=", "json", ".", "Marshal", "(", "vlanStats", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "jsonStats", ",", "err", "\n", "}", "\n\n", "return", "jsonStats", ",", "nil", "\n", "}" ]
// GetEndpointStats gets all endpoints from all ovs instances
[ "GetEndpointStats", "gets", "all", "endpoints", "from", "all", "ovs", "instances" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L749-L774
7,997
contiv/netplugin
drivers/ovsd/ovsdriver.go
InspectState
func (d *OvsDriver) InspectState() ([]byte, error) { driverState := make(map[string]interface{}) // get vlan switch state vlanState, err := d.switchDb["vlan"].InspectState() if err != nil { return []byte{}, err } // get vxlan switch state vxlanState, err := d.switchDb["vxlan"].InspectState() if err != nil { return []byte{}, err } // build the map driverState["vlan"] = vlanState driverState["vxlan"] = vxlanState // json marshall the map jsonState, err := json.Marshal(driverState) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return []byte{}, err } return jsonState, nil }
go
func (d *OvsDriver) InspectState() ([]byte, error) { driverState := make(map[string]interface{}) // get vlan switch state vlanState, err := d.switchDb["vlan"].InspectState() if err != nil { return []byte{}, err } // get vxlan switch state vxlanState, err := d.switchDb["vxlan"].InspectState() if err != nil { return []byte{}, err } // build the map driverState["vlan"] = vlanState driverState["vxlan"] = vxlanState // json marshall the map jsonState, err := json.Marshal(driverState) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return []byte{}, err } return jsonState, nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "InspectState", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "driverState", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "// get vlan switch state", "vlanState", ",", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "InspectState", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "// get vxlan switch state", "vxlanState", ",", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "InspectState", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "// build the map", "driverState", "[", "\"", "\"", "]", "=", "vlanState", "\n", "driverState", "[", "\"", "\"", "]", "=", "vxlanState", "\n\n", "// json marshall the map", "jsonState", ",", "err", ":=", "json", ".", "Marshal", "(", "driverState", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "jsonState", ",", "nil", "\n", "}" ]
// InspectState returns driver state as json string
[ "InspectState", "returns", "driver", "state", "as", "json", "string" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L777-L804
7,998
contiv/netplugin
drivers/ovsd/ovsdriver.go
InspectBgp
func (d *OvsDriver) InspectBgp() ([]byte, error) { // get vlan switch state bgpState, err := d.switchDb["vlan"].InspectBgp() if err != nil { return []byte{}, err } // json marshall the map jsonState, err := json.Marshal(bgpState) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return []byte{}, err } return jsonState, nil }
go
func (d *OvsDriver) InspectBgp() ([]byte, error) { // get vlan switch state bgpState, err := d.switchDb["vlan"].InspectBgp() if err != nil { return []byte{}, err } // json marshall the map jsonState, err := json.Marshal(bgpState) if err != nil { log.Errorf("Error encoding epstats. Err: %v", err) return []byte{}, err } return jsonState, nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "InspectBgp", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// get vlan switch state", "bgpState", ",", "err", ":=", "d", ".", "switchDb", "[", "\"", "\"", "]", ".", "InspectBgp", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "// json marshall the map", "jsonState", ",", "err", ":=", "json", ".", "Marshal", "(", "bgpState", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "jsonState", ",", "nil", "\n", "}" ]
// InspectBgp returns bgp state as json string
[ "InspectBgp", "returns", "bgp", "state", "as", "json", "string" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L807-L823
7,999
contiv/netplugin
drivers/ovsd/ovsdriver.go
GlobalConfigUpdate
func (d *OvsDriver) GlobalConfigUpdate(inst core.InstanceInfo) error { // convert the netplugin config to ofnet config // currently, its only ArpMode var cfg ofnet.OfnetGlobalConfig switch inst.ArpMode { case "flood": cfg.ArpMode = ofnet.ArpFlood default: // set the default to proxy for graceful upgrade cfg.ArpMode = ofnet.ArpProxy } errs := "" for _, sw := range d.switchDb { err := sw.GlobalConfigUpdate(cfg) if err != nil { errs += err.Error() } } if errs != "" { return errors.New(errs) } return nil }
go
func (d *OvsDriver) GlobalConfigUpdate(inst core.InstanceInfo) error { // convert the netplugin config to ofnet config // currently, its only ArpMode var cfg ofnet.OfnetGlobalConfig switch inst.ArpMode { case "flood": cfg.ArpMode = ofnet.ArpFlood default: // set the default to proxy for graceful upgrade cfg.ArpMode = ofnet.ArpProxy } errs := "" for _, sw := range d.switchDb { err := sw.GlobalConfigUpdate(cfg) if err != nil { errs += err.Error() } } if errs != "" { return errors.New(errs) } return nil }
[ "func", "(", "d", "*", "OvsDriver", ")", "GlobalConfigUpdate", "(", "inst", "core", ".", "InstanceInfo", ")", "error", "{", "// convert the netplugin config to ofnet config", "// currently, its only ArpMode", "var", "cfg", "ofnet", ".", "OfnetGlobalConfig", "\n", "switch", "inst", ".", "ArpMode", "{", "case", "\"", "\"", ":", "cfg", ".", "ArpMode", "=", "ofnet", ".", "ArpFlood", "\n", "default", ":", "// set the default to proxy for graceful upgrade", "cfg", ".", "ArpMode", "=", "ofnet", ".", "ArpProxy", "\n", "}", "\n\n", "errs", ":=", "\"", "\"", "\n", "for", "_", ",", "sw", ":=", "range", "d", ".", "switchDb", "{", "err", ":=", "sw", ".", "GlobalConfigUpdate", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "+=", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}", "\n", "if", "errs", "!=", "\"", "\"", "{", "return", "errors", ".", "New", "(", "errs", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GlobalConfigUpdate sets the global level configs like arp-mode
[ "GlobalConfigUpdate", "sets", "the", "global", "level", "configs", "like", "arp", "-", "mode" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsdriver.go#L826-L850