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,800 | contiv/netplugin | netmaster/mastercfg/policyState.go | InitPolicyMgr | func InitPolicyMgr(stateDriver core.StateDriver, ofm *ofnet.OfnetMaster) error {
// save statestore and ofnet masters
stateStore = stateDriver
ofnetMaster = ofm
// restore all existing epg policies
err := restoreEpgPolicies(stateDriver)
if err != nil {
log.Errorf("Error restoring EPG policies. ")
}
return nil
} | go | func InitPolicyMgr(stateDriver core.StateDriver, ofm *ofnet.OfnetMaster) error {
// save statestore and ofnet masters
stateStore = stateDriver
ofnetMaster = ofm
// restore all existing epg policies
err := restoreEpgPolicies(stateDriver)
if err != nil {
log.Errorf("Error restoring EPG policies. ")
}
return nil
} | [
"func",
"InitPolicyMgr",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"ofm",
"*",
"ofnet",
".",
"OfnetMaster",
")",
"error",
"{",
"// save statestore and ofnet masters",
"stateStore",
"=",
"stateDriver",
"\n",
"ofnetMaster",
"=",
"ofm",
"\n\n",
"// restore all existing epg policies",
"err",
":=",
"restoreEpgPolicies",
"(",
"stateDriver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // InitPolicyMgr initializes the policy manager | [
"InitPolicyMgr",
"initializes",
"the",
"policy",
"manager"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L60-L71 |
7,801 | contiv/netplugin | netmaster/mastercfg/policyState.go | NewEpgPolicy | func NewEpgPolicy(epgpKey string, epgID int, policy *contivModel.Policy) (*EpgPolicy, error) {
gp := new(EpgPolicy)
gp.EpgPolicyKey = epgpKey
gp.ID = epgpKey
gp.EndpointGroupID = epgID
gp.StateDriver = stateStore
log.Infof("Creating new epg policy: %s", epgpKey)
// init the dbs
gp.RuleMaps = make(map[string]*RuleMap)
// Install all rules within the policy
for ruleKey := range policy.LinkSets.Rules {
// find the rule
rule := contivModel.FindRule(ruleKey)
if rule == nil {
log.Errorf("Error finding the rule %s", ruleKey)
return nil, core.Errorf("rule not found")
}
log.Infof("Adding Rule %s to epgp policy %s", ruleKey, epgpKey)
// Add the rule to epg Policy
err := gp.AddRule(rule)
if err != nil {
log.Errorf("Error adding rule %s to epg polict %s. Err: %v", ruleKey, epgpKey, err)
return nil, err
}
}
// Save the policy state
err := gp.Write()
if err != nil {
return nil, err
}
// Save it in local cache
epgPolicyDb[epgpKey] = gp
log.Info("Created epg policy {%+v}", gp)
return gp, nil
} | go | func NewEpgPolicy(epgpKey string, epgID int, policy *contivModel.Policy) (*EpgPolicy, error) {
gp := new(EpgPolicy)
gp.EpgPolicyKey = epgpKey
gp.ID = epgpKey
gp.EndpointGroupID = epgID
gp.StateDriver = stateStore
log.Infof("Creating new epg policy: %s", epgpKey)
// init the dbs
gp.RuleMaps = make(map[string]*RuleMap)
// Install all rules within the policy
for ruleKey := range policy.LinkSets.Rules {
// find the rule
rule := contivModel.FindRule(ruleKey)
if rule == nil {
log.Errorf("Error finding the rule %s", ruleKey)
return nil, core.Errorf("rule not found")
}
log.Infof("Adding Rule %s to epgp policy %s", ruleKey, epgpKey)
// Add the rule to epg Policy
err := gp.AddRule(rule)
if err != nil {
log.Errorf("Error adding rule %s to epg polict %s. Err: %v", ruleKey, epgpKey, err)
return nil, err
}
}
// Save the policy state
err := gp.Write()
if err != nil {
return nil, err
}
// Save it in local cache
epgPolicyDb[epgpKey] = gp
log.Info("Created epg policy {%+v}", gp)
return gp, nil
} | [
"func",
"NewEpgPolicy",
"(",
"epgpKey",
"string",
",",
"epgID",
"int",
",",
"policy",
"*",
"contivModel",
".",
"Policy",
")",
"(",
"*",
"EpgPolicy",
",",
"error",
")",
"{",
"gp",
":=",
"new",
"(",
"EpgPolicy",
")",
"\n",
"gp",
".",
"EpgPolicyKey",
"=",
"epgpKey",
"\n",
"gp",
".",
"ID",
"=",
"epgpKey",
"\n",
"gp",
".",
"EndpointGroupID",
"=",
"epgID",
"\n",
"gp",
".",
"StateDriver",
"=",
"stateStore",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"epgpKey",
")",
"\n\n",
"// init the dbs",
"gp",
".",
"RuleMaps",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"RuleMap",
")",
"\n\n",
"// Install all rules within the policy",
"for",
"ruleKey",
":=",
"range",
"policy",
".",
"LinkSets",
".",
"Rules",
"{",
"// find the rule",
"rule",
":=",
"contivModel",
".",
"FindRule",
"(",
"ruleKey",
")",
"\n",
"if",
"rule",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ruleKey",
")",
"\n",
"return",
"nil",
",",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"epgpKey",
")",
"\n\n",
"// Add the rule to epg Policy",
"err",
":=",
"gp",
".",
"AddRule",
"(",
"rule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"epgpKey",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Save the policy state",
"err",
":=",
"gp",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Save it in local cache",
"epgPolicyDb",
"[",
"epgpKey",
"]",
"=",
"gp",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"gp",
")",
"\n\n",
"return",
"gp",
",",
"nil",
"\n",
"}"
] | // NewEpgPolicy creates a new policy instance attached to an endpoint group | [
"NewEpgPolicy",
"creates",
"a",
"new",
"policy",
"instance",
"attached",
"to",
"an",
"endpoint",
"group"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L74-L117 |
7,802 | contiv/netplugin | netmaster/mastercfg/policyState.go | restoreEpgPolicies | func restoreEpgPolicies(stateDriver core.StateDriver) error {
// read all epg policies
gp := new(EpgPolicy)
gp.StateDriver = stateDriver
gpCfgs, err := gp.ReadAll()
if err == nil {
for _, gpCfg := range gpCfgs {
epgp := gpCfg.(*EpgPolicy)
log.Infof("Restoring EpgPolicy: %+v", epgp)
// save it in cache
epgPolicyDb[epgp.EpgPolicyKey] = epgp
// Restore all rules within the policy
for ruleKey, ruleMap := range epgp.RuleMaps {
log.Infof("Restoring Rule %s, Rule: %+v", ruleKey, ruleMap.Rule)
// delete the entry from the map so that we can add it back
delete(epgp.RuleMaps, ruleKey)
// Add the rule to epg Policy
err := epgp.AddRule(ruleMap.Rule)
if err != nil {
log.Errorf("Error restoring rule %s. Err: %v", ruleKey, err)
return err
}
}
}
}
return nil
} | go | func restoreEpgPolicies(stateDriver core.StateDriver) error {
// read all epg policies
gp := new(EpgPolicy)
gp.StateDriver = stateDriver
gpCfgs, err := gp.ReadAll()
if err == nil {
for _, gpCfg := range gpCfgs {
epgp := gpCfg.(*EpgPolicy)
log.Infof("Restoring EpgPolicy: %+v", epgp)
// save it in cache
epgPolicyDb[epgp.EpgPolicyKey] = epgp
// Restore all rules within the policy
for ruleKey, ruleMap := range epgp.RuleMaps {
log.Infof("Restoring Rule %s, Rule: %+v", ruleKey, ruleMap.Rule)
// delete the entry from the map so that we can add it back
delete(epgp.RuleMaps, ruleKey)
// Add the rule to epg Policy
err := epgp.AddRule(ruleMap.Rule)
if err != nil {
log.Errorf("Error restoring rule %s. Err: %v", ruleKey, err)
return err
}
}
}
}
return nil
} | [
"func",
"restoreEpgPolicies",
"(",
"stateDriver",
"core",
".",
"StateDriver",
")",
"error",
"{",
"// read all epg policies",
"gp",
":=",
"new",
"(",
"EpgPolicy",
")",
"\n",
"gp",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"gpCfgs",
",",
"err",
":=",
"gp",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"gpCfg",
":=",
"range",
"gpCfgs",
"{",
"epgp",
":=",
"gpCfg",
".",
"(",
"*",
"EpgPolicy",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"epgp",
")",
"\n\n",
"// save it in cache",
"epgPolicyDb",
"[",
"epgp",
".",
"EpgPolicyKey",
"]",
"=",
"epgp",
"\n\n",
"// Restore all rules within the policy",
"for",
"ruleKey",
",",
"ruleMap",
":=",
"range",
"epgp",
".",
"RuleMaps",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"ruleMap",
".",
"Rule",
")",
"\n\n",
"// delete the entry from the map so that we can add it back",
"delete",
"(",
"epgp",
".",
"RuleMaps",
",",
"ruleKey",
")",
"\n\n",
"// Add the rule to epg Policy",
"err",
":=",
"epgp",
".",
"AddRule",
"(",
"ruleMap",
".",
"Rule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ruleKey",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // restoreEpgPolicies restores all EPG policies from state store | [
"restoreEpgPolicies",
"restores",
"all",
"EPG",
"policies",
"from",
"state",
"store"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L120-L151 |
7,803 | contiv/netplugin | netmaster/mastercfg/policyState.go | Delete | func (gp *EpgPolicy) Delete() error {
// delete from the DB
delete(epgPolicyDb, gp.EpgPolicyKey)
return gp.Clear()
} | go | func (gp *EpgPolicy) Delete() error {
// delete from the DB
delete(epgPolicyDb, gp.EpgPolicyKey)
return gp.Clear()
} | [
"func",
"(",
"gp",
"*",
"EpgPolicy",
")",
"Delete",
"(",
")",
"error",
"{",
"// delete from the DB",
"delete",
"(",
"epgPolicyDb",
",",
"gp",
".",
"EpgPolicyKey",
")",
"\n\n",
"return",
"gp",
".",
"Clear",
"(",
")",
"\n",
"}"
] | // Delete deletes the epg policy | [
"Delete",
"deletes",
"the",
"epg",
"policy"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L159-L164 |
7,804 | contiv/netplugin | netmaster/mastercfg/policyState.go | AddRule | func (gp *EpgPolicy) AddRule(rule *contivModel.Rule) error {
var dirs []string
// check if the rule exists already
if gp.RuleMaps[rule.Key] != nil {
// FIXME: see if we can update the rule
return core.Errorf("Rule already exists")
}
// Figure out all the directional rules we need to install
switch rule.Direction {
case "in":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"inRx", "inTx"}
} else {
dirs = []string{"inRx"}
}
case "out":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"outRx", "outTx"}
} else {
dirs = []string{"outTx"}
}
case "both":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"inRx", "inTx", "outRx", "outTx"}
} else {
dirs = []string{"inRx", "outTx"}
}
}
// create a ruleMap
ruleMap := new(RuleMap)
ruleMap.OfnetRules = make(map[string]*ofnet.OfnetPolicyRule)
ruleMap.Rule = rule
// Create ofnet rules
for _, dir := range dirs {
ofnetRule, err := gp.createOfnetRule(rule, dir)
if err != nil {
log.Errorf("Error creating %s ofnet rule for {%+v}. Err: %v", dir, rule, err)
return err
}
// add it to the rule map
ruleMap.OfnetRules[ofnetRule.RuleId] = ofnetRule
}
// save the rulemap
gp.RuleMaps[rule.Key] = ruleMap
return nil
} | go | func (gp *EpgPolicy) AddRule(rule *contivModel.Rule) error {
var dirs []string
// check if the rule exists already
if gp.RuleMaps[rule.Key] != nil {
// FIXME: see if we can update the rule
return core.Errorf("Rule already exists")
}
// Figure out all the directional rules we need to install
switch rule.Direction {
case "in":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"inRx", "inTx"}
} else {
dirs = []string{"inRx"}
}
case "out":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"outRx", "outTx"}
} else {
dirs = []string{"outTx"}
}
case "both":
if (rule.Protocol == "udp" || rule.Protocol == "tcp") && rule.Port != 0 {
dirs = []string{"inRx", "inTx", "outRx", "outTx"}
} else {
dirs = []string{"inRx", "outTx"}
}
}
// create a ruleMap
ruleMap := new(RuleMap)
ruleMap.OfnetRules = make(map[string]*ofnet.OfnetPolicyRule)
ruleMap.Rule = rule
// Create ofnet rules
for _, dir := range dirs {
ofnetRule, err := gp.createOfnetRule(rule, dir)
if err != nil {
log.Errorf("Error creating %s ofnet rule for {%+v}. Err: %v", dir, rule, err)
return err
}
// add it to the rule map
ruleMap.OfnetRules[ofnetRule.RuleId] = ofnetRule
}
// save the rulemap
gp.RuleMaps[rule.Key] = ruleMap
return nil
} | [
"func",
"(",
"gp",
"*",
"EpgPolicy",
")",
"AddRule",
"(",
"rule",
"*",
"contivModel",
".",
"Rule",
")",
"error",
"{",
"var",
"dirs",
"[",
"]",
"string",
"\n\n",
"// check if the rule exists already",
"if",
"gp",
".",
"RuleMaps",
"[",
"rule",
".",
"Key",
"]",
"!=",
"nil",
"{",
"// FIXME: see if we can update the rule",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Figure out all the directional rules we need to install",
"switch",
"rule",
".",
"Direction",
"{",
"case",
"\"",
"\"",
":",
"if",
"(",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
"||",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
")",
"&&",
"rule",
".",
"Port",
"!=",
"0",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"}",
"else",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"if",
"(",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
"||",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
")",
"&&",
"rule",
".",
"Port",
"!=",
"0",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"}",
"else",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"if",
"(",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
"||",
"rule",
".",
"Protocol",
"==",
"\"",
"\"",
")",
"&&",
"rule",
".",
"Port",
"!=",
"0",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"}",
"else",
"{",
"dirs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"// create a ruleMap",
"ruleMap",
":=",
"new",
"(",
"RuleMap",
")",
"\n",
"ruleMap",
".",
"OfnetRules",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ofnet",
".",
"OfnetPolicyRule",
")",
"\n",
"ruleMap",
".",
"Rule",
"=",
"rule",
"\n\n",
"// Create ofnet rules",
"for",
"_",
",",
"dir",
":=",
"range",
"dirs",
"{",
"ofnetRule",
",",
"err",
":=",
"gp",
".",
"createOfnetRule",
"(",
"rule",
",",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
",",
"rule",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// add it to the rule map",
"ruleMap",
".",
"OfnetRules",
"[",
"ofnetRule",
".",
"RuleId",
"]",
"=",
"ofnetRule",
"\n",
"}",
"\n\n",
"// save the rulemap",
"gp",
".",
"RuleMaps",
"[",
"rule",
".",
"Key",
"]",
"=",
"ruleMap",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AddRule adds a rule to epg policy | [
"AddRule",
"adds",
"a",
"rule",
"to",
"epg",
"policy"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L315-L368 |
7,805 | contiv/netplugin | netmaster/mastercfg/policyState.go | DelRule | func (gp *EpgPolicy) DelRule(rule *contivModel.Rule) error {
// check if the rule exists
ruleMap := gp.RuleMaps[rule.Key]
if ruleMap == nil {
return core.Errorf("Rule does not exists")
}
// Delete each ofnet rule under this policy rule
for _, ofnetRule := range ruleMap.OfnetRules {
log.Infof("Deleting rule {%+v} from policyDB", ofnetRule)
// Delete the rule from policyDB
err := ofnetMaster.DelRule(ofnetRule)
if err != nil {
log.Errorf("Error deleting the ofnet rule {%+v}. Err: %v", ofnetRule, err)
}
// Send DelRule to netplugin agents
err = delPolicyRuleState(ofnetRule)
if err != nil {
log.Errorf("Error deleting the ofnet rule {%+v}. Err: %v", ofnetRule, err)
}
}
// delete the cache
delete(gp.RuleMaps, rule.Key)
return nil
} | go | func (gp *EpgPolicy) DelRule(rule *contivModel.Rule) error {
// check if the rule exists
ruleMap := gp.RuleMaps[rule.Key]
if ruleMap == nil {
return core.Errorf("Rule does not exists")
}
// Delete each ofnet rule under this policy rule
for _, ofnetRule := range ruleMap.OfnetRules {
log.Infof("Deleting rule {%+v} from policyDB", ofnetRule)
// Delete the rule from policyDB
err := ofnetMaster.DelRule(ofnetRule)
if err != nil {
log.Errorf("Error deleting the ofnet rule {%+v}. Err: %v", ofnetRule, err)
}
// Send DelRule to netplugin agents
err = delPolicyRuleState(ofnetRule)
if err != nil {
log.Errorf("Error deleting the ofnet rule {%+v}. Err: %v", ofnetRule, err)
}
}
// delete the cache
delete(gp.RuleMaps, rule.Key)
return nil
} | [
"func",
"(",
"gp",
"*",
"EpgPolicy",
")",
"DelRule",
"(",
"rule",
"*",
"contivModel",
".",
"Rule",
")",
"error",
"{",
"// check if the rule exists",
"ruleMap",
":=",
"gp",
".",
"RuleMaps",
"[",
"rule",
".",
"Key",
"]",
"\n",
"if",
"ruleMap",
"==",
"nil",
"{",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Delete each ofnet rule under this policy rule",
"for",
"_",
",",
"ofnetRule",
":=",
"range",
"ruleMap",
".",
"OfnetRules",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ofnetRule",
")",
"\n\n",
"// Delete the rule from policyDB",
"err",
":=",
"ofnetMaster",
".",
"DelRule",
"(",
"ofnetRule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ofnetRule",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Send DelRule to netplugin agents",
"err",
"=",
"delPolicyRuleState",
"(",
"ofnetRule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ofnetRule",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// delete the cache",
"delete",
"(",
"gp",
".",
"RuleMaps",
",",
"rule",
".",
"Key",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // DelRule removes a rule from epg policy | [
"DelRule",
"removes",
"a",
"rule",
"from",
"epg",
"policy"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyState.go#L371-L399 |
7,806 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | parseEnv | func (cniApp *cniAppInfo) parseEnv() error {
cniApp.logFields = make(logger.Fields)
envVal := ""
for _, envName := range cniEnvList {
if envVal = os.Getenv(envName); envVal == "" {
return fmt.Errorf("failed to get env variable %s", envName)
}
logger.Infof("parsed env variable %s = [%s]", envName, envVal)
switch envName {
case envVarCniCommand:
cniApp.cniCmd = strings.ToUpper(envVal)
cniApp.logFields["CMD"] = envVal
if _, ok := map[string]int{cniapi.CniCmdAdd: 1,
cniapi.CniCmdDel: 2}[cniApp.cniCmd]; ok == false {
return fmt.Errorf("unknown CNI command %s", envName)
}
case envVarCniIfname:
cniApp.cniMesosAttr.CniIfname = envVal
case envVarCniNetns:
cniApp.cniMesosAttr.CniNetns = envVal
nsDir := filepath.Dir(envVal)
cniApp.netcfgFile = strings.Join([]string{nsDir, "netcontiv", "network.conf"}, "/")
logger.Infof("cni network config file location : %s", cniApp.netcfgFile)
case envVarCniContainerID:
cniApp.cniMesosAttr.CniContainerid = envVal
cniApp.logFields["CID"] = strings.Split(envVal, "-")[0]
logger.Debugf("added fields in logger CID: %s", cniApp.logFields["CID"])
default:
cniLog.Errorf("unknown CNI variable %s", envName)
}
}
// update logger
cniLog = logger.WithFields(cniApp.logFields)
return nil
} | go | func (cniApp *cniAppInfo) parseEnv() error {
cniApp.logFields = make(logger.Fields)
envVal := ""
for _, envName := range cniEnvList {
if envVal = os.Getenv(envName); envVal == "" {
return fmt.Errorf("failed to get env variable %s", envName)
}
logger.Infof("parsed env variable %s = [%s]", envName, envVal)
switch envName {
case envVarCniCommand:
cniApp.cniCmd = strings.ToUpper(envVal)
cniApp.logFields["CMD"] = envVal
if _, ok := map[string]int{cniapi.CniCmdAdd: 1,
cniapi.CniCmdDel: 2}[cniApp.cniCmd]; ok == false {
return fmt.Errorf("unknown CNI command %s", envName)
}
case envVarCniIfname:
cniApp.cniMesosAttr.CniIfname = envVal
case envVarCniNetns:
cniApp.cniMesosAttr.CniNetns = envVal
nsDir := filepath.Dir(envVal)
cniApp.netcfgFile = strings.Join([]string{nsDir, "netcontiv", "network.conf"}, "/")
logger.Infof("cni network config file location : %s", cniApp.netcfgFile)
case envVarCniContainerID:
cniApp.cniMesosAttr.CniContainerid = envVal
cniApp.logFields["CID"] = strings.Split(envVal, "-")[0]
logger.Debugf("added fields in logger CID: %s", cniApp.logFields["CID"])
default:
cniLog.Errorf("unknown CNI variable %s", envName)
}
}
// update logger
cniLog = logger.WithFields(cniApp.logFields)
return nil
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"parseEnv",
"(",
")",
"error",
"{",
"cniApp",
".",
"logFields",
"=",
"make",
"(",
"logger",
".",
"Fields",
")",
"\n",
"envVal",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"envName",
":=",
"range",
"cniEnvList",
"{",
"if",
"envVal",
"=",
"os",
".",
"Getenv",
"(",
"envName",
")",
";",
"envVal",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"envName",
")",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"envName",
",",
"envVal",
")",
"\n\n",
"switch",
"envName",
"{",
"case",
"envVarCniCommand",
":",
"cniApp",
".",
"cniCmd",
"=",
"strings",
".",
"ToUpper",
"(",
"envVal",
")",
"\n",
"cniApp",
".",
"logFields",
"[",
"\"",
"\"",
"]",
"=",
"envVal",
"\n",
"if",
"_",
",",
"ok",
":=",
"map",
"[",
"string",
"]",
"int",
"{",
"cniapi",
".",
"CniCmdAdd",
":",
"1",
",",
"cniapi",
".",
"CniCmdDel",
":",
"2",
"}",
"[",
"cniApp",
".",
"cniCmd",
"]",
";",
"ok",
"==",
"false",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"envName",
")",
"\n",
"}",
"\n\n",
"case",
"envVarCniIfname",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"CniIfname",
"=",
"envVal",
"\n\n",
"case",
"envVarCniNetns",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"CniNetns",
"=",
"envVal",
"\n",
"nsDir",
":=",
"filepath",
".",
"Dir",
"(",
"envVal",
")",
"\n",
"cniApp",
".",
"netcfgFile",
"=",
"strings",
".",
"Join",
"(",
"[",
"]",
"string",
"{",
"nsDir",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"\"",
"\"",
")",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniApp",
".",
"netcfgFile",
")",
"\n\n",
"case",
"envVarCniContainerID",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"CniContainerid",
"=",
"envVal",
"\n",
"cniApp",
".",
"logFields",
"[",
"\"",
"\"",
"]",
"=",
"strings",
".",
"Split",
"(",
"envVal",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"cniApp",
".",
"logFields",
"[",
"\"",
"\"",
"]",
")",
"\n\n",
"default",
":",
"cniLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"envName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// update logger",
"cniLog",
"=",
"logger",
".",
"WithFields",
"(",
"cniApp",
".",
"logFields",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // parse and save env. variables | [
"parse",
"and",
"save",
"env",
".",
"variables"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L61-L105 |
7,807 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | parseNwInfoLabels | func (cniApp *cniAppInfo) parseNwInfoLabels() {
var cniNetInfo struct {
Args struct {
Mesos struct {
NetworkInfo struct {
Labels struct {
NwLabel []cniapi.NetworkLabel `json:"labels"`
} `json:"labels"`
} `json:"network_info"`
} `json:"org.apache.mesos"`
} `json:"args"`
}
cniLog.Infof("parse config file %s ", cniApp.netcfgFile)
cfgFile, err := ioutil.ReadFile(cniApp.netcfgFile)
if err != nil {
cniLog.Warnf("%s", err)
return
}
if err := json.Unmarshal(cfgFile, &cniNetInfo); err != nil {
cniLog.Errorf("failed to parse %s, %s", cniApp.netcfgFile, err)
return
}
for idx, elem := range cniNetInfo.Args.Mesos.NetworkInfo.Labels.NwLabel {
cniLog.Infof("configured labels [%d] {key: %s, val: %s}", idx,
elem.Key, elem.Value)
// copy netplugin related labels
switch elem.Key {
case cniapi.LabelTenantName:
cniApp.cniMesosAttr.Labels.TenantName = elem.Value
case cniapi.LabelNetworkName:
cniApp.cniMesosAttr.Labels.NetworkName = elem.Value
case cniapi.LabelNetworkGroup:
cniApp.cniMesosAttr.Labels.NetworkGroup = elem.Value
}
}
} | go | func (cniApp *cniAppInfo) parseNwInfoLabels() {
var cniNetInfo struct {
Args struct {
Mesos struct {
NetworkInfo struct {
Labels struct {
NwLabel []cniapi.NetworkLabel `json:"labels"`
} `json:"labels"`
} `json:"network_info"`
} `json:"org.apache.mesos"`
} `json:"args"`
}
cniLog.Infof("parse config file %s ", cniApp.netcfgFile)
cfgFile, err := ioutil.ReadFile(cniApp.netcfgFile)
if err != nil {
cniLog.Warnf("%s", err)
return
}
if err := json.Unmarshal(cfgFile, &cniNetInfo); err != nil {
cniLog.Errorf("failed to parse %s, %s", cniApp.netcfgFile, err)
return
}
for idx, elem := range cniNetInfo.Args.Mesos.NetworkInfo.Labels.NwLabel {
cniLog.Infof("configured labels [%d] {key: %s, val: %s}", idx,
elem.Key, elem.Value)
// copy netplugin related labels
switch elem.Key {
case cniapi.LabelTenantName:
cniApp.cniMesosAttr.Labels.TenantName = elem.Value
case cniapi.LabelNetworkName:
cniApp.cniMesosAttr.Labels.NetworkName = elem.Value
case cniapi.LabelNetworkGroup:
cniApp.cniMesosAttr.Labels.NetworkGroup = elem.Value
}
}
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"parseNwInfoLabels",
"(",
")",
"{",
"var",
"cniNetInfo",
"struct",
"{",
"Args",
"struct",
"{",
"Mesos",
"struct",
"{",
"NetworkInfo",
"struct",
"{",
"Labels",
"struct",
"{",
"NwLabel",
"[",
"]",
"cniapi",
".",
"NetworkLabel",
"`json:\"labels\"`",
"\n",
"}",
"`json:\"labels\"`",
"\n",
"}",
"`json:\"network_info\"`",
"\n",
"}",
"`json:\"org.apache.mesos\"`",
"\n",
"}",
"`json:\"args\"`",
"\n",
"}",
"\n\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniApp",
".",
"netcfgFile",
")",
"\n",
"cfgFile",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"cniApp",
".",
"netcfgFile",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"cniLog",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"cfgFile",
",",
"&",
"cniNetInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"cniLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cniApp",
".",
"netcfgFile",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"idx",
",",
"elem",
":=",
"range",
"cniNetInfo",
".",
"Args",
".",
"Mesos",
".",
"NetworkInfo",
".",
"Labels",
".",
"NwLabel",
"{",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"idx",
",",
"elem",
".",
"Key",
",",
"elem",
".",
"Value",
")",
"\n\n",
"// copy netplugin related labels",
"switch",
"elem",
".",
"Key",
"{",
"case",
"cniapi",
".",
"LabelTenantName",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"Labels",
".",
"TenantName",
"=",
"elem",
".",
"Value",
"\n\n",
"case",
"cniapi",
".",
"LabelNetworkName",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"Labels",
".",
"NetworkName",
"=",
"elem",
".",
"Value",
"\n\n",
"case",
"cniapi",
".",
"LabelNetworkGroup",
":",
"cniApp",
".",
"cniMesosAttr",
".",
"Labels",
".",
"NetworkGroup",
"=",
"elem",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // parse labels from network_info | [
"parse",
"labels",
"from",
"network_info"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L108-L151 |
7,808 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | sendCniResp | func (cniApp *cniAppInfo) sendCniResp(cniResp []byte, retCode int) int {
cniLog.Infof("sent CNI response: %s ", cniResp)
fmt.Printf("%s\n", string(cniResp))
return retCode
} | go | func (cniApp *cniAppInfo) sendCniResp(cniResp []byte, retCode int) int {
cniLog.Infof("sent CNI response: %s ", cniResp)
fmt.Printf("%s\n", string(cniResp))
return retCode
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"sendCniResp",
"(",
"cniResp",
"[",
"]",
"byte",
",",
"retCode",
"int",
")",
"int",
"{",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniResp",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"cniResp",
")",
")",
"\n",
"return",
"retCode",
"\n",
"}"
] | // send response received from netplugin to stdout | [
"send",
"response",
"received",
"from",
"netplugin",
"to",
"stdout"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L154-L158 |
7,809 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | sendCniErrorResp | func (cniApp *cniAppInfo) sendCniErrorResp(errorMsg string) int {
cniLog.Infof("prepare CNI error response: %s ", errorMsg)
// CNI_ERROR_UNSUPPORTED is sent for all errors
cniResp := cniapi.CniCmdErrorResp{CniVersion: cniapi.CniDefaultVersion,
ErrCode: cniapi.CniStatusErrorUnsupportedField,
ErrMsg: "contiv: " + errorMsg}
jsonResp, err := json.Marshal(cniResp)
if err == nil {
fmt.Printf("%s\n", string(jsonResp))
cniLog.Infof("CNI error response: %s", string(jsonResp))
} else {
cniLog.Errorf("failed to convert CNI error response to JSON, %s ", err)
// send minimal response to stdout
fmt.Printf("{ \n")
fmt.Printf("\"cniVersion\": \"%s\" \n", cniResp.CniVersion)
fmt.Printf("\"code\": \"%d\" \n", cniResp.ErrCode)
fmt.Printf("\"msg\": \"%s %s\" \n", "contiv", cniResp.ErrMsg)
fmt.Printf("} \n")
}
return int(cniResp.ErrCode)
} | go | func (cniApp *cniAppInfo) sendCniErrorResp(errorMsg string) int {
cniLog.Infof("prepare CNI error response: %s ", errorMsg)
// CNI_ERROR_UNSUPPORTED is sent for all errors
cniResp := cniapi.CniCmdErrorResp{CniVersion: cniapi.CniDefaultVersion,
ErrCode: cniapi.CniStatusErrorUnsupportedField,
ErrMsg: "contiv: " + errorMsg}
jsonResp, err := json.Marshal(cniResp)
if err == nil {
fmt.Printf("%s\n", string(jsonResp))
cniLog.Infof("CNI error response: %s", string(jsonResp))
} else {
cniLog.Errorf("failed to convert CNI error response to JSON, %s ", err)
// send minimal response to stdout
fmt.Printf("{ \n")
fmt.Printf("\"cniVersion\": \"%s\" \n", cniResp.CniVersion)
fmt.Printf("\"code\": \"%d\" \n", cniResp.ErrCode)
fmt.Printf("\"msg\": \"%s %s\" \n", "contiv", cniResp.ErrMsg)
fmt.Printf("} \n")
}
return int(cniResp.ErrCode)
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"sendCniErrorResp",
"(",
"errorMsg",
"string",
")",
"int",
"{",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"errorMsg",
")",
"\n",
"// CNI_ERROR_UNSUPPORTED is sent for all errors",
"cniResp",
":=",
"cniapi",
".",
"CniCmdErrorResp",
"{",
"CniVersion",
":",
"cniapi",
".",
"CniDefaultVersion",
",",
"ErrCode",
":",
"cniapi",
".",
"CniStatusErrorUnsupportedField",
",",
"ErrMsg",
":",
"\"",
"\"",
"+",
"errorMsg",
"}",
"\n\n",
"jsonResp",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"cniResp",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"jsonResp",
")",
")",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"string",
"(",
"jsonResp",
")",
")",
"\n",
"}",
"else",
"{",
"cniLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"// send minimal response to stdout",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"cniResp",
".",
"CniVersion",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"cniResp",
".",
"ErrCode",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"cniResp",
".",
"ErrMsg",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"cniResp",
".",
"ErrCode",
")",
"\n",
"}"
] | // send error response & return code | [
"send",
"error",
"response",
"&",
"return",
"code"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L161-L182 |
7,810 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | handleHTTP | func (cniApp *cniAppInfo) handleHTTP(url string, jsonReq *bytes.Buffer) int {
cniLog.Infof("http POST url: %s data: %v", url, jsonReq)
httpResp, err := cniApp.httpClient.Post(url, "application/json", jsonReq)
if err != nil {
return cniApp.sendCniErrorResp("failed to get response from netplugin :" + err.Error())
}
defer httpResp.Body.Close()
switch httpResp.StatusCode {
case http.StatusOK:
cniLog.Infof("received http OK response from netplugin")
info, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return cniApp.sendCniErrorResp("failed to read success response from netplugin :" + err.Error())
}
return cniApp.sendCniResp(info, cniapi.CniStatusSuccess)
case http.StatusInternalServerError:
cniLog.Infof("received http error response from netplugin")
info, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return cniApp.sendCniErrorResp("failed to read error response from netplugin :" + err.Error())
}
return cniApp.sendCniResp(info, cniapi.CniStatusErrorUnsupportedField)
default:
cniLog.Infof("received unknown error from netplugin")
return cniApp.sendCniErrorResp("error response from netplugin: " + http.StatusText(httpResp.StatusCode))
}
} | go | func (cniApp *cniAppInfo) handleHTTP(url string, jsonReq *bytes.Buffer) int {
cniLog.Infof("http POST url: %s data: %v", url, jsonReq)
httpResp, err := cniApp.httpClient.Post(url, "application/json", jsonReq)
if err != nil {
return cniApp.sendCniErrorResp("failed to get response from netplugin :" + err.Error())
}
defer httpResp.Body.Close()
switch httpResp.StatusCode {
case http.StatusOK:
cniLog.Infof("received http OK response from netplugin")
info, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return cniApp.sendCniErrorResp("failed to read success response from netplugin :" + err.Error())
}
return cniApp.sendCniResp(info, cniapi.CniStatusSuccess)
case http.StatusInternalServerError:
cniLog.Infof("received http error response from netplugin")
info, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return cniApp.sendCniErrorResp("failed to read error response from netplugin :" + err.Error())
}
return cniApp.sendCniResp(info, cniapi.CniStatusErrorUnsupportedField)
default:
cniLog.Infof("received unknown error from netplugin")
return cniApp.sendCniErrorResp("error response from netplugin: " + http.StatusText(httpResp.StatusCode))
}
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"handleHTTP",
"(",
"url",
"string",
",",
"jsonReq",
"*",
"bytes",
".",
"Buffer",
")",
"int",
"{",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"url",
",",
"jsonReq",
")",
"\n",
"httpResp",
",",
"err",
":=",
"cniApp",
".",
"httpClient",
".",
"Post",
"(",
"url",
",",
"\"",
"\"",
",",
"jsonReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cniApp",
".",
"sendCniErrorResp",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"defer",
"httpResp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"switch",
"httpResp",
".",
"StatusCode",
"{",
"case",
"http",
".",
"StatusOK",
":",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"info",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"httpResp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cniApp",
".",
"sendCniErrorResp",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"cniApp",
".",
"sendCniResp",
"(",
"info",
",",
"cniapi",
".",
"CniStatusSuccess",
")",
"\n\n",
"case",
"http",
".",
"StatusInternalServerError",
":",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"info",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"httpResp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cniApp",
".",
"sendCniErrorResp",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"cniApp",
".",
"sendCniResp",
"(",
"info",
",",
"cniapi",
".",
"CniStatusErrorUnsupportedField",
")",
"\n\n",
"default",
":",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"cniApp",
".",
"sendCniErrorResp",
"(",
"\"",
"\"",
"+",
"http",
".",
"StatusText",
"(",
"httpResp",
".",
"StatusCode",
")",
")",
"\n",
"}",
"\n",
"}"
] | // handle http req & response to netplugin | [
"handle",
"http",
"req",
"&",
"response",
"to",
"netplugin"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L185-L216 |
7,811 | contiv/netplugin | mgmtfn/mesosplugin/netcontiv/cniplugin.go | init | func (cniApp *cniAppInfo) init() {
cniApp.serverURL = "http://localhost"
trans := &http.Transport{Dial: func(network, addr string) (net.Conn,
error) {
return net.Dial("unix", cniapi.ContivMesosSocket)
}}
cniApp.httpClient = &http.Client{Transport: trans}
} | go | func (cniApp *cniAppInfo) init() {
cniApp.serverURL = "http://localhost"
trans := &http.Transport{Dial: func(network, addr string) (net.Conn,
error) {
return net.Dial("unix", cniapi.ContivMesosSocket)
}}
cniApp.httpClient = &http.Client{Transport: trans}
} | [
"func",
"(",
"cniApp",
"*",
"cniAppInfo",
")",
"init",
"(",
")",
"{",
"cniApp",
".",
"serverURL",
"=",
"\"",
"\"",
"\n\n",
"trans",
":=",
"&",
"http",
".",
"Transport",
"{",
"Dial",
":",
"func",
"(",
"network",
",",
"addr",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"net",
".",
"Dial",
"(",
"\"",
"\"",
",",
"cniapi",
".",
"ContivMesosSocket",
")",
"\n",
"}",
"}",
"\n",
"cniApp",
".",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"trans",
"}",
"\n",
"}"
] | // initialize netplugin client | [
"initialize",
"netplugin",
"client"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/netcontiv/cniplugin.go#L235-L243 |
7,812 | contiv/netplugin | version/version.go | Get | func Get() *Info {
ver := Info{}
ver.GitCommit = gitCommit
ver.Version = version
ver.BuildTime = buildTime
return &ver
} | go | func Get() *Info {
ver := Info{}
ver.GitCommit = gitCommit
ver.Version = version
ver.BuildTime = buildTime
return &ver
} | [
"func",
"Get",
"(",
")",
"*",
"Info",
"{",
"ver",
":=",
"Info",
"{",
"}",
"\n",
"ver",
".",
"GitCommit",
"=",
"gitCommit",
"\n",
"ver",
".",
"Version",
"=",
"version",
"\n",
"ver",
".",
"BuildTime",
"=",
"buildTime",
"\n\n",
"return",
"&",
"ver",
"\n",
"}"
] | // Get gets the version information | [
"Get",
"gets",
"the",
"version",
"information"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/version/version.go#L36-L43 |
7,813 | contiv/netplugin | version/version.go | StringFromInfo | func StringFromInfo(ver *Info) string {
return fmt.Sprintf("Version: %s\n", ver.Version) +
fmt.Sprintf("GitCommit: %s\n", ver.GitCommit) +
fmt.Sprintf("BuildTime: %s\n", ver.BuildTime)
} | go | func StringFromInfo(ver *Info) string {
return fmt.Sprintf("Version: %s\n", ver.Version) +
fmt.Sprintf("GitCommit: %s\n", ver.GitCommit) +
fmt.Sprintf("BuildTime: %s\n", ver.BuildTime)
} | [
"func",
"StringFromInfo",
"(",
"ver",
"*",
"Info",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"ver",
".",
"Version",
")",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"ver",
".",
"GitCommit",
")",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"ver",
".",
"BuildTime",
")",
"\n",
"}"
] | // StringFromInfo prints the versioning details | [
"StringFromInfo",
"prints",
"the",
"versioning",
"details"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/version/version.go#L52-L56 |
7,814 | contiv/netplugin | mgmtfn/dockplugin/dockplugin.go | InitDockPlugin | func InitDockPlugin(np *plugin.NetPlugin, mode string) error {
// Save state
netPlugin = np
pluginMode = mode
// Get local hostname
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not retrieve hostname: %v", err)
}
log.Debugf("Configuring router")
router := mux.NewRouter()
s := router.Methods("POST").Subrouter()
dispatchMap := map[string]func(http.ResponseWriter, *http.Request){
"/Plugin.Activate": activate(hostname),
"/Plugin.Deactivate": deactivate(hostname),
"/NetworkDriver.GetCapabilities": getCapability,
"/NetworkDriver.CreateNetwork": createNetwork,
"/NetworkDriver.DeleteNetwork": deleteNetwork,
"/NetworkDriver.CreateEndpoint": createEndpoint(hostname),
"/NetworkDriver.DeleteEndpoint": deleteEndpoint(hostname),
"/NetworkDriver.EndpointOperInfo": endpointInfo,
"/NetworkDriver.Join": join,
"/NetworkDriver.Leave": leave,
"/NetworkDriver.AllocateNetwork": allocateNetwork,
"/NetworkDriver.FreeNetwork": freeNetwork,
"/NetworkDriver.ProgramExternalConnectivity": programExternalConnectivity,
"/NetworkDriver.RevokeExternalConnectivity": revokeExternalConnectivity,
"/NetworkDriver.DiscoverNew": discoverNew,
"/NetworkDriver.DiscoverDelete": discoverDelete,
"/IpamDriver.GetDefaultAddressSpaces": getDefaultAddressSpaces,
"/IpamDriver.RequestPool": requestPool,
"/IpamDriver.ReleasePool": releasePool,
"/IpamDriver.RequestAddress": requestAddress,
"/IpamDriver.ReleaseAddress": releaseAddress,
"/IpamDriver.GetCapabilities": getIpamCapability,
}
for dispatchPath, dispatchFunc := range dispatchMap {
s.HandleFunc(dispatchPath, logHandler(dispatchPath, dispatchFunc))
}
s.HandleFunc("/NetworkDriver.{*}", unknownAction)
s.HandleFunc("/IpamDriver.{*}", unknownAction)
driverPath := path.Join(pluginPath, driverName) + ".sock"
os.Remove(driverPath)
os.MkdirAll(pluginPath, 0700)
go func() {
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: driverPath, Net: "unix"})
if err != nil {
panic(err)
}
log.Infof("docker plugin listening on %s", driverPath)
server := &http.Server{Handler: router}
server.SetKeepAlivesEnabled(false)
server.Serve(l)
l.Close()
log.Infof("docker plugin closing %s", driverPath)
}()
return nil
} | go | func InitDockPlugin(np *plugin.NetPlugin, mode string) error {
// Save state
netPlugin = np
pluginMode = mode
// Get local hostname
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not retrieve hostname: %v", err)
}
log.Debugf("Configuring router")
router := mux.NewRouter()
s := router.Methods("POST").Subrouter()
dispatchMap := map[string]func(http.ResponseWriter, *http.Request){
"/Plugin.Activate": activate(hostname),
"/Plugin.Deactivate": deactivate(hostname),
"/NetworkDriver.GetCapabilities": getCapability,
"/NetworkDriver.CreateNetwork": createNetwork,
"/NetworkDriver.DeleteNetwork": deleteNetwork,
"/NetworkDriver.CreateEndpoint": createEndpoint(hostname),
"/NetworkDriver.DeleteEndpoint": deleteEndpoint(hostname),
"/NetworkDriver.EndpointOperInfo": endpointInfo,
"/NetworkDriver.Join": join,
"/NetworkDriver.Leave": leave,
"/NetworkDriver.AllocateNetwork": allocateNetwork,
"/NetworkDriver.FreeNetwork": freeNetwork,
"/NetworkDriver.ProgramExternalConnectivity": programExternalConnectivity,
"/NetworkDriver.RevokeExternalConnectivity": revokeExternalConnectivity,
"/NetworkDriver.DiscoverNew": discoverNew,
"/NetworkDriver.DiscoverDelete": discoverDelete,
"/IpamDriver.GetDefaultAddressSpaces": getDefaultAddressSpaces,
"/IpamDriver.RequestPool": requestPool,
"/IpamDriver.ReleasePool": releasePool,
"/IpamDriver.RequestAddress": requestAddress,
"/IpamDriver.ReleaseAddress": releaseAddress,
"/IpamDriver.GetCapabilities": getIpamCapability,
}
for dispatchPath, dispatchFunc := range dispatchMap {
s.HandleFunc(dispatchPath, logHandler(dispatchPath, dispatchFunc))
}
s.HandleFunc("/NetworkDriver.{*}", unknownAction)
s.HandleFunc("/IpamDriver.{*}", unknownAction)
driverPath := path.Join(pluginPath, driverName) + ".sock"
os.Remove(driverPath)
os.MkdirAll(pluginPath, 0700)
go func() {
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: driverPath, Net: "unix"})
if err != nil {
panic(err)
}
log.Infof("docker plugin listening on %s", driverPath)
server := &http.Server{Handler: router}
server.SetKeepAlivesEnabled(false)
server.Serve(l)
l.Close()
log.Infof("docker plugin closing %s", driverPath)
}()
return nil
} | [
"func",
"InitDockPlugin",
"(",
"np",
"*",
"plugin",
".",
"NetPlugin",
",",
"mode",
"string",
")",
"error",
"{",
"// Save state",
"netPlugin",
"=",
"np",
"\n",
"pluginMode",
"=",
"mode",
"\n\n",
"// Get local hostname",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n\n",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n",
"s",
":=",
"router",
".",
"Methods",
"(",
"\"",
"\"",
")",
".",
"Subrouter",
"(",
")",
"\n\n",
"dispatchMap",
":=",
"map",
"[",
"string",
"]",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"{",
"\"",
"\"",
":",
"activate",
"(",
"hostname",
")",
",",
"\"",
"\"",
":",
"deactivate",
"(",
"hostname",
")",
",",
"\"",
"\"",
":",
"getCapability",
",",
"\"",
"\"",
":",
"createNetwork",
",",
"\"",
"\"",
":",
"deleteNetwork",
",",
"\"",
"\"",
":",
"createEndpoint",
"(",
"hostname",
")",
",",
"\"",
"\"",
":",
"deleteEndpoint",
"(",
"hostname",
")",
",",
"\"",
"\"",
":",
"endpointInfo",
",",
"\"",
"\"",
":",
"join",
",",
"\"",
"\"",
":",
"leave",
",",
"\"",
"\"",
":",
"allocateNetwork",
",",
"\"",
"\"",
":",
"freeNetwork",
",",
"\"",
"\"",
":",
"programExternalConnectivity",
",",
"\"",
"\"",
":",
"revokeExternalConnectivity",
",",
"\"",
"\"",
":",
"discoverNew",
",",
"\"",
"\"",
":",
"discoverDelete",
",",
"\"",
"\"",
":",
"getDefaultAddressSpaces",
",",
"\"",
"\"",
":",
"requestPool",
",",
"\"",
"\"",
":",
"releasePool",
",",
"\"",
"\"",
":",
"requestAddress",
",",
"\"",
"\"",
":",
"releaseAddress",
",",
"\"",
"\"",
":",
"getIpamCapability",
",",
"}",
"\n\n",
"for",
"dispatchPath",
",",
"dispatchFunc",
":=",
"range",
"dispatchMap",
"{",
"s",
".",
"HandleFunc",
"(",
"dispatchPath",
",",
"logHandler",
"(",
"dispatchPath",
",",
"dispatchFunc",
")",
")",
"\n",
"}",
"\n\n",
"s",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"unknownAction",
")",
"\n",
"s",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"unknownAction",
")",
"\n\n",
"driverPath",
":=",
"path",
".",
"Join",
"(",
"pluginPath",
",",
"driverName",
")",
"+",
"\"",
"\"",
"\n",
"os",
".",
"Remove",
"(",
"driverPath",
")",
"\n",
"os",
".",
"MkdirAll",
"(",
"pluginPath",
",",
"0700",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"l",
",",
"err",
":=",
"net",
".",
"ListenUnix",
"(",
"\"",
"\"",
",",
"&",
"net",
".",
"UnixAddr",
"{",
"Name",
":",
"driverPath",
",",
"Net",
":",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"driverPath",
")",
"\n",
"server",
":=",
"&",
"http",
".",
"Server",
"{",
"Handler",
":",
"router",
"}",
"\n",
"server",
".",
"SetKeepAlivesEnabled",
"(",
"false",
")",
"\n",
"server",
".",
"Serve",
"(",
"l",
")",
"\n",
"l",
".",
"Close",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"driverPath",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // InitDockPlugin initializes the docker plugin | [
"InitDockPlugin",
"initializes",
"the",
"docker",
"plugin"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/dockplugin.go#L44-L111 |
7,815 | contiv/netplugin | mgmtfn/dockplugin/dockplugin.go | deactivate | func deactivate(hostname string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logEvent("deactivate")
}
} | go | func deactivate(hostname string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logEvent("deactivate")
}
} | [
"func",
"deactivate",
"(",
"hostname",
"string",
")",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"logEvent",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // deactivate the plugin | [
"deactivate",
"the",
"plugin"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/dockplugin.go#L159-L163 |
7,816 | contiv/netplugin | mgmtfn/dockplugin/dockplugin.go | activate | func activate(hostname string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logEvent("activate")
content, err := json.Marshal(plugins.Manifest{Implements: []string{"NetworkDriver", "IpamDriver"}})
if err != nil {
httpError(w, "Could not generate bootstrap response", err)
return
}
w.Write(content)
}
} | go | func activate(hostname string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logEvent("activate")
content, err := json.Marshal(plugins.Manifest{Implements: []string{"NetworkDriver", "IpamDriver"}})
if err != nil {
httpError(w, "Could not generate bootstrap response", err)
return
}
w.Write(content)
}
} | [
"func",
"activate",
"(",
"hostname",
"string",
")",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"logEvent",
"(",
"\"",
"\"",
")",
"\n\n",
"content",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"plugins",
".",
"Manifest",
"{",
"Implements",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"httpError",
"(",
"w",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"Write",
"(",
"content",
")",
"\n",
"}",
"\n",
"}"
] | // activate the plugin and register it as a network driver. | [
"activate",
"the",
"plugin",
"and",
"register",
"it",
"as",
"a",
"network",
"driver",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/dockplugin.go#L166-L178 |
7,817 | contiv/netplugin | mgmtfn/dockplugin/netDriver.go | GetDockerNetworkName | func GetDockerNetworkName(nwID string) (string, string, string, error) {
// first see if we can find the network in docknet oper state
dnetOper, err := docknet.FindDocknetByUUID(nwID)
if err == nil {
return dnetOper.TenantName, dnetOper.NetworkName, dnetOper.ServiceName, nil
}
if pluginMode == core.SwarmMode {
log.Errorf("Unable to find docknet info in objstore")
return "", "", "", err
}
// create docker client
docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "", nil, nil)
if err != nil {
log.Errorf("Unable to connect to docker. Error %v", err)
return "", "", "", errors.New("unable to connect to docker")
}
nwIDFilter := filters.NewArgs()
nwIDFilter.Add("id", nwID)
nwList, err := docker.NetworkList(context.Background(), types.NetworkListOptions{Filters: nwIDFilter})
if err != nil {
log.Infof("Error: %v", err)
return "", "", "", err
}
if len(nwList) != 1 {
if len(nwList) == 0 {
err = errors.New("network UUID not found")
} else {
err = errors.New("more than one network found with the same ID")
}
return "", "", "", err
}
nw := nwList[0]
log.Infof("Returning network name %s for ID %s", nw.Name, nwID)
// parse the network name
var tenantName, netName, serviceName string
names := strings.Split(nw.Name, "/")
if len(names) == 2 {
// has service.network/tenant format.
tenantName = names[1]
// parse service and network names
sNames := strings.Split(names[0], ".")
if len(sNames) == 2 {
// has service.network format
netName = sNames[1]
serviceName = sNames[0]
} else {
netName = sNames[0]
}
} else if len(names) == 1 {
// has service.network in default tenant
tenantName = defaultTenantName
// parse service and network names
sNames := strings.Split(names[0], ".")
if len(sNames) == 2 {
// has service.network format
netName = sNames[1]
serviceName = sNames[0]
} else {
netName = sNames[0]
}
} else {
log.Errorf("Invalid network name format for network %s", nw.Name)
return "", "", "", errors.New("invalid format")
}
return tenantName, netName, serviceName, nil
} | go | func GetDockerNetworkName(nwID string) (string, string, string, error) {
// first see if we can find the network in docknet oper state
dnetOper, err := docknet.FindDocknetByUUID(nwID)
if err == nil {
return dnetOper.TenantName, dnetOper.NetworkName, dnetOper.ServiceName, nil
}
if pluginMode == core.SwarmMode {
log.Errorf("Unable to find docknet info in objstore")
return "", "", "", err
}
// create docker client
docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "", nil, nil)
if err != nil {
log.Errorf("Unable to connect to docker. Error %v", err)
return "", "", "", errors.New("unable to connect to docker")
}
nwIDFilter := filters.NewArgs()
nwIDFilter.Add("id", nwID)
nwList, err := docker.NetworkList(context.Background(), types.NetworkListOptions{Filters: nwIDFilter})
if err != nil {
log.Infof("Error: %v", err)
return "", "", "", err
}
if len(nwList) != 1 {
if len(nwList) == 0 {
err = errors.New("network UUID not found")
} else {
err = errors.New("more than one network found with the same ID")
}
return "", "", "", err
}
nw := nwList[0]
log.Infof("Returning network name %s for ID %s", nw.Name, nwID)
// parse the network name
var tenantName, netName, serviceName string
names := strings.Split(nw.Name, "/")
if len(names) == 2 {
// has service.network/tenant format.
tenantName = names[1]
// parse service and network names
sNames := strings.Split(names[0], ".")
if len(sNames) == 2 {
// has service.network format
netName = sNames[1]
serviceName = sNames[0]
} else {
netName = sNames[0]
}
} else if len(names) == 1 {
// has service.network in default tenant
tenantName = defaultTenantName
// parse service and network names
sNames := strings.Split(names[0], ".")
if len(sNames) == 2 {
// has service.network format
netName = sNames[1]
serviceName = sNames[0]
} else {
netName = sNames[0]
}
} else {
log.Errorf("Invalid network name format for network %s", nw.Name)
return "", "", "", errors.New("invalid format")
}
return tenantName, netName, serviceName, nil
} | [
"func",
"GetDockerNetworkName",
"(",
"nwID",
"string",
")",
"(",
"string",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"// first see if we can find the network in docknet oper state",
"dnetOper",
",",
"err",
":=",
"docknet",
".",
"FindDocknetByUUID",
"(",
"nwID",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"dnetOper",
".",
"TenantName",
",",
"dnetOper",
".",
"NetworkName",
",",
"dnetOper",
".",
"ServiceName",
",",
"nil",
"\n",
"}",
"\n",
"if",
"pluginMode",
"==",
"core",
".",
"SwarmMode",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// create docker client",
"docker",
",",
"err",
":=",
"dockerclient",
".",
"NewClient",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"nwIDFilter",
":=",
"filters",
".",
"NewArgs",
"(",
")",
"\n",
"nwIDFilter",
".",
"Add",
"(",
"\"",
"\"",
",",
"nwID",
")",
"\n",
"nwList",
",",
"err",
":=",
"docker",
".",
"NetworkList",
"(",
"context",
".",
"Background",
"(",
")",
",",
"types",
".",
"NetworkListOptions",
"{",
"Filters",
":",
"nwIDFilter",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"nwList",
")",
"!=",
"1",
"{",
"if",
"len",
"(",
"nwList",
")",
"==",
"0",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"nw",
":=",
"nwList",
"[",
"0",
"]",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nw",
".",
"Name",
",",
"nwID",
")",
"\n\n",
"// parse the network name",
"var",
"tenantName",
",",
"netName",
",",
"serviceName",
"string",
"\n",
"names",
":=",
"strings",
".",
"Split",
"(",
"nw",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"names",
")",
"==",
"2",
"{",
"// has service.network/tenant format.",
"tenantName",
"=",
"names",
"[",
"1",
"]",
"\n\n",
"// parse service and network names",
"sNames",
":=",
"strings",
".",
"Split",
"(",
"names",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"sNames",
")",
"==",
"2",
"{",
"// has service.network format",
"netName",
"=",
"sNames",
"[",
"1",
"]",
"\n",
"serviceName",
"=",
"sNames",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"netName",
"=",
"sNames",
"[",
"0",
"]",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"names",
")",
"==",
"1",
"{",
"// has service.network in default tenant",
"tenantName",
"=",
"defaultTenantName",
"\n\n",
"// parse service and network names",
"sNames",
":=",
"strings",
".",
"Split",
"(",
"names",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"sNames",
")",
"==",
"2",
"{",
"// has service.network format",
"netName",
"=",
"sNames",
"[",
"1",
"]",
"\n",
"serviceName",
"=",
"sNames",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"netName",
"=",
"sNames",
"[",
"0",
"]",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nw",
".",
"Name",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"tenantName",
",",
"netName",
",",
"serviceName",
",",
"nil",
"\n",
"}"
] | // GetDockerNetworkName gets network name from network UUID | [
"GetDockerNetworkName",
"gets",
"network",
"name",
"from",
"network",
"UUID"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/netDriver.go#L534-L606 |
7,818 | contiv/netplugin | mgmtfn/dockplugin/netDriver.go | FindGroupFromTag | func FindGroupFromTag(epgTag string) (*mastercfg.EndpointGroupState, error) {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
epgCfg := &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
epgList, err := epgCfg.ReadAll()
if err != nil {
return nil, err
}
var epg *mastercfg.EndpointGroupState
found := false
for _, epgP := range epgList {
epg = epgP.(*mastercfg.EndpointGroupState)
if epg.GroupTag == epgTag {
found = true
break
}
}
if !found {
return nil, fmt.Errorf("Couldn't find group matching the tag %s", epgTag)
}
return epg, nil
} | go | func FindGroupFromTag(epgTag string) (*mastercfg.EndpointGroupState, error) {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
epgCfg := &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
epgList, err := epgCfg.ReadAll()
if err != nil {
return nil, err
}
var epg *mastercfg.EndpointGroupState
found := false
for _, epgP := range epgList {
epg = epgP.(*mastercfg.EndpointGroupState)
if epg.GroupTag == epgTag {
found = true
break
}
}
if !found {
return nil, fmt.Errorf("Couldn't find group matching the tag %s", epgTag)
}
return epg, nil
} | [
"func",
"FindGroupFromTag",
"(",
"epgTag",
"string",
")",
"(",
"*",
"mastercfg",
".",
"EndpointGroupState",
",",
"error",
")",
"{",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"epgCfg",
":=",
"&",
"mastercfg",
".",
"EndpointGroupState",
"{",
"}",
"\n",
"epgCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n\n",
"epgList",
",",
"err",
":=",
"epgCfg",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"epg",
"*",
"mastercfg",
".",
"EndpointGroupState",
"\n",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"epgP",
":=",
"range",
"epgList",
"{",
"epg",
"=",
"epgP",
".",
"(",
"*",
"mastercfg",
".",
"EndpointGroupState",
")",
"\n",
"if",
"epg",
".",
"GroupTag",
"==",
"epgTag",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgTag",
")",
"\n",
"}",
"\n",
"return",
"epg",
",",
"nil",
"\n",
"}"
] | // FindGroupFromTag finds the group that has matching tag | [
"FindGroupFromTag",
"finds",
"the",
"group",
"that",
"has",
"matching",
"tag"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/netDriver.go#L609-L636 |
7,819 | contiv/netplugin | mgmtfn/dockplugin/netDriver.go | FindNetworkFromTag | func FindNetworkFromTag(nwTag string) (*mastercfg.CfgNetworkState, error) {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
nwList, err := nwCfg.ReadAll()
if err != nil {
return nil, err
}
var nw *mastercfg.CfgNetworkState
found := false
for _, nwP := range nwList {
nw = nwP.(*mastercfg.CfgNetworkState)
if nw.NetworkTag == nwTag {
found = true
break
}
}
if !found {
return nil, fmt.Errorf("Couldn't find network matching the tag %s", nwTag)
}
return nw, nil
} | go | func FindNetworkFromTag(nwTag string) (*mastercfg.CfgNetworkState, error) {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
nwList, err := nwCfg.ReadAll()
if err != nil {
return nil, err
}
var nw *mastercfg.CfgNetworkState
found := false
for _, nwP := range nwList {
nw = nwP.(*mastercfg.CfgNetworkState)
if nw.NetworkTag == nwTag {
found = true
break
}
}
if !found {
return nil, fmt.Errorf("Couldn't find network matching the tag %s", nwTag)
}
return nw, nil
} | [
"func",
"FindNetworkFromTag",
"(",
"nwTag",
"string",
")",
"(",
"*",
"mastercfg",
".",
"CfgNetworkState",
",",
"error",
")",
"{",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"nwList",
",",
"err",
":=",
"nwCfg",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"nw",
"*",
"mastercfg",
".",
"CfgNetworkState",
"\n",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"nwP",
":=",
"range",
"nwList",
"{",
"nw",
"=",
"nwP",
".",
"(",
"*",
"mastercfg",
".",
"CfgNetworkState",
")",
"\n",
"if",
"nw",
".",
"NetworkTag",
"==",
"nwTag",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nwTag",
")",
"\n",
"}",
"\n",
"return",
"nw",
",",
"nil",
"\n",
"}"
] | // FindNetworkFromTag finds the network that has matching tag | [
"FindNetworkFromTag",
"finds",
"the",
"network",
"that",
"has",
"matching",
"tag"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/netDriver.go#L639-L663 |
7,820 | contiv/netplugin | mgmtfn/dockplugin/netDriver.go | createNetworkHelper | func createNetworkHelper(networkID string, tag string, IPv4Data, IPv6Data []driverapi.IPAMData) error {
var tenantName, networkName, serviceName string
var err error
if tag != "" {
// we need to map docker network to policy group or network using the tag
log.Infof("Received tag %s", tag)
var nw *mastercfg.CfgNetworkState
epg, err := FindGroupFromTag(tag)
if err != nil {
nw, err = FindNetworkFromTag(tag)
if err != nil {
return errors.New("failed to lookup tag")
}
}
if epg != nil {
tenantName = epg.TenantName
networkName = epg.NetworkName
serviceName = epg.GroupName
} else if nw != nil {
tenantName = nw.Tenant
networkName = nw.NetworkName
serviceName = ""
}
} else if len(IPv4Data) > 0 {
// if subnet is specified in docker command, we create a contiv network
subnetPool := ""
gateway := ""
if IPv4Data[0].Pool != nil {
subnetPool = IPv4Data[0].Pool.String()
}
if IPv4Data[0].Gateway != nil {
gateway = strings.Split(IPv4Data[0].Gateway.String(), "/")[0]
}
subnetv6 := ""
gatewayv6 := ""
if len(IPv6Data) > 0 {
if IPv6Data[0].Pool != nil {
subnetv6 = IPv6Data[0].Pool.String()
}
if IPv6Data[0].Gateway != nil {
gatewayv6 = strings.Split(IPv6Data[0].Gateway.String(), "/")[0]
}
}
// build key and URL
keyStr := "default" + ":" + networkID
url := "/api/v1/networks/" + keyStr + "/"
tenantName = "default"
networkName = networkID
serviceName = ""
req := client.Network{
TenantName: tenantName,
NetworkName: networkName,
Subnet: subnetPool,
Gateway: gateway,
Ipv6Subnet: subnetv6,
Ipv6Gateway: gatewayv6,
Encap: "vxlan",
}
var resp client.Network
err = cluster.MasterPostReq(url, &req, &resp)
if err != nil {
log.Errorf("failed to create network in netmaster: %s", err.Error())
return errors.New("failed to create network in netmaster")
}
log.Infof("Created contiv network %+v", req)
}
// Create docknet oper state to map the docker network to contiv network
// We do not create a network in docker as it is created explicitly by user
err = docknet.CreateDockNetState(tenantName, networkName, serviceName, networkID)
if err != nil {
log.Errorf("Error creating docknet state: %s", err.Error())
return errors.New("Error creating docknet state")
}
return nil
} | go | func createNetworkHelper(networkID string, tag string, IPv4Data, IPv6Data []driverapi.IPAMData) error {
var tenantName, networkName, serviceName string
var err error
if tag != "" {
// we need to map docker network to policy group or network using the tag
log.Infof("Received tag %s", tag)
var nw *mastercfg.CfgNetworkState
epg, err := FindGroupFromTag(tag)
if err != nil {
nw, err = FindNetworkFromTag(tag)
if err != nil {
return errors.New("failed to lookup tag")
}
}
if epg != nil {
tenantName = epg.TenantName
networkName = epg.NetworkName
serviceName = epg.GroupName
} else if nw != nil {
tenantName = nw.Tenant
networkName = nw.NetworkName
serviceName = ""
}
} else if len(IPv4Data) > 0 {
// if subnet is specified in docker command, we create a contiv network
subnetPool := ""
gateway := ""
if IPv4Data[0].Pool != nil {
subnetPool = IPv4Data[0].Pool.String()
}
if IPv4Data[0].Gateway != nil {
gateway = strings.Split(IPv4Data[0].Gateway.String(), "/")[0]
}
subnetv6 := ""
gatewayv6 := ""
if len(IPv6Data) > 0 {
if IPv6Data[0].Pool != nil {
subnetv6 = IPv6Data[0].Pool.String()
}
if IPv6Data[0].Gateway != nil {
gatewayv6 = strings.Split(IPv6Data[0].Gateway.String(), "/")[0]
}
}
// build key and URL
keyStr := "default" + ":" + networkID
url := "/api/v1/networks/" + keyStr + "/"
tenantName = "default"
networkName = networkID
serviceName = ""
req := client.Network{
TenantName: tenantName,
NetworkName: networkName,
Subnet: subnetPool,
Gateway: gateway,
Ipv6Subnet: subnetv6,
Ipv6Gateway: gatewayv6,
Encap: "vxlan",
}
var resp client.Network
err = cluster.MasterPostReq(url, &req, &resp)
if err != nil {
log.Errorf("failed to create network in netmaster: %s", err.Error())
return errors.New("failed to create network in netmaster")
}
log.Infof("Created contiv network %+v", req)
}
// Create docknet oper state to map the docker network to contiv network
// We do not create a network in docker as it is created explicitly by user
err = docknet.CreateDockNetState(tenantName, networkName, serviceName, networkID)
if err != nil {
log.Errorf("Error creating docknet state: %s", err.Error())
return errors.New("Error creating docknet state")
}
return nil
} | [
"func",
"createNetworkHelper",
"(",
"networkID",
"string",
",",
"tag",
"string",
",",
"IPv4Data",
",",
"IPv6Data",
"[",
"]",
"driverapi",
".",
"IPAMData",
")",
"error",
"{",
"var",
"tenantName",
",",
"networkName",
",",
"serviceName",
"string",
"\n",
"var",
"err",
"error",
"\n",
"if",
"tag",
"!=",
"\"",
"\"",
"{",
"// we need to map docker network to policy group or network using the tag",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"var",
"nw",
"*",
"mastercfg",
".",
"CfgNetworkState",
"\n",
"epg",
",",
"err",
":=",
"FindGroupFromTag",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"nw",
",",
"err",
"=",
"FindNetworkFromTag",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"epg",
"!=",
"nil",
"{",
"tenantName",
"=",
"epg",
".",
"TenantName",
"\n",
"networkName",
"=",
"epg",
".",
"NetworkName",
"\n",
"serviceName",
"=",
"epg",
".",
"GroupName",
"\n",
"}",
"else",
"if",
"nw",
"!=",
"nil",
"{",
"tenantName",
"=",
"nw",
".",
"Tenant",
"\n",
"networkName",
"=",
"nw",
".",
"NetworkName",
"\n",
"serviceName",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"IPv4Data",
")",
">",
"0",
"{",
"// if subnet is specified in docker command, we create a contiv network",
"subnetPool",
":=",
"\"",
"\"",
"\n",
"gateway",
":=",
"\"",
"\"",
"\n",
"if",
"IPv4Data",
"[",
"0",
"]",
".",
"Pool",
"!=",
"nil",
"{",
"subnetPool",
"=",
"IPv4Data",
"[",
"0",
"]",
".",
"Pool",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"IPv4Data",
"[",
"0",
"]",
".",
"Gateway",
"!=",
"nil",
"{",
"gateway",
"=",
"strings",
".",
"Split",
"(",
"IPv4Data",
"[",
"0",
"]",
".",
"Gateway",
".",
"String",
"(",
")",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"}",
"\n",
"subnetv6",
":=",
"\"",
"\"",
"\n",
"gatewayv6",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"IPv6Data",
")",
">",
"0",
"{",
"if",
"IPv6Data",
"[",
"0",
"]",
".",
"Pool",
"!=",
"nil",
"{",
"subnetv6",
"=",
"IPv6Data",
"[",
"0",
"]",
".",
"Pool",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"IPv6Data",
"[",
"0",
"]",
".",
"Gateway",
"!=",
"nil",
"{",
"gatewayv6",
"=",
"strings",
".",
"Split",
"(",
"IPv6Data",
"[",
"0",
"]",
".",
"Gateway",
".",
"String",
"(",
")",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"// build key and URL",
"keyStr",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"networkID",
"\n",
"url",
":=",
"\"",
"\"",
"+",
"keyStr",
"+",
"\"",
"\"",
"\n\n",
"tenantName",
"=",
"\"",
"\"",
"\n",
"networkName",
"=",
"networkID",
"\n",
"serviceName",
"=",
"\"",
"\"",
"\n\n",
"req",
":=",
"client",
".",
"Network",
"{",
"TenantName",
":",
"tenantName",
",",
"NetworkName",
":",
"networkName",
",",
"Subnet",
":",
"subnetPool",
",",
"Gateway",
":",
"gateway",
",",
"Ipv6Subnet",
":",
"subnetv6",
",",
"Ipv6Gateway",
":",
"gatewayv6",
",",
"Encap",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"var",
"resp",
"client",
".",
"Network",
"\n",
"err",
"=",
"cluster",
".",
"MasterPostReq",
"(",
"url",
",",
"&",
"req",
",",
"&",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"req",
")",
"\n",
"}",
"\n",
"// Create docknet oper state to map the docker network to contiv network",
"// We do not create a network in docker as it is created explicitly by user",
"err",
"=",
"docknet",
".",
"CreateDockNetState",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
",",
"networkID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createNetworkHelper creates the association between docker network and contiv network
// if tag is given map docker net to epg or network, else create a contiv network | [
"createNetworkHelper",
"creates",
"the",
"association",
"between",
"docker",
"network",
"and",
"contiv",
"network",
"if",
"tag",
"is",
"given",
"map",
"docker",
"net",
"to",
"epg",
"or",
"network",
"else",
"create",
"a",
"contiv",
"network"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/netDriver.go#L667-L744 |
7,821 | contiv/netplugin | mgmtfn/dockplugin/netDriver.go | deleteNetworkHelper | func deleteNetworkHelper(networkID string) error {
dnet, err := docknet.FindDocknetByUUID(networkID)
if err == nil {
// delete the dnet oper state
err = docknet.DeleteDockNetState(dnet.TenantName, dnet.NetworkName, dnet.ServiceName)
if err != nil {
msg := fmt.Sprintf("Could not delete docknet for nwID %s: %s", networkID, err.Error())
log.Errorf(msg)
return errors.New(msg)
}
log.Infof("Deleted docker network mapping for %v", networkID)
} else {
msg := fmt.Sprintf("Could not find Docker network %s: %s", networkID, err.Error())
log.Errorf(msg)
}
netID := networkID + ".default"
_, err = utils.GetNetwork(netID)
if err == nil {
// if we find a contiv network with the ID hash, then it must be
// a docker created network (from the libnetwork create api).
// build key and URL
keyStr := "default" + ":" + networkID
url := "/api/v1/networks/" + keyStr + "/"
err = cluster.MasterDelReq(url)
if err != nil {
msg := fmt.Sprintf("Failed to delete network: %s", err.Error())
log.Errorf(msg)
return errors.New(msg)
}
log.Infof("Deleted contiv network %v", networkID)
} else {
log.Infof("Could not find contiv network %v", networkID)
}
return nil
} | go | func deleteNetworkHelper(networkID string) error {
dnet, err := docknet.FindDocknetByUUID(networkID)
if err == nil {
// delete the dnet oper state
err = docknet.DeleteDockNetState(dnet.TenantName, dnet.NetworkName, dnet.ServiceName)
if err != nil {
msg := fmt.Sprintf("Could not delete docknet for nwID %s: %s", networkID, err.Error())
log.Errorf(msg)
return errors.New(msg)
}
log.Infof("Deleted docker network mapping for %v", networkID)
} else {
msg := fmt.Sprintf("Could not find Docker network %s: %s", networkID, err.Error())
log.Errorf(msg)
}
netID := networkID + ".default"
_, err = utils.GetNetwork(netID)
if err == nil {
// if we find a contiv network with the ID hash, then it must be
// a docker created network (from the libnetwork create api).
// build key and URL
keyStr := "default" + ":" + networkID
url := "/api/v1/networks/" + keyStr + "/"
err = cluster.MasterDelReq(url)
if err != nil {
msg := fmt.Sprintf("Failed to delete network: %s", err.Error())
log.Errorf(msg)
return errors.New(msg)
}
log.Infof("Deleted contiv network %v", networkID)
} else {
log.Infof("Could not find contiv network %v", networkID)
}
return nil
} | [
"func",
"deleteNetworkHelper",
"(",
"networkID",
"string",
")",
"error",
"{",
"dnet",
",",
"err",
":=",
"docknet",
".",
"FindDocknetByUUID",
"(",
"networkID",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// delete the dnet oper state",
"err",
"=",
"docknet",
".",
"DeleteDockNetState",
"(",
"dnet",
".",
"TenantName",
",",
"dnet",
".",
"NetworkName",
",",
"dnet",
".",
"ServiceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"networkID",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"log",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"msg",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"networkID",
")",
"\n",
"}",
"else",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"networkID",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"log",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"}",
"\n\n",
"netID",
":=",
"networkID",
"+",
"\"",
"\"",
"\n",
"_",
",",
"err",
"=",
"utils",
".",
"GetNetwork",
"(",
"netID",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// if we find a contiv network with the ID hash, then it must be",
"// a docker created network (from the libnetwork create api).",
"// build key and URL",
"keyStr",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"networkID",
"\n",
"url",
":=",
"\"",
"\"",
"+",
"keyStr",
"+",
"\"",
"\"",
"\n\n",
"err",
"=",
"cluster",
".",
"MasterDelReq",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"log",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"msg",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"networkID",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"networkID",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // deleteNetworkHelper removes the association between docker network
// and contiv network. We have to remove docker network state before
// remove network in contiv. | [
"deleteNetworkHelper",
"removes",
"the",
"association",
"between",
"docker",
"network",
"and",
"contiv",
"network",
".",
"We",
"have",
"to",
"remove",
"docker",
"network",
"state",
"before",
"remove",
"network",
"in",
"contiv",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/dockplugin/netDriver.go#L749-L786 |
7,822 | contiv/netplugin | netplugin/agent/docker_event.go | handleDockerEvents | func (ag *Agent) handleDockerEvents(events <-chan events.Message, errs <-chan error) {
for {
select {
case err := <-errs:
if err != nil && err == io.EOF {
log.Errorf("Closing the events channel. Err: %+v", err)
return
}
if err != nil && err != io.EOF {
log.Errorf("Received error from docker events. Err: %+v", err)
}
case event := <-events:
log.Debugf("Received Docker event: {%#v}\n", event)
// process events only when LB services exist.
if !ag.lbServiceExist() {
continue
}
switch event.Status {
case "start":
endpointUpdReq := &master.UpdateEndpointRequest{}
defaultHeaders := map[string]string{"User-Agent": "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")"}
cli, err := dockerclient.NewClient("unix:///var/run/docker.sock", "v1.21", nil, defaultHeaders)
if err != nil {
panic(err)
}
containerInfo, err := cli.ContainerInspect(context.Background(), event.ID)
if err != nil {
log.Errorf("Container Inspect failed :%s", err)
break
}
if event.ID != "" {
labelMap := getLabelsFromContainerInspect(&containerInfo)
containerTenant := getTenantFromContainerInspect(&containerInfo)
networkName, ipAddress, err := getEpNetworkInfoFromContainerInspect(&containerInfo)
if err != nil {
log.Errorf("Error getting container network info for %v.Err:%s", event.ID, err)
}
endpoint := getEndpointFromContainerInspect(&containerInfo)
if ipAddress != "" {
//Create provider info
endpointUpdReq.IPAddress = ipAddress
endpointUpdReq.ContainerID = event.ID
endpointUpdReq.Tenant = containerTenant
endpointUpdReq.Network = networkName
endpointUpdReq.Event = "start"
endpointUpdReq.EndpointID = endpoint
endpointUpdReq.EPCommonName = containerInfo.Name
endpointUpdReq.Labels = make(map[string]string)
for k, v := range labelMap {
endpointUpdReq.Labels[k] = v
}
}
var epUpdResp master.UpdateEndpointResponse
log.Infof("Sending Endpoint update request to master: {%+v}", endpointUpdReq)
err = cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
if err != nil {
log.Errorf("Event: 'start' , Http error posting endpoint update, Error:%s", err)
}
} else {
log.Errorf("Unable to fetch container labels for container %s ", event.ID)
}
case "die":
endpointUpdReq := &master.UpdateEndpointRequest{}
endpointUpdReq.ContainerID = event.ID
endpointUpdReq.Event = "die"
var epUpdResp master.UpdateEndpointResponse
log.Infof("Sending Endpoint update request to master: {%+v} on container delete", endpointUpdReq)
err := cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
if err != nil {
log.Errorf("Event:'die' Http error posting endpoint update, Error:%s", err)
}
}
}
}
} | go | func (ag *Agent) handleDockerEvents(events <-chan events.Message, errs <-chan error) {
for {
select {
case err := <-errs:
if err != nil && err == io.EOF {
log.Errorf("Closing the events channel. Err: %+v", err)
return
}
if err != nil && err != io.EOF {
log.Errorf("Received error from docker events. Err: %+v", err)
}
case event := <-events:
log.Debugf("Received Docker event: {%#v}\n", event)
// process events only when LB services exist.
if !ag.lbServiceExist() {
continue
}
switch event.Status {
case "start":
endpointUpdReq := &master.UpdateEndpointRequest{}
defaultHeaders := map[string]string{"User-Agent": "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")"}
cli, err := dockerclient.NewClient("unix:///var/run/docker.sock", "v1.21", nil, defaultHeaders)
if err != nil {
panic(err)
}
containerInfo, err := cli.ContainerInspect(context.Background(), event.ID)
if err != nil {
log.Errorf("Container Inspect failed :%s", err)
break
}
if event.ID != "" {
labelMap := getLabelsFromContainerInspect(&containerInfo)
containerTenant := getTenantFromContainerInspect(&containerInfo)
networkName, ipAddress, err := getEpNetworkInfoFromContainerInspect(&containerInfo)
if err != nil {
log.Errorf("Error getting container network info for %v.Err:%s", event.ID, err)
}
endpoint := getEndpointFromContainerInspect(&containerInfo)
if ipAddress != "" {
//Create provider info
endpointUpdReq.IPAddress = ipAddress
endpointUpdReq.ContainerID = event.ID
endpointUpdReq.Tenant = containerTenant
endpointUpdReq.Network = networkName
endpointUpdReq.Event = "start"
endpointUpdReq.EndpointID = endpoint
endpointUpdReq.EPCommonName = containerInfo.Name
endpointUpdReq.Labels = make(map[string]string)
for k, v := range labelMap {
endpointUpdReq.Labels[k] = v
}
}
var epUpdResp master.UpdateEndpointResponse
log.Infof("Sending Endpoint update request to master: {%+v}", endpointUpdReq)
err = cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
if err != nil {
log.Errorf("Event: 'start' , Http error posting endpoint update, Error:%s", err)
}
} else {
log.Errorf("Unable to fetch container labels for container %s ", event.ID)
}
case "die":
endpointUpdReq := &master.UpdateEndpointRequest{}
endpointUpdReq.ContainerID = event.ID
endpointUpdReq.Event = "die"
var epUpdResp master.UpdateEndpointResponse
log.Infof("Sending Endpoint update request to master: {%+v} on container delete", endpointUpdReq)
err := cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
if err != nil {
log.Errorf("Event:'die' Http error posting endpoint update, Error:%s", err)
}
}
}
}
} | [
"func",
"(",
"ag",
"*",
"Agent",
")",
"handleDockerEvents",
"(",
"events",
"<-",
"chan",
"events",
".",
"Message",
",",
"errs",
"<-",
"chan",
"error",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"err",
":=",
"<-",
"errs",
":",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"==",
"io",
".",
"EOF",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"event",
":=",
"<-",
"events",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"event",
")",
"\n",
"// process events only when LB services exist.",
"if",
"!",
"ag",
".",
"lbServiceExist",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"switch",
"event",
".",
"Status",
"{",
"case",
"\"",
"\"",
":",
"endpointUpdReq",
":=",
"&",
"master",
".",
"UpdateEndpointRequest",
"{",
"}",
"\n",
"defaultHeaders",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"+",
"dockerversion",
".",
"Version",
"+",
"\"",
"\"",
"+",
"runtime",
".",
"GOOS",
"+",
"\"",
"\"",
"}",
"\n",
"cli",
",",
"err",
":=",
"dockerclient",
".",
"NewClient",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"defaultHeaders",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"containerInfo",
",",
"err",
":=",
"cli",
".",
"ContainerInspect",
"(",
"context",
".",
"Background",
"(",
")",
",",
"event",
".",
"ID",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"if",
"event",
".",
"ID",
"!=",
"\"",
"\"",
"{",
"labelMap",
":=",
"getLabelsFromContainerInspect",
"(",
"&",
"containerInfo",
")",
"\n",
"containerTenant",
":=",
"getTenantFromContainerInspect",
"(",
"&",
"containerInfo",
")",
"\n",
"networkName",
",",
"ipAddress",
",",
"err",
":=",
"getEpNetworkInfoFromContainerInspect",
"(",
"&",
"containerInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"event",
".",
"ID",
",",
"err",
")",
"\n",
"}",
"\n",
"endpoint",
":=",
"getEndpointFromContainerInspect",
"(",
"&",
"containerInfo",
")",
"\n\n",
"if",
"ipAddress",
"!=",
"\"",
"\"",
"{",
"//Create provider info",
"endpointUpdReq",
".",
"IPAddress",
"=",
"ipAddress",
"\n",
"endpointUpdReq",
".",
"ContainerID",
"=",
"event",
".",
"ID",
"\n",
"endpointUpdReq",
".",
"Tenant",
"=",
"containerTenant",
"\n",
"endpointUpdReq",
".",
"Network",
"=",
"networkName",
"\n",
"endpointUpdReq",
".",
"Event",
"=",
"\"",
"\"",
"\n",
"endpointUpdReq",
".",
"EndpointID",
"=",
"endpoint",
"\n",
"endpointUpdReq",
".",
"EPCommonName",
"=",
"containerInfo",
".",
"Name",
"\n",
"endpointUpdReq",
".",
"Labels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"labelMap",
"{",
"endpointUpdReq",
".",
"Labels",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"epUpdResp",
"master",
".",
"UpdateEndpointResponse",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"endpointUpdReq",
")",
"\n\n",
"err",
"=",
"cluster",
".",
"MasterPostReq",
"(",
"\"",
"\"",
",",
"endpointUpdReq",
",",
"&",
"epUpdResp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"event",
".",
"ID",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"endpointUpdReq",
":=",
"&",
"master",
".",
"UpdateEndpointRequest",
"{",
"}",
"\n",
"endpointUpdReq",
".",
"ContainerID",
"=",
"event",
".",
"ID",
"\n",
"endpointUpdReq",
".",
"Event",
"=",
"\"",
"\"",
"\n",
"var",
"epUpdResp",
"master",
".",
"UpdateEndpointResponse",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"endpointUpdReq",
")",
"\n",
"err",
":=",
"cluster",
".",
"MasterPostReq",
"(",
"\"",
"\"",
",",
"endpointUpdReq",
",",
"&",
"epUpdResp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Handles docker events monitored by dockerclient. Currently we only handle
// container start and die event | [
"Handles",
"docker",
"events",
"monitored",
"by",
"dockerclient",
".",
"Currently",
"we",
"only",
"handle",
"container",
"start",
"and",
"die",
"event"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/docker_event.go#L48-L131 |
7,823 | contiv/netplugin | netplugin/agent/docker_event.go | getLabelsFromContainerInspect | func getLabelsFromContainerInspect(containerInfo *types.ContainerJSON) map[string]string {
if containerInfo != nil && containerInfo.Config != nil {
return containerInfo.Config.Labels
}
return nil
} | go | func getLabelsFromContainerInspect(containerInfo *types.ContainerJSON) map[string]string {
if containerInfo != nil && containerInfo.Config != nil {
return containerInfo.Config.Labels
}
return nil
} | [
"func",
"getLabelsFromContainerInspect",
"(",
"containerInfo",
"*",
"types",
".",
"ContainerJSON",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"containerInfo",
"!=",
"nil",
"&&",
"containerInfo",
".",
"Config",
"!=",
"nil",
"{",
"return",
"containerInfo",
".",
"Config",
".",
"Labels",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | //getLabelsFromContainerInspect returns the labels associated with the container | [
"getLabelsFromContainerInspect",
"returns",
"the",
"labels",
"associated",
"with",
"the",
"container"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/docker_event.go#L134-L139 |
7,824 | contiv/netplugin | netplugin/agent/docker_event.go | getTenantFromContainerInspect | func getTenantFromContainerInspect(containerInfo *types.ContainerJSON) string {
tenant := "default"
if containerInfo != nil && containerInfo.NetworkSettings != nil {
for network := range containerInfo.NetworkSettings.Networks {
if strings.Contains(network, "/") {
//network name is of the form networkname/tenantname for non default tenant
tenant = strings.Split(network, "/")[1]
}
}
}
return tenant
} | go | func getTenantFromContainerInspect(containerInfo *types.ContainerJSON) string {
tenant := "default"
if containerInfo != nil && containerInfo.NetworkSettings != nil {
for network := range containerInfo.NetworkSettings.Networks {
if strings.Contains(network, "/") {
//network name is of the form networkname/tenantname for non default tenant
tenant = strings.Split(network, "/")[1]
}
}
}
return tenant
} | [
"func",
"getTenantFromContainerInspect",
"(",
"containerInfo",
"*",
"types",
".",
"ContainerJSON",
")",
"string",
"{",
"tenant",
":=",
"\"",
"\"",
"\n",
"if",
"containerInfo",
"!=",
"nil",
"&&",
"containerInfo",
".",
"NetworkSettings",
"!=",
"nil",
"{",
"for",
"network",
":=",
"range",
"containerInfo",
".",
"NetworkSettings",
".",
"Networks",
"{",
"if",
"strings",
".",
"Contains",
"(",
"network",
",",
"\"",
"\"",
")",
"{",
"//network name is of the form networkname/tenantname for non default tenant",
"tenant",
"=",
"strings",
".",
"Split",
"(",
"network",
",",
"\"",
"\"",
")",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"tenant",
"\n",
"}"
] | //getTenantFromContainerInspect returns the tenant the container belongs to. | [
"getTenantFromContainerInspect",
"returns",
"the",
"tenant",
"the",
"container",
"belongs",
"to",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/agent/docker_event.go#L142-L153 |
7,825 | contiv/netplugin | drivers/vppd/vppdriver.go | Init | func (d *VppDriver) Init(info *core.InstanceInfo) error {
log.Infof("Initializing vppdriver")
return nil
} | go | func (d *VppDriver) Init(info *core.InstanceInfo) error {
log.Infof("Initializing vppdriver")
return nil
} | [
"func",
"(",
"d",
"*",
"VppDriver",
")",
"Init",
"(",
"info",
"*",
"core",
".",
"InstanceInfo",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Init is not implemented. | [
"Init",
"is",
"not",
"implemented",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/vppd/vppdriver.go#L66-L70 |
7,826 | contiv/netplugin | drivers/vppd/vppdriver.go | DeleteEndpoint | func (d *VppDriver) DeleteEndpoint(id string) (err error) {
log.Infof("Not implemented")
return nil
} | go | func (d *VppDriver) DeleteEndpoint(id string) (err error) {
log.Infof("Not implemented")
return nil
} | [
"func",
"(",
"d",
"*",
"VppDriver",
")",
"DeleteEndpoint",
"(",
"id",
"string",
")",
"(",
"err",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteEndpoint is not implemented. | [
"DeleteEndpoint",
"is",
"not",
"implemented",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/vppd/vppdriver.go#L103-L106 |
7,827 | contiv/netplugin | drivers/vppd/vppdriver.go | AddPeerHost | func (d *VppDriver) AddPeerHost(node core.ServiceInfo) error {
log.Infof("Not implemented")
return nil
} | go | func (d *VppDriver) AddPeerHost(node core.ServiceInfo) error {
log.Infof("Not implemented")
return nil
} | [
"func",
"(",
"d",
"*",
"VppDriver",
")",
"AddPeerHost",
"(",
"node",
"core",
".",
"ServiceInfo",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // AddPeerHost is not implemented. | [
"AddPeerHost",
"is",
"not",
"implemented",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/vppd/vppdriver.go#L133-L136 |
7,828 | contiv/netplugin | drivers/vppd/vppdriver.go | GlobalConfigUpdate | func (d *VppDriver) GlobalConfigUpdate(inst core.InstanceInfo) error {
log.Infof("Not implemented")
return nil
} | go | func (d *VppDriver) GlobalConfigUpdate(inst core.InstanceInfo) error {
log.Infof("Not implemented")
return nil
} | [
"func",
"(",
"d",
"*",
"VppDriver",
")",
"GlobalConfigUpdate",
"(",
"inst",
"core",
".",
"InstanceInfo",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // GlobalConfigUpdate is not implemented | [
"GlobalConfigUpdate",
"is",
"not",
"implemented"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/vppd/vppdriver.go#L203-L206 |
7,829 | contiv/netplugin | netmaster/master/api.go | ReleaseAddressHandler | func ReleaseAddressHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var relReq AddressReleaseRequest
var networkID string
var epgName string
var epgCfg *mastercfg.EndpointGroupState
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&relReq)
if err != nil {
log.Errorf("Error decoding ReleaseAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received AddressReleaseRequest: %+v", relReq)
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
networkID, epgName = getNwAndEpgFromAddrReq(relReq.NetworkID)
if len(epgName) > 0 {
epgCfg = &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
if err = epgCfg.Read(epgName); err != nil {
log.Errorf("failed to read epg %s, %s", epgName, err)
return nil, err
}
log.Infof("AddressReleaseRequest for network: %s epg: %s", networkID, epgName)
}
// find the network from network id
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("network %s is not operational", relReq.NetworkID)
return nil, err
}
// release addresses
err = networkReleaseAddress(nwCfg, epgCfg, relReq.IPv4Address)
if err != nil {
log.Errorf("Failed to release address. Err: %v", err)
return nil, err
}
return "success", nil
} | go | func ReleaseAddressHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var relReq AddressReleaseRequest
var networkID string
var epgName string
var epgCfg *mastercfg.EndpointGroupState
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&relReq)
if err != nil {
log.Errorf("Error decoding ReleaseAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received AddressReleaseRequest: %+v", relReq)
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
networkID, epgName = getNwAndEpgFromAddrReq(relReq.NetworkID)
if len(epgName) > 0 {
epgCfg = &mastercfg.EndpointGroupState{}
epgCfg.StateDriver = stateDriver
if err = epgCfg.Read(epgName); err != nil {
log.Errorf("failed to read epg %s, %s", epgName, err)
return nil, err
}
log.Infof("AddressReleaseRequest for network: %s epg: %s", networkID, epgName)
}
// find the network from network id
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(networkID)
if err != nil {
log.Errorf("network %s is not operational", relReq.NetworkID)
return nil, err
}
// release addresses
err = networkReleaseAddress(nwCfg, epgCfg, relReq.IPv4Address)
if err != nil {
log.Errorf("Failed to release address. Err: %v", err)
return nil, err
}
return "success", nil
} | [
"func",
"ReleaseAddressHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"relReq",
"AddressReleaseRequest",
"\n",
"var",
"networkID",
"string",
"\n",
"var",
"epgName",
"string",
"\n",
"var",
"epgCfg",
"*",
"mastercfg",
".",
"EndpointGroupState",
"\n\n",
"// Get object from the request",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"relReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"relReq",
")",
"\n\n",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"networkID",
",",
"epgName",
"=",
"getNwAndEpgFromAddrReq",
"(",
"relReq",
".",
"NetworkID",
")",
"\n",
"if",
"len",
"(",
"epgName",
")",
">",
"0",
"{",
"epgCfg",
"=",
"&",
"mastercfg",
".",
"EndpointGroupState",
"{",
"}",
"\n",
"epgCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"if",
"err",
"=",
"epgCfg",
".",
"Read",
"(",
"epgName",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epgName",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"networkID",
",",
"epgName",
")",
"\n",
"}",
"\n\n",
"// find the network from network id",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"nwCfg",
".",
"Read",
"(",
"networkID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"relReq",
".",
"NetworkID",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// release addresses",
"err",
"=",
"networkReleaseAddress",
"(",
"nwCfg",
",",
"epgCfg",
",",
"relReq",
".",
"IPv4Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] | // ReleaseAddressHandler releases addresses | [
"ReleaseAddressHandler",
"releases",
"addresses"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/api.go#L275-L323 |
7,830 | contiv/netplugin | netmaster/master/api.go | CreateEndpointHandler | func CreateEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var epReq CreateEndpointRequest
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&epReq)
if err != nil {
log.Errorf("Error decoding AllocAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received CreateEndpointRequest: %+v", epReq)
// Take a global lock for address allocation
addrMutex.Lock()
defer addrMutex.Unlock()
// Gte the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
// find the network from network id
netID := epReq.NetworkName + "." + epReq.TenantName
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(netID)
if err != nil {
log.Errorf("network %s is not operational", netID)
return nil, err
}
// Create the endpoint
epCfg, err := CreateEndpoint(stateDriver, nwCfg, &epReq)
if err != nil {
log.Errorf("CreateEndpoint failure for ep: %v. Err: %v", epReq.ConfigEP, err)
return nil, err
}
// build ep create response
epResp := CreateEndpointResponse{
EndpointConfig: *epCfg,
}
// return the response
return epResp, nil
} | go | func CreateEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var epReq CreateEndpointRequest
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&epReq)
if err != nil {
log.Errorf("Error decoding AllocAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received CreateEndpointRequest: %+v", epReq)
// Take a global lock for address allocation
addrMutex.Lock()
defer addrMutex.Unlock()
// Gte the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
// find the network from network id
netID := epReq.NetworkName + "." + epReq.TenantName
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err = nwCfg.Read(netID)
if err != nil {
log.Errorf("network %s is not operational", netID)
return nil, err
}
// Create the endpoint
epCfg, err := CreateEndpoint(stateDriver, nwCfg, &epReq)
if err != nil {
log.Errorf("CreateEndpoint failure for ep: %v. Err: %v", epReq.ConfigEP, err)
return nil, err
}
// build ep create response
epResp := CreateEndpointResponse{
EndpointConfig: *epCfg,
}
// return the response
return epResp, nil
} | [
"func",
"CreateEndpointHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"epReq",
"CreateEndpointRequest",
"\n\n",
"// Get object from the request",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"epReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"epReq",
")",
"\n",
"// Take a global lock for address allocation",
"addrMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"addrMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Gte the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// find the network from network id",
"netID",
":=",
"epReq",
".",
"NetworkName",
"+",
"\"",
"\"",
"+",
"epReq",
".",
"TenantName",
"\n",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"nwCfg",
".",
"Read",
"(",
"netID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"netID",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create the endpoint",
"epCfg",
",",
"err",
":=",
"CreateEndpoint",
"(",
"stateDriver",
",",
"nwCfg",
",",
"&",
"epReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epReq",
".",
"ConfigEP",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// build ep create response",
"epResp",
":=",
"CreateEndpointResponse",
"{",
"EndpointConfig",
":",
"*",
"epCfg",
",",
"}",
"\n\n",
"// return the response",
"return",
"epResp",
",",
"nil",
"\n",
"}"
] | // CreateEndpointHandler handles create endpoint requests | [
"CreateEndpointHandler",
"handles",
"create",
"endpoint",
"requests"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/api.go#L326-L371 |
7,831 | contiv/netplugin | netmaster/master/api.go | DeleteEndpointHandler | func DeleteEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var epdelReq DeleteEndpointRequest
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&epdelReq)
if err != nil {
log.Errorf("Error decoding AllocAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received DeleteEndpointRequest: %+v", epdelReq)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
// Take a global lock for address release
addrMutex.Lock()
defer addrMutex.Unlock()
// build the endpoint ID
netID := epdelReq.NetworkName + "." + epdelReq.TenantName
epID := getEpName(netID, &intent.ConfigEP{Container: epdelReq.EndpointID})
// delete the endpoint
epCfg, err := DeleteEndpointID(stateDriver, epID)
if err != nil {
log.Errorf("Error deleting endpoint: %v", epID)
return nil, err
}
// build the response
delResp := DeleteEndpointResponse{
EndpointConfig: *epCfg,
}
// done. return resp
return delResp, nil
} | go | func DeleteEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
var epdelReq DeleteEndpointRequest
// Get object from the request
err := json.NewDecoder(r.Body).Decode(&epdelReq)
if err != nil {
log.Errorf("Error decoding AllocAddressHandler. Err %v", err)
return nil, err
}
log.Infof("Received DeleteEndpointRequest: %+v", epdelReq)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return nil, err
}
// Take a global lock for address release
addrMutex.Lock()
defer addrMutex.Unlock()
// build the endpoint ID
netID := epdelReq.NetworkName + "." + epdelReq.TenantName
epID := getEpName(netID, &intent.ConfigEP{Container: epdelReq.EndpointID})
// delete the endpoint
epCfg, err := DeleteEndpointID(stateDriver, epID)
if err != nil {
log.Errorf("Error deleting endpoint: %v", epID)
return nil, err
}
// build the response
delResp := DeleteEndpointResponse{
EndpointConfig: *epCfg,
}
// done. return resp
return delResp, nil
} | [
"func",
"DeleteEndpointHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"epdelReq",
"DeleteEndpointRequest",
"\n\n",
"// Get object from the request",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"epdelReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"epdelReq",
")",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Take a global lock for address release",
"addrMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"addrMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// build the endpoint ID",
"netID",
":=",
"epdelReq",
".",
"NetworkName",
"+",
"\"",
"\"",
"+",
"epdelReq",
".",
"TenantName",
"\n",
"epID",
":=",
"getEpName",
"(",
"netID",
",",
"&",
"intent",
".",
"ConfigEP",
"{",
"Container",
":",
"epdelReq",
".",
"EndpointID",
"}",
")",
"\n\n",
"// delete the endpoint",
"epCfg",
",",
"err",
":=",
"DeleteEndpointID",
"(",
"stateDriver",
",",
"epID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"epID",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// build the response",
"delResp",
":=",
"DeleteEndpointResponse",
"{",
"EndpointConfig",
":",
"*",
"epCfg",
",",
"}",
"\n\n",
"// done. return resp",
"return",
"delResp",
",",
"nil",
"\n",
"}"
] | // DeleteEndpointHandler handles delete endpoint requests | [
"DeleteEndpointHandler",
"handles",
"delete",
"endpoint",
"requests"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/api.go#L374-L414 |
7,832 | contiv/netplugin | mgmtfn/mesosplugin/cniserver.go | parseCniArgs | func (cniReq *cniServer) parseCniArgs(httpBody []byte) error {
if err := json.Unmarshal(httpBody, &cniReq.pluginArgs); err != nil {
return fmt.Errorf("failed to parse JSON req: %s", err.Error())
}
cniLog.Debugf("parsed ifname: %s, netns: %s, container-id: %s,"+
"tenant: %s, network-name: %s, network-group: %s",
cniReq.pluginArgs.CniIfname, cniReq.pluginArgs.CniNetns,
cniReq.pluginArgs.CniContainerid,
cniReq.pluginArgs.Labels.TenantName,
cniReq.pluginArgs.Labels.NetworkName,
cniReq.pluginArgs.Labels.NetworkGroup)
// set defaults
cniReq.endPointLabels = map[string]string{cniapi.LabelNetworkName: "default-net",
cniapi.LabelTenantName: "default"}
for _, label := range []string{cniapi.LabelTenantName, cniapi.LabelNetworkName,
cniapi.LabelNetworkGroup} {
switch label {
case cniapi.LabelTenantName:
if len(cniReq.pluginArgs.Labels.TenantName) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.TenantName
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelTenantName,
cniReq.endPointLabels[label])
case cniapi.LabelNetworkName:
if len(cniReq.pluginArgs.Labels.NetworkName) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkName
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkName,
cniReq.endPointLabels[label])
case cniapi.LabelNetworkGroup:
if len(cniReq.pluginArgs.Labels.NetworkGroup) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkGroup
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkGroup,
cniReq.endPointLabels[label])
}
}
cniReq.networkID = cniReq.endPointLabels[cniapi.LabelNetworkName] + "." +
cniReq.endPointLabels[cniapi.LabelTenantName]
cniLog.Infof("network fdn %s", cniReq.networkID)
cniReq.endpointID = cniReq.networkID + "-" +
cniReq.pluginArgs.CniContainerid
cniLog.Infof("endpoint fdn %s", cniReq.endpointID)
return nil
} | go | func (cniReq *cniServer) parseCniArgs(httpBody []byte) error {
if err := json.Unmarshal(httpBody, &cniReq.pluginArgs); err != nil {
return fmt.Errorf("failed to parse JSON req: %s", err.Error())
}
cniLog.Debugf("parsed ifname: %s, netns: %s, container-id: %s,"+
"tenant: %s, network-name: %s, network-group: %s",
cniReq.pluginArgs.CniIfname, cniReq.pluginArgs.CniNetns,
cniReq.pluginArgs.CniContainerid,
cniReq.pluginArgs.Labels.TenantName,
cniReq.pluginArgs.Labels.NetworkName,
cniReq.pluginArgs.Labels.NetworkGroup)
// set defaults
cniReq.endPointLabels = map[string]string{cniapi.LabelNetworkName: "default-net",
cniapi.LabelTenantName: "default"}
for _, label := range []string{cniapi.LabelTenantName, cniapi.LabelNetworkName,
cniapi.LabelNetworkGroup} {
switch label {
case cniapi.LabelTenantName:
if len(cniReq.pluginArgs.Labels.TenantName) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.TenantName
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelTenantName,
cniReq.endPointLabels[label])
case cniapi.LabelNetworkName:
if len(cniReq.pluginArgs.Labels.NetworkName) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkName
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkName,
cniReq.endPointLabels[label])
case cniapi.LabelNetworkGroup:
if len(cniReq.pluginArgs.Labels.NetworkGroup) > 0 {
cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkGroup
}
cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkGroup,
cniReq.endPointLabels[label])
}
}
cniReq.networkID = cniReq.endPointLabels[cniapi.LabelNetworkName] + "." +
cniReq.endPointLabels[cniapi.LabelTenantName]
cniLog.Infof("network fdn %s", cniReq.networkID)
cniReq.endpointID = cniReq.networkID + "-" +
cniReq.pluginArgs.CniContainerid
cniLog.Infof("endpoint fdn %s", cniReq.endpointID)
return nil
} | [
"func",
"(",
"cniReq",
"*",
"cniServer",
")",
"parseCniArgs",
"(",
"httpBody",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"httpBody",
",",
"&",
"cniReq",
".",
"pluginArgs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"cniLog",
".",
"Debugf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"cniReq",
".",
"pluginArgs",
".",
"CniIfname",
",",
"cniReq",
".",
"pluginArgs",
".",
"CniNetns",
",",
"cniReq",
".",
"pluginArgs",
".",
"CniContainerid",
",",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"TenantName",
",",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkName",
",",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkGroup",
")",
"\n\n",
"// set defaults",
"cniReq",
".",
"endPointLabels",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"cniapi",
".",
"LabelNetworkName",
":",
"\"",
"\"",
",",
"cniapi",
".",
"LabelTenantName",
":",
"\"",
"\"",
"}",
"\n\n",
"for",
"_",
",",
"label",
":=",
"range",
"[",
"]",
"string",
"{",
"cniapi",
".",
"LabelTenantName",
",",
"cniapi",
".",
"LabelNetworkName",
",",
"cniapi",
".",
"LabelNetworkGroup",
"}",
"{",
"switch",
"label",
"{",
"case",
"cniapi",
".",
"LabelTenantName",
":",
"if",
"len",
"(",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"TenantName",
")",
">",
"0",
"{",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
"=",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"TenantName",
"\n",
"}",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniapi",
".",
"LabelTenantName",
",",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
")",
"\n\n",
"case",
"cniapi",
".",
"LabelNetworkName",
":",
"if",
"len",
"(",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkName",
")",
">",
"0",
"{",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
"=",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkName",
"\n",
"}",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniapi",
".",
"LabelNetworkName",
",",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
")",
"\n\n",
"case",
"cniapi",
".",
"LabelNetworkGroup",
":",
"if",
"len",
"(",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkGroup",
")",
">",
"0",
"{",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
"=",
"cniReq",
".",
"pluginArgs",
".",
"Labels",
".",
"NetworkGroup",
"\n",
"}",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniapi",
".",
"LabelNetworkGroup",
",",
"cniReq",
".",
"endPointLabels",
"[",
"label",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"cniReq",
".",
"networkID",
"=",
"cniReq",
".",
"endPointLabels",
"[",
"cniapi",
".",
"LabelNetworkName",
"]",
"+",
"\"",
"\"",
"+",
"cniReq",
".",
"endPointLabels",
"[",
"cniapi",
".",
"LabelTenantName",
"]",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniReq",
".",
"networkID",
")",
"\n",
"cniReq",
".",
"endpointID",
"=",
"cniReq",
".",
"networkID",
"+",
"\"",
"\"",
"+",
"cniReq",
".",
"pluginArgs",
".",
"CniContainerid",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cniReq",
".",
"endpointID",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // parse & save labels | [
"parse",
"&",
"save",
"labels"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/cniserver.go#L95-L147 |
7,833 | contiv/netplugin | mgmtfn/mesosplugin/cniserver.go | InitPlugin | func InitPlugin(netPlugin *plugin.NetPlugin) {
cniLog = log.WithField("plugin", "mesos")
cniLog.Infof("starting Mesos CNI server")
router := mux.NewRouter()
// register handlers for cni plugin
subRtr := router.Headers("Content-Type", "application/json").Subrouter()
subRtr.HandleFunc(cniapi.MesosNwIntfAdd, httpWrapper(mesosNwIntfAdd)).Methods("POST")
subRtr.HandleFunc(cniapi.MesosNwIntfDel, httpWrapper(mesosNwIntfDel)).Methods("POST")
router.HandleFunc("/{*}", unknownReq)
sockFile := cniapi.ContivMesosSocket
os.Remove(sockFile)
os.MkdirAll(cniapi.PluginPath, 0700)
cniDriverInit(netPlugin)
go func() {
lsock, err := net.ListenUnix("unix", &net.UnixAddr{Name: sockFile, Net: "unix"})
if err != nil {
cniLog.Errorf("Mesos CNI server failed: %s", err)
return
}
cniLog.Infof("Mesos CNI server is listening on %s", sockFile)
http.Serve(lsock, router)
lsock.Close()
cniLog.Infof("Mesos CNI server socket %s closed ", sockFile)
}()
} | go | func InitPlugin(netPlugin *plugin.NetPlugin) {
cniLog = log.WithField("plugin", "mesos")
cniLog.Infof("starting Mesos CNI server")
router := mux.NewRouter()
// register handlers for cni plugin
subRtr := router.Headers("Content-Type", "application/json").Subrouter()
subRtr.HandleFunc(cniapi.MesosNwIntfAdd, httpWrapper(mesosNwIntfAdd)).Methods("POST")
subRtr.HandleFunc(cniapi.MesosNwIntfDel, httpWrapper(mesosNwIntfDel)).Methods("POST")
router.HandleFunc("/{*}", unknownReq)
sockFile := cniapi.ContivMesosSocket
os.Remove(sockFile)
os.MkdirAll(cniapi.PluginPath, 0700)
cniDriverInit(netPlugin)
go func() {
lsock, err := net.ListenUnix("unix", &net.UnixAddr{Name: sockFile, Net: "unix"})
if err != nil {
cniLog.Errorf("Mesos CNI server failed: %s", err)
return
}
cniLog.Infof("Mesos CNI server is listening on %s", sockFile)
http.Serve(lsock, router)
lsock.Close()
cniLog.Infof("Mesos CNI server socket %s closed ", sockFile)
}()
} | [
"func",
"InitPlugin",
"(",
"netPlugin",
"*",
"plugin",
".",
"NetPlugin",
")",
"{",
"cniLog",
"=",
"log",
".",
"WithField",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n\n",
"// register handlers for cni plugin",
"subRtr",
":=",
"router",
".",
"Headers",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Subrouter",
"(",
")",
"\n",
"subRtr",
".",
"HandleFunc",
"(",
"cniapi",
".",
"MesosNwIntfAdd",
",",
"httpWrapper",
"(",
"mesosNwIntfAdd",
")",
")",
".",
"Methods",
"(",
"\"",
"\"",
")",
"\n",
"subRtr",
".",
"HandleFunc",
"(",
"cniapi",
".",
"MesosNwIntfDel",
",",
"httpWrapper",
"(",
"mesosNwIntfDel",
")",
")",
".",
"Methods",
"(",
"\"",
"\"",
")",
"\n",
"router",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"unknownReq",
")",
"\n\n",
"sockFile",
":=",
"cniapi",
".",
"ContivMesosSocket",
"\n",
"os",
".",
"Remove",
"(",
"sockFile",
")",
"\n",
"os",
".",
"MkdirAll",
"(",
"cniapi",
".",
"PluginPath",
",",
"0700",
")",
"\n\n",
"cniDriverInit",
"(",
"netPlugin",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"lsock",
",",
"err",
":=",
"net",
".",
"ListenUnix",
"(",
"\"",
"\"",
",",
"&",
"net",
".",
"UnixAddr",
"{",
"Name",
":",
"sockFile",
",",
"Net",
":",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cniLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"sockFile",
")",
"\n",
"http",
".",
"Serve",
"(",
"lsock",
",",
"router",
")",
"\n",
"lsock",
".",
"Close",
"(",
")",
"\n",
"cniLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"sockFile",
")",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // InitPlugin registers REST endpoints to handle requests from Mesos CNI plugins | [
"InitPlugin",
"registers",
"REST",
"endpoints",
"to",
"handle",
"requests",
"from",
"Mesos",
"CNI",
"plugins"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/mesosplugin/cniserver.go#L191-L221 |
7,834 | contiv/netplugin | objdb/objdb.go | RegisterPlugin | func RegisterPlugin(name string, plugin Plugin) error {
pluginMutex.Lock()
defer pluginMutex.Unlock()
pluginList[name] = plugin
return nil
} | go | func RegisterPlugin(name string, plugin Plugin) error {
pluginMutex.Lock()
defer pluginMutex.Unlock()
pluginList[name] = plugin
return nil
} | [
"func",
"RegisterPlugin",
"(",
"name",
"string",
",",
"plugin",
"Plugin",
")",
"error",
"{",
"pluginMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pluginMutex",
".",
"Unlock",
"(",
")",
"\n",
"pluginList",
"[",
"name",
"]",
"=",
"plugin",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // RegisterPlugin Register a plugin | [
"RegisterPlugin",
"Register",
"a",
"plugin"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/objdb.go#L121-L127 |
7,835 | contiv/netplugin | objdb/objdb.go | GetPlugin | func GetPlugin(name string) Plugin {
// Find the conf store
pluginMutex.Lock()
defer pluginMutex.Unlock()
if pluginList[name] == nil {
log.Errorf("Objdb Plugin %s not registered", name)
return nil
}
return pluginList[name]
} | go | func GetPlugin(name string) Plugin {
// Find the conf store
pluginMutex.Lock()
defer pluginMutex.Unlock()
if pluginList[name] == nil {
log.Errorf("Objdb Plugin %s not registered", name)
return nil
}
return pluginList[name]
} | [
"func",
"GetPlugin",
"(",
"name",
"string",
")",
"Plugin",
"{",
"// Find the conf store",
"pluginMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pluginMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"pluginList",
"[",
"name",
"]",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"pluginList",
"[",
"name",
"]",
"\n",
"}"
] | // GetPlugin returns the plugin by name | [
"GetPlugin",
"returns",
"the",
"plugin",
"by",
"name"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/objdb.go#L130-L140 |
7,836 | contiv/netplugin | objdb/client.go | InitClient | func InitClient(storeName string, storeURLs []string) (API, error) {
plugin := GetPlugin(storeName)
if plugin == nil {
log.Errorf("Invalid DB type %s", storeName)
return nil, errors.New("unsupported DB type")
}
cl, err := plugin.NewClient(storeURLs)
if err != nil {
log.Errorf("Error creating client %s to url %v. Err: %v", storeName, storeURLs, err)
return nil, err
}
return cl, nil
} | go | func InitClient(storeName string, storeURLs []string) (API, error) {
plugin := GetPlugin(storeName)
if plugin == nil {
log.Errorf("Invalid DB type %s", storeName)
return nil, errors.New("unsupported DB type")
}
cl, err := plugin.NewClient(storeURLs)
if err != nil {
log.Errorf("Error creating client %s to url %v. Err: %v", storeName, storeURLs, err)
return nil, err
}
return cl, nil
} | [
"func",
"InitClient",
"(",
"storeName",
"string",
",",
"storeURLs",
"[",
"]",
"string",
")",
"(",
"API",
",",
"error",
")",
"{",
"plugin",
":=",
"GetPlugin",
"(",
"storeName",
")",
"\n",
"if",
"plugin",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"storeName",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cl",
",",
"err",
":=",
"plugin",
".",
"NewClient",
"(",
"storeURLs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"storeName",
",",
"storeURLs",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"cl",
",",
"nil",
"\n",
"}"
] | // InitClient aims to support multi endpoints | [
"InitClient",
"aims",
"to",
"support",
"multi",
"endpoints"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/client.go#L28-L40 |
7,837 | contiv/netplugin | objdb/client.go | NewClient | func NewClient(dbURL string) (API, error) {
// check if we should use default db
if dbURL == "" {
dbURL = defaultDbURL
}
parts := strings.Split(dbURL, "://")
if len(parts) < 2 {
log.Errorf("Invalid DB URL format %s", dbURL)
return nil, errors.New("invalid DB URL")
}
clientName := parts[0]
clientURL := parts[1]
return InitClient(clientName, []string{"http://" + clientURL})
} | go | func NewClient(dbURL string) (API, error) {
// check if we should use default db
if dbURL == "" {
dbURL = defaultDbURL
}
parts := strings.Split(dbURL, "://")
if len(parts) < 2 {
log.Errorf("Invalid DB URL format %s", dbURL)
return nil, errors.New("invalid DB URL")
}
clientName := parts[0]
clientURL := parts[1]
return InitClient(clientName, []string{"http://" + clientURL})
} | [
"func",
"NewClient",
"(",
"dbURL",
"string",
")",
"(",
"API",
",",
"error",
")",
"{",
"// check if we should use default db",
"if",
"dbURL",
"==",
"\"",
"\"",
"{",
"dbURL",
"=",
"defaultDbURL",
"\n",
"}",
"\n\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"dbURL",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dbURL",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"clientName",
":=",
"parts",
"[",
"0",
"]",
"\n",
"clientURL",
":=",
"parts",
"[",
"1",
"]",
"\n\n",
"return",
"InitClient",
"(",
"clientName",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"+",
"clientURL",
"}",
")",
"\n",
"}"
] | // NewClient Create a new conf store | [
"NewClient",
"Create",
"a",
"new",
"conf",
"store"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/objdb/client.go#L43-L58 |
7,838 | contiv/netplugin | netmaster/docknet/docknet.go | GetDocknetName | func GetDocknetName(tenantName, networkName, epgName string) string {
netName := ""
// if epg is specified, always use that, else use nw
if epgName == "" {
netName = networkName
} else {
netName = epgName
}
// add tenant suffix if not the default tenant
if tenantName != defaultTenantName {
netName = netName + "/" + tenantName
}
return netName
} | go | func GetDocknetName(tenantName, networkName, epgName string) string {
netName := ""
// if epg is specified, always use that, else use nw
if epgName == "" {
netName = networkName
} else {
netName = epgName
}
// add tenant suffix if not the default tenant
if tenantName != defaultTenantName {
netName = netName + "/" + tenantName
}
return netName
} | [
"func",
"GetDocknetName",
"(",
"tenantName",
",",
"networkName",
",",
"epgName",
"string",
")",
"string",
"{",
"netName",
":=",
"\"",
"\"",
"\n",
"// if epg is specified, always use that, else use nw",
"if",
"epgName",
"==",
"\"",
"\"",
"{",
"netName",
"=",
"networkName",
"\n",
"}",
"else",
"{",
"netName",
"=",
"epgName",
"\n",
"}",
"\n\n",
"// add tenant suffix if not the default tenant",
"if",
"tenantName",
"!=",
"defaultTenantName",
"{",
"netName",
"=",
"netName",
"+",
"\"",
"\"",
"+",
"tenantName",
"\n",
"}",
"\n\n",
"return",
"netName",
"\n",
"}"
] | // GetDocknetName trims default tenant from network name | [
"GetDocknetName",
"trims",
"default",
"tenant",
"from",
"network",
"name"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L86-L102 |
7,839 | contiv/netplugin | netmaster/docknet/docknet.go | UpdateDockerV2PluginName | func UpdateDockerV2PluginName(netDriver string, ipamDriver string) {
log.Infof("docker v2plugin (%s) updated to %s and ipam (%s) updated to %s",
netDriverName, netDriver, ipamDriverName, ipamDriver)
netDriverName = netDriver
ipamDriverName = ipamDriver
} | go | func UpdateDockerV2PluginName(netDriver string, ipamDriver string) {
log.Infof("docker v2plugin (%s) updated to %s and ipam (%s) updated to %s",
netDriverName, netDriver, ipamDriverName, ipamDriver)
netDriverName = netDriver
ipamDriverName = ipamDriver
} | [
"func",
"UpdateDockerV2PluginName",
"(",
"netDriver",
"string",
",",
"ipamDriver",
"string",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"netDriverName",
",",
"netDriver",
",",
"ipamDriverName",
",",
"ipamDriver",
")",
"\n",
"netDriverName",
"=",
"netDriver",
"\n",
"ipamDriverName",
"=",
"ipamDriver",
"\n",
"}"
] | // UpdateDockerV2PluginName update the docker v2 plugin name | [
"UpdateDockerV2PluginName",
"update",
"the",
"docker",
"v2",
"plugin",
"name"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L105-L110 |
7,840 | contiv/netplugin | netmaster/docknet/docknet.go | DeleteDockNet | func DeleteDockNet(tenantName, networkName, serviceName string) error {
// Trim default tenant name
docknetName := GetDocknetName(tenantName, networkName, serviceName)
// connect to docker
defaultHeaders := map[string]string{"User-Agent": "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")"}
docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "v1.23", nil, defaultHeaders)
if err != nil {
log.Errorf("Unable to connect to docker. Error %v", err)
return errors.New("unable to connect to docker")
}
// check whether the network is present in docker
_, err = docker.NetworkInspect(context.Background(), docknetName)
if err != nil {
log.Warnf("Couldnt find network %s in docker", docknetName)
}
docknetDeleted := (err != nil)
log.Infof("Deleting docker network: %+v", docknetName)
// Delete network
err = docker.NetworkRemove(context.Background(), docknetName)
if err != nil {
if !docknetDeleted {
log.Errorf("Error deleting network %s. Err: %v", docknetName, err)
return err
}
// since it was already deleted from docker ignore the error
log.Infof("Ignoring error in deleting docker network %s. Err: %v", docknetName, err)
}
err = DeleteDockNetState(tenantName, networkName, serviceName)
if docknetDeleted && strings.Contains(err.Error(), "key not found") {
// Ignore the error as docknet was already deleted
err = nil
}
return err
} | go | func DeleteDockNet(tenantName, networkName, serviceName string) error {
// Trim default tenant name
docknetName := GetDocknetName(tenantName, networkName, serviceName)
// connect to docker
defaultHeaders := map[string]string{"User-Agent": "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")"}
docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "v1.23", nil, defaultHeaders)
if err != nil {
log.Errorf("Unable to connect to docker. Error %v", err)
return errors.New("unable to connect to docker")
}
// check whether the network is present in docker
_, err = docker.NetworkInspect(context.Background(), docknetName)
if err != nil {
log.Warnf("Couldnt find network %s in docker", docknetName)
}
docknetDeleted := (err != nil)
log.Infof("Deleting docker network: %+v", docknetName)
// Delete network
err = docker.NetworkRemove(context.Background(), docknetName)
if err != nil {
if !docknetDeleted {
log.Errorf("Error deleting network %s. Err: %v", docknetName, err)
return err
}
// since it was already deleted from docker ignore the error
log.Infof("Ignoring error in deleting docker network %s. Err: %v", docknetName, err)
}
err = DeleteDockNetState(tenantName, networkName, serviceName)
if docknetDeleted && strings.Contains(err.Error(), "key not found") {
// Ignore the error as docknet was already deleted
err = nil
}
return err
} | [
"func",
"DeleteDockNet",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
"string",
")",
"error",
"{",
"// Trim default tenant name",
"docknetName",
":=",
"GetDocknetName",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n\n",
"// connect to docker",
"defaultHeaders",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"+",
"dockerversion",
".",
"Version",
"+",
"\"",
"\"",
"+",
"runtime",
".",
"GOOS",
"+",
"\"",
"\"",
"}",
"\n",
"docker",
",",
"err",
":=",
"dockerclient",
".",
"NewClient",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"defaultHeaders",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// check whether the network is present in docker",
"_",
",",
"err",
"=",
"docker",
".",
"NetworkInspect",
"(",
"context",
".",
"Background",
"(",
")",
",",
"docknetName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"docknetName",
")",
"\n",
"}",
"\n",
"docknetDeleted",
":=",
"(",
"err",
"!=",
"nil",
")",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"docknetName",
")",
"\n\n",
"// Delete network",
"err",
"=",
"docker",
".",
"NetworkRemove",
"(",
"context",
".",
"Background",
"(",
")",
",",
"docknetName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"docknetDeleted",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"docknetName",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"// since it was already deleted from docker ignore the error",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"docknetName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"DeleteDockNetState",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n",
"if",
"docknetDeleted",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"// Ignore the error as docknet was already deleted",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteDockNet deletes a network in docker daemon | [
"DeleteDockNet",
"deletes",
"a",
"network",
"in",
"docker",
"daemon"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L206-L244 |
7,841 | contiv/netplugin | netmaster/docknet/docknet.go | CreateDockNetState | func CreateDockNetState(tenantName, networkName, serviceName, docknetID string) error {
log.Infof("Adding DockNetState for %s.%s.%s --> %s", tenantName, networkName, serviceName, docknetID)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet add %v", err)
return err
}
// save docknet oper state
dnetOper := DnetOperState{
TenantName: tenantName,
NetworkName: networkName,
ServiceName: serviceName,
DocknetUUID: docknetID,
}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// write the dnet oper state
return dnetOper.Write()
} | go | func CreateDockNetState(tenantName, networkName, serviceName, docknetID string) error {
log.Infof("Adding DockNetState for %s.%s.%s --> %s", tenantName, networkName, serviceName, docknetID)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet add %v", err)
return err
}
// save docknet oper state
dnetOper := DnetOperState{
TenantName: tenantName,
NetworkName: networkName,
ServiceName: serviceName,
DocknetUUID: docknetID,
}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// write the dnet oper state
return dnetOper.Write()
} | [
"func",
"CreateDockNetState",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
",",
"docknetID",
"string",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
",",
"docknetID",
")",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save docknet oper state",
"dnetOper",
":=",
"DnetOperState",
"{",
"TenantName",
":",
"tenantName",
",",
"NetworkName",
":",
"networkName",
",",
"ServiceName",
":",
"serviceName",
",",
"DocknetUUID",
":",
"docknetID",
",",
"}",
"\n",
"dnetOper",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n",
"dnetOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n\n",
"// write the dnet oper state",
"return",
"dnetOper",
".",
"Write",
"(",
")",
"\n",
"}"
] | // CreateDockNetState creates an entry in the docknet state store | [
"CreateDockNetState",
"creates",
"an",
"entry",
"in",
"the",
"docknet",
"state",
"store"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L247-L269 |
7,842 | contiv/netplugin | netmaster/docknet/docknet.go | DeleteDockNetState | func DeleteDockNetState(tenantName, networkName, serviceName string) error {
log.Infof("Deleting DockNetState for %s.%s.%s", tenantName, networkName, serviceName)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet del %v", err)
return err
}
// save docknet oper state
dnetOper := DnetOperState{}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// write the dnet oper state
return dnetOper.Clear()
} | go | func DeleteDockNetState(tenantName, networkName, serviceName string) error {
log.Infof("Deleting DockNetState for %s.%s.%s", tenantName, networkName, serviceName)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet del %v", err)
return err
}
// save docknet oper state
dnetOper := DnetOperState{}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// write the dnet oper state
return dnetOper.Clear()
} | [
"func",
"DeleteDockNetState",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
"string",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save docknet oper state",
"dnetOper",
":=",
"DnetOperState",
"{",
"}",
"\n",
"dnetOper",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n",
"dnetOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n\n",
"// write the dnet oper state",
"return",
"dnetOper",
".",
"Clear",
"(",
")",
"\n",
"}"
] | // DeleteDockNetState delete the docknet entry from state store | [
"DeleteDockNetState",
"delete",
"the",
"docknet",
"entry",
"from",
"state",
"store"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L272-L289 |
7,843 | contiv/netplugin | netmaster/docknet/docknet.go | GetDocknetState | func GetDocknetState(tenantName, networkName, serviceName string) (*DnetOperState, error) {
log.Infof("GetDocknetState for %s.%s.%s", tenantName, networkName, serviceName)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet %v", err)
return nil, err
}
// save docknet oper state
dnetOper := DnetOperState{}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// Read the dnet oper state
err = dnetOper.Read(dnetOper.ID)
if err == nil {
return &dnetOper, nil
}
return nil, err
} | go | func GetDocknetState(tenantName, networkName, serviceName string) (*DnetOperState, error) {
log.Infof("GetDocknetState for %s.%s.%s", tenantName, networkName, serviceName)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't get state driver for docknet %v", err)
return nil, err
}
// save docknet oper state
dnetOper := DnetOperState{}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver
// Read the dnet oper state
err = dnetOper.Read(dnetOper.ID)
if err == nil {
return &dnetOper, nil
}
return nil, err
} | [
"func",
"GetDocknetState",
"(",
"tenantName",
",",
"networkName",
",",
"serviceName",
"string",
")",
"(",
"*",
"DnetOperState",
",",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// save docknet oper state",
"dnetOper",
":=",
"DnetOperState",
"{",
"}",
"\n",
"dnetOper",
".",
"ID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tenantName",
",",
"networkName",
",",
"serviceName",
")",
"\n",
"dnetOper",
".",
"StateDriver",
"=",
"stateDriver",
"\n\n",
"// Read the dnet oper state",
"err",
"=",
"dnetOper",
".",
"Read",
"(",
"dnetOper",
".",
"ID",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"&",
"dnetOper",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}"
] | // GetDocknetState gets the docknet entry from state store | [
"GetDocknetState",
"gets",
"the",
"docknet",
"entry",
"from",
"state",
"store"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L292-L313 |
7,844 | contiv/netplugin | netmaster/docknet/docknet.go | FindDocknetByUUID | func FindDocknetByUUID(dnetID string) (*DnetOperState, error) {
log.Infof("find docker network '%s' ", dnetID)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't read global config %v", err)
return nil, err
}
tmpDnet := DnetOperState{}
tmpDnet.StateDriver = stateDriver
dnetOperList, err := tmpDnet.ReadAll()
if err != nil {
log.Errorf("Error getting docknet list. Err: %v", err)
return nil, err
}
// Walk all dnets and find the matching UUID
for _, dnet := range dnetOperList {
if dnet.(*DnetOperState).DocknetUUID == dnetID {
return dnet.(*DnetOperState), nil
}
}
return nil, errors.New("docknet UUID not found")
} | go | func FindDocknetByUUID(dnetID string) (*DnetOperState, error) {
log.Infof("find docker network '%s' ", dnetID)
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't read global config %v", err)
return nil, err
}
tmpDnet := DnetOperState{}
tmpDnet.StateDriver = stateDriver
dnetOperList, err := tmpDnet.ReadAll()
if err != nil {
log.Errorf("Error getting docknet list. Err: %v", err)
return nil, err
}
// Walk all dnets and find the matching UUID
for _, dnet := range dnetOperList {
if dnet.(*DnetOperState).DocknetUUID == dnetID {
return dnet.(*DnetOperState), nil
}
}
return nil, errors.New("docknet UUID not found")
} | [
"func",
"FindDocknetByUUID",
"(",
"dnetID",
"string",
")",
"(",
"*",
"DnetOperState",
",",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"dnetID",
")",
"\n\n",
"// Get the state driver",
"stateDriver",
",",
"err",
":=",
"utils",
".",
"GetStateDriver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tmpDnet",
":=",
"DnetOperState",
"{",
"}",
"\n",
"tmpDnet",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"dnetOperList",
",",
"err",
":=",
"tmpDnet",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Walk all dnets and find the matching UUID",
"for",
"_",
",",
"dnet",
":=",
"range",
"dnetOperList",
"{",
"if",
"dnet",
".",
"(",
"*",
"DnetOperState",
")",
".",
"DocknetUUID",
"==",
"dnetID",
"{",
"return",
"dnet",
".",
"(",
"*",
"DnetOperState",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // FindDocknetByUUID find the docknet by UUID | [
"FindDocknetByUUID",
"find",
"the",
"docknet",
"by",
"UUID"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/docknet/docknet.go#L316-L342 |
7,845 | contiv/netplugin | utils/k8sutils/k8sutils.go | GetK8SConfig | func GetK8SConfig(pCfg *ContivConfig) error {
bytes, err := ioutil.ReadFile(contivKubeCfgFile)
if err != nil {
return err
}
pCfg.SvcSubnet = defSvcSubnet
err = json.Unmarshal(bytes, pCfg)
if err != nil {
return fmt.Errorf("Error parsing config file: %s", err)
}
// If no client certs or token is specified, get the default token
if len(strings.TrimSpace(pCfg.K8sCert)) == 0 && len(strings.TrimSpace(pCfg.K8sToken)) == 0 {
pCfg.K8sToken, err = getDefaultToken()
if err != nil {
log.Errorf("Failed: %v", err)
return err
}
}
return nil
} | go | func GetK8SConfig(pCfg *ContivConfig) error {
bytes, err := ioutil.ReadFile(contivKubeCfgFile)
if err != nil {
return err
}
pCfg.SvcSubnet = defSvcSubnet
err = json.Unmarshal(bytes, pCfg)
if err != nil {
return fmt.Errorf("Error parsing config file: %s", err)
}
// If no client certs or token is specified, get the default token
if len(strings.TrimSpace(pCfg.K8sCert)) == 0 && len(strings.TrimSpace(pCfg.K8sToken)) == 0 {
pCfg.K8sToken, err = getDefaultToken()
if err != nil {
log.Errorf("Failed: %v", err)
return err
}
}
return nil
} | [
"func",
"GetK8SConfig",
"(",
"pCfg",
"*",
"ContivConfig",
")",
"error",
"{",
"bytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"contivKubeCfgFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"pCfg",
".",
"SvcSubnet",
"=",
"defSvcSubnet",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"bytes",
",",
"pCfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// If no client certs or token is specified, get the default token",
"if",
"len",
"(",
"strings",
".",
"TrimSpace",
"(",
"pCfg",
".",
"K8sCert",
")",
")",
"==",
"0",
"&&",
"len",
"(",
"strings",
".",
"TrimSpace",
"(",
"pCfg",
".",
"K8sToken",
")",
")",
"==",
"0",
"{",
"pCfg",
".",
"K8sToken",
",",
"err",
"=",
"getDefaultToken",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // GetK8SConfig reads and parses the contivKubeCfgFile | [
"GetK8SConfig",
"reads",
"and",
"parses",
"the",
"contivKubeCfgFile"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/k8sutils/k8sutils.go#L32-L54 |
7,846 | contiv/netplugin | utils/k8sutils/k8sutils.go | SetUpK8SClient | func SetUpK8SClient() (*kubernetes.Clientset, error) {
var contivK8sCfg ContivConfig
err := GetK8SConfig(&contivK8sCfg)
if err != nil {
log.Errorf("Failed to get K8S config: %v", err)
return nil, err
}
// init k8s client
restCfg := &k8sRest.Config{
Host: contivK8sCfg.K8sAPIServer,
BearerToken: contivK8sCfg.K8sToken,
TLSClientConfig: k8sRest.TLSClientConfig{CAFile: contivK8sCfg.K8sCa},
}
clientSet, err := kubernetes.NewForConfig(restCfg)
if err != nil {
log.Errorf("failed to create kubernetes client instance %s, %+v", err, restCfg)
return nil, err
}
return clientSet, nil
} | go | func SetUpK8SClient() (*kubernetes.Clientset, error) {
var contivK8sCfg ContivConfig
err := GetK8SConfig(&contivK8sCfg)
if err != nil {
log.Errorf("Failed to get K8S config: %v", err)
return nil, err
}
// init k8s client
restCfg := &k8sRest.Config{
Host: contivK8sCfg.K8sAPIServer,
BearerToken: contivK8sCfg.K8sToken,
TLSClientConfig: k8sRest.TLSClientConfig{CAFile: contivK8sCfg.K8sCa},
}
clientSet, err := kubernetes.NewForConfig(restCfg)
if err != nil {
log.Errorf("failed to create kubernetes client instance %s, %+v", err, restCfg)
return nil, err
}
return clientSet, nil
} | [
"func",
"SetUpK8SClient",
"(",
")",
"(",
"*",
"kubernetes",
".",
"Clientset",
",",
"error",
")",
"{",
"var",
"contivK8sCfg",
"ContivConfig",
"\n",
"err",
":=",
"GetK8SConfig",
"(",
"&",
"contivK8sCfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// init k8s client",
"restCfg",
":=",
"&",
"k8sRest",
".",
"Config",
"{",
"Host",
":",
"contivK8sCfg",
".",
"K8sAPIServer",
",",
"BearerToken",
":",
"contivK8sCfg",
".",
"K8sToken",
",",
"TLSClientConfig",
":",
"k8sRest",
".",
"TLSClientConfig",
"{",
"CAFile",
":",
"contivK8sCfg",
".",
"K8sCa",
"}",
",",
"}",
"\n",
"clientSet",
",",
"err",
":=",
"kubernetes",
".",
"NewForConfig",
"(",
"restCfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"restCfg",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"clientSet",
",",
"nil",
"\n",
"}"
] | // SetUpK8SClient init K8S client | [
"SetUpK8SClient",
"init",
"K8S",
"client"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/k8sutils/k8sutils.go#L57-L78 |
7,847 | contiv/netplugin | utils/k8sutils/k8sutils.go | getDefaultToken | func getDefaultToken() (string, error) {
bytes, err := ioutil.ReadFile(tokenFile)
if err != nil {
log.Errorf("Failed: %v", err)
return "", err
}
return string(bytes), nil
} | go | func getDefaultToken() (string, error) {
bytes, err := ioutil.ReadFile(tokenFile)
if err != nil {
log.Errorf("Failed: %v", err)
return "", err
}
return string(bytes), nil
} | [
"func",
"getDefaultToken",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"bytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"tokenFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"string",
"(",
"bytes",
")",
",",
"nil",
"\n",
"}"
] | // getDefaultToken gets the token to access kubernetes API Server
// from the secrets loaded on the container | [
"getDefaultToken",
"gets",
"the",
"token",
"to",
"access",
"kubernetes",
"API",
"Server",
"from",
"the",
"secrets",
"loaded",
"on",
"the",
"container"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/k8sutils/k8sutils.go#L82-L89 |
7,848 | contiv/netplugin | netmaster/master/network.go | CreateNetworks | func CreateNetworks(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
// Validate the config
err := validateNetworkConfig(tenant)
if err != nil {
log.Errorf("error validating network config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
err = CreateNetwork(network, stateDriver, tenant.Name)
if err != nil {
log.Errorf("Error creating network {%+v}. Err: %v", network, err)
return err
}
}
return err
} | go | func CreateNetworks(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
// Validate the config
err := validateNetworkConfig(tenant)
if err != nil {
log.Errorf("error validating network config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
err = CreateNetwork(network, stateDriver, tenant.Name)
if err != nil {
log.Errorf("Error creating network {%+v}. Err: %v", network, err)
return err
}
}
return err
} | [
"func",
"CreateNetworks",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"tenant",
"*",
"intent",
".",
"ConfigTenant",
")",
"error",
"{",
"// Validate the config",
"err",
":=",
"validateNetworkConfig",
"(",
"tenant",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"network",
":=",
"range",
"tenant",
".",
"Networks",
"{",
"err",
"=",
"CreateNetwork",
"(",
"network",
",",
"stateDriver",
",",
"tenant",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"network",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // CreateNetworks creates the necessary virtual networks for the tenant
// provided by ConfigTenant. | [
"CreateNetworks",
"creates",
"the",
"necessary",
"virtual",
"networks",
"for",
"the",
"tenant",
"provided",
"by",
"ConfigTenant",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/network.go#L207-L224 |
7,849 | contiv/netplugin | netmaster/master/network.go | DeleteNetworkID | func DeleteNetworkID(stateDriver core.StateDriver, netID string) error {
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err := nwCfg.Read(netID)
if err != nil {
log.Errorf("network %s is not operational", netID)
return err
}
// Will Skip docker network deletion for ACI fabric mode.
aci, _ := IsAciConfigured()
if nwCfg.NwType != "infra" {
// For Infra nw, endpoint delete initiated by netplugin
// Check if there are any active endpoints
if hasActiveEndpoints(nwCfg) {
return core.Errorf("Error: Network has active endpoints")
}
if GetClusterMode() == core.Docker && aci == false {
// Delete the docker network
err = docknet.DeleteDockNet(nwCfg.Tenant, nwCfg.NetworkName, "")
if err != nil {
log.Errorf("Error deleting network %s. Err: %v", netID, err)
// DeleteDockNet will fail when network has active endpoints.
// No damage is done yet. It is safe to fail.
return err
}
}
}
gstate.GlobalMutex.Lock()
defer gstate.GlobalMutex.Unlock()
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err = gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant info for %q. Error: %s", nwCfg.Tenant, err)
return err
}
// Free resource associated with the network
err = freeNetworkResources(stateDriver, nwCfg, gCfg)
if err != nil {
// Error while freeing up vlan/vxlan/subnet/gateway resources
// This can only happen because of defects in code
// No need of any corrective handling here
return err
}
err = nwCfg.Clear()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
return err
} | go | func DeleteNetworkID(stateDriver core.StateDriver, netID string) error {
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
err := nwCfg.Read(netID)
if err != nil {
log.Errorf("network %s is not operational", netID)
return err
}
// Will Skip docker network deletion for ACI fabric mode.
aci, _ := IsAciConfigured()
if nwCfg.NwType != "infra" {
// For Infra nw, endpoint delete initiated by netplugin
// Check if there are any active endpoints
if hasActiveEndpoints(nwCfg) {
return core.Errorf("Error: Network has active endpoints")
}
if GetClusterMode() == core.Docker && aci == false {
// Delete the docker network
err = docknet.DeleteDockNet(nwCfg.Tenant, nwCfg.NetworkName, "")
if err != nil {
log.Errorf("Error deleting network %s. Err: %v", netID, err)
// DeleteDockNet will fail when network has active endpoints.
// No damage is done yet. It is safe to fail.
return err
}
}
}
gstate.GlobalMutex.Lock()
defer gstate.GlobalMutex.Unlock()
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err = gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant info for %q. Error: %s", nwCfg.Tenant, err)
return err
}
// Free resource associated with the network
err = freeNetworkResources(stateDriver, nwCfg, gCfg)
if err != nil {
// Error while freeing up vlan/vxlan/subnet/gateway resources
// This can only happen because of defects in code
// No need of any corrective handling here
return err
}
err = nwCfg.Clear()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
return err
} | [
"func",
"DeleteNetworkID",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"netID",
"string",
")",
"error",
"{",
"nwCfg",
":=",
"&",
"mastercfg",
".",
"CfgNetworkState",
"{",
"}",
"\n",
"nwCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
":=",
"nwCfg",
".",
"Read",
"(",
"netID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"netID",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Will Skip docker network deletion for ACI fabric mode.",
"aci",
",",
"_",
":=",
"IsAciConfigured",
"(",
")",
"\n\n",
"if",
"nwCfg",
".",
"NwType",
"!=",
"\"",
"\"",
"{",
"// For Infra nw, endpoint delete initiated by netplugin",
"// Check if there are any active endpoints",
"if",
"hasActiveEndpoints",
"(",
"nwCfg",
")",
"{",
"return",
"core",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"GetClusterMode",
"(",
")",
"==",
"core",
".",
"Docker",
"&&",
"aci",
"==",
"false",
"{",
"// Delete the docker network",
"err",
"=",
"docknet",
".",
"DeleteDockNet",
"(",
"nwCfg",
".",
"Tenant",
",",
"nwCfg",
".",
"NetworkName",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"netID",
",",
"err",
")",
"\n",
"// DeleteDockNet will fail when network has active endpoints.",
"// No damage is done yet. It is safe to fail.",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"gstate",
".",
"GlobalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"gstate",
".",
"GlobalMutex",
".",
"Unlock",
"(",
")",
"\n",
"gCfg",
":=",
"&",
"gstate",
".",
"Cfg",
"{",
"}",
"\n",
"gCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n",
"err",
"=",
"gCfg",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nwCfg",
".",
"Tenant",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Free resource associated with the network",
"err",
"=",
"freeNetworkResources",
"(",
"stateDriver",
",",
"nwCfg",
",",
"gCfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Error while freeing up vlan/vxlan/subnet/gateway resources",
"// This can only happen because of defects in code",
"// No need of any corrective handling here",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"nwCfg",
".",
"Clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // DeleteNetworkID removes a network by ID. | [
"DeleteNetworkID",
"removes",
"a",
"network",
"by",
"ID",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/network.go#L248-L305 |
7,850 | contiv/netplugin | netmaster/master/network.go | DeleteNetworks | func DeleteNetworks(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err := gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant state. Error: %s", err)
return err
}
err = validateNetworkConfig(tenant)
if err != nil {
log.Errorf("error validating network config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
networkID := network.Name + "." + tenant.Name
err = DeleteNetworkID(stateDriver, networkID)
if err != nil {
return err
}
}
return err
} | go | func DeleteNetworks(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err := gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant state. Error: %s", err)
return err
}
err = validateNetworkConfig(tenant)
if err != nil {
log.Errorf("error validating network config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
networkID := network.Name + "." + tenant.Name
err = DeleteNetworkID(stateDriver, networkID)
if err != nil {
return err
}
}
return err
} | [
"func",
"DeleteNetworks",
"(",
"stateDriver",
"core",
".",
"StateDriver",
",",
"tenant",
"*",
"intent",
".",
"ConfigTenant",
")",
"error",
"{",
"gCfg",
":=",
"&",
"gstate",
".",
"Cfg",
"{",
"}",
"\n",
"gCfg",
".",
"StateDriver",
"=",
"stateDriver",
"\n\n",
"err",
":=",
"gCfg",
".",
"Read",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"validateNetworkConfig",
"(",
"tenant",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"network",
":=",
"range",
"tenant",
".",
"Networks",
"{",
"networkID",
":=",
"network",
".",
"Name",
"+",
"\"",
"\"",
"+",
"tenant",
".",
"Name",
"\n",
"err",
"=",
"DeleteNetworkID",
"(",
"stateDriver",
",",
"networkID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // DeleteNetworks removes all the virtual networks for a given tenant. | [
"DeleteNetworks",
"removes",
"all",
"the",
"virtual",
"networks",
"for",
"a",
"given",
"tenant",
"."
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/network.go#L308-L333 |
7,851 | contiv/netplugin | netmaster/master/network.go | networkReleaseAddress | func networkReleaseAddress(nwCfg *mastercfg.CfgNetworkState, epgCfg *mastercfg.EndpointGroupState, ipAddress string) error {
isIPv6 := netutils.IsIPv6(ipAddress)
if isIPv6 {
hostID, err := netutils.GetIPv6HostID(nwCfg.SubnetIP, nwCfg.SubnetLen, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if _, found := nwCfg.IPv6AllocMap[hostID]; found {
nwCfg.EpAddrCount--
}
delete(nwCfg.IPv6AllocMap, hostID)
} else {
if epgCfg != nil && len(epgCfg.IPPool) > 0 {
log.Infof("releasing epg ip: %s", ipAddress)
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s pool %s. Error: %s",
ipAddress, epgCfg.IPPool, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if epgCfg.EPGIPAllocMap.Test(ipAddrValue) {
nwCfg.EpAddrCount--
}
epgCfg.EPGIPAllocMap.Clear(ipAddrValue)
if err := epgCfg.Write(); err != nil {
log.Errorf("error writing epg config. Error: %s", err)
return err
}
} else {
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if nwCfg.IPAllocMap.Test(ipAddrValue) {
nwCfg.EpAddrCount--
}
nwCfg.IPAllocMap.Clear(ipAddrValue)
log.Infof("Releasing IP Address: %v"+
"from networkId:%+v", ipAddrValue,
nwCfg.NetworkName)
}
}
err := nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
return nil
} | go | func networkReleaseAddress(nwCfg *mastercfg.CfgNetworkState, epgCfg *mastercfg.EndpointGroupState, ipAddress string) error {
isIPv6 := netutils.IsIPv6(ipAddress)
if isIPv6 {
hostID, err := netutils.GetIPv6HostID(nwCfg.SubnetIP, nwCfg.SubnetLen, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if _, found := nwCfg.IPv6AllocMap[hostID]; found {
nwCfg.EpAddrCount--
}
delete(nwCfg.IPv6AllocMap, hostID)
} else {
if epgCfg != nil && len(epgCfg.IPPool) > 0 {
log.Infof("releasing epg ip: %s", ipAddress)
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s pool %s. Error: %s",
ipAddress, epgCfg.IPPool, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if epgCfg.EPGIPAllocMap.Test(ipAddrValue) {
nwCfg.EpAddrCount--
}
epgCfg.EPGIPAllocMap.Clear(ipAddrValue)
if err := epgCfg.Write(); err != nil {
log.Errorf("error writing epg config. Error: %s", err)
return err
}
} else {
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if nwCfg.IPAllocMap.Test(ipAddrValue) {
nwCfg.EpAddrCount--
}
nwCfg.IPAllocMap.Clear(ipAddrValue)
log.Infof("Releasing IP Address: %v"+
"from networkId:%+v", ipAddrValue,
nwCfg.NetworkName)
}
}
err := nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
return nil
} | [
"func",
"networkReleaseAddress",
"(",
"nwCfg",
"*",
"mastercfg",
".",
"CfgNetworkState",
",",
"epgCfg",
"*",
"mastercfg",
".",
"EndpointGroupState",
",",
"ipAddress",
"string",
")",
"error",
"{",
"isIPv6",
":=",
"netutils",
".",
"IsIPv6",
"(",
"ipAddress",
")",
"\n",
"if",
"isIPv6",
"{",
"hostID",
",",
"err",
":=",
"netutils",
".",
"GetIPv6HostID",
"(",
"nwCfg",
".",
"SubnetIP",
",",
"nwCfg",
".",
"SubnetLen",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipAddress",
",",
"nwCfg",
".",
"SubnetIP",
",",
"nwCfg",
".",
"SubnetLen",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"// networkReleaseAddress is called from multiple places",
"// Make sure we decrement the EpCount only if the IPAddress",
"// was not already freed earlier",
"if",
"_",
",",
"found",
":=",
"nwCfg",
".",
"IPv6AllocMap",
"[",
"hostID",
"]",
";",
"found",
"{",
"nwCfg",
".",
"EpAddrCount",
"--",
"\n",
"}",
"\n",
"delete",
"(",
"nwCfg",
".",
"IPv6AllocMap",
",",
"hostID",
")",
"\n",
"}",
"else",
"{",
"if",
"epgCfg",
"!=",
"nil",
"&&",
"len",
"(",
"epgCfg",
".",
"IPPool",
")",
">",
"0",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ipAddress",
")",
"\n",
"ipAddrValue",
",",
"err",
":=",
"netutils",
".",
"GetIPNumber",
"(",
"nwCfg",
".",
"SubnetIP",
",",
"nwCfg",
".",
"SubnetLen",
",",
"32",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipAddress",
",",
"epgCfg",
".",
"IPPool",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"// networkReleaseAddress is called from multiple places",
"// Make sure we decrement the EpCount only if the IPAddress",
"// was not already freed earlier",
"if",
"epgCfg",
".",
"EPGIPAllocMap",
".",
"Test",
"(",
"ipAddrValue",
")",
"{",
"nwCfg",
".",
"EpAddrCount",
"--",
"\n",
"}",
"\n",
"epgCfg",
".",
"EPGIPAllocMap",
".",
"Clear",
"(",
"ipAddrValue",
")",
"\n",
"if",
"err",
":=",
"epgCfg",
".",
"Write",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"ipAddrValue",
",",
"err",
":=",
"netutils",
".",
"GetIPNumber",
"(",
"nwCfg",
".",
"SubnetIP",
",",
"nwCfg",
".",
"SubnetLen",
",",
"32",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipAddress",
",",
"nwCfg",
".",
"SubnetIP",
",",
"nwCfg",
".",
"SubnetLen",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"// networkReleaseAddress is called from multiple places",
"// Make sure we decrement the EpCount only if the IPAddress",
"// was not already freed earlier",
"if",
"nwCfg",
".",
"IPAllocMap",
".",
"Test",
"(",
"ipAddrValue",
")",
"{",
"nwCfg",
".",
"EpAddrCount",
"--",
"\n",
"}",
"\n",
"nwCfg",
".",
"IPAllocMap",
".",
"Clear",
"(",
"ipAddrValue",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"ipAddrValue",
",",
"nwCfg",
".",
"NetworkName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"nwCfg",
".",
"Write",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // networkReleaseAddress release the ip address | [
"networkReleaseAddress",
"release",
"the",
"ip",
"address"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/master/network.go#L464-L527 |
7,852 | contiv/netplugin | netplugin/cluster/cluster.go | addMaster | func addMaster(netplugin *plugin.NetPlugin, srvInfo objdb.ServiceInfo) error {
// save it in db
MasterDB[masterKey(srvInfo)] = &srvInfo
// tell the plugin about the master
return netplugin.AddMaster(core.ServiceInfo{
HostAddr: srvInfo.HostAddr,
Port: netmasterRPCPort,
})
} | go | func addMaster(netplugin *plugin.NetPlugin, srvInfo objdb.ServiceInfo) error {
// save it in db
MasterDB[masterKey(srvInfo)] = &srvInfo
// tell the plugin about the master
return netplugin.AddMaster(core.ServiceInfo{
HostAddr: srvInfo.HostAddr,
Port: netmasterRPCPort,
})
} | [
"func",
"addMaster",
"(",
"netplugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"srvInfo",
"objdb",
".",
"ServiceInfo",
")",
"error",
"{",
"// save it in db",
"MasterDB",
"[",
"masterKey",
"(",
"srvInfo",
")",
"]",
"=",
"&",
"srvInfo",
"\n",
"// tell the plugin about the master",
"return",
"netplugin",
".",
"AddMaster",
"(",
"core",
".",
"ServiceInfo",
"{",
"HostAddr",
":",
"srvInfo",
".",
"HostAddr",
",",
"Port",
":",
"netmasterRPCPort",
",",
"}",
")",
"\n",
"}"
] | // Add a master node | [
"Add",
"a",
"master",
"node"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L52-L60 |
7,853 | contiv/netplugin | netplugin/cluster/cluster.go | deleteMaster | func deleteMaster(netplugin *plugin.NetPlugin, srvInfo objdb.ServiceInfo) error {
// delete from the db
delete(MasterDB, masterKey(srvInfo))
// tel plugin about it
return netplugin.DeleteMaster(core.ServiceInfo{
HostAddr: srvInfo.HostAddr,
Port: netmasterRPCPort,
})
} | go | func deleteMaster(netplugin *plugin.NetPlugin, srvInfo objdb.ServiceInfo) error {
// delete from the db
delete(MasterDB, masterKey(srvInfo))
// tel plugin about it
return netplugin.DeleteMaster(core.ServiceInfo{
HostAddr: srvInfo.HostAddr,
Port: netmasterRPCPort,
})
} | [
"func",
"deleteMaster",
"(",
"netplugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"srvInfo",
"objdb",
".",
"ServiceInfo",
")",
"error",
"{",
"// delete from the db",
"delete",
"(",
"MasterDB",
",",
"masterKey",
"(",
"srvInfo",
")",
")",
"\n\n",
"// tel plugin about it",
"return",
"netplugin",
".",
"DeleteMaster",
"(",
"core",
".",
"ServiceInfo",
"{",
"HostAddr",
":",
"srvInfo",
".",
"HostAddr",
",",
"Port",
":",
"netmasterRPCPort",
",",
"}",
")",
"\n",
"}"
] | // delete master node | [
"delete",
"master",
"node"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L63-L72 |
7,854 | contiv/netplugin | netplugin/cluster/cluster.go | getMasterLockHolder | func getMasterLockHolder() (string, error) {
// Create the lock
leaderLock, err := ObjdbClient.NewLock("netmaster/leader", "", 0)
if err != nil {
log.Fatalf("Could not create leader lock. Err: %v", err)
}
// get current holder of leader lock
masterNode := leaderLock.GetHolder()
if masterNode == "" {
log.Errorf("No leader node found")
return "", errors.New("no leader node")
}
return masterNode, nil
} | go | func getMasterLockHolder() (string, error) {
// Create the lock
leaderLock, err := ObjdbClient.NewLock("netmaster/leader", "", 0)
if err != nil {
log.Fatalf("Could not create leader lock. Err: %v", err)
}
// get current holder of leader lock
masterNode := leaderLock.GetHolder()
if masterNode == "" {
log.Errorf("No leader node found")
return "", errors.New("no leader node")
}
return masterNode, nil
} | [
"func",
"getMasterLockHolder",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Create the lock",
"leaderLock",
",",
"err",
":=",
"ObjdbClient",
".",
"NewLock",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// get current holder of leader lock",
"masterNode",
":=",
"leaderLock",
".",
"GetHolder",
"(",
")",
"\n",
"if",
"masterNode",
"==",
"\"",
"\"",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"masterNode",
",",
"nil",
"\n",
"}"
] | // getMasterLockHolder returns the IP of current master lock hoder | [
"getMasterLockHolder",
"returns",
"the",
"IP",
"of",
"current",
"master",
"lock",
"hoder"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L75-L90 |
7,855 | contiv/netplugin | netplugin/cluster/cluster.go | MasterPostReq | func MasterPostReq(path string, req interface{}, resp interface{}) error {
return masterReq(path, req, resp, false)
} | go | func MasterPostReq(path string, req interface{}, resp interface{}) error {
return masterReq(path, req, resp, false)
} | [
"func",
"MasterPostReq",
"(",
"path",
"string",
",",
"req",
"interface",
"{",
"}",
",",
"resp",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"masterReq",
"(",
"path",
",",
"req",
",",
"resp",
",",
"false",
")",
"\n",
"}"
] | // MasterPostReq makes a POST request to master node | [
"MasterPostReq",
"makes",
"a",
"POST",
"request",
"to",
"master",
"node"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L161-L163 |
7,856 | contiv/netplugin | netplugin/cluster/cluster.go | registerService | func registerService(objClient objdb.API, ctrlIP, vtepIP, hostname string, vxlanUDPPort int) error {
// netplugin service info
srvInfo := objdb.ServiceInfo{
ServiceName: "netplugin",
TTL: 10,
HostAddr: ctrlIP,
Port: netpluginRPCPort1,
Hostname: hostname,
}
// Register the node with service registry
err := objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
srvInfo = objdb.ServiceInfo{
ServiceName: "netplugin",
TTL: 10,
HostAddr: ctrlIP,
Port: netpluginRPCPort2,
Hostname: hostname,
}
// Register the node with service registry
err = objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
// netplugn VTEP service info
srvInfo = objdb.ServiceInfo{
ServiceName: "netplugin.vtep",
TTL: 10,
HostAddr: vtepIP,
Port: vxlanUDPPort,
Hostname: hostname,
}
// Register the node with service registry
err = objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
log.Infof("Registered netplugin service with registry")
return nil
} | go | func registerService(objClient objdb.API, ctrlIP, vtepIP, hostname string, vxlanUDPPort int) error {
// netplugin service info
srvInfo := objdb.ServiceInfo{
ServiceName: "netplugin",
TTL: 10,
HostAddr: ctrlIP,
Port: netpluginRPCPort1,
Hostname: hostname,
}
// Register the node with service registry
err := objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
srvInfo = objdb.ServiceInfo{
ServiceName: "netplugin",
TTL: 10,
HostAddr: ctrlIP,
Port: netpluginRPCPort2,
Hostname: hostname,
}
// Register the node with service registry
err = objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
// netplugn VTEP service info
srvInfo = objdb.ServiceInfo{
ServiceName: "netplugin.vtep",
TTL: 10,
HostAddr: vtepIP,
Port: vxlanUDPPort,
Hostname: hostname,
}
// Register the node with service registry
err = objClient.RegisterService(srvInfo)
if err != nil {
log.Fatalf("Error registering service. Err: %v", err)
return err
}
log.Infof("Registered netplugin service with registry")
return nil
} | [
"func",
"registerService",
"(",
"objClient",
"objdb",
".",
"API",
",",
"ctrlIP",
",",
"vtepIP",
",",
"hostname",
"string",
",",
"vxlanUDPPort",
"int",
")",
"error",
"{",
"// netplugin service info",
"srvInfo",
":=",
"objdb",
".",
"ServiceInfo",
"{",
"ServiceName",
":",
"\"",
"\"",
",",
"TTL",
":",
"10",
",",
"HostAddr",
":",
"ctrlIP",
",",
"Port",
":",
"netpluginRPCPort1",
",",
"Hostname",
":",
"hostname",
",",
"}",
"\n\n",
"// Register the node with service registry",
"err",
":=",
"objClient",
".",
"RegisterService",
"(",
"srvInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"srvInfo",
"=",
"objdb",
".",
"ServiceInfo",
"{",
"ServiceName",
":",
"\"",
"\"",
",",
"TTL",
":",
"10",
",",
"HostAddr",
":",
"ctrlIP",
",",
"Port",
":",
"netpluginRPCPort2",
",",
"Hostname",
":",
"hostname",
",",
"}",
"\n\n",
"// Register the node with service registry",
"err",
"=",
"objClient",
".",
"RegisterService",
"(",
"srvInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// netplugn VTEP service info",
"srvInfo",
"=",
"objdb",
".",
"ServiceInfo",
"{",
"ServiceName",
":",
"\"",
"\"",
",",
"TTL",
":",
"10",
",",
"HostAddr",
":",
"vtepIP",
",",
"Port",
":",
"vxlanUDPPort",
",",
"Hostname",
":",
"hostname",
",",
"}",
"\n\n",
"// Register the node with service registry",
"err",
"=",
"objClient",
".",
"RegisterService",
"(",
"srvInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Register netplugin with service registry | [
"Register",
"netplugin",
"with",
"service",
"registry"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L171-L221 |
7,857 | contiv/netplugin | netplugin/cluster/cluster.go | peerDiscoveryLoop | func peerDiscoveryLoop(netplugin *plugin.NetPlugin, objClient objdb.API, ctrlIP, vtepIP string) {
// Create channels for watch thread
nodeEventCh := make(chan objdb.WatchServiceEvent, 1)
watchStopCh := make(chan bool, 1)
masterEventCh := make(chan objdb.WatchServiceEvent, 1)
masterWatchStopCh := make(chan bool, 1)
// Start a watch on netmaster
err := objClient.WatchService("netmaster.rpc", masterEventCh, masterWatchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netmaster service. Err: %v", err)
}
// Start a watch on netplugin service
err = objClient.WatchService("netplugin.vtep", nodeEventCh, watchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netplugin service. Err: %v", err)
}
for {
select {
case srvEvent := <-nodeEventCh:
log.Debugf("Received netplugin service watch event: %+v", srvEvent)
// collect the info about the node
nodeInfo := srvEvent.ServiceInfo
// check if its our own info coming back to us
if nodeInfo.HostAddr == vtepIP {
break
}
// Handle based on event type
if srvEvent.EventType == objdb.WatchServiceEventAdd {
log.Infof("Node add event for {%+v}", nodeInfo)
// add the node
err := netplugin.AddPeerHost(core.ServiceInfo{
HostAddr: nodeInfo.HostAddr,
Port: netplugin.PluginConfig.Instance.VxlanUDPPort,
})
if err != nil {
log.Errorf("Error adding node {%+v}. Err: %v", nodeInfo, err)
}
} else if srvEvent.EventType == objdb.WatchServiceEventDel {
log.Infof("Node delete event for {%+v}", nodeInfo)
// remove the node
err := netplugin.DeletePeerHost(core.ServiceInfo{
HostAddr: nodeInfo.HostAddr,
Port: netplugin.PluginConfig.Instance.VxlanUDPPort,
})
if err != nil {
log.Errorf("Error deleting node {%+v}. Err: %v", nodeInfo, err)
}
}
case srvEvent := <-masterEventCh:
log.Infof("Received netmaster service watch event: %+v", srvEvent)
// collect the info about the node
nodeInfo := srvEvent.ServiceInfo
// Handle based on event type
if srvEvent.EventType == objdb.WatchServiceEventAdd {
log.Infof("Master add event for {%+v}", nodeInfo)
// Add the master
err := addMaster(netplugin, nodeInfo)
if err != nil {
log.Errorf("Error adding master {%+v}. Err: %v", nodeInfo, err)
}
} else if srvEvent.EventType == objdb.WatchServiceEventDel {
log.Infof("Master delete event for {%+v}", nodeInfo)
// Delete the master
err := deleteMaster(netplugin, nodeInfo)
if err != nil {
log.Errorf("Error deleting master {%+v}. Err: %v", nodeInfo, err)
}
}
}
// Dont process next peer event for another 100ms
time.Sleep(100 * time.Millisecond)
}
} | go | func peerDiscoveryLoop(netplugin *plugin.NetPlugin, objClient objdb.API, ctrlIP, vtepIP string) {
// Create channels for watch thread
nodeEventCh := make(chan objdb.WatchServiceEvent, 1)
watchStopCh := make(chan bool, 1)
masterEventCh := make(chan objdb.WatchServiceEvent, 1)
masterWatchStopCh := make(chan bool, 1)
// Start a watch on netmaster
err := objClient.WatchService("netmaster.rpc", masterEventCh, masterWatchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netmaster service. Err: %v", err)
}
// Start a watch on netplugin service
err = objClient.WatchService("netplugin.vtep", nodeEventCh, watchStopCh)
if err != nil {
log.Fatalf("Could not start a watch on netplugin service. Err: %v", err)
}
for {
select {
case srvEvent := <-nodeEventCh:
log.Debugf("Received netplugin service watch event: %+v", srvEvent)
// collect the info about the node
nodeInfo := srvEvent.ServiceInfo
// check if its our own info coming back to us
if nodeInfo.HostAddr == vtepIP {
break
}
// Handle based on event type
if srvEvent.EventType == objdb.WatchServiceEventAdd {
log.Infof("Node add event for {%+v}", nodeInfo)
// add the node
err := netplugin.AddPeerHost(core.ServiceInfo{
HostAddr: nodeInfo.HostAddr,
Port: netplugin.PluginConfig.Instance.VxlanUDPPort,
})
if err != nil {
log.Errorf("Error adding node {%+v}. Err: %v", nodeInfo, err)
}
} else if srvEvent.EventType == objdb.WatchServiceEventDel {
log.Infof("Node delete event for {%+v}", nodeInfo)
// remove the node
err := netplugin.DeletePeerHost(core.ServiceInfo{
HostAddr: nodeInfo.HostAddr,
Port: netplugin.PluginConfig.Instance.VxlanUDPPort,
})
if err != nil {
log.Errorf("Error deleting node {%+v}. Err: %v", nodeInfo, err)
}
}
case srvEvent := <-masterEventCh:
log.Infof("Received netmaster service watch event: %+v", srvEvent)
// collect the info about the node
nodeInfo := srvEvent.ServiceInfo
// Handle based on event type
if srvEvent.EventType == objdb.WatchServiceEventAdd {
log.Infof("Master add event for {%+v}", nodeInfo)
// Add the master
err := addMaster(netplugin, nodeInfo)
if err != nil {
log.Errorf("Error adding master {%+v}. Err: %v", nodeInfo, err)
}
} else if srvEvent.EventType == objdb.WatchServiceEventDel {
log.Infof("Master delete event for {%+v}", nodeInfo)
// Delete the master
err := deleteMaster(netplugin, nodeInfo)
if err != nil {
log.Errorf("Error deleting master {%+v}. Err: %v", nodeInfo, err)
}
}
}
// Dont process next peer event for another 100ms
time.Sleep(100 * time.Millisecond)
}
} | [
"func",
"peerDiscoveryLoop",
"(",
"netplugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"objClient",
"objdb",
".",
"API",
",",
"ctrlIP",
",",
"vtepIP",
"string",
")",
"{",
"// Create channels for watch thread",
"nodeEventCh",
":=",
"make",
"(",
"chan",
"objdb",
".",
"WatchServiceEvent",
",",
"1",
")",
"\n",
"watchStopCh",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"masterEventCh",
":=",
"make",
"(",
"chan",
"objdb",
".",
"WatchServiceEvent",
",",
"1",
")",
"\n",
"masterWatchStopCh",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n\n",
"// Start a watch on netmaster",
"err",
":=",
"objClient",
".",
"WatchService",
"(",
"\"",
"\"",
",",
"masterEventCh",
",",
"masterWatchStopCh",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Start a watch on netplugin service",
"err",
"=",
"objClient",
".",
"WatchService",
"(",
"\"",
"\"",
",",
"nodeEventCh",
",",
"watchStopCh",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"srvEvent",
":=",
"<-",
"nodeEventCh",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"srvEvent",
")",
"\n\n",
"// collect the info about the node",
"nodeInfo",
":=",
"srvEvent",
".",
"ServiceInfo",
"\n\n",
"// check if its our own info coming back to us",
"if",
"nodeInfo",
".",
"HostAddr",
"==",
"vtepIP",
"{",
"break",
"\n",
"}",
"\n\n",
"// Handle based on event type",
"if",
"srvEvent",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventAdd",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeInfo",
")",
"\n\n",
"// add the node",
"err",
":=",
"netplugin",
".",
"AddPeerHost",
"(",
"core",
".",
"ServiceInfo",
"{",
"HostAddr",
":",
"nodeInfo",
".",
"HostAddr",
",",
"Port",
":",
"netplugin",
".",
"PluginConfig",
".",
"Instance",
".",
"VxlanUDPPort",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeInfo",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"srvEvent",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventDel",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeInfo",
")",
"\n\n",
"// remove the node",
"err",
":=",
"netplugin",
".",
"DeletePeerHost",
"(",
"core",
".",
"ServiceInfo",
"{",
"HostAddr",
":",
"nodeInfo",
".",
"HostAddr",
",",
"Port",
":",
"netplugin",
".",
"PluginConfig",
".",
"Instance",
".",
"VxlanUDPPort",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeInfo",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"srvEvent",
":=",
"<-",
"masterEventCh",
":",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"srvEvent",
")",
"\n\n",
"// collect the info about the node",
"nodeInfo",
":=",
"srvEvent",
".",
"ServiceInfo",
"\n\n",
"// Handle based on event type",
"if",
"srvEvent",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventAdd",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeInfo",
")",
"\n\n",
"// Add the master",
"err",
":=",
"addMaster",
"(",
"netplugin",
",",
"nodeInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeInfo",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"srvEvent",
".",
"EventType",
"==",
"objdb",
".",
"WatchServiceEventDel",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeInfo",
")",
"\n\n",
"// Delete the master",
"err",
":=",
"deleteMaster",
"(",
"netplugin",
",",
"nodeInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeInfo",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Dont process next peer event for another 100ms",
"time",
".",
"Sleep",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n",
"}"
] | // Main loop to discover peer hosts and masters | [
"Main",
"loop",
"to",
"discover",
"peer",
"hosts",
"and",
"masters"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L224-L309 |
7,858 | contiv/netplugin | netplugin/cluster/cluster.go | Init | func Init(storeDriver string, storeURLs []string) error {
var err error
// Create an objdb client
ObjdbClient, err = objdb.InitClient(storeDriver, storeURLs)
return err
} | go | func Init(storeDriver string, storeURLs []string) error {
var err error
// Create an objdb client
ObjdbClient, err = objdb.InitClient(storeDriver, storeURLs)
return err
} | [
"func",
"Init",
"(",
"storeDriver",
"string",
",",
"storeURLs",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// Create an objdb client",
"ObjdbClient",
",",
"err",
"=",
"objdb",
".",
"InitClient",
"(",
"storeDriver",
",",
"storeURLs",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Init initializes the cluster module | [
"Init",
"initializes",
"the",
"cluster",
"module"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L312-L319 |
7,859 | contiv/netplugin | netplugin/cluster/cluster.go | RunLoop | func RunLoop(netplugin *plugin.NetPlugin, ctrlIP, vtepIP, hostname string) error {
// Register ourselves
err := registerService(ObjdbClient, ctrlIP, vtepIP, hostname, netplugin.PluginConfig.Instance.VxlanUDPPort)
// Start peer discovery loop
go peerDiscoveryLoop(netplugin, ObjdbClient, ctrlIP, vtepIP)
return err
} | go | func RunLoop(netplugin *plugin.NetPlugin, ctrlIP, vtepIP, hostname string) error {
// Register ourselves
err := registerService(ObjdbClient, ctrlIP, vtepIP, hostname, netplugin.PluginConfig.Instance.VxlanUDPPort)
// Start peer discovery loop
go peerDiscoveryLoop(netplugin, ObjdbClient, ctrlIP, vtepIP)
return err
} | [
"func",
"RunLoop",
"(",
"netplugin",
"*",
"plugin",
".",
"NetPlugin",
",",
"ctrlIP",
",",
"vtepIP",
",",
"hostname",
"string",
")",
"error",
"{",
"// Register ourselves",
"err",
":=",
"registerService",
"(",
"ObjdbClient",
",",
"ctrlIP",
",",
"vtepIP",
",",
"hostname",
",",
"netplugin",
".",
"PluginConfig",
".",
"Instance",
".",
"VxlanUDPPort",
")",
"\n\n",
"// Start peer discovery loop",
"go",
"peerDiscoveryLoop",
"(",
"netplugin",
",",
"ObjdbClient",
",",
"ctrlIP",
",",
"vtepIP",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // RunLoop registers netplugin service with cluster store and runs peer discovery | [
"RunLoop",
"registers",
"netplugin",
"service",
"with",
"cluster",
"store",
"and",
"runs",
"peer",
"discovery"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netplugin/cluster/cluster.go#L322-L330 |
7,860 | contiv/netplugin | contivmodel/contivModel.go | makeHttpHandler | func makeHttpHandler(handlerFunc HttpApiFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
// Send HTTP response
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
// Send HTTP response as Json
err = writeJSON(w, http.StatusOK, resp)
if err != nil {
log.Errorf("Error generating json. Err: %v", err)
}
}
}
} | go | func makeHttpHandler(handlerFunc HttpApiFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
// Send HTTP response
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
// Send HTTP response as Json
err = writeJSON(w, http.StatusOK, resp)
if err != nil {
log.Errorf("Error generating json. Err: %v", err)
}
}
}
} | [
"func",
"makeHttpHandler",
"(",
"handlerFunc",
"HttpApiFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"// Create a closure and return an anonymous function",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Call the handler",
"resp",
",",
"err",
":=",
"handlerFunc",
"(",
"w",
",",
"r",
",",
"mux",
".",
"Vars",
"(",
"r",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Log error",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Method",
",",
"r",
".",
"URL",
",",
"err",
")",
"\n\n",
"// Send HTTP response",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"else",
"{",
"// Send HTTP response as Json",
"err",
"=",
"writeJSON",
"(",
"w",
",",
"http",
".",
"StatusOK",
",",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Simple Wrapper for http handlers | [
"Simple",
"Wrapper",
"for",
"http",
"handlers"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L848-L867 |
7,861 | contiv/netplugin | contivmodel/contivModel.go | GetOperAciGw | func GetOperAciGw(obj *AciGwInspect) error {
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AciGwCb.AciGwGetOper(obj)
if err != nil {
log.Errorf("AciGwDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperAciGw(obj *AciGwInspect) error {
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AciGwCb.AciGwGetOper(obj)
if err != nil {
log.Errorf("AciGwDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperAciGw",
"(",
"obj",
"*",
"AciGwInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"AciGwCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"AciGwCb",
".",
"AciGwGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a aciGwOper object | [
"Get",
"a",
"aciGwOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1099-L1114 |
7,862 | contiv/netplugin | contivmodel/contivModel.go | CreateAciGw | func CreateAciGw(obj *AciGw) error {
// Validate parameters
err := ValidateAciGw(obj)
if err != nil {
log.Errorf("ValidateAciGw retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.aciGwMutex.Lock()
key := collections.aciGws[obj.Key]
collections.aciGwMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.AciGwCb.AciGwUpdate(collections.aciGws[obj.Key], obj)
if err != nil {
log.Errorf("AciGwUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.aciGwMutex.Lock()
saveObj = collections.aciGws[obj.Key]
collections.aciGwMutex.Unlock()
} else {
// save it in cache
collections.aciGwMutex.Lock()
collections.aciGws[obj.Key] = obj
collections.aciGwMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.AciGwCb.AciGwCreate(obj)
if err != nil {
log.Errorf("AciGwCreate retruned error for: %+v. Err: %v", obj, err)
collections.aciGwMutex.Lock()
delete(collections.aciGws, obj.Key)
collections.aciGwMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.aciGwMutex.Lock()
err = saveObj.Write()
collections.aciGwMutex.Unlock()
if err != nil {
log.Errorf("Error saving aciGw %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateAciGw(obj *AciGw) error {
// Validate parameters
err := ValidateAciGw(obj)
if err != nil {
log.Errorf("ValidateAciGw retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.aciGwMutex.Lock()
key := collections.aciGws[obj.Key]
collections.aciGwMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.AciGwCb.AciGwUpdate(collections.aciGws[obj.Key], obj)
if err != nil {
log.Errorf("AciGwUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.aciGwMutex.Lock()
saveObj = collections.aciGws[obj.Key]
collections.aciGwMutex.Unlock()
} else {
// save it in cache
collections.aciGwMutex.Lock()
collections.aciGws[obj.Key] = obj
collections.aciGwMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.AciGwCb.AciGwCreate(obj)
if err != nil {
log.Errorf("AciGwCreate retruned error for: %+v. Err: %v", obj, err)
collections.aciGwMutex.Lock()
delete(collections.aciGws, obj.Key)
collections.aciGwMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.aciGwMutex.Lock()
err = saveObj.Write()
collections.aciGwMutex.Unlock()
if err != nil {
log.Errorf("Error saving aciGw %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateAciGw",
"(",
"obj",
"*",
"AciGw",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateAciGw",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"AciGwCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"aciGws",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"AciGwCb",
".",
"AciGwUpdate",
"(",
"collections",
".",
"aciGws",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"aciGws",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"aciGws",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"AciGwCb",
".",
"AciGwCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"aciGws",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a aciGw object | [
"Create",
"a",
"aciGw",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1195-L1255 |
7,863 | contiv/netplugin | contivmodel/contivModel.go | FindAciGw | func FindAciGw(key string) *AciGw {
collections.aciGwMutex.Lock()
defer collections.aciGwMutex.Unlock()
obj := collections.aciGws[key]
if obj == nil {
return nil
}
return obj
} | go | func FindAciGw(key string) *AciGw {
collections.aciGwMutex.Lock()
defer collections.aciGwMutex.Unlock()
obj := collections.aciGws[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindAciGw",
"(",
"key",
"string",
")",
"*",
"AciGw",
"{",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"aciGws",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to aciGw from collection | [
"Return",
"a",
"pointer",
"to",
"aciGw",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1258-L1268 |
7,864 | contiv/netplugin | contivmodel/contivModel.go | DeleteAciGw | func DeleteAciGw(key string) error {
collections.aciGwMutex.Lock()
obj := collections.aciGws[key]
collections.aciGwMutex.Unlock()
if obj == nil {
log.Errorf("aciGw %s not found", key)
return errors.New("aciGw not found")
}
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AciGwCb.AciGwDelete(obj)
if err != nil {
log.Errorf("AciGwDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.aciGwMutex.Lock()
err = obj.Delete()
collections.aciGwMutex.Unlock()
if err != nil {
log.Errorf("Error deleting aciGw %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.aciGwMutex.Lock()
delete(collections.aciGws, key)
collections.aciGwMutex.Unlock()
return nil
} | go | func DeleteAciGw(key string) error {
collections.aciGwMutex.Lock()
obj := collections.aciGws[key]
collections.aciGwMutex.Unlock()
if obj == nil {
log.Errorf("aciGw %s not found", key)
return errors.New("aciGw not found")
}
// Check if we handle this object
if objCallbackHandler.AciGwCb == nil {
log.Errorf("No callback registered for aciGw object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AciGwCb.AciGwDelete(obj)
if err != nil {
log.Errorf("AciGwDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.aciGwMutex.Lock()
err = obj.Delete()
collections.aciGwMutex.Unlock()
if err != nil {
log.Errorf("Error deleting aciGw %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.aciGwMutex.Lock()
delete(collections.aciGws, key)
collections.aciGwMutex.Unlock()
return nil
} | [
"func",
"DeleteAciGw",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"aciGws",
"[",
"key",
"]",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"AciGwCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"AciGwCb",
".",
"AciGwDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"aciGws",
",",
"key",
")",
"\n",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a aciGw object | [
"Delete",
"a",
"aciGw",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1271-L1307 |
7,865 | contiv/netplugin | contivmodel/contivModel.go | ValidateAciGw | func ValidateAciGw(obj *AciGw) error {
collections.aciGwMutex.Lock()
defer collections.aciGwMutex.Unlock()
// Validate key is correct
keyStr := obj.Name
if obj.Key != keyStr {
log.Errorf("Expecting AciGw Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.EnforcePolicies) > 64 {
return errors.New("enforcePolicies string too long")
}
enforcePoliciesMatch := regexp.MustCompile("^(yes|no){1}$")
if enforcePoliciesMatch.MatchString(obj.EnforcePolicies) == false {
return errors.New("enforcePolicies string invalid format")
}
if len(obj.IncludeCommonTenant) > 64 {
return errors.New("includeCommonTenant string too long")
}
includeCommonTenantMatch := regexp.MustCompile("^(yes|no){1}$")
if includeCommonTenantMatch.MatchString(obj.IncludeCommonTenant) == false {
return errors.New("includeCommonTenant string invalid format")
}
if len(obj.Name) > 64 {
return errors.New("name string too long")
}
nameMatch := regexp.MustCompile("^(aciGw)$")
if nameMatch.MatchString(obj.Name) == false {
return errors.New("name string invalid format")
}
if len(obj.NodeBindings) > 2048 {
return errors.New("nodeBindings string too long")
}
nodeBindingsMatch := regexp.MustCompile("^$|^(topology/pod-[0-9]{1,4}/node-[0-9]{1,4}){1}(,topology/pod-[0-9]{1,4}/node-[0-9]{1,4})*$")
if nodeBindingsMatch.MatchString(obj.NodeBindings) == false {
return errors.New("nodeBindings string invalid format")
}
if len(obj.PathBindings) > 2048 {
return errors.New("pathBindings string too long")
}
pathBindingsMatch := regexp.MustCompile("^$|^(topology/pod-[0-9]{1,4}/paths-[0-9]{1,4}/pathep-\\[eth[0-9]{1,2}/[0-9]{1,2}\\]){1}(,topology/pod-[0-9]{1,4}/paths-[0-9]{1,4}/pathep-\\[eth[0-9]{1,2}/[0-9]{1,2}\\])*$")
if pathBindingsMatch.MatchString(obj.PathBindings) == false {
return errors.New("pathBindings string invalid format")
}
if len(obj.PhysicalDomain) > 128 {
return errors.New("physicalDomain string too long")
}
physicalDomainMatch := 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 physicalDomainMatch.MatchString(obj.PhysicalDomain) == false {
return errors.New("physicalDomain string invalid format")
}
return nil
} | go | func ValidateAciGw(obj *AciGw) error {
collections.aciGwMutex.Lock()
defer collections.aciGwMutex.Unlock()
// Validate key is correct
keyStr := obj.Name
if obj.Key != keyStr {
log.Errorf("Expecting AciGw Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.EnforcePolicies) > 64 {
return errors.New("enforcePolicies string too long")
}
enforcePoliciesMatch := regexp.MustCompile("^(yes|no){1}$")
if enforcePoliciesMatch.MatchString(obj.EnforcePolicies) == false {
return errors.New("enforcePolicies string invalid format")
}
if len(obj.IncludeCommonTenant) > 64 {
return errors.New("includeCommonTenant string too long")
}
includeCommonTenantMatch := regexp.MustCompile("^(yes|no){1}$")
if includeCommonTenantMatch.MatchString(obj.IncludeCommonTenant) == false {
return errors.New("includeCommonTenant string invalid format")
}
if len(obj.Name) > 64 {
return errors.New("name string too long")
}
nameMatch := regexp.MustCompile("^(aciGw)$")
if nameMatch.MatchString(obj.Name) == false {
return errors.New("name string invalid format")
}
if len(obj.NodeBindings) > 2048 {
return errors.New("nodeBindings string too long")
}
nodeBindingsMatch := regexp.MustCompile("^$|^(topology/pod-[0-9]{1,4}/node-[0-9]{1,4}){1}(,topology/pod-[0-9]{1,4}/node-[0-9]{1,4})*$")
if nodeBindingsMatch.MatchString(obj.NodeBindings) == false {
return errors.New("nodeBindings string invalid format")
}
if len(obj.PathBindings) > 2048 {
return errors.New("pathBindings string too long")
}
pathBindingsMatch := regexp.MustCompile("^$|^(topology/pod-[0-9]{1,4}/paths-[0-9]{1,4}/pathep-\\[eth[0-9]{1,2}/[0-9]{1,2}\\]){1}(,topology/pod-[0-9]{1,4}/paths-[0-9]{1,4}/pathep-\\[eth[0-9]{1,2}/[0-9]{1,2}\\])*$")
if pathBindingsMatch.MatchString(obj.PathBindings) == false {
return errors.New("pathBindings string invalid format")
}
if len(obj.PhysicalDomain) > 128 {
return errors.New("physicalDomain string too long")
}
physicalDomainMatch := 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 physicalDomainMatch.MatchString(obj.PhysicalDomain) == false {
return errors.New("physicalDomain string invalid format")
}
return nil
} | [
"func",
"ValidateAciGw",
"(",
"obj",
"*",
"AciGw",
")",
"error",
"{",
"collections",
".",
"aciGwMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"aciGwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"Name",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"EnforcePolicies",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"enforcePoliciesMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"enforcePoliciesMatch",
".",
"MatchString",
"(",
"obj",
".",
"EnforcePolicies",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"IncludeCommonTenant",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"includeCommonTenantMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"includeCommonTenantMatch",
".",
"MatchString",
"(",
"obj",
".",
"IncludeCommonTenant",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"Name",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"nameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"nameMatch",
".",
"MatchString",
"(",
"obj",
".",
"Name",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"NodeBindings",
")",
">",
"2048",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"nodeBindingsMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"nodeBindingsMatch",
".",
"MatchString",
"(",
"obj",
".",
"NodeBindings",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"PathBindings",
")",
">",
"2048",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pathBindingsMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"pathBindingsMatch",
".",
"MatchString",
"(",
"obj",
".",
"PathBindings",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"PhysicalDomain",
")",
">",
"128",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"physicalDomainMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"physicalDomainMatch",
".",
"MatchString",
"(",
"obj",
".",
"PhysicalDomain",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate a aciGw object | [
"Validate",
"a",
"aciGw",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1370-L1438 |
7,866 | contiv/netplugin | contivmodel/contivModel.go | CreateAppProfile | func CreateAppProfile(obj *AppProfile) error {
// Validate parameters
err := ValidateAppProfile(obj)
if err != nil {
log.Errorf("ValidateAppProfile retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.AppProfileCb == nil {
log.Errorf("No callback registered for appProfile object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.appProfileMutex.Lock()
key := collections.appProfiles[obj.Key]
collections.appProfileMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.AppProfileCb.AppProfileUpdate(collections.appProfiles[obj.Key], obj)
if err != nil {
log.Errorf("AppProfileUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.appProfileMutex.Lock()
saveObj = collections.appProfiles[obj.Key]
collections.appProfileMutex.Unlock()
} else {
// save it in cache
collections.appProfileMutex.Lock()
collections.appProfiles[obj.Key] = obj
collections.appProfileMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.AppProfileCb.AppProfileCreate(obj)
if err != nil {
log.Errorf("AppProfileCreate retruned error for: %+v. Err: %v", obj, err)
collections.appProfileMutex.Lock()
delete(collections.appProfiles, obj.Key)
collections.appProfileMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.appProfileMutex.Lock()
err = saveObj.Write()
collections.appProfileMutex.Unlock()
if err != nil {
log.Errorf("Error saving appProfile %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateAppProfile(obj *AppProfile) error {
// Validate parameters
err := ValidateAppProfile(obj)
if err != nil {
log.Errorf("ValidateAppProfile retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.AppProfileCb == nil {
log.Errorf("No callback registered for appProfile object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.appProfileMutex.Lock()
key := collections.appProfiles[obj.Key]
collections.appProfileMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.AppProfileCb.AppProfileUpdate(collections.appProfiles[obj.Key], obj)
if err != nil {
log.Errorf("AppProfileUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.appProfileMutex.Lock()
saveObj = collections.appProfiles[obj.Key]
collections.appProfileMutex.Unlock()
} else {
// save it in cache
collections.appProfileMutex.Lock()
collections.appProfiles[obj.Key] = obj
collections.appProfileMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.AppProfileCb.AppProfileCreate(obj)
if err != nil {
log.Errorf("AppProfileCreate retruned error for: %+v. Err: %v", obj, err)
collections.appProfileMutex.Lock()
delete(collections.appProfiles, obj.Key)
collections.appProfileMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.appProfileMutex.Lock()
err = saveObj.Write()
collections.appProfileMutex.Unlock()
if err != nil {
log.Errorf("Error saving appProfile %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateAppProfile",
"(",
"obj",
"*",
"AppProfile",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateAppProfile",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"AppProfileCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"appProfiles",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"AppProfileCb",
".",
"AppProfileUpdate",
"(",
"collections",
".",
"appProfiles",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"appProfiles",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"appProfiles",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"AppProfileCb",
".",
"AppProfileCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"appProfiles",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a appProfile object | [
"Create",
"a",
"appProfile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1539-L1599 |
7,867 | contiv/netplugin | contivmodel/contivModel.go | FindAppProfile | func FindAppProfile(key string) *AppProfile {
collections.appProfileMutex.Lock()
defer collections.appProfileMutex.Unlock()
obj := collections.appProfiles[key]
if obj == nil {
return nil
}
return obj
} | go | func FindAppProfile(key string) *AppProfile {
collections.appProfileMutex.Lock()
defer collections.appProfileMutex.Unlock()
obj := collections.appProfiles[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindAppProfile",
"(",
"key",
"string",
")",
"*",
"AppProfile",
"{",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"appProfiles",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to appProfile from collection | [
"Return",
"a",
"pointer",
"to",
"appProfile",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1602-L1612 |
7,868 | contiv/netplugin | contivmodel/contivModel.go | DeleteAppProfile | func DeleteAppProfile(key string) error {
collections.appProfileMutex.Lock()
obj := collections.appProfiles[key]
collections.appProfileMutex.Unlock()
if obj == nil {
log.Errorf("appProfile %s not found", key)
return errors.New("appProfile not found")
}
// Check if we handle this object
if objCallbackHandler.AppProfileCb == nil {
log.Errorf("No callback registered for appProfile object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AppProfileCb.AppProfileDelete(obj)
if err != nil {
log.Errorf("AppProfileDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.appProfileMutex.Lock()
err = obj.Delete()
collections.appProfileMutex.Unlock()
if err != nil {
log.Errorf("Error deleting appProfile %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.appProfileMutex.Lock()
delete(collections.appProfiles, key)
collections.appProfileMutex.Unlock()
return nil
} | go | func DeleteAppProfile(key string) error {
collections.appProfileMutex.Lock()
obj := collections.appProfiles[key]
collections.appProfileMutex.Unlock()
if obj == nil {
log.Errorf("appProfile %s not found", key)
return errors.New("appProfile not found")
}
// Check if we handle this object
if objCallbackHandler.AppProfileCb == nil {
log.Errorf("No callback registered for appProfile object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.AppProfileCb.AppProfileDelete(obj)
if err != nil {
log.Errorf("AppProfileDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.appProfileMutex.Lock()
err = obj.Delete()
collections.appProfileMutex.Unlock()
if err != nil {
log.Errorf("Error deleting appProfile %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.appProfileMutex.Lock()
delete(collections.appProfiles, key)
collections.appProfileMutex.Unlock()
return nil
} | [
"func",
"DeleteAppProfile",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"appProfiles",
"[",
"key",
"]",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"AppProfileCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"AppProfileCb",
".",
"AppProfileDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"appProfiles",
",",
"key",
")",
"\n",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a appProfile object | [
"Delete",
"a",
"appProfile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1615-L1651 |
7,869 | contiv/netplugin | contivmodel/contivModel.go | ValidateAppProfile | func ValidateAppProfile(obj *AppProfile) error {
collections.appProfileMutex.Lock()
defer collections.appProfileMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.AppProfileName
if obj.Key != keyStr {
log.Errorf("Expecting AppProfile Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.AppProfileName) > 64 {
return errors.New("appProfileName string too long")
}
appProfileNameMatch := 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 appProfileNameMatch.MatchString(obj.AppProfileName) == false {
return errors.New("appProfileName 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 ValidateAppProfile(obj *AppProfile) error {
collections.appProfileMutex.Lock()
defer collections.appProfileMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.AppProfileName
if obj.Key != keyStr {
log.Errorf("Expecting AppProfile Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.AppProfileName) > 64 {
return errors.New("appProfileName string too long")
}
appProfileNameMatch := 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 appProfileNameMatch.MatchString(obj.AppProfileName) == false {
return errors.New("appProfileName 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",
"ValidateAppProfile",
"(",
"obj",
"*",
"AppProfile",
")",
"error",
"{",
"collections",
".",
"appProfileMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"appProfileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"TenantName",
"+",
"\"",
"\"",
"+",
"obj",
".",
"AppProfileName",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"AppProfileName",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"appProfileNameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"appProfileNameMatch",
".",
"MatchString",
"(",
"obj",
".",
"AppProfileName",
")",
"==",
"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 appProfile object | [
"Validate",
"a",
"appProfile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1714-L1746 |
7,870 | contiv/netplugin | contivmodel/contivModel.go | GetOperBgp | func GetOperBgp(obj *BgpInspect) error {
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.BgpCb.BgpGetOper(obj)
if err != nil {
log.Errorf("BgpDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperBgp(obj *BgpInspect) error {
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.BgpCb.BgpGetOper(obj)
if err != nil {
log.Errorf("BgpDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperBgp",
"(",
"obj",
"*",
"BgpInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"BgpCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"BgpCb",
".",
"BgpGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a BgpOper object | [
"Get",
"a",
"BgpOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1774-L1789 |
7,871 | contiv/netplugin | contivmodel/contivModel.go | CreateBgp | func CreateBgp(obj *Bgp) error {
// Validate parameters
err := ValidateBgp(obj)
if err != nil {
log.Errorf("ValidateBgp retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.BgpMutex.Lock()
key := collections.Bgps[obj.Key]
collections.BgpMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.BgpCb.BgpUpdate(collections.Bgps[obj.Key], obj)
if err != nil {
log.Errorf("BgpUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.BgpMutex.Lock()
saveObj = collections.Bgps[obj.Key]
collections.BgpMutex.Unlock()
} else {
// save it in cache
collections.BgpMutex.Lock()
collections.Bgps[obj.Key] = obj
collections.BgpMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.BgpCb.BgpCreate(obj)
if err != nil {
log.Errorf("BgpCreate retruned error for: %+v. Err: %v", obj, err)
collections.BgpMutex.Lock()
delete(collections.Bgps, obj.Key)
collections.BgpMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.BgpMutex.Lock()
err = saveObj.Write()
collections.BgpMutex.Unlock()
if err != nil {
log.Errorf("Error saving Bgp %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateBgp(obj *Bgp) error {
// Validate parameters
err := ValidateBgp(obj)
if err != nil {
log.Errorf("ValidateBgp retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.BgpMutex.Lock()
key := collections.Bgps[obj.Key]
collections.BgpMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.BgpCb.BgpUpdate(collections.Bgps[obj.Key], obj)
if err != nil {
log.Errorf("BgpUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.BgpMutex.Lock()
saveObj = collections.Bgps[obj.Key]
collections.BgpMutex.Unlock()
} else {
// save it in cache
collections.BgpMutex.Lock()
collections.Bgps[obj.Key] = obj
collections.BgpMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.BgpCb.BgpCreate(obj)
if err != nil {
log.Errorf("BgpCreate retruned error for: %+v. Err: %v", obj, err)
collections.BgpMutex.Lock()
delete(collections.Bgps, obj.Key)
collections.BgpMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.BgpMutex.Lock()
err = saveObj.Write()
collections.BgpMutex.Unlock()
if err != nil {
log.Errorf("Error saving Bgp %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateBgp",
"(",
"obj",
"*",
"Bgp",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateBgp",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"BgpCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"Bgps",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"BgpCb",
".",
"BgpUpdate",
"(",
"collections",
".",
"Bgps",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"Bgps",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"Bgps",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"BgpCb",
".",
"BgpCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"Bgps",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a Bgp object | [
"Create",
"a",
"Bgp",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1870-L1930 |
7,872 | contiv/netplugin | contivmodel/contivModel.go | FindBgp | func FindBgp(key string) *Bgp {
collections.BgpMutex.Lock()
defer collections.BgpMutex.Unlock()
obj := collections.Bgps[key]
if obj == nil {
return nil
}
return obj
} | go | func FindBgp(key string) *Bgp {
collections.BgpMutex.Lock()
defer collections.BgpMutex.Unlock()
obj := collections.Bgps[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindBgp",
"(",
"key",
"string",
")",
"*",
"Bgp",
"{",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"Bgps",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to Bgp from collection | [
"Return",
"a",
"pointer",
"to",
"Bgp",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1933-L1943 |
7,873 | contiv/netplugin | contivmodel/contivModel.go | DeleteBgp | func DeleteBgp(key string) error {
collections.BgpMutex.Lock()
obj := collections.Bgps[key]
collections.BgpMutex.Unlock()
if obj == nil {
log.Errorf("Bgp %s not found", key)
return errors.New("Bgp not found")
}
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.BgpCb.BgpDelete(obj)
if err != nil {
log.Errorf("BgpDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.BgpMutex.Lock()
err = obj.Delete()
collections.BgpMutex.Unlock()
if err != nil {
log.Errorf("Error deleting Bgp %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.BgpMutex.Lock()
delete(collections.Bgps, key)
collections.BgpMutex.Unlock()
return nil
} | go | func DeleteBgp(key string) error {
collections.BgpMutex.Lock()
obj := collections.Bgps[key]
collections.BgpMutex.Unlock()
if obj == nil {
log.Errorf("Bgp %s not found", key)
return errors.New("Bgp not found")
}
// Check if we handle this object
if objCallbackHandler.BgpCb == nil {
log.Errorf("No callback registered for Bgp object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.BgpCb.BgpDelete(obj)
if err != nil {
log.Errorf("BgpDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.BgpMutex.Lock()
err = obj.Delete()
collections.BgpMutex.Unlock()
if err != nil {
log.Errorf("Error deleting Bgp %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.BgpMutex.Lock()
delete(collections.Bgps, key)
collections.BgpMutex.Unlock()
return nil
} | [
"func",
"DeleteBgp",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"Bgps",
"[",
"key",
"]",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"BgpCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"BgpCb",
".",
"BgpDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"Bgps",
",",
"key",
")",
"\n",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a Bgp object | [
"Delete",
"a",
"Bgp",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L1946-L1982 |
7,874 | contiv/netplugin | contivmodel/contivModel.go | ValidateBgp | func ValidateBgp(obj *Bgp) error {
collections.BgpMutex.Lock()
defer collections.BgpMutex.Unlock()
// Validate key is correct
keyStr := obj.Hostname
if obj.Key != keyStr {
log.Errorf("Expecting Bgp Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.As) > 64 {
return errors.New("as string too long")
}
if len(obj.Hostname) > 256 {
return errors.New("hostname string too long")
}
hostnameMatch := 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 hostnameMatch.MatchString(obj.Hostname) == false {
return errors.New("hostname string invalid format")
}
if len(obj.Neighbor) > 15 {
return errors.New("neighbor string too long")
}
neighborMatch := 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 neighborMatch.MatchString(obj.Neighbor) == false {
return errors.New("neighbor string invalid format")
}
if len(obj.NeighborAs) > 64 {
return errors.New("neighbor-as string too long")
}
routeripMatch := 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 routeripMatch.MatchString(obj.Routerip) == false {
return errors.New("routerip string invalid format")
}
return nil
} | go | func ValidateBgp(obj *Bgp) error {
collections.BgpMutex.Lock()
defer collections.BgpMutex.Unlock()
// Validate key is correct
keyStr := obj.Hostname
if obj.Key != keyStr {
log.Errorf("Expecting Bgp Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.As) > 64 {
return errors.New("as string too long")
}
if len(obj.Hostname) > 256 {
return errors.New("hostname string too long")
}
hostnameMatch := 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 hostnameMatch.MatchString(obj.Hostname) == false {
return errors.New("hostname string invalid format")
}
if len(obj.Neighbor) > 15 {
return errors.New("neighbor string too long")
}
neighborMatch := 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 neighborMatch.MatchString(obj.Neighbor) == false {
return errors.New("neighbor string invalid format")
}
if len(obj.NeighborAs) > 64 {
return errors.New("neighbor-as string too long")
}
routeripMatch := 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 routeripMatch.MatchString(obj.Routerip) == false {
return errors.New("routerip string invalid format")
}
return nil
} | [
"func",
"ValidateBgp",
"(",
"obj",
"*",
"Bgp",
")",
"error",
"{",
"collections",
".",
"BgpMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"BgpMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"Hostname",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"As",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"Hostname",
")",
">",
"256",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"hostnameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"hostnameMatch",
".",
"MatchString",
"(",
"obj",
".",
"Hostname",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"Neighbor",
")",
">",
"15",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"neighborMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"if",
"neighborMatch",
".",
"MatchString",
"(",
"obj",
".",
"Neighbor",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"NeighborAs",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"routeripMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"routeripMatch",
".",
"MatchString",
"(",
"obj",
".",
"Routerip",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate a Bgp object | [
"Validate",
"a",
"Bgp",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2045-L2090 |
7,875 | contiv/netplugin | contivmodel/contivModel.go | GetOperEndpoint | func GetOperEndpoint(obj *EndpointInspect) error {
// Check if we handle this object
if objCallbackHandler.EndpointCb == nil {
log.Errorf("No callback registered for endpoint object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointCb.EndpointGetOper(obj)
if err != nil {
log.Errorf("EndpointDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperEndpoint(obj *EndpointInspect) error {
// Check if we handle this object
if objCallbackHandler.EndpointCb == nil {
log.Errorf("No callback registered for endpoint object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointCb.EndpointGetOper(obj)
if err != nil {
log.Errorf("EndpointDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperEndpoint",
"(",
"obj",
"*",
"EndpointInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"EndpointCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"EndpointCb",
".",
"EndpointGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a endpointOper object | [
"Get",
"a",
"endpointOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2109-L2124 |
7,876 | contiv/netplugin | contivmodel/contivModel.go | GetOperEndpointGroup | func GetOperEndpointGroup(obj *EndpointGroupInspect) error {
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointGroupCb.EndpointGroupGetOper(obj)
if err != nil {
log.Errorf("EndpointGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperEndpointGroup(obj *EndpointGroupInspect) error {
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointGroupCb.EndpointGroupGetOper(obj)
if err != nil {
log.Errorf("EndpointGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperEndpointGroup",
"(",
"obj",
"*",
"EndpointGroupInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"EndpointGroupCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"EndpointGroupCb",
".",
"EndpointGroupGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a endpointGroupOper object | [
"Get",
"a",
"endpointGroupOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2152-L2167 |
7,877 | contiv/netplugin | contivmodel/contivModel.go | CreateEndpointGroup | func CreateEndpointGroup(obj *EndpointGroup) error {
// Validate parameters
err := ValidateEndpointGroup(obj)
if err != nil {
log.Errorf("ValidateEndpointGroup retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.endpointGroupMutex.Lock()
key := collections.endpointGroups[obj.Key]
collections.endpointGroupMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.EndpointGroupCb.EndpointGroupUpdate(collections.endpointGroups[obj.Key], obj)
if err != nil {
log.Errorf("EndpointGroupUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.endpointGroupMutex.Lock()
saveObj = collections.endpointGroups[obj.Key]
collections.endpointGroupMutex.Unlock()
} else {
// save it in cache
collections.endpointGroupMutex.Lock()
collections.endpointGroups[obj.Key] = obj
collections.endpointGroupMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.EndpointGroupCb.EndpointGroupCreate(obj)
if err != nil {
log.Errorf("EndpointGroupCreate retruned error for: %+v. Err: %v", obj, err)
collections.endpointGroupMutex.Lock()
delete(collections.endpointGroups, obj.Key)
collections.endpointGroupMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.endpointGroupMutex.Lock()
err = saveObj.Write()
collections.endpointGroupMutex.Unlock()
if err != nil {
log.Errorf("Error saving endpointGroup %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateEndpointGroup(obj *EndpointGroup) error {
// Validate parameters
err := ValidateEndpointGroup(obj)
if err != nil {
log.Errorf("ValidateEndpointGroup retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.endpointGroupMutex.Lock()
key := collections.endpointGroups[obj.Key]
collections.endpointGroupMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.EndpointGroupCb.EndpointGroupUpdate(collections.endpointGroups[obj.Key], obj)
if err != nil {
log.Errorf("EndpointGroupUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.endpointGroupMutex.Lock()
saveObj = collections.endpointGroups[obj.Key]
collections.endpointGroupMutex.Unlock()
} else {
// save it in cache
collections.endpointGroupMutex.Lock()
collections.endpointGroups[obj.Key] = obj
collections.endpointGroupMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.EndpointGroupCb.EndpointGroupCreate(obj)
if err != nil {
log.Errorf("EndpointGroupCreate retruned error for: %+v. Err: %v", obj, err)
collections.endpointGroupMutex.Lock()
delete(collections.endpointGroups, obj.Key)
collections.endpointGroupMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.endpointGroupMutex.Lock()
err = saveObj.Write()
collections.endpointGroupMutex.Unlock()
if err != nil {
log.Errorf("Error saving endpointGroup %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateEndpointGroup",
"(",
"obj",
"*",
"EndpointGroup",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateEndpointGroup",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"EndpointGroupCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"endpointGroups",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"EndpointGroupCb",
".",
"EndpointGroupUpdate",
"(",
"collections",
".",
"endpointGroups",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"endpointGroups",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"endpointGroups",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"EndpointGroupCb",
".",
"EndpointGroupCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"endpointGroups",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a endpointGroup object | [
"Create",
"a",
"endpointGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2248-L2308 |
7,878 | contiv/netplugin | contivmodel/contivModel.go | FindEndpointGroup | func FindEndpointGroup(key string) *EndpointGroup {
collections.endpointGroupMutex.Lock()
defer collections.endpointGroupMutex.Unlock()
obj := collections.endpointGroups[key]
if obj == nil {
return nil
}
return obj
} | go | func FindEndpointGroup(key string) *EndpointGroup {
collections.endpointGroupMutex.Lock()
defer collections.endpointGroupMutex.Unlock()
obj := collections.endpointGroups[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindEndpointGroup",
"(",
"key",
"string",
")",
"*",
"EndpointGroup",
"{",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"endpointGroups",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to endpointGroup from collection | [
"Return",
"a",
"pointer",
"to",
"endpointGroup",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2311-L2321 |
7,879 | contiv/netplugin | contivmodel/contivModel.go | DeleteEndpointGroup | func DeleteEndpointGroup(key string) error {
collections.endpointGroupMutex.Lock()
obj := collections.endpointGroups[key]
collections.endpointGroupMutex.Unlock()
if obj == nil {
log.Errorf("endpointGroup %s not found", key)
return errors.New("endpointGroup not found")
}
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointGroupCb.EndpointGroupDelete(obj)
if err != nil {
log.Errorf("EndpointGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.endpointGroupMutex.Lock()
err = obj.Delete()
collections.endpointGroupMutex.Unlock()
if err != nil {
log.Errorf("Error deleting endpointGroup %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.endpointGroupMutex.Lock()
delete(collections.endpointGroups, key)
collections.endpointGroupMutex.Unlock()
return nil
} | go | func DeleteEndpointGroup(key string) error {
collections.endpointGroupMutex.Lock()
obj := collections.endpointGroups[key]
collections.endpointGroupMutex.Unlock()
if obj == nil {
log.Errorf("endpointGroup %s not found", key)
return errors.New("endpointGroup not found")
}
// Check if we handle this object
if objCallbackHandler.EndpointGroupCb == nil {
log.Errorf("No callback registered for endpointGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.EndpointGroupCb.EndpointGroupDelete(obj)
if err != nil {
log.Errorf("EndpointGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.endpointGroupMutex.Lock()
err = obj.Delete()
collections.endpointGroupMutex.Unlock()
if err != nil {
log.Errorf("Error deleting endpointGroup %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.endpointGroupMutex.Lock()
delete(collections.endpointGroups, key)
collections.endpointGroupMutex.Unlock()
return nil
} | [
"func",
"DeleteEndpointGroup",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"endpointGroups",
"[",
"key",
"]",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"EndpointGroupCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"EndpointGroupCb",
".",
"EndpointGroupDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"endpointGroups",
",",
"key",
")",
"\n",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a endpointGroup object | [
"Delete",
"a",
"endpointGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2324-L2360 |
7,880 | contiv/netplugin | contivmodel/contivModel.go | ValidateEndpointGroup | func ValidateEndpointGroup(obj *EndpointGroup) error {
collections.endpointGroupMutex.Lock()
defer collections.endpointGroupMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.GroupName
if obj.Key != keyStr {
log.Errorf("Expecting EndpointGroup Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.CfgdTag) > 128 {
return errors.New("cfgdTag string too long")
}
cfgdTagMatch := 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 cfgdTagMatch.MatchString(obj.CfgdTag) == false {
return errors.New("cfgdTag string invalid format")
}
if len(obj.GroupName) > 64 {
return errors.New("groupName string too long")
}
groupNameMatch := 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 groupNameMatch.MatchString(obj.GroupName) == false {
return errors.New("groupName string invalid format")
}
ipPoolMatch := 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])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))?$")
if ipPoolMatch.MatchString(obj.IpPool) == false {
return errors.New("ipPool string invalid format")
}
if len(obj.NetProfile) > 64 {
return errors.New("netProfile string too long")
}
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.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 ValidateEndpointGroup(obj *EndpointGroup) error {
collections.endpointGroupMutex.Lock()
defer collections.endpointGroupMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.GroupName
if obj.Key != keyStr {
log.Errorf("Expecting EndpointGroup Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.CfgdTag) > 128 {
return errors.New("cfgdTag string too long")
}
cfgdTagMatch := 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 cfgdTagMatch.MatchString(obj.CfgdTag) == false {
return errors.New("cfgdTag string invalid format")
}
if len(obj.GroupName) > 64 {
return errors.New("groupName string too long")
}
groupNameMatch := 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 groupNameMatch.MatchString(obj.GroupName) == false {
return errors.New("groupName string invalid format")
}
ipPoolMatch := 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])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))?$")
if ipPoolMatch.MatchString(obj.IpPool) == false {
return errors.New("ipPool string invalid format")
}
if len(obj.NetProfile) > 64 {
return errors.New("netProfile string too long")
}
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.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",
"ValidateEndpointGroup",
"(",
"obj",
"*",
"EndpointGroup",
")",
"error",
"{",
"collections",
".",
"endpointGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"endpointGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"TenantName",
"+",
"\"",
"\"",
"+",
"obj",
".",
"GroupName",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"CfgdTag",
")",
">",
"128",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cfgdTagMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"cfgdTagMatch",
".",
"MatchString",
"(",
"obj",
".",
"CfgdTag",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"GroupName",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"groupNameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"groupNameMatch",
".",
"MatchString",
"(",
"obj",
".",
"GroupName",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ipPoolMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"ipPoolMatch",
".",
"MatchString",
"(",
"obj",
".",
"IpPool",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"NetProfile",
")",
">",
"64",
"{",
"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",
".",
"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 endpointGroup object | [
"Validate",
"a",
"endpointGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2423-L2482 |
7,881 | contiv/netplugin | contivmodel/contivModel.go | CreateExtContractsGroup | func CreateExtContractsGroup(obj *ExtContractsGroup) error {
// Validate parameters
err := ValidateExtContractsGroup(obj)
if err != nil {
log.Errorf("ValidateExtContractsGroup retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.ExtContractsGroupCb == nil {
log.Errorf("No callback registered for extContractsGroup object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.extContractsGroupMutex.Lock()
key := collections.extContractsGroups[obj.Key]
collections.extContractsGroupMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupUpdate(collections.extContractsGroups[obj.Key], obj)
if err != nil {
log.Errorf("ExtContractsGroupUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.extContractsGroupMutex.Lock()
saveObj = collections.extContractsGroups[obj.Key]
collections.extContractsGroupMutex.Unlock()
} else {
// save it in cache
collections.extContractsGroupMutex.Lock()
collections.extContractsGroups[obj.Key] = obj
collections.extContractsGroupMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupCreate(obj)
if err != nil {
log.Errorf("ExtContractsGroupCreate retruned error for: %+v. Err: %v", obj, err)
collections.extContractsGroupMutex.Lock()
delete(collections.extContractsGroups, obj.Key)
collections.extContractsGroupMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.extContractsGroupMutex.Lock()
err = saveObj.Write()
collections.extContractsGroupMutex.Unlock()
if err != nil {
log.Errorf("Error saving extContractsGroup %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateExtContractsGroup(obj *ExtContractsGroup) error {
// Validate parameters
err := ValidateExtContractsGroup(obj)
if err != nil {
log.Errorf("ValidateExtContractsGroup retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.ExtContractsGroupCb == nil {
log.Errorf("No callback registered for extContractsGroup object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.extContractsGroupMutex.Lock()
key := collections.extContractsGroups[obj.Key]
collections.extContractsGroupMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupUpdate(collections.extContractsGroups[obj.Key], obj)
if err != nil {
log.Errorf("ExtContractsGroupUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.extContractsGroupMutex.Lock()
saveObj = collections.extContractsGroups[obj.Key]
collections.extContractsGroupMutex.Unlock()
} else {
// save it in cache
collections.extContractsGroupMutex.Lock()
collections.extContractsGroups[obj.Key] = obj
collections.extContractsGroupMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupCreate(obj)
if err != nil {
log.Errorf("ExtContractsGroupCreate retruned error for: %+v. Err: %v", obj, err)
collections.extContractsGroupMutex.Lock()
delete(collections.extContractsGroups, obj.Key)
collections.extContractsGroupMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.extContractsGroupMutex.Lock()
err = saveObj.Write()
collections.extContractsGroupMutex.Unlock()
if err != nil {
log.Errorf("Error saving extContractsGroup %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateExtContractsGroup",
"(",
"obj",
"*",
"ExtContractsGroup",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateExtContractsGroup",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"ExtContractsGroupCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"extContractsGroups",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"ExtContractsGroupCb",
".",
"ExtContractsGroupUpdate",
"(",
"collections",
".",
"extContractsGroups",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"extContractsGroups",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"extContractsGroups",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"ExtContractsGroupCb",
".",
"ExtContractsGroupCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"extContractsGroups",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a extContractsGroup object | [
"Create",
"a",
"extContractsGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2583-L2643 |
7,882 | contiv/netplugin | contivmodel/contivModel.go | FindExtContractsGroup | func FindExtContractsGroup(key string) *ExtContractsGroup {
collections.extContractsGroupMutex.Lock()
defer collections.extContractsGroupMutex.Unlock()
obj := collections.extContractsGroups[key]
if obj == nil {
return nil
}
return obj
} | go | func FindExtContractsGroup(key string) *ExtContractsGroup {
collections.extContractsGroupMutex.Lock()
defer collections.extContractsGroupMutex.Unlock()
obj := collections.extContractsGroups[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindExtContractsGroup",
"(",
"key",
"string",
")",
"*",
"ExtContractsGroup",
"{",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"extContractsGroups",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to extContractsGroup from collection | [
"Return",
"a",
"pointer",
"to",
"extContractsGroup",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2646-L2656 |
7,883 | contiv/netplugin | contivmodel/contivModel.go | DeleteExtContractsGroup | func DeleteExtContractsGroup(key string) error {
collections.extContractsGroupMutex.Lock()
obj := collections.extContractsGroups[key]
collections.extContractsGroupMutex.Unlock()
if obj == nil {
log.Errorf("extContractsGroup %s not found", key)
return errors.New("extContractsGroup not found")
}
// Check if we handle this object
if objCallbackHandler.ExtContractsGroupCb == nil {
log.Errorf("No callback registered for extContractsGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupDelete(obj)
if err != nil {
log.Errorf("ExtContractsGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.extContractsGroupMutex.Lock()
err = obj.Delete()
collections.extContractsGroupMutex.Unlock()
if err != nil {
log.Errorf("Error deleting extContractsGroup %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.extContractsGroupMutex.Lock()
delete(collections.extContractsGroups, key)
collections.extContractsGroupMutex.Unlock()
return nil
} | go | func DeleteExtContractsGroup(key string) error {
collections.extContractsGroupMutex.Lock()
obj := collections.extContractsGroups[key]
collections.extContractsGroupMutex.Unlock()
if obj == nil {
log.Errorf("extContractsGroup %s not found", key)
return errors.New("extContractsGroup not found")
}
// Check if we handle this object
if objCallbackHandler.ExtContractsGroupCb == nil {
log.Errorf("No callback registered for extContractsGroup object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.ExtContractsGroupCb.ExtContractsGroupDelete(obj)
if err != nil {
log.Errorf("ExtContractsGroupDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.extContractsGroupMutex.Lock()
err = obj.Delete()
collections.extContractsGroupMutex.Unlock()
if err != nil {
log.Errorf("Error deleting extContractsGroup %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.extContractsGroupMutex.Lock()
delete(collections.extContractsGroups, key)
collections.extContractsGroupMutex.Unlock()
return nil
} | [
"func",
"DeleteExtContractsGroup",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"extContractsGroups",
"[",
"key",
"]",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"ExtContractsGroupCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"ExtContractsGroupCb",
".",
"ExtContractsGroupDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"extContractsGroups",
",",
"key",
")",
"\n",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a extContractsGroup object | [
"Delete",
"a",
"extContractsGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2659-L2695 |
7,884 | contiv/netplugin | contivmodel/contivModel.go | ValidateExtContractsGroup | func ValidateExtContractsGroup(obj *ExtContractsGroup) error {
collections.extContractsGroupMutex.Lock()
defer collections.extContractsGroupMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.ContractsGroupName
if obj.Key != keyStr {
log.Errorf("Expecting ExtContractsGroup Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.ContractsGroupName) > 64 {
return errors.New("contractsGroupName string too long")
}
contractsGroupNameMatch := 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 contractsGroupNameMatch.MatchString(obj.ContractsGroupName) == false {
return errors.New("contractsGroupName 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 ValidateExtContractsGroup(obj *ExtContractsGroup) error {
collections.extContractsGroupMutex.Lock()
defer collections.extContractsGroupMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.ContractsGroupName
if obj.Key != keyStr {
log.Errorf("Expecting ExtContractsGroup Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.ContractsGroupName) > 64 {
return errors.New("contractsGroupName string too long")
}
contractsGroupNameMatch := 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 contractsGroupNameMatch.MatchString(obj.ContractsGroupName) == false {
return errors.New("contractsGroupName 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",
"ValidateExtContractsGroup",
"(",
"obj",
"*",
"ExtContractsGroup",
")",
"error",
"{",
"collections",
".",
"extContractsGroupMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"extContractsGroupMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"TenantName",
"+",
"\"",
"\"",
"+",
"obj",
".",
"ContractsGroupName",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"ContractsGroupName",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"contractsGroupNameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"contractsGroupNameMatch",
".",
"MatchString",
"(",
"obj",
".",
"ContractsGroupName",
")",
"==",
"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 extContractsGroup object | [
"Validate",
"a",
"extContractsGroup",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2758-L2790 |
7,885 | contiv/netplugin | contivmodel/contivModel.go | GetOperGlobal | func GetOperGlobal(obj *GlobalInspect) error {
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.GlobalCb.GlobalGetOper(obj)
if err != nil {
log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperGlobal(obj *GlobalInspect) error {
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.GlobalCb.GlobalGetOper(obj)
if err != nil {
log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperGlobal",
"(",
"obj",
"*",
"GlobalInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"GlobalCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"GlobalCb",
".",
"GlobalGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a globalOper object | [
"Get",
"a",
"globalOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2818-L2833 |
7,886 | contiv/netplugin | contivmodel/contivModel.go | CreateGlobal | func CreateGlobal(obj *Global) error {
// Validate parameters
err := ValidateGlobal(obj)
if err != nil {
log.Errorf("ValidateGlobal retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.globalMutex.Lock()
key := collections.globals[obj.Key]
collections.globalMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.GlobalCb.GlobalUpdate(collections.globals[obj.Key], obj)
if err != nil {
log.Errorf("GlobalUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.globalMutex.Lock()
saveObj = collections.globals[obj.Key]
collections.globalMutex.Unlock()
} else {
// save it in cache
collections.globalMutex.Lock()
collections.globals[obj.Key] = obj
collections.globalMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.GlobalCb.GlobalCreate(obj)
if err != nil {
log.Errorf("GlobalCreate retruned error for: %+v. Err: %v", obj, err)
collections.globalMutex.Lock()
delete(collections.globals, obj.Key)
collections.globalMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.globalMutex.Lock()
err = saveObj.Write()
collections.globalMutex.Unlock()
if err != nil {
log.Errorf("Error saving global %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateGlobal(obj *Global) error {
// Validate parameters
err := ValidateGlobal(obj)
if err != nil {
log.Errorf("ValidateGlobal retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.globalMutex.Lock()
key := collections.globals[obj.Key]
collections.globalMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.GlobalCb.GlobalUpdate(collections.globals[obj.Key], obj)
if err != nil {
log.Errorf("GlobalUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.globalMutex.Lock()
saveObj = collections.globals[obj.Key]
collections.globalMutex.Unlock()
} else {
// save it in cache
collections.globalMutex.Lock()
collections.globals[obj.Key] = obj
collections.globalMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.GlobalCb.GlobalCreate(obj)
if err != nil {
log.Errorf("GlobalCreate retruned error for: %+v. Err: %v", obj, err)
collections.globalMutex.Lock()
delete(collections.globals, obj.Key)
collections.globalMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.globalMutex.Lock()
err = saveObj.Write()
collections.globalMutex.Unlock()
if err != nil {
log.Errorf("Error saving global %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateGlobal",
"(",
"obj",
"*",
"Global",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateGlobal",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"GlobalCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"globals",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"GlobalCb",
".",
"GlobalUpdate",
"(",
"collections",
".",
"globals",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"globals",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"globals",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"GlobalCb",
".",
"GlobalCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"globals",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a global object | [
"Create",
"a",
"global",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2914-L2974 |
7,887 | contiv/netplugin | contivmodel/contivModel.go | FindGlobal | func FindGlobal(key string) *Global {
collections.globalMutex.Lock()
defer collections.globalMutex.Unlock()
obj := collections.globals[key]
if obj == nil {
return nil
}
return obj
} | go | func FindGlobal(key string) *Global {
collections.globalMutex.Lock()
defer collections.globalMutex.Unlock()
obj := collections.globals[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindGlobal",
"(",
"key",
"string",
")",
"*",
"Global",
"{",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"globals",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to global from collection | [
"Return",
"a",
"pointer",
"to",
"global",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2977-L2987 |
7,888 | contiv/netplugin | contivmodel/contivModel.go | DeleteGlobal | func DeleteGlobal(key string) error {
collections.globalMutex.Lock()
obj := collections.globals[key]
collections.globalMutex.Unlock()
if obj == nil {
log.Errorf("global %s not found", key)
return errors.New("global not found")
}
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.GlobalCb.GlobalDelete(obj)
if err != nil {
log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.globalMutex.Lock()
err = obj.Delete()
collections.globalMutex.Unlock()
if err != nil {
log.Errorf("Error deleting global %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.globalMutex.Lock()
delete(collections.globals, key)
collections.globalMutex.Unlock()
return nil
} | go | func DeleteGlobal(key string) error {
collections.globalMutex.Lock()
obj := collections.globals[key]
collections.globalMutex.Unlock()
if obj == nil {
log.Errorf("global %s not found", key)
return errors.New("global not found")
}
// Check if we handle this object
if objCallbackHandler.GlobalCb == nil {
log.Errorf("No callback registered for global object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.GlobalCb.GlobalDelete(obj)
if err != nil {
log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.globalMutex.Lock()
err = obj.Delete()
collections.globalMutex.Unlock()
if err != nil {
log.Errorf("Error deleting global %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.globalMutex.Lock()
delete(collections.globals, key)
collections.globalMutex.Unlock()
return nil
} | [
"func",
"DeleteGlobal",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"globals",
"[",
"key",
"]",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"GlobalCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"GlobalCb",
".",
"GlobalDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"globals",
",",
"key",
")",
"\n",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a global object | [
"Delete",
"a",
"global",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L2990-L3026 |
7,889 | contiv/netplugin | contivmodel/contivModel.go | ValidateGlobal | func ValidateGlobal(obj *Global) error {
collections.globalMutex.Lock()
defer collections.globalMutex.Unlock()
// Validate key is correct
keyStr := obj.Name
if obj.Key != keyStr {
log.Errorf("Expecting Global Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.ArpMode) > 64 {
return errors.New("arpMode string too long")
}
arpModeMatch := regexp.MustCompile("^(proxy|flood)?$")
if arpModeMatch.MatchString(obj.ArpMode) == false {
return errors.New("arpMode string invalid format")
}
if len(obj.FwdMode) > 64 {
return errors.New("fwdMode string too long")
}
fwdModeMatch := regexp.MustCompile("^(bridge|routing)?$")
if fwdModeMatch.MatchString(obj.FwdMode) == false {
return errors.New("fwdMode string invalid format")
}
if len(obj.Name) > 64 {
return errors.New("name string too long")
}
nameMatch := regexp.MustCompile("^(global)$")
if nameMatch.MatchString(obj.Name) == false {
return errors.New("name string invalid format")
}
if len(obj.NetworkInfraType) > 64 {
return errors.New("networkInfraType string too long")
}
networkInfraTypeMatch := regexp.MustCompile("^(aci|aci-opflex|default)?$")
if networkInfraTypeMatch.MatchString(obj.NetworkInfraType) == false {
return errors.New("networkInfraType string invalid format")
}
pvtSubnetMatch := 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})/16$")
if pvtSubnetMatch.MatchString(obj.PvtSubnet) == false {
return errors.New("pvtSubnet string invalid format")
}
vlansMatch := regexp.MustCompile("^([0-9]{1,4}?-[0-9]{1,4}?)$")
if vlansMatch.MatchString(obj.Vlans) == false {
return errors.New("vlans string invalid format")
}
vxlansMatch := regexp.MustCompile("^([0-9]{1,8}?-[0-9]{1,8}?)$")
if vxlansMatch.MatchString(obj.Vxlans) == false {
return errors.New("vxlans string invalid format")
}
return nil
} | go | func ValidateGlobal(obj *Global) error {
collections.globalMutex.Lock()
defer collections.globalMutex.Unlock()
// Validate key is correct
keyStr := obj.Name
if obj.Key != keyStr {
log.Errorf("Expecting Global Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.ArpMode) > 64 {
return errors.New("arpMode string too long")
}
arpModeMatch := regexp.MustCompile("^(proxy|flood)?$")
if arpModeMatch.MatchString(obj.ArpMode) == false {
return errors.New("arpMode string invalid format")
}
if len(obj.FwdMode) > 64 {
return errors.New("fwdMode string too long")
}
fwdModeMatch := regexp.MustCompile("^(bridge|routing)?$")
if fwdModeMatch.MatchString(obj.FwdMode) == false {
return errors.New("fwdMode string invalid format")
}
if len(obj.Name) > 64 {
return errors.New("name string too long")
}
nameMatch := regexp.MustCompile("^(global)$")
if nameMatch.MatchString(obj.Name) == false {
return errors.New("name string invalid format")
}
if len(obj.NetworkInfraType) > 64 {
return errors.New("networkInfraType string too long")
}
networkInfraTypeMatch := regexp.MustCompile("^(aci|aci-opflex|default)?$")
if networkInfraTypeMatch.MatchString(obj.NetworkInfraType) == false {
return errors.New("networkInfraType string invalid format")
}
pvtSubnetMatch := 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})/16$")
if pvtSubnetMatch.MatchString(obj.PvtSubnet) == false {
return errors.New("pvtSubnet string invalid format")
}
vlansMatch := regexp.MustCompile("^([0-9]{1,4}?-[0-9]{1,4}?)$")
if vlansMatch.MatchString(obj.Vlans) == false {
return errors.New("vlans string invalid format")
}
vxlansMatch := regexp.MustCompile("^([0-9]{1,8}?-[0-9]{1,8}?)$")
if vxlansMatch.MatchString(obj.Vxlans) == false {
return errors.New("vxlans string invalid format")
}
return nil
} | [
"func",
"ValidateGlobal",
"(",
"obj",
"*",
"Global",
")",
"error",
"{",
"collections",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"Name",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"ArpMode",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"arpModeMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"arpModeMatch",
".",
"MatchString",
"(",
"obj",
".",
"ArpMode",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"FwdMode",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"fwdModeMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"fwdModeMatch",
".",
"MatchString",
"(",
"obj",
".",
"FwdMode",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"Name",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"nameMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"nameMatch",
".",
"MatchString",
"(",
"obj",
".",
"Name",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"NetworkInfraType",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"networkInfraTypeMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"networkInfraTypeMatch",
".",
"MatchString",
"(",
"obj",
".",
"NetworkInfraType",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pvtSubnetMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"if",
"pvtSubnetMatch",
".",
"MatchString",
"(",
"obj",
".",
"PvtSubnet",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"vlansMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"vlansMatch",
".",
"MatchString",
"(",
"obj",
".",
"Vlans",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"vxlansMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"vxlansMatch",
".",
"MatchString",
"(",
"obj",
".",
"Vxlans",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate a global object | [
"Validate",
"a",
"global",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3089-L3154 |
7,890 | contiv/netplugin | contivmodel/contivModel.go | CreateNetprofile | func CreateNetprofile(obj *Netprofile) error {
// Validate parameters
err := ValidateNetprofile(obj)
if err != nil {
log.Errorf("ValidateNetprofile retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.NetprofileCb == nil {
log.Errorf("No callback registered for netprofile object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.netprofileMutex.Lock()
key := collections.netprofiles[obj.Key]
collections.netprofileMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.NetprofileCb.NetprofileUpdate(collections.netprofiles[obj.Key], obj)
if err != nil {
log.Errorf("NetprofileUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.netprofileMutex.Lock()
saveObj = collections.netprofiles[obj.Key]
collections.netprofileMutex.Unlock()
} else {
// save it in cache
collections.netprofileMutex.Lock()
collections.netprofiles[obj.Key] = obj
collections.netprofileMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.NetprofileCb.NetprofileCreate(obj)
if err != nil {
log.Errorf("NetprofileCreate retruned error for: %+v. Err: %v", obj, err)
collections.netprofileMutex.Lock()
delete(collections.netprofiles, obj.Key)
collections.netprofileMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.netprofileMutex.Lock()
err = saveObj.Write()
collections.netprofileMutex.Unlock()
if err != nil {
log.Errorf("Error saving netprofile %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateNetprofile(obj *Netprofile) error {
// Validate parameters
err := ValidateNetprofile(obj)
if err != nil {
log.Errorf("ValidateNetprofile retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.NetprofileCb == nil {
log.Errorf("No callback registered for netprofile object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.netprofileMutex.Lock()
key := collections.netprofiles[obj.Key]
collections.netprofileMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.NetprofileCb.NetprofileUpdate(collections.netprofiles[obj.Key], obj)
if err != nil {
log.Errorf("NetprofileUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.netprofileMutex.Lock()
saveObj = collections.netprofiles[obj.Key]
collections.netprofileMutex.Unlock()
} else {
// save it in cache
collections.netprofileMutex.Lock()
collections.netprofiles[obj.Key] = obj
collections.netprofileMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.NetprofileCb.NetprofileCreate(obj)
if err != nil {
log.Errorf("NetprofileCreate retruned error for: %+v. Err: %v", obj, err)
collections.netprofileMutex.Lock()
delete(collections.netprofiles, obj.Key)
collections.netprofileMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.netprofileMutex.Lock()
err = saveObj.Write()
collections.netprofileMutex.Unlock()
if err != nil {
log.Errorf("Error saving netprofile %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateNetprofile",
"(",
"obj",
"*",
"Netprofile",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateNetprofile",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"NetprofileCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"netprofiles",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"NetprofileCb",
".",
"NetprofileUpdate",
"(",
"collections",
".",
"netprofiles",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"netprofiles",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"netprofiles",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"NetprofileCb",
".",
"NetprofileCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"netprofiles",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a netprofile object | [
"Create",
"a",
"netprofile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3255-L3315 |
7,891 | contiv/netplugin | contivmodel/contivModel.go | FindNetprofile | func FindNetprofile(key string) *Netprofile {
collections.netprofileMutex.Lock()
defer collections.netprofileMutex.Unlock()
obj := collections.netprofiles[key]
if obj == nil {
return nil
}
return obj
} | go | func FindNetprofile(key string) *Netprofile {
collections.netprofileMutex.Lock()
defer collections.netprofileMutex.Unlock()
obj := collections.netprofiles[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindNetprofile",
"(",
"key",
"string",
")",
"*",
"Netprofile",
"{",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"netprofiles",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to netprofile from collection | [
"Return",
"a",
"pointer",
"to",
"netprofile",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3318-L3328 |
7,892 | contiv/netplugin | contivmodel/contivModel.go | DeleteNetprofile | func DeleteNetprofile(key string) error {
collections.netprofileMutex.Lock()
obj := collections.netprofiles[key]
collections.netprofileMutex.Unlock()
if obj == nil {
log.Errorf("netprofile %s not found", key)
return errors.New("netprofile not found")
}
// Check if we handle this object
if objCallbackHandler.NetprofileCb == nil {
log.Errorf("No callback registered for netprofile object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetprofileCb.NetprofileDelete(obj)
if err != nil {
log.Errorf("NetprofileDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.netprofileMutex.Lock()
err = obj.Delete()
collections.netprofileMutex.Unlock()
if err != nil {
log.Errorf("Error deleting netprofile %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.netprofileMutex.Lock()
delete(collections.netprofiles, key)
collections.netprofileMutex.Unlock()
return nil
} | go | func DeleteNetprofile(key string) error {
collections.netprofileMutex.Lock()
obj := collections.netprofiles[key]
collections.netprofileMutex.Unlock()
if obj == nil {
log.Errorf("netprofile %s not found", key)
return errors.New("netprofile not found")
}
// Check if we handle this object
if objCallbackHandler.NetprofileCb == nil {
log.Errorf("No callback registered for netprofile object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetprofileCb.NetprofileDelete(obj)
if err != nil {
log.Errorf("NetprofileDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.netprofileMutex.Lock()
err = obj.Delete()
collections.netprofileMutex.Unlock()
if err != nil {
log.Errorf("Error deleting netprofile %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.netprofileMutex.Lock()
delete(collections.netprofiles, key)
collections.netprofileMutex.Unlock()
return nil
} | [
"func",
"DeleteNetprofile",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"netprofiles",
"[",
"key",
"]",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"NetprofileCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"NetprofileCb",
".",
"NetprofileDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"netprofiles",
",",
"key",
")",
"\n",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a netprofile object | [
"Delete",
"a",
"netprofile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3331-L3367 |
7,893 | contiv/netplugin | contivmodel/contivModel.go | ValidateNetprofile | func ValidateNetprofile(obj *Netprofile) error {
collections.netprofileMutex.Lock()
defer collections.netprofileMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.ProfileName
if obj.Key != keyStr {
log.Errorf("Expecting Netprofile Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if obj.DSCP == 0 {
obj.DSCP = 0
}
if obj.DSCP > 63 {
return errors.New("DSCP Value Out of bound")
}
if len(obj.Bandwidth) > 64 {
return errors.New("bandwidth string too long")
}
bandwidthMatch := regexp.MustCompile("^([1-9][0-9]* (([kmgKMG{1}]bps)|[kmgKMG{1}]|(kb|Kb|Gb|gb|Mb|mb)))?$|^([1-9][0-9]*(((k|m|g|K|G|M)bps)|(k|m|g|K|M|G)|(kb|Kb|Gb|gb|Mb|mb)))?$")
if bandwidthMatch.MatchString(obj.Bandwidth) == false {
return errors.New("bandwidth string invalid format")
}
if obj.Burst > 10486 {
return errors.New("burst Value Out of bound")
}
if len(obj.ProfileName) > 64 {
return errors.New("profileName string too long")
}
return nil
} | go | func ValidateNetprofile(obj *Netprofile) error {
collections.netprofileMutex.Lock()
defer collections.netprofileMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.ProfileName
if obj.Key != keyStr {
log.Errorf("Expecting Netprofile Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if obj.DSCP == 0 {
obj.DSCP = 0
}
if obj.DSCP > 63 {
return errors.New("DSCP Value Out of bound")
}
if len(obj.Bandwidth) > 64 {
return errors.New("bandwidth string too long")
}
bandwidthMatch := regexp.MustCompile("^([1-9][0-9]* (([kmgKMG{1}]bps)|[kmgKMG{1}]|(kb|Kb|Gb|gb|Mb|mb)))?$|^([1-9][0-9]*(((k|m|g|K|G|M)bps)|(k|m|g|K|M|G)|(kb|Kb|Gb|gb|Mb|mb)))?$")
if bandwidthMatch.MatchString(obj.Bandwidth) == false {
return errors.New("bandwidth string invalid format")
}
if obj.Burst > 10486 {
return errors.New("burst Value Out of bound")
}
if len(obj.ProfileName) > 64 {
return errors.New("profileName string too long")
}
return nil
} | [
"func",
"ValidateNetprofile",
"(",
"obj",
"*",
"Netprofile",
")",
"error",
"{",
"collections",
".",
"netprofileMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"netprofileMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"TenantName",
"+",
"\"",
"\"",
"+",
"obj",
".",
"ProfileName",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"obj",
".",
"DSCP",
"==",
"0",
"{",
"obj",
".",
"DSCP",
"=",
"0",
"\n",
"}",
"\n\n",
"if",
"obj",
".",
"DSCP",
">",
"63",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"Bandwidth",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"bandwidthMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"bandwidthMatch",
".",
"MatchString",
"(",
"obj",
".",
"Bandwidth",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"obj",
".",
"Burst",
">",
"10486",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"obj",
".",
"ProfileName",
")",
">",
"64",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate a netprofile object | [
"Validate",
"a",
"netprofile",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3430-L3469 |
7,894 | contiv/netplugin | contivmodel/contivModel.go | GetOperNetwork | func GetOperNetwork(obj *NetworkInspect) error {
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetworkCb.NetworkGetOper(obj)
if err != nil {
log.Errorf("NetworkDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperNetwork(obj *NetworkInspect) error {
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetworkCb.NetworkGetOper(obj)
if err != nil {
log.Errorf("NetworkDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperNetwork",
"(",
"obj",
"*",
"NetworkInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"NetworkCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"NetworkCb",
".",
"NetworkGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a networkOper object | [
"Get",
"a",
"networkOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3497-L3512 |
7,895 | contiv/netplugin | contivmodel/contivModel.go | CreateNetwork | func CreateNetwork(obj *Network) error {
// Validate parameters
err := ValidateNetwork(obj)
if err != nil {
log.Errorf("ValidateNetwork retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.networkMutex.Lock()
key := collections.networks[obj.Key]
collections.networkMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.NetworkCb.NetworkUpdate(collections.networks[obj.Key], obj)
if err != nil {
log.Errorf("NetworkUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.networkMutex.Lock()
saveObj = collections.networks[obj.Key]
collections.networkMutex.Unlock()
} else {
// save it in cache
collections.networkMutex.Lock()
collections.networks[obj.Key] = obj
collections.networkMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.NetworkCb.NetworkCreate(obj)
if err != nil {
log.Errorf("NetworkCreate retruned error for: %+v. Err: %v", obj, err)
collections.networkMutex.Lock()
delete(collections.networks, obj.Key)
collections.networkMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.networkMutex.Lock()
err = saveObj.Write()
collections.networkMutex.Unlock()
if err != nil {
log.Errorf("Error saving network %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | go | func CreateNetwork(obj *Network) error {
// Validate parameters
err := ValidateNetwork(obj)
if err != nil {
log.Errorf("ValidateNetwork retruned error for: %+v. Err: %v", obj, err)
return err
}
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
saveObj := obj
collections.networkMutex.Lock()
key := collections.networks[obj.Key]
collections.networkMutex.Unlock()
// Check if object already exists
if key != nil {
// Perform Update callback
err = objCallbackHandler.NetworkCb.NetworkUpdate(collections.networks[obj.Key], obj)
if err != nil {
log.Errorf("NetworkUpdate retruned error for: %+v. Err: %v", obj, err)
return err
}
// save the original object after update
collections.networkMutex.Lock()
saveObj = collections.networks[obj.Key]
collections.networkMutex.Unlock()
} else {
// save it in cache
collections.networkMutex.Lock()
collections.networks[obj.Key] = obj
collections.networkMutex.Unlock()
// Perform Create callback
err = objCallbackHandler.NetworkCb.NetworkCreate(obj)
if err != nil {
log.Errorf("NetworkCreate retruned error for: %+v. Err: %v", obj, err)
collections.networkMutex.Lock()
delete(collections.networks, obj.Key)
collections.networkMutex.Unlock()
return err
}
}
// Write it to modeldb
collections.networkMutex.Lock()
err = saveObj.Write()
collections.networkMutex.Unlock()
if err != nil {
log.Errorf("Error saving network %s to db. Err: %v", saveObj.Key, err)
return err
}
return nil
} | [
"func",
"CreateNetwork",
"(",
"obj",
"*",
"Network",
")",
"error",
"{",
"// Validate parameters",
"err",
":=",
"ValidateNetwork",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"NetworkCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"saveObj",
":=",
"obj",
"\n\n",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"key",
":=",
"collections",
".",
"networks",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if object already exists",
"if",
"key",
"!=",
"nil",
"{",
"// Perform Update callback",
"err",
"=",
"objCallbackHandler",
".",
"NetworkCb",
".",
"NetworkUpdate",
"(",
"collections",
".",
"networks",
"[",
"obj",
".",
"Key",
"]",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// save the original object after update",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"saveObj",
"=",
"collections",
".",
"networks",
"[",
"obj",
".",
"Key",
"]",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"// save it in cache",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"collections",
".",
"networks",
"[",
"obj",
".",
"Key",
"]",
"=",
"obj",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Perform Create callback",
"err",
"=",
"objCallbackHandler",
".",
"NetworkCb",
".",
"NetworkCreate",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"networks",
",",
"obj",
".",
"Key",
")",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write it to modeldb",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"saveObj",
".",
"Write",
"(",
")",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"saveObj",
".",
"Key",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Create a network object | [
"Create",
"a",
"network",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3593-L3653 |
7,896 | contiv/netplugin | contivmodel/contivModel.go | FindNetwork | func FindNetwork(key string) *Network {
collections.networkMutex.Lock()
defer collections.networkMutex.Unlock()
obj := collections.networks[key]
if obj == nil {
return nil
}
return obj
} | go | func FindNetwork(key string) *Network {
collections.networkMutex.Lock()
defer collections.networkMutex.Unlock()
obj := collections.networks[key]
if obj == nil {
return nil
}
return obj
} | [
"func",
"FindNetwork",
"(",
"key",
"string",
")",
"*",
"Network",
"{",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"obj",
":=",
"collections",
".",
"networks",
"[",
"key",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"obj",
"\n",
"}"
] | // Return a pointer to network from collection | [
"Return",
"a",
"pointer",
"to",
"network",
"from",
"collection"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3656-L3666 |
7,897 | contiv/netplugin | contivmodel/contivModel.go | DeleteNetwork | func DeleteNetwork(key string) error {
collections.networkMutex.Lock()
obj := collections.networks[key]
collections.networkMutex.Unlock()
if obj == nil {
log.Errorf("network %s not found", key)
return errors.New("network not found")
}
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetworkCb.NetworkDelete(obj)
if err != nil {
log.Errorf("NetworkDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.networkMutex.Lock()
err = obj.Delete()
collections.networkMutex.Unlock()
if err != nil {
log.Errorf("Error deleting network %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.networkMutex.Lock()
delete(collections.networks, key)
collections.networkMutex.Unlock()
return nil
} | go | func DeleteNetwork(key string) error {
collections.networkMutex.Lock()
obj := collections.networks[key]
collections.networkMutex.Unlock()
if obj == nil {
log.Errorf("network %s not found", key)
return errors.New("network not found")
}
// Check if we handle this object
if objCallbackHandler.NetworkCb == nil {
log.Errorf("No callback registered for network object")
return errors.New("Invalid object type")
}
// Perform callback
err := objCallbackHandler.NetworkCb.NetworkDelete(obj)
if err != nil {
log.Errorf("NetworkDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
// delete it from modeldb
collections.networkMutex.Lock()
err = obj.Delete()
collections.networkMutex.Unlock()
if err != nil {
log.Errorf("Error deleting network %s. Err: %v", obj.Key, err)
}
// delete it from cache
collections.networkMutex.Lock()
delete(collections.networks, key)
collections.networkMutex.Unlock()
return nil
} | [
"func",
"DeleteNetwork",
"(",
"key",
"string",
")",
"error",
"{",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"obj",
":=",
"collections",
".",
"networks",
"[",
"key",
"]",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"NetworkCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"NetworkCb",
".",
"NetworkDelete",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete it from modeldb",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
"=",
"obj",
".",
"Delete",
"(",
")",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
".",
"Key",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// delete it from cache",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"collections",
".",
"networks",
",",
"key",
")",
"\n",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete a network object | [
"Delete",
"a",
"network",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3669-L3705 |
7,898 | contiv/netplugin | contivmodel/contivModel.go | ValidateNetwork | func ValidateNetwork(obj *Network) error {
collections.networkMutex.Lock()
defer collections.networkMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.NetworkName
if obj.Key != keyStr {
log.Errorf("Expecting Network Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.CfgdTag) > 128 {
return errors.New("cfgdTag string too long")
}
cfgdTagMatch := 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 cfgdTagMatch.MatchString(obj.CfgdTag) == false {
return errors.New("cfgdTag string invalid format")
}
encapMatch := regexp.MustCompile("^(vlan|vxlan)$")
if encapMatch.MatchString(obj.Encap) == false {
return errors.New("encap string invalid format")
}
gatewayMatch := 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 gatewayMatch.MatchString(obj.Gateway) == false {
return errors.New("gateway string invalid format")
}
ipv6GatewayMatch := regexp.MustCompile("^(((([0-9]|[a-f]|[A-F]){1,4})((\\:([0-9]|[a-f]|[A-F]){1,4}){7}))|(((([0-9]|[a-f]|[A-F]){1,4}\\:){0,6}|\\:)((\\:([0-9]|[a-f]|[A-F]){1,4}){0,6}|\\:)))?$")
if ipv6GatewayMatch.MatchString(obj.Ipv6Gateway) == false {
return errors.New("ipv6Gateway string invalid format")
}
ipv6SubnetMatch := regexp.MustCompile("^((((([0-9]|[a-f]|[A-F]){1,4})((\\:([0-9]|[a-f]|[A-F]){1,4}){7}))|(((([0-9]|[a-f]|[A-F]){1,4}\\:){0,6}|\\:)((\\:([0-9]|[a-f]|[A-F]){1,4}){0,6}|\\:)))/(1[0-2][0-7]|[1-9][0-9]|[1-9]))?$")
if ipv6SubnetMatch.MatchString(obj.Ipv6Subnet) == false {
return errors.New("ipv6Subnet 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 obj.NwType == "" {
obj.NwType = "data"
}
nwTypeMatch := regexp.MustCompile("^(infra|data)$")
if nwTypeMatch.MatchString(obj.NwType) == false {
return errors.New("nwType string invalid format")
}
if obj.PktTag > 1.6777216e+07 {
return errors.New("pktTag Value Out of bound")
}
subnetMatch := 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])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))?/(3[0-1]|2[0-9]|1[0-9]|[1-9])$")
if subnetMatch.MatchString(obj.Subnet) == false {
return errors.New("subnet 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 ValidateNetwork(obj *Network) error {
collections.networkMutex.Lock()
defer collections.networkMutex.Unlock()
// Validate key is correct
keyStr := obj.TenantName + ":" + obj.NetworkName
if obj.Key != keyStr {
log.Errorf("Expecting Network Key: %s. Got: %s", keyStr, obj.Key)
return errors.New("Invalid Key")
}
// Validate each field
if len(obj.CfgdTag) > 128 {
return errors.New("cfgdTag string too long")
}
cfgdTagMatch := 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 cfgdTagMatch.MatchString(obj.CfgdTag) == false {
return errors.New("cfgdTag string invalid format")
}
encapMatch := regexp.MustCompile("^(vlan|vxlan)$")
if encapMatch.MatchString(obj.Encap) == false {
return errors.New("encap string invalid format")
}
gatewayMatch := 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 gatewayMatch.MatchString(obj.Gateway) == false {
return errors.New("gateway string invalid format")
}
ipv6GatewayMatch := regexp.MustCompile("^(((([0-9]|[a-f]|[A-F]){1,4})((\\:([0-9]|[a-f]|[A-F]){1,4}){7}))|(((([0-9]|[a-f]|[A-F]){1,4}\\:){0,6}|\\:)((\\:([0-9]|[a-f]|[A-F]){1,4}){0,6}|\\:)))?$")
if ipv6GatewayMatch.MatchString(obj.Ipv6Gateway) == false {
return errors.New("ipv6Gateway string invalid format")
}
ipv6SubnetMatch := regexp.MustCompile("^((((([0-9]|[a-f]|[A-F]){1,4})((\\:([0-9]|[a-f]|[A-F]){1,4}){7}))|(((([0-9]|[a-f]|[A-F]){1,4}\\:){0,6}|\\:)((\\:([0-9]|[a-f]|[A-F]){1,4}){0,6}|\\:)))/(1[0-2][0-7]|[1-9][0-9]|[1-9]))?$")
if ipv6SubnetMatch.MatchString(obj.Ipv6Subnet) == false {
return errors.New("ipv6Subnet 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 obj.NwType == "" {
obj.NwType = "data"
}
nwTypeMatch := regexp.MustCompile("^(infra|data)$")
if nwTypeMatch.MatchString(obj.NwType) == false {
return errors.New("nwType string invalid format")
}
if obj.PktTag > 1.6777216e+07 {
return errors.New("pktTag Value Out of bound")
}
subnetMatch := 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])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))?/(3[0-1]|2[0-9]|1[0-9]|[1-9])$")
if subnetMatch.MatchString(obj.Subnet) == false {
return errors.New("subnet 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",
"ValidateNetwork",
"(",
"obj",
"*",
"Network",
")",
"error",
"{",
"collections",
".",
"networkMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"collections",
".",
"networkMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate key is correct",
"keyStr",
":=",
"obj",
".",
"TenantName",
"+",
"\"",
"\"",
"+",
"obj",
".",
"NetworkName",
"\n",
"if",
"obj",
".",
"Key",
"!=",
"keyStr",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyStr",
",",
"obj",
".",
"Key",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate each field",
"if",
"len",
"(",
"obj",
".",
"CfgdTag",
")",
">",
"128",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cfgdTagMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"cfgdTagMatch",
".",
"MatchString",
"(",
"obj",
".",
"CfgdTag",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"encapMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"encapMatch",
".",
"MatchString",
"(",
"obj",
".",
"Encap",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"gatewayMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"if",
"gatewayMatch",
".",
"MatchString",
"(",
"obj",
".",
"Gateway",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ipv6GatewayMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"ipv6GatewayMatch",
".",
"MatchString",
"(",
"obj",
".",
"Ipv6Gateway",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ipv6SubnetMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"ipv6SubnetMatch",
".",
"MatchString",
"(",
"obj",
".",
"Ipv6Subnet",
")",
"==",
"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",
"obj",
".",
"NwType",
"==",
"\"",
"\"",
"{",
"obj",
".",
"NwType",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"nwTypeMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"if",
"nwTypeMatch",
".",
"MatchString",
"(",
"obj",
".",
"NwType",
")",
"==",
"false",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"obj",
".",
"PktTag",
">",
"1.6777216e+07",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"subnetMatch",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\"",
")",
"\n",
"if",
"subnetMatch",
".",
"MatchString",
"(",
"obj",
".",
"Subnet",
")",
"==",
"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 network object | [
"Validate",
"a",
"network",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3768-L3847 |
7,899 | contiv/netplugin | contivmodel/contivModel.go | GetOperPolicy | func GetOperPolicy(obj *PolicyInspect) error {
// 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.PolicyGetOper(obj)
if err != nil {
log.Errorf("PolicyDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | go | func GetOperPolicy(obj *PolicyInspect) error {
// 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.PolicyGetOper(obj)
if err != nil {
log.Errorf("PolicyDelete retruned error for: %+v. Err: %v", obj, err)
return err
}
return nil
} | [
"func",
"GetOperPolicy",
"(",
"obj",
"*",
"PolicyInspect",
")",
"error",
"{",
"// Check if we handle this object",
"if",
"objCallbackHandler",
".",
"PolicyCb",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform callback",
"err",
":=",
"objCallbackHandler",
".",
"PolicyCb",
".",
"PolicyGetOper",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get a policyOper object | [
"Get",
"a",
"policyOper",
"object"
] | 965773066d2b8ebed3514979949061a03d46fd20 | https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/contivModel.go#L3875-L3890 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.