id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
8,100
contiv/netplugin
contivmodel/client/contivModelClient.go
AciGwInspect
func (c *ContivClient) AciGwInspect(name string) (*AciGwInspect, error) { // build key and URL keyStr := name url := c.baseURL + "/api/v1/inspect/aciGws/" + keyStr + "/" // http get the object var obj AciGwInspect err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting aciGw %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
go
func (c *ContivClient) AciGwInspect(name string) (*AciGwInspect, error) { // build key and URL keyStr := name url := c.baseURL + "/api/v1/inspect/aciGws/" + keyStr + "/" // http get the object var obj AciGwInspect err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting aciGw %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "AciGwInspect", "(", "name", "string", ")", "(", "*", "AciGwInspect", ",", "error", ")", "{", "// build key and URL", "keyStr", ":=", "name", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "var", "obj", "AciGwInspect", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "obj", ",", "nil", "\n", "}" ]
// AciGwInspect gets the aciGwInspect object
[ "AciGwInspect", "gets", "the", "aciGwInspect", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L952-L966
8,101
contiv/netplugin
contivmodel/client/contivModelClient.go
AppProfilePost
func (c *ContivClient) AppProfilePost(obj *AppProfile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.AppProfileName url := c.baseURL + "/api/v1/appProfiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating appProfile %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) AppProfilePost(obj *AppProfile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.AppProfileName url := c.baseURL + "/api/v1/appProfiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating appProfile %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "AppProfilePost", "(", "obj", "*", "AppProfile", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "AppProfileName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AppProfilePost posts the appProfile object
[ "AppProfilePost", "posts", "the", "appProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L969-L982
8,102
contiv/netplugin
contivmodel/client/contivModelClient.go
AppProfileList
func (c *ContivClient) AppProfileList() (*[]*AppProfile, error) { // build key and URL url := c.baseURL + "/api/v1/appProfiles/" // http get the object var objList []*AppProfile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting appProfiles. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) AppProfileList() (*[]*AppProfile, error) { // build key and URL url := c.baseURL + "/api/v1/appProfiles/" // http get the object var objList []*AppProfile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting appProfiles. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "AppProfileList", "(", ")", "(", "*", "[", "]", "*", "AppProfile", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "AppProfile", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// AppProfileList lists all appProfile objects
[ "AppProfileList", "lists", "all", "appProfile", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L985-L998
8,103
contiv/netplugin
contivmodel/client/contivModelClient.go
BgpPost
func (c *ContivClient) BgpPost(obj *Bgp) error { // build key and URL keyStr := obj.Hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating Bgp %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) BgpPost(obj *Bgp) error { // build key and URL keyStr := obj.Hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating Bgp %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "BgpPost", "(", "obj", "*", "Bgp", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "Hostname", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// BgpPost posts the Bgp object
[ "BgpPost", "posts", "the", "Bgp", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1051-L1064
8,104
contiv/netplugin
contivmodel/client/contivModelClient.go
BgpList
func (c *ContivClient) BgpList() (*[]*Bgp, error) { // build key and URL url := c.baseURL + "/api/v1/Bgps/" // http get the object var objList []*Bgp err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting Bgps. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) BgpList() (*[]*Bgp, error) { // build key and URL url := c.baseURL + "/api/v1/Bgps/" // http get the object var objList []*Bgp err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting Bgps. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "BgpList", "(", ")", "(", "*", "[", "]", "*", "Bgp", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Bgp", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// BgpList lists all Bgp objects
[ "BgpList", "lists", "all", "Bgp", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1067-L1080
8,105
contiv/netplugin
contivmodel/client/contivModelClient.go
BgpGet
func (c *ContivClient) BgpGet(hostname string) (*Bgp, error) { // build key and URL keyStr := hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http get the object var obj Bgp err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting Bgp %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
go
func (c *ContivClient) BgpGet(hostname string) (*Bgp, error) { // build key and URL keyStr := hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http get the object var obj Bgp err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting Bgp %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "BgpGet", "(", "hostname", "string", ")", "(", "*", "Bgp", ",", "error", ")", "{", "// build key and URL", "keyStr", ":=", "hostname", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "var", "obj", "Bgp", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "obj", ",", "nil", "\n", "}" ]
// BgpGet gets the Bgp object
[ "BgpGet", "gets", "the", "Bgp", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1083-L1097
8,106
contiv/netplugin
contivmodel/client/contivModelClient.go
BgpDelete
func (c *ContivClient) BgpDelete(hostname string) error { // build key and URL keyStr := hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http get the object err := c.httpDelete(url) if err != nil { log.Debugf("Error deleting Bgp %s. Err: %v", keyStr, err) return err } return nil }
go
func (c *ContivClient) BgpDelete(hostname string) error { // build key and URL keyStr := hostname url := c.baseURL + "/api/v1/Bgps/" + keyStr + "/" // http get the object err := c.httpDelete(url) if err != nil { log.Debugf("Error deleting Bgp %s. Err: %v", keyStr, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "BgpDelete", "(", "hostname", "string", ")", "error", "{", "// build key and URL", "keyStr", ":=", "hostname", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "err", ":=", "c", ".", "httpDelete", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// BgpDelete deletes the Bgp object
[ "BgpDelete", "deletes", "the", "Bgp", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1100-L1113
8,107
contiv/netplugin
contivmodel/client/contivModelClient.go
EndpointInspect
func (c *ContivClient) EndpointInspect(endpointID string) (*EndpointInspect, error) { // build key and URL keyStr := endpointID url := c.baseURL + "/api/v1/inspect/endpoints/" + keyStr + "/" // http get the object var obj EndpointInspect err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting endpoint %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
go
func (c *ContivClient) EndpointInspect(endpointID string) (*EndpointInspect, error) { // build key and URL keyStr := endpointID url := c.baseURL + "/api/v1/inspect/endpoints/" + keyStr + "/" // http get the object var obj EndpointInspect err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting endpoint %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "EndpointInspect", "(", "endpointID", "string", ")", "(", "*", "EndpointInspect", ",", "error", ")", "{", "// build key and URL", "keyStr", ":=", "endpointID", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "var", "obj", "EndpointInspect", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "obj", ",", "nil", "\n", "}" ]
// EndpointInspect gets the endpointInspect object
[ "EndpointInspect", "gets", "the", "endpointInspect", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1133-L1147
8,108
contiv/netplugin
contivmodel/client/contivModelClient.go
EndpointGroupPost
func (c *ContivClient) EndpointGroupPost(obj *EndpointGroup) error { // build key and URL keyStr := obj.TenantName + ":" + obj.GroupName url := c.baseURL + "/api/v1/endpointGroups/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating endpointGroup %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) EndpointGroupPost(obj *EndpointGroup) error { // build key and URL keyStr := obj.TenantName + ":" + obj.GroupName url := c.baseURL + "/api/v1/endpointGroups/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating endpointGroup %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "EndpointGroupPost", "(", "obj", "*", "EndpointGroup", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "GroupName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// EndpointGroupPost posts the endpointGroup object
[ "EndpointGroupPost", "posts", "the", "endpointGroup", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1150-L1163
8,109
contiv/netplugin
contivmodel/client/contivModelClient.go
EndpointGroupList
func (c *ContivClient) EndpointGroupList() (*[]*EndpointGroup, error) { // build key and URL url := c.baseURL + "/api/v1/endpointGroups/" // http get the object var objList []*EndpointGroup err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting endpointGroups. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) EndpointGroupList() (*[]*EndpointGroup, error) { // build key and URL url := c.baseURL + "/api/v1/endpointGroups/" // http get the object var objList []*EndpointGroup err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting endpointGroups. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "EndpointGroupList", "(", ")", "(", "*", "[", "]", "*", "EndpointGroup", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "EndpointGroup", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// EndpointGroupList lists all endpointGroup objects
[ "EndpointGroupList", "lists", "all", "endpointGroup", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1166-L1179
8,110
contiv/netplugin
contivmodel/client/contivModelClient.go
ExtContractsGroupPost
func (c *ContivClient) ExtContractsGroupPost(obj *ExtContractsGroup) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ContractsGroupName url := c.baseURL + "/api/v1/extContractsGroups/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating extContractsGroup %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) ExtContractsGroupPost(obj *ExtContractsGroup) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ContractsGroupName url := c.baseURL + "/api/v1/extContractsGroups/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating extContractsGroup %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "ExtContractsGroupPost", "(", "obj", "*", "ExtContractsGroup", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "ContractsGroupName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ExtContractsGroupPost posts the extContractsGroup object
[ "ExtContractsGroupPost", "posts", "the", "extContractsGroup", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1232-L1245
8,111
contiv/netplugin
contivmodel/client/contivModelClient.go
ExtContractsGroupList
func (c *ContivClient) ExtContractsGroupList() (*[]*ExtContractsGroup, error) { // build key and URL url := c.baseURL + "/api/v1/extContractsGroups/" // http get the object var objList []*ExtContractsGroup err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting extContractsGroups. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) ExtContractsGroupList() (*[]*ExtContractsGroup, error) { // build key and URL url := c.baseURL + "/api/v1/extContractsGroups/" // http get the object var objList []*ExtContractsGroup err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting extContractsGroups. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "ExtContractsGroupList", "(", ")", "(", "*", "[", "]", "*", "ExtContractsGroup", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "ExtContractsGroup", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// ExtContractsGroupList lists all extContractsGroup objects
[ "ExtContractsGroupList", "lists", "all", "extContractsGroup", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1248-L1261
8,112
contiv/netplugin
contivmodel/client/contivModelClient.go
GlobalPost
func (c *ContivClient) GlobalPost(obj *Global) error { // build key and URL keyStr := obj.Name url := c.baseURL + "/api/v1/globals/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating global %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) GlobalPost(obj *Global) error { // build key and URL keyStr := obj.Name url := c.baseURL + "/api/v1/globals/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating global %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "GlobalPost", "(", "obj", "*", "Global", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "Name", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GlobalPost posts the global object
[ "GlobalPost", "posts", "the", "global", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1314-L1327
8,113
contiv/netplugin
contivmodel/client/contivModelClient.go
GlobalList
func (c *ContivClient) GlobalList() (*[]*Global, error) { // build key and URL url := c.baseURL + "/api/v1/globals/" // http get the object var objList []*Global err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting globals. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) GlobalList() (*[]*Global, error) { // build key and URL url := c.baseURL + "/api/v1/globals/" // http get the object var objList []*Global err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting globals. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "GlobalList", "(", ")", "(", "*", "[", "]", "*", "Global", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Global", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// GlobalList lists all global objects
[ "GlobalList", "lists", "all", "global", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1330-L1343
8,114
contiv/netplugin
contivmodel/client/contivModelClient.go
NetprofilePost
func (c *ContivClient) NetprofilePost(obj *Netprofile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ProfileName url := c.baseURL + "/api/v1/netprofiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating netprofile %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) NetprofilePost(obj *Netprofile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ProfileName url := c.baseURL + "/api/v1/netprofiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating netprofile %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "NetprofilePost", "(", "obj", "*", "Netprofile", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "ProfileName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// NetprofilePost posts the netprofile object
[ "NetprofilePost", "posts", "the", "netprofile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1396-L1409
8,115
contiv/netplugin
contivmodel/client/contivModelClient.go
NetprofileList
func (c *ContivClient) NetprofileList() (*[]*Netprofile, error) { // build key and URL url := c.baseURL + "/api/v1/netprofiles/" // http get the object var objList []*Netprofile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting netprofiles. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) NetprofileList() (*[]*Netprofile, error) { // build key and URL url := c.baseURL + "/api/v1/netprofiles/" // http get the object var objList []*Netprofile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting netprofiles. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "NetprofileList", "(", ")", "(", "*", "[", "]", "*", "Netprofile", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Netprofile", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// NetprofileList lists all netprofile objects
[ "NetprofileList", "lists", "all", "netprofile", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1412-L1425
8,116
contiv/netplugin
contivmodel/client/contivModelClient.go
NetworkPost
func (c *ContivClient) NetworkPost(obj *Network) error { // build key and URL keyStr := obj.TenantName + ":" + obj.NetworkName url := c.baseURL + "/api/v1/networks/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating network %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) NetworkPost(obj *Network) error { // build key and URL keyStr := obj.TenantName + ":" + obj.NetworkName url := c.baseURL + "/api/v1/networks/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating network %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "NetworkPost", "(", "obj", "*", "Network", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "NetworkName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// NetworkPost posts the network object
[ "NetworkPost", "posts", "the", "network", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1478-L1491
8,117
contiv/netplugin
contivmodel/client/contivModelClient.go
NetworkList
func (c *ContivClient) NetworkList() (*[]*Network, error) { // build key and URL url := c.baseURL + "/api/v1/networks/" // http get the object var objList []*Network err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting networks. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) NetworkList() (*[]*Network, error) { // build key and URL url := c.baseURL + "/api/v1/networks/" // http get the object var objList []*Network err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting networks. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "NetworkList", "(", ")", "(", "*", "[", "]", "*", "Network", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Network", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// NetworkList lists all network objects
[ "NetworkList", "lists", "all", "network", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1494-L1507
8,118
contiv/netplugin
contivmodel/client/contivModelClient.go
PolicyPost
func (c *ContivClient) PolicyPost(obj *Policy) error { // build key and URL keyStr := obj.TenantName + ":" + obj.PolicyName url := c.baseURL + "/api/v1/policys/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating policy %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) PolicyPost(obj *Policy) error { // build key and URL keyStr := obj.TenantName + ":" + obj.PolicyName url := c.baseURL + "/api/v1/policys/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating policy %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "PolicyPost", "(", "obj", "*", "Policy", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "PolicyName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PolicyPost posts the policy object
[ "PolicyPost", "posts", "the", "policy", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1560-L1573
8,119
contiv/netplugin
contivmodel/client/contivModelClient.go
PolicyList
func (c *ContivClient) PolicyList() (*[]*Policy, error) { // build key and URL url := c.baseURL + "/api/v1/policys/" // http get the object var objList []*Policy err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting policys. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) PolicyList() (*[]*Policy, error) { // build key and URL url := c.baseURL + "/api/v1/policys/" // http get the object var objList []*Policy err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting policys. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "PolicyList", "(", ")", "(", "*", "[", "]", "*", "Policy", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Policy", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// PolicyList lists all policy objects
[ "PolicyList", "lists", "all", "policy", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1576-L1589
8,120
contiv/netplugin
contivmodel/client/contivModelClient.go
RulePost
func (c *ContivClient) RulePost(obj *Rule) error { // build key and URL keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID url := c.baseURL + "/api/v1/rules/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating rule %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) RulePost(obj *Rule) error { // build key and URL keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID url := c.baseURL + "/api/v1/rules/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating rule %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "RulePost", "(", "obj", "*", "Rule", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "PolicyName", "+", "\"", "\"", "+", "obj", ".", "RuleID", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RulePost posts the rule object
[ "RulePost", "posts", "the", "rule", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1642-L1655
8,121
contiv/netplugin
contivmodel/client/contivModelClient.go
RuleList
func (c *ContivClient) RuleList() (*[]*Rule, error) { // build key and URL url := c.baseURL + "/api/v1/rules/" // http get the object var objList []*Rule err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting rules. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) RuleList() (*[]*Rule, error) { // build key and URL url := c.baseURL + "/api/v1/rules/" // http get the object var objList []*Rule err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting rules. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "RuleList", "(", ")", "(", "*", "[", "]", "*", "Rule", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Rule", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// RuleList lists all rule objects
[ "RuleList", "lists", "all", "rule", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1658-L1671
8,122
contiv/netplugin
contivmodel/client/contivModelClient.go
ServiceLBPost
func (c *ContivClient) ServiceLBPost(obj *ServiceLB) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ServiceName url := c.baseURL + "/api/v1/serviceLBs/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating serviceLB %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) ServiceLBPost(obj *ServiceLB) error { // build key and URL keyStr := obj.TenantName + ":" + obj.ServiceName url := c.baseURL + "/api/v1/serviceLBs/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating serviceLB %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "ServiceLBPost", "(", "obj", "*", "ServiceLB", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "ServiceName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ServiceLBPost posts the serviceLB object
[ "ServiceLBPost", "posts", "the", "serviceLB", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1724-L1737
8,123
contiv/netplugin
contivmodel/client/contivModelClient.go
ServiceLBList
func (c *ContivClient) ServiceLBList() (*[]*ServiceLB, error) { // build key and URL url := c.baseURL + "/api/v1/serviceLBs/" // http get the object var objList []*ServiceLB err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting serviceLBs. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) ServiceLBList() (*[]*ServiceLB, error) { // build key and URL url := c.baseURL + "/api/v1/serviceLBs/" // http get the object var objList []*ServiceLB err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting serviceLBs. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "ServiceLBList", "(", ")", "(", "*", "[", "]", "*", "ServiceLB", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "ServiceLB", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// ServiceLBList lists all serviceLB objects
[ "ServiceLBList", "lists", "all", "serviceLB", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1740-L1753
8,124
contiv/netplugin
contivmodel/client/contivModelClient.go
TenantPost
func (c *ContivClient) TenantPost(obj *Tenant) error { // build key and URL keyStr := obj.TenantName url := c.baseURL + "/api/v1/tenants/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating tenant %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) TenantPost(obj *Tenant) error { // build key and URL keyStr := obj.TenantName url := c.baseURL + "/api/v1/tenants/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating tenant %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "TenantPost", "(", "obj", "*", "Tenant", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// TenantPost posts the tenant object
[ "TenantPost", "posts", "the", "tenant", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1806-L1819
8,125
contiv/netplugin
contivmodel/client/contivModelClient.go
TenantList
func (c *ContivClient) TenantList() (*[]*Tenant, error) { // build key and URL url := c.baseURL + "/api/v1/tenants/" // http get the object var objList []*Tenant err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting tenants. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) TenantList() (*[]*Tenant, error) { // build key and URL url := c.baseURL + "/api/v1/tenants/" // http get the object var objList []*Tenant err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting tenants. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "TenantList", "(", ")", "(", "*", "[", "]", "*", "Tenant", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Tenant", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// TenantList lists all tenant objects
[ "TenantList", "lists", "all", "tenant", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1822-L1835
8,126
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumePost
func (c *ContivClient) VolumePost(obj *Volume) error { // build key and URL keyStr := obj.TenantName + ":" + obj.VolumeName url := c.baseURL + "/api/v1/volumes/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating volume %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) VolumePost(obj *Volume) error { // build key and URL keyStr := obj.TenantName + ":" + obj.VolumeName url := c.baseURL + "/api/v1/volumes/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating volume %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumePost", "(", "obj", "*", "Volume", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "VolumeName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// VolumePost posts the volume object
[ "VolumePost", "posts", "the", "volume", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1888-L1901
8,127
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumeList
func (c *ContivClient) VolumeList() (*[]*Volume, error) { // build key and URL url := c.baseURL + "/api/v1/volumes/" // http get the object var objList []*Volume err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting volumes. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) VolumeList() (*[]*Volume, error) { // build key and URL url := c.baseURL + "/api/v1/volumes/" // http get the object var objList []*Volume err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting volumes. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumeList", "(", ")", "(", "*", "[", "]", "*", "Volume", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "Volume", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// VolumeList lists all volume objects
[ "VolumeList", "lists", "all", "volume", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1904-L1917
8,128
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumeProfilePost
func (c *ContivClient) VolumeProfilePost(obj *VolumeProfile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.VolumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating volumeProfile %+v. Err: %v", obj, err) return err } return nil }
go
func (c *ContivClient) VolumeProfilePost(obj *VolumeProfile) error { // build key and URL keyStr := obj.TenantName + ":" + obj.VolumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http post the object err := c.httpPost(url, obj) if err != nil { log.Debugf("Error creating volumeProfile %+v. Err: %v", obj, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumeProfilePost", "(", "obj", "*", "VolumeProfile", ")", "error", "{", "// build key and URL", "keyStr", ":=", "obj", ".", "TenantName", "+", "\"", "\"", "+", "obj", ".", "VolumeProfileName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http post the object", "err", ":=", "c", ".", "httpPost", "(", "url", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "obj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// VolumeProfilePost posts the volumeProfile object
[ "VolumeProfilePost", "posts", "the", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1970-L1983
8,129
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumeProfileList
func (c *ContivClient) VolumeProfileList() (*[]*VolumeProfile, error) { // build key and URL url := c.baseURL + "/api/v1/volumeProfiles/" // http get the object var objList []*VolumeProfile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting volumeProfiles. Err: %v", err) return nil, err } return &objList, nil }
go
func (c *ContivClient) VolumeProfileList() (*[]*VolumeProfile, error) { // build key and URL url := c.baseURL + "/api/v1/volumeProfiles/" // http get the object var objList []*VolumeProfile err := c.httpGet(url, &objList) if err != nil { log.Debugf("Error getting volumeProfiles. Err: %v", err) return nil, err } return &objList, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumeProfileList", "(", ")", "(", "*", "[", "]", "*", "VolumeProfile", ",", "error", ")", "{", "// build key and URL", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "// http get the object", "var", "objList", "[", "]", "*", "VolumeProfile", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "objList", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objList", ",", "nil", "\n", "}" ]
// VolumeProfileList lists all volumeProfile objects
[ "VolumeProfileList", "lists", "all", "volumeProfile", "objects" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L1986-L1999
8,130
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumeProfileGet
func (c *ContivClient) VolumeProfileGet(tenantName string, volumeProfileName string) (*VolumeProfile, error) { // build key and URL keyStr := tenantName + ":" + volumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http get the object var obj VolumeProfile err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting volumeProfile %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
go
func (c *ContivClient) VolumeProfileGet(tenantName string, volumeProfileName string) (*VolumeProfile, error) { // build key and URL keyStr := tenantName + ":" + volumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http get the object var obj VolumeProfile err := c.httpGet(url, &obj) if err != nil { log.Debugf("Error getting volumeProfile %+v. Err: %v", keyStr, err) return nil, err } return &obj, nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumeProfileGet", "(", "tenantName", "string", ",", "volumeProfileName", "string", ")", "(", "*", "VolumeProfile", ",", "error", ")", "{", "// build key and URL", "keyStr", ":=", "tenantName", "+", "\"", "\"", "+", "volumeProfileName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "var", "obj", "VolumeProfile", "\n", "err", ":=", "c", ".", "httpGet", "(", "url", ",", "&", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "obj", ",", "nil", "\n", "}" ]
// VolumeProfileGet gets the volumeProfile object
[ "VolumeProfileGet", "gets", "the", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L2002-L2016
8,131
contiv/netplugin
contivmodel/client/contivModelClient.go
VolumeProfileDelete
func (c *ContivClient) VolumeProfileDelete(tenantName string, volumeProfileName string) error { // build key and URL keyStr := tenantName + ":" + volumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http get the object err := c.httpDelete(url) if err != nil { log.Debugf("Error deleting volumeProfile %s. Err: %v", keyStr, err) return err } return nil }
go
func (c *ContivClient) VolumeProfileDelete(tenantName string, volumeProfileName string) error { // build key and URL keyStr := tenantName + ":" + volumeProfileName url := c.baseURL + "/api/v1/volumeProfiles/" + keyStr + "/" // http get the object err := c.httpDelete(url) if err != nil { log.Debugf("Error deleting volumeProfile %s. Err: %v", keyStr, err) return err } return nil }
[ "func", "(", "c", "*", "ContivClient", ")", "VolumeProfileDelete", "(", "tenantName", "string", ",", "volumeProfileName", "string", ")", "error", "{", "// build key and URL", "keyStr", ":=", "tenantName", "+", "\"", "\"", "+", "volumeProfileName", "\n", "url", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "keyStr", "+", "\"", "\"", "\n\n", "// http get the object", "err", ":=", "c", ".", "httpDelete", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "keyStr", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// VolumeProfileDelete deletes the volumeProfile object
[ "VolumeProfileDelete", "deletes", "the", "volumeProfile", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/contivmodel/client/contivModelClient.go#L2019-L2032
8,132
contiv/netplugin
netmaster/resources/stateresourcemanager.go
NewStateResourceManager
func NewStateResourceManager(sd core.StateDriver) (*StateResourceManager, error) { if gStateResourceManager != nil { return nil, core.Errorf("state-based resource manager instance already exists.") } gStateResourceManager = &StateResourceManager{stateDriver: sd} err := gStateResourceManager.Init() if err != nil { return nil, err } return gStateResourceManager, nil }
go
func NewStateResourceManager(sd core.StateDriver) (*StateResourceManager, error) { if gStateResourceManager != nil { return nil, core.Errorf("state-based resource manager instance already exists.") } gStateResourceManager = &StateResourceManager{stateDriver: sd} err := gStateResourceManager.Init() if err != nil { return nil, err } return gStateResourceManager, nil }
[ "func", "NewStateResourceManager", "(", "sd", "core", ".", "StateDriver", ")", "(", "*", "StateResourceManager", ",", "error", ")", "{", "if", "gStateResourceManager", "!=", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "gStateResourceManager", "=", "&", "StateResourceManager", "{", "stateDriver", ":", "sd", "}", "\n", "err", ":=", "gStateResourceManager", ".", "Init", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "gStateResourceManager", ",", "nil", "\n", "}" ]
// NewStateResourceManager instantiates a state based resource manager
[ "NewStateResourceManager", "instantiates", "a", "state", "based", "resource", "manager" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L40-L52
8,133
contiv/netplugin
netmaster/resources/stateresourcemanager.go
GetStateResourceManager
func GetStateResourceManager() (*StateResourceManager, error) { if gStateResourceManager == nil { return nil, core.Errorf("state-based resource manager has not been not created.") } return gStateResourceManager, nil }
go
func GetStateResourceManager() (*StateResourceManager, error) { if gStateResourceManager == nil { return nil, core.Errorf("state-based resource manager has not been not created.") } return gStateResourceManager, nil }
[ "func", "GetStateResourceManager", "(", ")", "(", "*", "StateResourceManager", ",", "error", ")", "{", "if", "gStateResourceManager", "==", "nil", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "gStateResourceManager", ",", "nil", "\n", "}" ]
// GetStateResourceManager returns the singleton instance of the state based // resource manager
[ "GetStateResourceManager", "returns", "the", "singleton", "instance", "of", "the", "state", "based", "resource", "manager" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L56-L62
8,134
contiv/netplugin
netmaster/resources/stateresourcemanager.go
DefineResource
func (rm *StateResourceManager) DefineResource(id, desc string, rsrcCfg interface{}) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if alreadyExists { return core.Errorf("Resource with id: %q already exists", id) } return rsrc.Init(rsrcCfg) }
go
func (rm *StateResourceManager) DefineResource(id, desc string, rsrcCfg interface{}) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if alreadyExists { return core.Errorf("Resource with id: %q already exists", id) } return rsrc.Init(rsrcCfg) }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "DefineResource", "(", "id", ",", "desc", "string", ",", "rsrcCfg", "interface", "{", "}", ")", "error", "{", "// XXX: need to take care of distibuted updates, locks etc here", "rsrc", ",", "alreadyExists", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "alreadyExists", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n\n", "return", "rsrc", ".", "Init", "(", "rsrcCfg", ")", "\n", "}" ]
// DefineResource initializes a new resource.
[ "DefineResource", "initializes", "a", "new", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L118-L131
8,135
contiv/netplugin
netmaster/resources/stateresourcemanager.go
UndefineResource
func (rm *StateResourceManager) UndefineResource(id, desc string) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } rsrc.Deinit() return nil }
go
func (rm *StateResourceManager) UndefineResource(id, desc string) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } rsrc.Deinit() return nil }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "UndefineResource", "(", "id", ",", "desc", "string", ")", "error", "{", "// XXX: need to take care of distibuted updates, locks etc here", "rsrc", ",", "alreadyExists", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "alreadyExists", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "desc", ",", "id", ")", "\n", "}", "\n\n", "rsrc", ".", "Deinit", "(", ")", "\n", "return", "nil", "\n\n", "}" ]
// UndefineResource deinitializes a resource.
[ "UndefineResource", "deinitializes", "a", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L134-L149
8,136
contiv/netplugin
netmaster/resources/stateresourcemanager.go
RedefineResource
func (rm *StateResourceManager) RedefineResource(id, desc string, rsrcCfg interface{}) error { rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } rsrc.Reinit(rsrcCfg) return nil }
go
func (rm *StateResourceManager) RedefineResource(id, desc string, rsrcCfg interface{}) error { rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } rsrc.Reinit(rsrcCfg) return nil }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "RedefineResource", "(", "id", ",", "desc", "string", ",", "rsrcCfg", "interface", "{", "}", ")", "error", "{", "rsrc", ",", "alreadyExists", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "alreadyExists", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "desc", ",", "id", ")", "\n", "}", "\n\n", "rsrc", ".", "Reinit", "(", "rsrcCfg", ")", "\n", "return", "nil", "\n\n", "}" ]
// RedefineResource deinitializes a resource.
[ "RedefineResource", "deinitializes", "a", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L152-L167
8,137
contiv/netplugin
netmaster/resources/stateresourcemanager.go
GetResourceList
func (rm *StateResourceManager) GetResourceList(id, desc string) (uint, string) { // XXX: need to take care of distibuted updates, locks etc here rsrc, _, err := rm.findResource(id, desc) if err != nil { log.Errorf("unable to find resource %s desc %s", id, desc) return 0, "" } return rsrc.GetList() }
go
func (rm *StateResourceManager) GetResourceList(id, desc string) (uint, string) { // XXX: need to take care of distibuted updates, locks etc here rsrc, _, err := rm.findResource(id, desc) if err != nil { log.Errorf("unable to find resource %s desc %s", id, desc) return 0, "" } return rsrc.GetList() }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "GetResourceList", "(", "id", ",", "desc", "string", ")", "(", "uint", ",", "string", ")", "{", "// XXX: need to take care of distibuted updates, locks etc here", "rsrc", ",", "_", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "desc", ")", "\n", "return", "0", ",", "\"", "\"", "\n", "}", "\n\n", "return", "rsrc", ".", "GetList", "(", ")", "\n", "}" ]
// GetResourceList get the list of allocated as string for inspection
[ "GetResourceList", "get", "the", "list", "of", "allocated", "as", "string", "for", "inspection" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L170-L179
8,138
contiv/netplugin
netmaster/resources/stateresourcemanager.go
AllocateResourceVal
func (rm *StateResourceManager) AllocateResourceVal(id, desc string, reqValue interface{}) (interface{}, error) { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return nil, err } if !alreadyExists { return nil, core.Errorf("No resource found for description: %q and id: %q", desc, id) } return rsrc.Allocate(reqValue) }
go
func (rm *StateResourceManager) AllocateResourceVal(id, desc string, reqValue interface{}) (interface{}, error) { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return nil, err } if !alreadyExists { return nil, core.Errorf("No resource found for description: %q and id: %q", desc, id) } return rsrc.Allocate(reqValue) }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "AllocateResourceVal", "(", "id", ",", "desc", "string", ",", "reqValue", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "// XXX: need to take care of distibuted updates, locks etc here", "rsrc", ",", "alreadyExists", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "!", "alreadyExists", "{", "return", "nil", ",", "core", ".", "Errorf", "(", "\"", "\"", ",", "desc", ",", "id", ")", "\n", "}", "\n\n", "return", "rsrc", ".", "Allocate", "(", "reqValue", ")", "\n", "}" ]
// AllocateResourceVal yields the core.Resource for the id and description.
[ "AllocateResourceVal", "yields", "the", "core", ".", "Resource", "for", "the", "id", "and", "description", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L182-L196
8,139
contiv/netplugin
netmaster/resources/stateresourcemanager.go
DeallocateResourceVal
func (rm *StateResourceManager) DeallocateResourceVal(id, desc string, value interface{}) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } return rsrc.Deallocate(value) }
go
func (rm *StateResourceManager) DeallocateResourceVal(id, desc string, value interface{}) error { // XXX: need to take care of distibuted updates, locks etc here rsrc, alreadyExists, err := rm.findResource(id, desc) if err != nil { return err } if !alreadyExists { return core.Errorf("No resource found for description: %q and id: %q", desc, id) } return rsrc.Deallocate(value) }
[ "func", "(", "rm", "*", "StateResourceManager", ")", "DeallocateResourceVal", "(", "id", ",", "desc", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "// XXX: need to take care of distibuted updates, locks etc here", "rsrc", ",", "alreadyExists", ",", "err", ":=", "rm", ".", "findResource", "(", "id", ",", "desc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "alreadyExists", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "desc", ",", "id", ")", "\n", "}", "\n\n", "return", "rsrc", ".", "Deallocate", "(", "value", ")", "\n", "}" ]
// DeallocateResourceVal removes a value from the resource.
[ "DeallocateResourceVal", "removes", "a", "value", "from", "the", "resource", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/resources/stateresourcemanager.go#L199-L213
8,140
contiv/netplugin
netmaster/mastercfg/globalState.go
ReadAll
func (s *GlobConfig) ReadAll() ([]core.State, error) { return s.StateDriver.ReadAllState(globalConfigPathPrefix, s, json.Unmarshal) }
go
func (s *GlobConfig) ReadAll() ([]core.State, error) { return s.StateDriver.ReadAllState(globalConfigPathPrefix, s, json.Unmarshal) }
[ "func", "(", "s", "*", "GlobConfig", ")", "ReadAll", "(", ")", "(", "[", "]", "core", ".", "State", ",", "error", ")", "{", "return", "s", ".", "StateDriver", ".", "ReadAllState", "(", "globalConfigPathPrefix", ",", "s", ",", "json", ".", "Unmarshal", ")", "\n", "}" ]
// ReadAll reads all the state for master global configurations and returns it.
[ "ReadAll", "reads", "all", "the", "state", "for", "master", "global", "configurations", "and", "returns", "it", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/globalState.go#L63-L65
8,141
contiv/netplugin
drivers/ovsd/ovsSwitch.go
getPvtIP
func (sw *OvsSwitch) getPvtIP(portName string) net.IP { if strings.Contains(portName, "vport") { port := strings.Replace(portName, "vvport", "", 1) portNum, err := strconv.Atoi(port) if err == nil { ipStr, _ := netutils.PortToHostIPMAC(portNum, sw.hostPvtNW) log.Infof("PvtIP: %s", ipStr) ips := strings.Split(ipStr, "/") if len(ips) > 0 { return net.ParseIP(ips[0]) } } log.Errorf("Error getting port number from %s - %v", port, err) } log.Infof("No pvt IP for port %s", portName) return nil }
go
func (sw *OvsSwitch) getPvtIP(portName string) net.IP { if strings.Contains(portName, "vport") { port := strings.Replace(portName, "vvport", "", 1) portNum, err := strconv.Atoi(port) if err == nil { ipStr, _ := netutils.PortToHostIPMAC(portNum, sw.hostPvtNW) log.Infof("PvtIP: %s", ipStr) ips := strings.Split(ipStr, "/") if len(ips) > 0 { return net.ParseIP(ips[0]) } } log.Errorf("Error getting port number from %s - %v", port, err) } log.Infof("No pvt IP for port %s", portName) return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "getPvtIP", "(", "portName", "string", ")", "net", ".", "IP", "{", "if", "strings", ".", "Contains", "(", "portName", ",", "\"", "\"", ")", "{", "port", ":=", "strings", ".", "Replace", "(", "portName", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "portNum", ",", "err", ":=", "strconv", ".", "Atoi", "(", "port", ")", "\n", "if", "err", "==", "nil", "{", "ipStr", ",", "_", ":=", "netutils", ".", "PortToHostIPMAC", "(", "portNum", ",", "sw", ".", "hostPvtNW", ")", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "ipStr", ")", "\n", "ips", ":=", "strings", ".", "Split", "(", "ipStr", ",", "\"", "\"", ")", "\n", "if", "len", "(", "ips", ")", ">", "0", "{", "return", "net", ".", "ParseIP", "(", "ips", "[", "0", "]", ")", "\n", "}", "\n", "}", "\n\n", "log", ".", "Errorf", "(", "\"", "\"", ",", "port", ",", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "portName", ")", "\n\n", "return", "nil", "\n", "}" ]
// getPvtIP returns a private IP for the port
[ "getPvtIP", "returns", "a", "private", "IP", "for", "the", "port" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L63-L81
8,142
contiv/netplugin
drivers/ovsd/ovsSwitch.go
GetUplinkInterfaces
func (sw *OvsSwitch) GetUplinkInterfaces(uplinkID string) []string { uplink, _ := sw.uplinkDb.Get(uplinkID) if uplink == nil { return nil } return uplink.([]string) }
go
func (sw *OvsSwitch) GetUplinkInterfaces(uplinkID string) []string { uplink, _ := sw.uplinkDb.Get(uplinkID) if uplink == nil { return nil } return uplink.([]string) }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "GetUplinkInterfaces", "(", "uplinkID", "string", ")", "[", "]", "string", "{", "uplink", ",", "_", ":=", "sw", ".", "uplinkDb", ".", "Get", "(", "uplinkID", ")", "\n", "if", "uplink", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "uplink", ".", "(", "[", "]", "string", ")", "\n", "}" ]
// GetUplinkInterfaces returns the list of interface associated with the uplink port
[ "GetUplinkInterfaces", "returns", "the", "list", "of", "interface", "associated", "with", "the", "uplink", "port" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L84-L90
8,143
contiv/netplugin
drivers/ovsd/ovsSwitch.go
NewOvsSwitch
func NewOvsSwitch(bridgeName, netType, localIP, fwdMode string, vlanIntf []string, hostPvtNW int, vxlanUDPPort int) (*OvsSwitch, error) { var err error var datapath string var ofnetPort, ctrlrPort uint16 log.Infof("Received request to create new ovs switch bridge:%s, localIP:%s, fwdMode:%s", bridgeName, localIP, fwdMode) sw := new(OvsSwitch) sw.bridgeName = bridgeName sw.netType = netType sw.uplinkDb = cmap.New() sw.hostPvtNW = hostPvtNW sw.vxlanEncapMtu, err = netutils.GetHostLowestLinkMtu() if err != nil { log.Fatalf("Failed to get Host Node MTU. Err: %v", err) } // Create OVS db driver sw.ovsdbDriver, err = NewOvsdbDriver(bridgeName, "secure", vxlanUDPPort) if err != nil { log.Fatalf("Error creating ovsdb driver. Err: %v", err) } sw.ovsdbDriver.ovsSwitch = sw if netType == "vxlan" { ofnetPort = vxlanOfnetPort ctrlrPort = vxlanCtrlerPort switch fwdMode { case "bridge": datapath = "vxlan" case "routing": datapath = "vrouter" default: log.Errorf("Invalid datapath mode") return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'") } // Create an ofnet agent sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP), ofnetPort, ctrlrPort, vlanIntf) if err != nil { log.Fatalf("Error initializing ofnet") return nil, err } } else if netType == "vlan" { ofnetPort = vlanOfnetPort ctrlrPort = vlanCtrlerPort switch fwdMode { case "bridge": datapath = "vlan" case "routing": datapath = "vlrouter" default: log.Errorf("Invalid datapath mode") return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'") } // Create an ofnet agent sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP), ofnetPort, ctrlrPort, vlanIntf) if err != nil { log.Fatalf("Error initializing ofnet") return nil, err } } else if netType == "host" { err = fmt.Errorf("Explicit host-net not supported") return nil, err } // Add controller to the OVS ctrlerIP := "127.0.0.1" target := fmt.Sprintf("tcp:%s:%d", ctrlerIP, ctrlrPort) if !sw.ovsdbDriver.IsControllerPresent(target) { err = sw.ovsdbDriver.AddController(ctrlerIP, ctrlrPort) if err != nil { log.Errorf("Error adding controller to switch: %s. Err: %v", bridgeName, err) return nil, err } } log.Infof("Waiting for OVS switch(%s) to connect..", netType) // Wait for a while for OVS switch to connect to agent if sw.ofnetAgent != nil { sw.ofnetAgent.WaitForSwitchConnection() } log.Infof("Switch (%s) connected.", netType) return sw, nil }
go
func NewOvsSwitch(bridgeName, netType, localIP, fwdMode string, vlanIntf []string, hostPvtNW int, vxlanUDPPort int) (*OvsSwitch, error) { var err error var datapath string var ofnetPort, ctrlrPort uint16 log.Infof("Received request to create new ovs switch bridge:%s, localIP:%s, fwdMode:%s", bridgeName, localIP, fwdMode) sw := new(OvsSwitch) sw.bridgeName = bridgeName sw.netType = netType sw.uplinkDb = cmap.New() sw.hostPvtNW = hostPvtNW sw.vxlanEncapMtu, err = netutils.GetHostLowestLinkMtu() if err != nil { log.Fatalf("Failed to get Host Node MTU. Err: %v", err) } // Create OVS db driver sw.ovsdbDriver, err = NewOvsdbDriver(bridgeName, "secure", vxlanUDPPort) if err != nil { log.Fatalf("Error creating ovsdb driver. Err: %v", err) } sw.ovsdbDriver.ovsSwitch = sw if netType == "vxlan" { ofnetPort = vxlanOfnetPort ctrlrPort = vxlanCtrlerPort switch fwdMode { case "bridge": datapath = "vxlan" case "routing": datapath = "vrouter" default: log.Errorf("Invalid datapath mode") return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'") } // Create an ofnet agent sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP), ofnetPort, ctrlrPort, vlanIntf) if err != nil { log.Fatalf("Error initializing ofnet") return nil, err } } else if netType == "vlan" { ofnetPort = vlanOfnetPort ctrlrPort = vlanCtrlerPort switch fwdMode { case "bridge": datapath = "vlan" case "routing": datapath = "vlrouter" default: log.Errorf("Invalid datapath mode") return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'") } // Create an ofnet agent sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP), ofnetPort, ctrlrPort, vlanIntf) if err != nil { log.Fatalf("Error initializing ofnet") return nil, err } } else if netType == "host" { err = fmt.Errorf("Explicit host-net not supported") return nil, err } // Add controller to the OVS ctrlerIP := "127.0.0.1" target := fmt.Sprintf("tcp:%s:%d", ctrlerIP, ctrlrPort) if !sw.ovsdbDriver.IsControllerPresent(target) { err = sw.ovsdbDriver.AddController(ctrlerIP, ctrlrPort) if err != nil { log.Errorf("Error adding controller to switch: %s. Err: %v", bridgeName, err) return nil, err } } log.Infof("Waiting for OVS switch(%s) to connect..", netType) // Wait for a while for OVS switch to connect to agent if sw.ofnetAgent != nil { sw.ofnetAgent.WaitForSwitchConnection() } log.Infof("Switch (%s) connected.", netType) return sw, nil }
[ "func", "NewOvsSwitch", "(", "bridgeName", ",", "netType", ",", "localIP", ",", "fwdMode", "string", ",", "vlanIntf", "[", "]", "string", ",", "hostPvtNW", "int", ",", "vxlanUDPPort", "int", ")", "(", "*", "OvsSwitch", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "datapath", "string", "\n", "var", "ofnetPort", ",", "ctrlrPort", "uint16", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "bridgeName", ",", "localIP", ",", "fwdMode", ")", "\n", "sw", ":=", "new", "(", "OvsSwitch", ")", "\n", "sw", ".", "bridgeName", "=", "bridgeName", "\n", "sw", ".", "netType", "=", "netType", "\n", "sw", ".", "uplinkDb", "=", "cmap", ".", "New", "(", ")", "\n", "sw", ".", "hostPvtNW", "=", "hostPvtNW", "\n", "sw", ".", "vxlanEncapMtu", ",", "err", "=", "netutils", ".", "GetHostLowestLinkMtu", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Create OVS db driver", "sw", ".", "ovsdbDriver", ",", "err", "=", "NewOvsdbDriver", "(", "bridgeName", ",", "\"", "\"", ",", "vxlanUDPPort", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "sw", ".", "ovsdbDriver", ".", "ovsSwitch", "=", "sw", "\n\n", "if", "netType", "==", "\"", "\"", "{", "ofnetPort", "=", "vxlanOfnetPort", "\n", "ctrlrPort", "=", "vxlanCtrlerPort", "\n", "switch", "fwdMode", "{", "case", "\"", "\"", ":", "datapath", "=", "\"", "\"", "\n", "case", "\"", "\"", ":", "datapath", "=", "\"", "\"", "\n", "default", ":", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "// Create an ofnet agent", "sw", ".", "ofnetAgent", ",", "err", "=", "ofnet", ".", "NewOfnetAgent", "(", "bridgeName", ",", "datapath", ",", "net", ".", "ParseIP", "(", "localIP", ")", ",", "ofnetPort", ",", "ctrlrPort", ",", "vlanIntf", ")", "\n\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "}", "else", "if", "netType", "==", "\"", "\"", "{", "ofnetPort", "=", "vlanOfnetPort", "\n", "ctrlrPort", "=", "vlanCtrlerPort", "\n", "switch", "fwdMode", "{", "case", "\"", "\"", ":", "datapath", "=", "\"", "\"", "\n", "case", "\"", "\"", ":", "datapath", "=", "\"", "\"", "\n", "default", ":", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "// Create an ofnet agent", "sw", ".", "ofnetAgent", ",", "err", "=", "ofnet", ".", "NewOfnetAgent", "(", "bridgeName", ",", "datapath", ",", "net", ".", "ParseIP", "(", "localIP", ")", ",", "ofnetPort", ",", "ctrlrPort", ",", "vlanIntf", ")", "\n\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "}", "else", "if", "netType", "==", "\"", "\"", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Add controller to the OVS", "ctrlerIP", ":=", "\"", "\"", "\n", "target", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctrlerIP", ",", "ctrlrPort", ")", "\n", "if", "!", "sw", ".", "ovsdbDriver", ".", "IsControllerPresent", "(", "target", ")", "{", "err", "=", "sw", ".", "ovsdbDriver", ".", "AddController", "(", "ctrlerIP", ",", "ctrlrPort", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "bridgeName", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "netType", ")", "\n\n", "// Wait for a while for OVS switch to connect to agent", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "sw", ".", "ofnetAgent", ".", "WaitForSwitchConnection", "(", ")", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "netType", ")", "\n\n", "return", "sw", ",", "nil", "\n", "}" ]
// NewOvsSwitch Creates a new OVS switch instance
[ "NewOvsSwitch", "Creates", "a", "new", "OVS", "switch", "instance" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L93-L185
8,144
contiv/netplugin
drivers/ovsd/ovsSwitch.go
Delete
func (sw *OvsSwitch) Delete() { if sw.ofnetAgent != nil { sw.ofnetAgent.Delete() } if sw.ovsdbDriver != nil { sw.ovsdbDriver.Delete() // Wait a little for OVS switch to be deleted time.Sleep(300 * time.Millisecond) } }
go
func (sw *OvsSwitch) Delete() { if sw.ofnetAgent != nil { sw.ofnetAgent.Delete() } if sw.ovsdbDriver != nil { sw.ovsdbDriver.Delete() // Wait a little for OVS switch to be deleted time.Sleep(300 * time.Millisecond) } }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "Delete", "(", ")", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "sw", ".", "ofnetAgent", ".", "Delete", "(", ")", "\n", "}", "\n", "if", "sw", ".", "ovsdbDriver", "!=", "nil", "{", "sw", ".", "ovsdbDriver", ".", "Delete", "(", ")", "\n\n", "// Wait a little for OVS switch to be deleted", "time", ".", "Sleep", "(", "300", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "}" ]
// Delete performs cleanup prior to destruction of the OvsDriver
[ "Delete", "performs", "cleanup", "prior", "to", "destruction", "of", "the", "OvsDriver" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L188-L198
8,145
contiv/netplugin
drivers/ovsd/ovsSwitch.go
createVethPair
func createVethPair(name1, name2 string) error { log.Infof("Creating Veth pairs with name: %s, %s", name1, name2) // Veth pair params veth := &netlink.Veth{ LinkAttrs: netlink.LinkAttrs{ Name: name1, TxQLen: 0, }, PeerName: name2, } // Create the veth pair if err := netlink.LinkAdd(veth); err != nil { log.Errorf("error creating veth pair: %v", err) return err } return nil }
go
func createVethPair(name1, name2 string) error { log.Infof("Creating Veth pairs with name: %s, %s", name1, name2) // Veth pair params veth := &netlink.Veth{ LinkAttrs: netlink.LinkAttrs{ Name: name1, TxQLen: 0, }, PeerName: name2, } // Create the veth pair if err := netlink.LinkAdd(veth); err != nil { log.Errorf("error creating veth pair: %v", err) return err } return nil }
[ "func", "createVethPair", "(", "name1", ",", "name2", "string", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "name1", ",", "name2", ")", "\n\n", "// Veth pair params", "veth", ":=", "&", "netlink", ".", "Veth", "{", "LinkAttrs", ":", "netlink", ".", "LinkAttrs", "{", "Name", ":", "name1", ",", "TxQLen", ":", "0", ",", "}", ",", "PeerName", ":", "name2", ",", "}", "\n\n", "// Create the veth pair", "if", "err", ":=", "netlink", ".", "LinkAdd", "(", "veth", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// createVethPair creates veth interface pairs with specified name
[ "createVethPair", "creates", "veth", "interface", "pairs", "with", "specified", "name" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L227-L246
8,146
contiv/netplugin
drivers/ovsd/ovsSwitch.go
setLinkMtu
func setLinkMtu(name string, mtu int) error { iface, err := netlink.LinkByName(name) if err != nil { return err } return netlink.LinkSetMTU(iface, mtu) }
go
func setLinkMtu(name string, mtu int) error { iface, err := netlink.LinkByName(name) if err != nil { return err } return netlink.LinkSetMTU(iface, mtu) }
[ "func", "setLinkMtu", "(", "name", "string", ",", "mtu", "int", ")", "error", "{", "iface", ",", "err", ":=", "netlink", ".", "LinkByName", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "netlink", ".", "LinkSetMTU", "(", "iface", ",", "mtu", ")", "\n", "}" ]
// Set the link mtu
[ "Set", "the", "link", "mtu" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L280-L286
8,147
contiv/netplugin
drivers/ovsd/ovsSwitch.go
getOvsPortName
func getOvsPortName(intfName string, skipVethPair bool) string { var ovsPortName string if useVethPair && !skipVethPair { ovsPortName = strings.Replace(intfName, "port", "vport", 1) } else { ovsPortName = intfName } return ovsPortName }
go
func getOvsPortName(intfName string, skipVethPair bool) string { var ovsPortName string if useVethPair && !skipVethPair { ovsPortName = strings.Replace(intfName, "port", "vport", 1) } else { ovsPortName = intfName } return ovsPortName }
[ "func", "getOvsPortName", "(", "intfName", "string", ",", "skipVethPair", "bool", ")", "string", "{", "var", "ovsPortName", "string", "\n\n", "if", "useVethPair", "&&", "!", "skipVethPair", "{", "ovsPortName", "=", "strings", ".", "Replace", "(", "intfName", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "}", "else", "{", "ovsPortName", "=", "intfName", "\n", "}", "\n\n", "return", "ovsPortName", "\n", "}" ]
// getOvsPortName returns OVS port name depending on if we use Veth pairs // For infra nw, dont use Veth pair
[ "getOvsPortName", "returns", "OVS", "port", "name", "depending", "on", "if", "we", "use", "Veth", "pairs", "For", "infra", "nw", "dont", "use", "Veth", "pair" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L290-L300
8,148
contiv/netplugin
drivers/ovsd/ovsSwitch.go
UpdateEndpoint
func (sw *OvsSwitch) UpdateEndpoint(ovsPortName string, burst, dscp int, epgBandwidth int64) error { // update bandwidth err := sw.ovsdbDriver.UpdatePolicingRate(ovsPortName, burst, epgBandwidth) if err != nil { return err } // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", ovsPortName, err) return err } // Build the updated endpoint info endpoint := ofnet.EndpointInfo{ PortNo: ofpPort, Dscp: dscp, } // update endpoint state in ofnet err = sw.ofnetAgent.UpdateLocalEndpoint(endpoint) if err != nil { log.Errorf("Error updating local port %s to ofnet. Err: %v", ovsPortName, err) return err } return nil }
go
func (sw *OvsSwitch) UpdateEndpoint(ovsPortName string, burst, dscp int, epgBandwidth int64) error { // update bandwidth err := sw.ovsdbDriver.UpdatePolicingRate(ovsPortName, burst, epgBandwidth) if err != nil { return err } // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", ovsPortName, err) return err } // Build the updated endpoint info endpoint := ofnet.EndpointInfo{ PortNo: ofpPort, Dscp: dscp, } // update endpoint state in ofnet err = sw.ofnetAgent.UpdateLocalEndpoint(endpoint) if err != nil { log.Errorf("Error updating local port %s to ofnet. Err: %v", ovsPortName, err) return err } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "UpdateEndpoint", "(", "ovsPortName", "string", ",", "burst", ",", "dscp", "int", ",", "epgBandwidth", "int64", ")", "error", "{", "// update bandwidth", "err", ":=", "sw", ".", "ovsdbDriver", ".", "UpdatePolicingRate", "(", "ovsPortName", ",", "burst", ",", "epgBandwidth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Build the updated endpoint info", "endpoint", ":=", "ofnet", ".", "EndpointInfo", "{", "PortNo", ":", "ofpPort", ",", "Dscp", ":", "dscp", ",", "}", "\n\n", "// update endpoint state in ofnet", "err", "=", "sw", ".", "ofnetAgent", ".", "UpdateLocalEndpoint", "(", "endpoint", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UpdateEndpoint updates endpoint state
[ "UpdateEndpoint", "updates", "endpoint", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L424-L452
8,149
contiv/netplugin
drivers/ovsd/ovsSwitch.go
UpdatePort
func (sw *OvsSwitch) UpdatePort(intfName string, cfgEp *mastercfg.CfgEndpointState, pktTag, nwPktTag, dscp int, skipVethPair bool) error { // Get OVS port name ovsPortName := getOvsPortName(intfName, skipVethPair) // Add the endpoint to ofnet // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", ovsPortName, err) return err } macAddr, _ := net.ParseMAC(cfgEp.MacAddress) // Build the endpoint info endpoint := ofnet.EndpointInfo{ PortNo: ofpPort, MacAddr: macAddr, Vlan: uint16(nwPktTag), IpAddr: net.ParseIP(cfgEp.IPAddress), Ipv6Addr: net.ParseIP(cfgEp.IPv6Address), EndpointGroup: cfgEp.EndpointGroupID, EndpointGroupVlan: uint16(pktTag), Dscp: dscp, } // Add the local port to ofnet if sw.ofnetAgent == nil { log.Infof("Skipping adding localport to ofnet") return nil } err = sw.ofnetAgent.AddLocalEndpoint(endpoint) if err != nil { log.Errorf("Error adding local port %s to ofnet. Err: %v", ovsPortName, err) return err } return nil }
go
func (sw *OvsSwitch) UpdatePort(intfName string, cfgEp *mastercfg.CfgEndpointState, pktTag, nwPktTag, dscp int, skipVethPair bool) error { // Get OVS port name ovsPortName := getOvsPortName(intfName, skipVethPair) // Add the endpoint to ofnet // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", ovsPortName, err) return err } macAddr, _ := net.ParseMAC(cfgEp.MacAddress) // Build the endpoint info endpoint := ofnet.EndpointInfo{ PortNo: ofpPort, MacAddr: macAddr, Vlan: uint16(nwPktTag), IpAddr: net.ParseIP(cfgEp.IPAddress), Ipv6Addr: net.ParseIP(cfgEp.IPv6Address), EndpointGroup: cfgEp.EndpointGroupID, EndpointGroupVlan: uint16(pktTag), Dscp: dscp, } // Add the local port to ofnet if sw.ofnetAgent == nil { log.Infof("Skipping adding localport to ofnet") return nil } err = sw.ofnetAgent.AddLocalEndpoint(endpoint) if err != nil { log.Errorf("Error adding local port %s to ofnet. Err: %v", ovsPortName, err) return err } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "UpdatePort", "(", "intfName", "string", ",", "cfgEp", "*", "mastercfg", ".", "CfgEndpointState", ",", "pktTag", ",", "nwPktTag", ",", "dscp", "int", ",", "skipVethPair", "bool", ")", "error", "{", "// Get OVS port name", "ovsPortName", ":=", "getOvsPortName", "(", "intfName", ",", "skipVethPair", ")", "\n\n", "// Add the endpoint to ofnet", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "macAddr", ",", "_", ":=", "net", ".", "ParseMAC", "(", "cfgEp", ".", "MacAddress", ")", "\n\n", "// Build the endpoint info", "endpoint", ":=", "ofnet", ".", "EndpointInfo", "{", "PortNo", ":", "ofpPort", ",", "MacAddr", ":", "macAddr", ",", "Vlan", ":", "uint16", "(", "nwPktTag", ")", ",", "IpAddr", ":", "net", ".", "ParseIP", "(", "cfgEp", ".", "IPAddress", ")", ",", "Ipv6Addr", ":", "net", ".", "ParseIP", "(", "cfgEp", ".", "IPv6Address", ")", ",", "EndpointGroup", ":", "cfgEp", ".", "EndpointGroupID", ",", "EndpointGroupVlan", ":", "uint16", "(", "pktTag", ")", ",", "Dscp", ":", "dscp", ",", "}", "\n\n", "// Add the local port to ofnet", "if", "sw", ".", "ofnetAgent", "==", "nil", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "err", "=", "sw", ".", "ofnetAgent", ".", "AddLocalEndpoint", "(", "endpoint", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdatePort updates an OVS port without creating it
[ "UpdatePort", "updates", "an", "OVS", "port", "without", "creating", "it" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L455-L493
8,150
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DeletePort
func (sw *OvsSwitch) DeletePort(epOper *drivers.OperEndpointState, skipVethPair bool) error { if epOper.VtepIP != "" { return nil } // Get the OVS port name ovsPortName := getOvsPortName(epOper.PortName, skipVethPair) // Get the openflow port number for the interface and remove from ofnet ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err == nil { if sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveLocalEndpoint(ofpPort) } } else { if sw.ofnetAgent != nil { var tenantName string netParts := strings.Split(epOper.NetID, ".") if len(netParts) == 2 { tenantName = netParts[1] } else { tenantName = "default" } epID := sw.ofnetAgent.GetEndpointIdByIpVrf(net.ParseIP(epOper.IPAddress), tenantName) err = sw.ofnetAgent.RemoveLocalEndpointByID(epID) } } if err != nil { log.Errorf("Error removing endpoint %+v from ofnet. Err: %v", epOper, err) // continue with further cleanup } // Delete it from ovsdb err = sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) // continue with further cleanup } // Delete the Veth pairs if required if useVethPair && !skipVethPair { // Delete a Veth pair verr := deleteVethPair(ovsPortName, epOper.PortName) if verr != nil { log.Errorf("Error deleting veth pairs. Err: %v", verr) return verr } } return err }
go
func (sw *OvsSwitch) DeletePort(epOper *drivers.OperEndpointState, skipVethPair bool) error { if epOper.VtepIP != "" { return nil } // Get the OVS port name ovsPortName := getOvsPortName(epOper.PortName, skipVethPair) // Get the openflow port number for the interface and remove from ofnet ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err == nil { if sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveLocalEndpoint(ofpPort) } } else { if sw.ofnetAgent != nil { var tenantName string netParts := strings.Split(epOper.NetID, ".") if len(netParts) == 2 { tenantName = netParts[1] } else { tenantName = "default" } epID := sw.ofnetAgent.GetEndpointIdByIpVrf(net.ParseIP(epOper.IPAddress), tenantName) err = sw.ofnetAgent.RemoveLocalEndpointByID(epID) } } if err != nil { log.Errorf("Error removing endpoint %+v from ofnet. Err: %v", epOper, err) // continue with further cleanup } // Delete it from ovsdb err = sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) // continue with further cleanup } // Delete the Veth pairs if required if useVethPair && !skipVethPair { // Delete a Veth pair verr := deleteVethPair(ovsPortName, epOper.PortName) if verr != nil { log.Errorf("Error deleting veth pairs. Err: %v", verr) return verr } } return err }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DeletePort", "(", "epOper", "*", "drivers", ".", "OperEndpointState", ",", "skipVethPair", "bool", ")", "error", "{", "if", "epOper", ".", "VtepIP", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "// Get the OVS port name", "ovsPortName", ":=", "getOvsPortName", "(", "epOper", ".", "PortName", ",", "skipVethPair", ")", "\n\n", "// Get the openflow port number for the interface and remove from ofnet", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "ovsPortName", ")", "\n", "if", "err", "==", "nil", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", "=", "sw", ".", "ofnetAgent", ".", "RemoveLocalEndpoint", "(", "ofpPort", ")", "\n", "}", "\n", "}", "else", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "var", "tenantName", "string", "\n", "netParts", ":=", "strings", ".", "Split", "(", "epOper", ".", "NetID", ",", "\"", "\"", ")", "\n", "if", "len", "(", "netParts", ")", "==", "2", "{", "tenantName", "=", "netParts", "[", "1", "]", "\n", "}", "else", "{", "tenantName", "=", "\"", "\"", "\n", "}", "\n", "epID", ":=", "sw", ".", "ofnetAgent", ".", "GetEndpointIdByIpVrf", "(", "net", ".", "ParseIP", "(", "epOper", ".", "IPAddress", ")", ",", "tenantName", ")", "\n", "err", "=", "sw", ".", "ofnetAgent", ".", "RemoveLocalEndpointByID", "(", "epID", ")", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epOper", ",", "err", ")", "\n", "// continue with further cleanup", "}", "\n\n", "// Delete it from ovsdb", "err", "=", "sw", ".", "ovsdbDriver", ".", "DeletePort", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "// continue with further cleanup", "}", "\n\n", "// Delete the Veth pairs if required", "if", "useVethPair", "&&", "!", "skipVethPair", "{", "// Delete a Veth pair", "verr", ":=", "deleteVethPair", "(", "ovsPortName", ",", "epOper", ".", "PortName", ")", "\n", "if", "verr", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "verr", ")", "\n", "return", "verr", "\n", "}", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// DeletePort removes a port from OVS
[ "DeletePort", "removes", "a", "port", "from", "OVS" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L496-L547
8,151
contiv/netplugin
drivers/ovsd/ovsSwitch.go
vxlanIfName
func vxlanIfName(vtepIP string) string { return fmt.Sprintf(vxlanIfNameFmt, strings.Replace(vtepIP, ".", "", -1)) }
go
func vxlanIfName(vtepIP string) string { return fmt.Sprintf(vxlanIfNameFmt, strings.Replace(vtepIP, ".", "", -1)) }
[ "func", "vxlanIfName", "(", "vtepIP", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "vxlanIfNameFmt", ",", "strings", ".", "Replace", "(", "vtepIP", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", ")", "\n", "}" ]
// vxlanIfName returns formatted vxlan interface name
[ "vxlanIfName", "returns", "formatted", "vxlan", "interface", "name" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L550-L552
8,152
contiv/netplugin
drivers/ovsd/ovsSwitch.go
CreateVtep
func (sw *OvsSwitch) CreateVtep(vtepIP string) error { // Create interface name for VTEP intfName := vxlanIfName(vtepIP) log.Infof("Creating VTEP intf %s for IP %s", intfName, vtepIP) // Check if it already exists isPresent, vsifName := sw.ovsdbDriver.IsVtepPresent(vtepIP) if !isPresent || (vsifName != intfName) { // Ask ovsdb to create it err := sw.ovsdbDriver.CreateVtep(intfName, vtepIP) if err != nil { log.Errorf("Error creating VTEP port %s. Err: %v", intfName, err) } } // Wait a little for OVS to create the interface time.Sleep(300 * time.Millisecond) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(intfName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return err } // Add info about VTEP port to ofnet if sw.ofnetAgent != nil { err = sw.ofnetAgent.AddVtepPort(ofpPort, net.ParseIP(vtepIP)) if err != nil { log.Errorf("Error adding VTEP port %s to ofnet. Err: %v", intfName, err) return err } } return nil }
go
func (sw *OvsSwitch) CreateVtep(vtepIP string) error { // Create interface name for VTEP intfName := vxlanIfName(vtepIP) log.Infof("Creating VTEP intf %s for IP %s", intfName, vtepIP) // Check if it already exists isPresent, vsifName := sw.ovsdbDriver.IsVtepPresent(vtepIP) if !isPresent || (vsifName != intfName) { // Ask ovsdb to create it err := sw.ovsdbDriver.CreateVtep(intfName, vtepIP) if err != nil { log.Errorf("Error creating VTEP port %s. Err: %v", intfName, err) } } // Wait a little for OVS to create the interface time.Sleep(300 * time.Millisecond) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(intfName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return err } // Add info about VTEP port to ofnet if sw.ofnetAgent != nil { err = sw.ofnetAgent.AddVtepPort(ofpPort, net.ParseIP(vtepIP)) if err != nil { log.Errorf("Error adding VTEP port %s to ofnet. Err: %v", intfName, err) return err } } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "CreateVtep", "(", "vtepIP", "string", ")", "error", "{", "// Create interface name for VTEP", "intfName", ":=", "vxlanIfName", "(", "vtepIP", ")", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "intfName", ",", "vtepIP", ")", "\n\n", "// Check if it already exists", "isPresent", ",", "vsifName", ":=", "sw", ".", "ovsdbDriver", ".", "IsVtepPresent", "(", "vtepIP", ")", "\n", "if", "!", "isPresent", "||", "(", "vsifName", "!=", "intfName", ")", "{", "// Ask ovsdb to create it", "err", ":=", "sw", ".", "ovsdbDriver", ".", "CreateVtep", "(", "intfName", ",", "vtepIP", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Wait a little for OVS to create the interface", "time", ".", "Sleep", "(", "300", "*", "time", ".", "Millisecond", ")", "\n\n", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "intfName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Add info about VTEP port to ofnet", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", "=", "sw", ".", "ofnetAgent", ".", "AddVtepPort", "(", "ofpPort", ",", "net", ".", "ParseIP", "(", "vtepIP", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CreateVtep creates a VTEP interface
[ "CreateVtep", "creates", "a", "VTEP", "interface" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L555-L591
8,153
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DeleteVtep
func (sw *OvsSwitch) DeleteVtep(vtepIP string) error { // Build vtep interface name intfName := vxlanIfName(vtepIP) log.Infof("Deleting VTEP intf %s for IP %s", intfName, vtepIP) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(intfName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return err } // Add info about VTEP port to ofnet if sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveVtepPort(ofpPort, net.ParseIP(vtepIP)) if err != nil { log.Errorf("Error deleting VTEP port %s to ofnet. Err: %v", intfName, err) return err } } // ask ovsdb to delete the VTEP return sw.ovsdbDriver.DeleteVtep(intfName) }
go
func (sw *OvsSwitch) DeleteVtep(vtepIP string) error { // Build vtep interface name intfName := vxlanIfName(vtepIP) log.Infof("Deleting VTEP intf %s for IP %s", intfName, vtepIP) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(intfName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return err } // Add info about VTEP port to ofnet if sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveVtepPort(ofpPort, net.ParseIP(vtepIP)) if err != nil { log.Errorf("Error deleting VTEP port %s to ofnet. Err: %v", intfName, err) return err } } // ask ovsdb to delete the VTEP return sw.ovsdbDriver.DeleteVtep(intfName) }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DeleteVtep", "(", "vtepIP", "string", ")", "error", "{", "// Build vtep interface name", "intfName", ":=", "vxlanIfName", "(", "vtepIP", ")", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "intfName", ",", "vtepIP", ")", "\n\n", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "intfName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Add info about VTEP port to ofnet", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", "=", "sw", ".", "ofnetAgent", ".", "RemoveVtepPort", "(", "ofpPort", ",", "net", ".", "ParseIP", "(", "vtepIP", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// ask ovsdb to delete the VTEP", "return", "sw", ".", "ovsdbDriver", ".", "DeleteVtep", "(", "intfName", ")", "\n", "}" ]
// DeleteVtep deletes a VTEP
[ "DeleteVtep", "deletes", "a", "VTEP" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L594-L618
8,154
contiv/netplugin
drivers/ovsd/ovsSwitch.go
HandleLinkUpdates
func (sw *OvsSwitch) HandleLinkUpdates(linkUpd ofnet.LinkUpdateInfo) { for intfListObj := range sw.uplinkDb.IterBuffered() { intfList := intfListObj.Val.([]string) for _, intf := range intfList { if intf == linkUpd.LinkName { portName := intfListObj.Key portUpds := ofnet.PortUpdates{ PortName: portName, Updates: []ofnet.PortUpdate{ { UpdateType: ofnet.LacpUpdate, UpdateInfo: linkUpd, }, }, } err := sw.ofnetAgent.UpdateUplink(portName, portUpds) if err != nil { log.Errorf("Update uplink failed. Err: %+v", err) } return } } } }
go
func (sw *OvsSwitch) HandleLinkUpdates(linkUpd ofnet.LinkUpdateInfo) { for intfListObj := range sw.uplinkDb.IterBuffered() { intfList := intfListObj.Val.([]string) for _, intf := range intfList { if intf == linkUpd.LinkName { portName := intfListObj.Key portUpds := ofnet.PortUpdates{ PortName: portName, Updates: []ofnet.PortUpdate{ { UpdateType: ofnet.LacpUpdate, UpdateInfo: linkUpd, }, }, } err := sw.ofnetAgent.UpdateUplink(portName, portUpds) if err != nil { log.Errorf("Update uplink failed. Err: %+v", err) } return } } } }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "HandleLinkUpdates", "(", "linkUpd", "ofnet", ".", "LinkUpdateInfo", ")", "{", "for", "intfListObj", ":=", "range", "sw", ".", "uplinkDb", ".", "IterBuffered", "(", ")", "{", "intfList", ":=", "intfListObj", ".", "Val", ".", "(", "[", "]", "string", ")", "\n", "for", "_", ",", "intf", ":=", "range", "intfList", "{", "if", "intf", "==", "linkUpd", ".", "LinkName", "{", "portName", ":=", "intfListObj", ".", "Key", "\n", "portUpds", ":=", "ofnet", ".", "PortUpdates", "{", "PortName", ":", "portName", ",", "Updates", ":", "[", "]", "ofnet", ".", "PortUpdate", "{", "{", "UpdateType", ":", "ofnet", ".", "LacpUpdate", ",", "UpdateInfo", ":", "linkUpd", ",", "}", ",", "}", ",", "}", "\n", "err", ":=", "sw", ".", "ofnetAgent", ".", "UpdateUplink", "(", "portName", ",", "portUpds", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// HandleLinkUpdates handle link updates and update the datapath
[ "HandleLinkUpdates", "handle", "link", "updates", "and", "update", "the", "datapath" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L761-L784
8,155
contiv/netplugin
drivers/ovsd/ovsSwitch.go
RemoveUplinks
func (sw *OvsSwitch) RemoveUplinks() error { var err error // some error checking if sw.netType != "vlan" { log.Fatalf("Can not remove uplink from OVS type %s.", sw.netType) } for intfListObj := range sw.uplinkDb.IterBuffered() { intfList := intfListObj.Val.([]string) portName := intfListObj.Key // Remove uplink from agent err = sw.ofnetAgent.RemoveUplink(portName) if err != nil { log.Errorf("Error removing uplink %s. Err: %v", portName, err) return err } log.Infof("Removed uplink %s from ofnet", portName) isPortPresent := sw.ovsdbDriver.IsPortNamePresent(portName) if len(intfList) == 1 { isPortPresent = sw.ovsdbDriver.IsPortNamePresent(intfList[0]) } if isPortPresent { if len(intfList) == 1 { err = sw.ovsdbDriver.DeletePort(intfList[0]) } else { err = sw.ovsdbDriver.DeletePortBond(portName, intfList) } if err != nil { log.Errorf("Error deleting uplink %s from OVS. Err: %v", portName, err) return err } } time.Sleep(time.Second) sw.uplinkDb.Remove(portName) log.Infof("Removed uplink %s(%+v) from OVS switch %s.", portName, intfList, sw.bridgeName) } return nil }
go
func (sw *OvsSwitch) RemoveUplinks() error { var err error // some error checking if sw.netType != "vlan" { log.Fatalf("Can not remove uplink from OVS type %s.", sw.netType) } for intfListObj := range sw.uplinkDb.IterBuffered() { intfList := intfListObj.Val.([]string) portName := intfListObj.Key // Remove uplink from agent err = sw.ofnetAgent.RemoveUplink(portName) if err != nil { log.Errorf("Error removing uplink %s. Err: %v", portName, err) return err } log.Infof("Removed uplink %s from ofnet", portName) isPortPresent := sw.ovsdbDriver.IsPortNamePresent(portName) if len(intfList) == 1 { isPortPresent = sw.ovsdbDriver.IsPortNamePresent(intfList[0]) } if isPortPresent { if len(intfList) == 1 { err = sw.ovsdbDriver.DeletePort(intfList[0]) } else { err = sw.ovsdbDriver.DeletePortBond(portName, intfList) } if err != nil { log.Errorf("Error deleting uplink %s from OVS. Err: %v", portName, err) return err } } time.Sleep(time.Second) sw.uplinkDb.Remove(portName) log.Infof("Removed uplink %s(%+v) from OVS switch %s.", portName, intfList, sw.bridgeName) } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "RemoveUplinks", "(", ")", "error", "{", "var", "err", "error", "\n\n", "// some error checking", "if", "sw", ".", "netType", "!=", "\"", "\"", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "sw", ".", "netType", ")", "\n", "}", "\n\n", "for", "intfListObj", ":=", "range", "sw", ".", "uplinkDb", ".", "IterBuffered", "(", ")", "{", "intfList", ":=", "intfListObj", ".", "Val", ".", "(", "[", "]", "string", ")", "\n", "portName", ":=", "intfListObj", ".", "Key", "\n\n", "// Remove uplink from agent", "err", "=", "sw", ".", "ofnetAgent", ".", "RemoveUplink", "(", "portName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "portName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "portName", ")", "\n\n", "isPortPresent", ":=", "sw", ".", "ovsdbDriver", ".", "IsPortNamePresent", "(", "portName", ")", "\n", "if", "len", "(", "intfList", ")", "==", "1", "{", "isPortPresent", "=", "sw", ".", "ovsdbDriver", ".", "IsPortNamePresent", "(", "intfList", "[", "0", "]", ")", "\n", "}", "\n", "if", "isPortPresent", "{", "if", "len", "(", "intfList", ")", "==", "1", "{", "err", "=", "sw", ".", "ovsdbDriver", ".", "DeletePort", "(", "intfList", "[", "0", "]", ")", "\n", "}", "else", "{", "err", "=", "sw", ".", "ovsdbDriver", ".", "DeletePortBond", "(", "portName", ",", "intfList", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "portName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "time", ".", "Sleep", "(", "time", ".", "Second", ")", "\n", "sw", ".", "uplinkDb", ".", "Remove", "(", "portName", ")", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "portName", ",", "intfList", ",", "sw", ".", "bridgeName", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RemoveUplinks removes uplink ports from the OVS
[ "RemoveUplinks", "removes", "uplink", "ports", "from", "the", "OVS" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L787-L830
8,156
contiv/netplugin
drivers/ovsd/ovsSwitch.go
AddHostPort
func (sw *OvsSwitch) AddHostPort(intfName string, intfNum, network int, isHostNS bool) (string, error) { var err error // some error checking if sw.netType != "vxlan" { log.Fatalf("Can not add host port to OVS type %s.", sw.netType) } ovsPortType := "" ovsPortName := getOvsPortName(intfName, isHostNS) if isHostNS { ovsPortType = "internal" } else { log.Infof("Host port in container name space -- ignore") return "", nil } portID := "host" + intfName // If the port already exists in OVS, remove it first if sw.ovsdbDriver.IsPortNamePresent(ovsPortName) { log.Infof("Removing existing interface entry %s from OVS", ovsPortName) // Delete it from ovsdb err := sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) } } // Ask OVSDB driver to add the port as an access port err = sw.ovsdbDriver.CreatePort(ovsPortName, ovsPortType, portID, hostVLAN, 0, 0) if err != nil { log.Errorf("Error adding hostport %s to OVS. Err: %v", intfName, err) return "", err } // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return "", err } // Assign an IP based on the intfnumber ipStr, macStr := netutils.PortToHostIPMAC(intfNum, network) mac, _ := net.ParseMAC(macStr) portInfo := ofnet.HostPortInfo{ PortNo: ofpPort, MacAddr: mac, IpAddr: ipStr, Kind: "NAT", } // Add to ofnet if this is the hostNS port. netutils.SetInterfaceMac(intfName, macStr) netutils.SetInterfaceIP(intfName, ipStr) err = setLinkUp(intfName) if sw.ofnetAgent != nil { err = sw.ofnetAgent.AddHostPort(portInfo) if err != nil { log.Errorf("Error adding host port %s. Err: %v", intfName, err) return "", err } } log.Infof("Added host port %s to OVS switch %s.", intfName, sw.bridgeName) defer func() { if err != nil { sw.ovsdbDriver.DeletePort(intfName) } }() return ipStr, nil }
go
func (sw *OvsSwitch) AddHostPort(intfName string, intfNum, network int, isHostNS bool) (string, error) { var err error // some error checking if sw.netType != "vxlan" { log.Fatalf("Can not add host port to OVS type %s.", sw.netType) } ovsPortType := "" ovsPortName := getOvsPortName(intfName, isHostNS) if isHostNS { ovsPortType = "internal" } else { log.Infof("Host port in container name space -- ignore") return "", nil } portID := "host" + intfName // If the port already exists in OVS, remove it first if sw.ovsdbDriver.IsPortNamePresent(ovsPortName) { log.Infof("Removing existing interface entry %s from OVS", ovsPortName) // Delete it from ovsdb err := sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) } } // Ask OVSDB driver to add the port as an access port err = sw.ovsdbDriver.CreatePort(ovsPortName, ovsPortType, portID, hostVLAN, 0, 0) if err != nil { log.Errorf("Error adding hostport %s to OVS. Err: %v", intfName, err) return "", err } // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) return "", err } // Assign an IP based on the intfnumber ipStr, macStr := netutils.PortToHostIPMAC(intfNum, network) mac, _ := net.ParseMAC(macStr) portInfo := ofnet.HostPortInfo{ PortNo: ofpPort, MacAddr: mac, IpAddr: ipStr, Kind: "NAT", } // Add to ofnet if this is the hostNS port. netutils.SetInterfaceMac(intfName, macStr) netutils.SetInterfaceIP(intfName, ipStr) err = setLinkUp(intfName) if sw.ofnetAgent != nil { err = sw.ofnetAgent.AddHostPort(portInfo) if err != nil { log.Errorf("Error adding host port %s. Err: %v", intfName, err) return "", err } } log.Infof("Added host port %s to OVS switch %s.", intfName, sw.bridgeName) defer func() { if err != nil { sw.ovsdbDriver.DeletePort(intfName) } }() return ipStr, nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "AddHostPort", "(", "intfName", "string", ",", "intfNum", ",", "network", "int", ",", "isHostNS", "bool", ")", "(", "string", ",", "error", ")", "{", "var", "err", "error", "\n\n", "// some error checking", "if", "sw", ".", "netType", "!=", "\"", "\"", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "sw", ".", "netType", ")", "\n", "}", "\n\n", "ovsPortType", ":=", "\"", "\"", "\n", "ovsPortName", ":=", "getOvsPortName", "(", "intfName", ",", "isHostNS", ")", "\n", "if", "isHostNS", "{", "ovsPortType", "=", "\"", "\"", "\n", "}", "else", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", ",", "nil", "\n", "}", "\n\n", "portID", ":=", "\"", "\"", "+", "intfName", "\n\n", "// If the port already exists in OVS, remove it first", "if", "sw", ".", "ovsdbDriver", ".", "IsPortNamePresent", "(", "ovsPortName", ")", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "ovsPortName", ")", "\n\n", "// Delete it from ovsdb", "err", ":=", "sw", ".", "ovsdbDriver", ".", "DeletePort", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Ask OVSDB driver to add the port as an access port", "err", "=", "sw", ".", "ovsdbDriver", ".", "CreatePort", "(", "ovsPortName", ",", "ovsPortType", ",", "portID", ",", "hostVLAN", ",", "0", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// Assign an IP based on the intfnumber", "ipStr", ",", "macStr", ":=", "netutils", ".", "PortToHostIPMAC", "(", "intfNum", ",", "network", ")", "\n", "mac", ",", "_", ":=", "net", ".", "ParseMAC", "(", "macStr", ")", "\n\n", "portInfo", ":=", "ofnet", ".", "HostPortInfo", "{", "PortNo", ":", "ofpPort", ",", "MacAddr", ":", "mac", ",", "IpAddr", ":", "ipStr", ",", "Kind", ":", "\"", "\"", ",", "}", "\n", "// Add to ofnet if this is the hostNS port.", "netutils", ".", "SetInterfaceMac", "(", "intfName", ",", "macStr", ")", "\n", "netutils", ".", "SetInterfaceIP", "(", "intfName", ",", "ipStr", ")", "\n", "err", "=", "setLinkUp", "(", "intfName", ")", "\n\n", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", "=", "sw", ".", "ofnetAgent", ".", "AddHostPort", "(", "portInfo", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "intfName", ",", "sw", ".", "bridgeName", ")", "\n\n", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "sw", ".", "ovsdbDriver", ".", "DeletePort", "(", "intfName", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "ipStr", ",", "nil", "\n", "}" ]
// AddHostPort adds a host port to the OVS
[ "AddHostPort", "adds", "a", "host", "port", "to", "the", "OVS" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L833-L909
8,157
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DelHostPort
func (sw *OvsSwitch) DelHostPort(intfName string, isHostNS bool) error { var err error ovsPortName := getOvsPortName(intfName, isHostNS) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) } // If the port already exists in OVS, remove it first if sw.ovsdbDriver.IsPortNamePresent(ovsPortName) { log.Debugf("Removing interface entry %s from OVS", ovsPortName) // Delete it from ovsdb err := sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) } } if isHostNS && sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveHostPort(ofpPort) if err != nil { log.Errorf("Error deleting host port %s. Err: %v", intfName, err) return err } } return nil }
go
func (sw *OvsSwitch) DelHostPort(intfName string, isHostNS bool) error { var err error ovsPortName := getOvsPortName(intfName, isHostNS) // Get the openflow port number for the interface ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName) if err != nil { log.Errorf("Could not find the OVS port %s. Err: %v", intfName, err) } // If the port already exists in OVS, remove it first if sw.ovsdbDriver.IsPortNamePresent(ovsPortName) { log.Debugf("Removing interface entry %s from OVS", ovsPortName) // Delete it from ovsdb err := sw.ovsdbDriver.DeletePort(ovsPortName) if err != nil { log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err) } } if isHostNS && sw.ofnetAgent != nil { err = sw.ofnetAgent.RemoveHostPort(ofpPort) if err != nil { log.Errorf("Error deleting host port %s. Err: %v", intfName, err) return err } } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DelHostPort", "(", "intfName", "string", ",", "isHostNS", "bool", ")", "error", "{", "var", "err", "error", "\n\n", "ovsPortName", ":=", "getOvsPortName", "(", "intfName", ",", "isHostNS", ")", "\n", "// Get the openflow port number for the interface", "ofpPort", ",", "err", ":=", "sw", ".", "ovsdbDriver", ".", "GetOfpPortNo", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "}", "\n", "// If the port already exists in OVS, remove it first", "if", "sw", ".", "ovsdbDriver", ".", "IsPortNamePresent", "(", "ovsPortName", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "ovsPortName", ")", "\n\n", "// Delete it from ovsdb", "err", ":=", "sw", ".", "ovsdbDriver", ".", "DeletePort", "(", "ovsPortName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "ovsPortName", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "isHostNS", "&&", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", "=", "sw", ".", "ofnetAgent", ".", "RemoveHostPort", "(", "ofpPort", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "intfName", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DelHostPort removes a host port from the OVS
[ "DelHostPort", "removes", "a", "host", "port", "from", "the", "OVS" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L912-L941
8,158
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DeleteMaster
func (sw *OvsSwitch) DeleteMaster(node core.ServiceInfo) error { // Build master info masterInfo := ofnet.OfnetNode{ HostAddr: node.HostAddr, HostPort: uint16(node.Port), } // remove the master if sw.ofnetAgent != nil { err := sw.ofnetAgent.RemoveMaster(&masterInfo) if err != nil { log.Errorf("Error deleting ofnet master %+v. Err: %v", masterInfo, err) return err } } return nil }
go
func (sw *OvsSwitch) DeleteMaster(node core.ServiceInfo) error { // Build master info masterInfo := ofnet.OfnetNode{ HostAddr: node.HostAddr, HostPort: uint16(node.Port), } // remove the master if sw.ofnetAgent != nil { err := sw.ofnetAgent.RemoveMaster(&masterInfo) if err != nil { log.Errorf("Error deleting ofnet master %+v. Err: %v", masterInfo, err) return err } } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DeleteMaster", "(", "node", "core", ".", "ServiceInfo", ")", "error", "{", "// Build master info", "masterInfo", ":=", "ofnet", ".", "OfnetNode", "{", "HostAddr", ":", "node", ".", "HostAddr", ",", "HostPort", ":", "uint16", "(", "node", ".", "Port", ")", ",", "}", "\n\n", "// remove the master", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", ":=", "sw", ".", "ofnetAgent", ".", "RemoveMaster", "(", "&", "masterInfo", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "masterInfo", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteMaster deletes master node
[ "DeleteMaster", "deletes", "master", "node" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L966-L983
8,159
contiv/netplugin
drivers/ovsd/ovsSwitch.go
AddBgp
func (sw *OvsSwitch) AddBgp(hostname string, routerIP string, As string, neighborAs, neighbor string) error { if sw.netType == "vlan" && sw.ofnetAgent != nil { err := sw.ofnetAgent.AddBgp(routerIP, As, neighborAs, neighbor) if err != nil { log.Errorf("Error adding BGP server") return err } } return nil }
go
func (sw *OvsSwitch) AddBgp(hostname string, routerIP string, As string, neighborAs, neighbor string) error { if sw.netType == "vlan" && sw.ofnetAgent != nil { err := sw.ofnetAgent.AddBgp(routerIP, As, neighborAs, neighbor) if err != nil { log.Errorf("Error adding BGP server") return err } } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "AddBgp", "(", "hostname", "string", ",", "routerIP", "string", ",", "As", "string", ",", "neighborAs", ",", "neighbor", "string", ")", "error", "{", "if", "sw", ".", "netType", "==", "\"", "\"", "&&", "sw", ".", "ofnetAgent", "!=", "nil", "{", "err", ":=", "sw", ".", "ofnetAgent", ".", "AddBgp", "(", "routerIP", ",", "As", ",", "neighborAs", ",", "neighbor", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddBgp adds a bgp config to host
[ "AddBgp", "adds", "a", "bgp", "config", "to", "host" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L986-L997
8,160
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DeleteBgp
func (sw *OvsSwitch) DeleteBgp() error { if sw.netType == "vlan" && sw.ofnetAgent != nil { // Delete vlan/vni mapping err := sw.ofnetAgent.DeleteBgp() if err != nil { log.Errorf("Error removing bgp server Err: %v", err) return err } } return nil }
go
func (sw *OvsSwitch) DeleteBgp() error { if sw.netType == "vlan" && sw.ofnetAgent != nil { // Delete vlan/vni mapping err := sw.ofnetAgent.DeleteBgp() if err != nil { log.Errorf("Error removing bgp server Err: %v", err) return err } } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DeleteBgp", "(", ")", "error", "{", "if", "sw", ".", "netType", "==", "\"", "\"", "&&", "sw", ".", "ofnetAgent", "!=", "nil", "{", "// Delete vlan/vni mapping", "err", ":=", "sw", ".", "ofnetAgent", ".", "DeleteBgp", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteBgp deletes bgp config from host
[ "DeleteBgp", "deletes", "bgp", "config", "from", "host" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1000-L1011
8,161
contiv/netplugin
drivers/ovsd/ovsSwitch.go
AddSvcSpec
func (sw *OvsSwitch) AddSvcSpec(svcName string, spec *ofnet.ServiceSpec) error { log.Infof("OvsSwitch AddSvcSpec %s", svcName) if sw.ofnetAgent != nil { return sw.ofnetAgent.AddSvcSpec(svcName, spec) } return nil }
go
func (sw *OvsSwitch) AddSvcSpec(svcName string, spec *ofnet.ServiceSpec) error { log.Infof("OvsSwitch AddSvcSpec %s", svcName) if sw.ofnetAgent != nil { return sw.ofnetAgent.AddSvcSpec(svcName, spec) } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "AddSvcSpec", "(", "svcName", "string", ",", "spec", "*", "ofnet", ".", "ServiceSpec", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "svcName", ")", "\n", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "return", "sw", ".", "ofnetAgent", ".", "AddSvcSpec", "(", "svcName", ",", "spec", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddSvcSpec invokes ofnetAgent api
[ "AddSvcSpec", "invokes", "ofnetAgent", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1014-L1021
8,162
contiv/netplugin
drivers/ovsd/ovsSwitch.go
DelSvcSpec
func (sw *OvsSwitch) DelSvcSpec(svcName string, spec *ofnet.ServiceSpec) error { if sw.ofnetAgent != nil { return sw.ofnetAgent.DelSvcSpec(svcName, spec) } return nil }
go
func (sw *OvsSwitch) DelSvcSpec(svcName string, spec *ofnet.ServiceSpec) error { if sw.ofnetAgent != nil { return sw.ofnetAgent.DelSvcSpec(svcName, spec) } return nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "DelSvcSpec", "(", "svcName", "string", ",", "spec", "*", "ofnet", ".", "ServiceSpec", ")", "error", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "return", "sw", ".", "ofnetAgent", ".", "DelSvcSpec", "(", "svcName", ",", "spec", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DelSvcSpec invokes ofnetAgent api
[ "DelSvcSpec", "invokes", "ofnetAgent", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1024-L1030
8,163
contiv/netplugin
drivers/ovsd/ovsSwitch.go
SvcProviderUpdate
func (sw *OvsSwitch) SvcProviderUpdate(svcName string, providers []string) { if sw.ofnetAgent != nil { sw.ofnetAgent.SvcProviderUpdate(svcName, providers) } }
go
func (sw *OvsSwitch) SvcProviderUpdate(svcName string, providers []string) { if sw.ofnetAgent != nil { sw.ofnetAgent.SvcProviderUpdate(svcName, providers) } }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "SvcProviderUpdate", "(", "svcName", "string", ",", "providers", "[", "]", "string", ")", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "sw", ".", "ofnetAgent", ".", "SvcProviderUpdate", "(", "svcName", ",", "providers", ")", "\n", "}", "\n", "}" ]
// SvcProviderUpdate invokes ofnetAgent api
[ "SvcProviderUpdate", "invokes", "ofnetAgent", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1033-L1037
8,164
contiv/netplugin
drivers/ovsd/ovsSwitch.go
GetEndpointStats
func (sw *OvsSwitch) GetEndpointStats() (map[string]*ofnet.OfnetEndpointStats, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } stats, err := sw.ofnetAgent.GetEndpointStats() if err != nil { log.Errorf("Error: %v", err) return nil, err } log.Debugf("stats: %+v", stats) return stats, nil }
go
func (sw *OvsSwitch) GetEndpointStats() (map[string]*ofnet.OfnetEndpointStats, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } stats, err := sw.ofnetAgent.GetEndpointStats() if err != nil { log.Errorf("Error: %v", err) return nil, err } log.Debugf("stats: %+v", stats) return stats, nil }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "GetEndpointStats", "(", ")", "(", "map", "[", "string", "]", "*", "ofnet", ".", "OfnetEndpointStats", ",", "error", ")", "{", "if", "sw", ".", "ofnetAgent", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "stats", ",", "err", ":=", "sw", ".", "ofnetAgent", ".", "GetEndpointStats", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "log", ".", "Debugf", "(", "\"", "\"", ",", "stats", ")", "\n\n", "return", "stats", ",", "nil", "\n", "}" ]
// GetEndpointStats invokes ofnetAgent api
[ "GetEndpointStats", "invokes", "ofnetAgent", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1040-L1054
8,165
contiv/netplugin
drivers/ovsd/ovsSwitch.go
InspectState
func (sw *OvsSwitch) InspectState() (interface{}, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } return sw.ofnetAgent.InspectState() }
go
func (sw *OvsSwitch) InspectState() (interface{}, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } return sw.ofnetAgent.InspectState() }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "InspectState", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "sw", ".", "ofnetAgent", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "sw", ".", "ofnetAgent", ".", "InspectState", "(", ")", "\n", "}" ]
// InspectState ireturns ofnet state in json form
[ "InspectState", "ireturns", "ofnet", "state", "in", "json", "form" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1057-L1062
8,166
contiv/netplugin
drivers/ovsd/ovsSwitch.go
InspectBgp
func (sw *OvsSwitch) InspectBgp() (interface{}, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } return sw.ofnetAgent.InspectBgp() }
go
func (sw *OvsSwitch) InspectBgp() (interface{}, error) { if sw.ofnetAgent == nil { return nil, errors.New("no ofnet agent") } return sw.ofnetAgent.InspectBgp() }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "InspectBgp", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "sw", ".", "ofnetAgent", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "sw", ".", "ofnetAgent", ".", "InspectBgp", "(", ")", "\n", "}" ]
// InspectBgp returns ofnet state in json form
[ "InspectBgp", "returns", "ofnet", "state", "in", "json", "form" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1065-L1070
8,167
contiv/netplugin
drivers/ovsd/ovsSwitch.go
GlobalConfigUpdate
func (sw *OvsSwitch) GlobalConfigUpdate(cfg ofnet.OfnetGlobalConfig) error { if sw.ofnetAgent == nil { return errors.New("no ofnet agent") } return sw.ofnetAgent.GlobalConfigUpdate(cfg) }
go
func (sw *OvsSwitch) GlobalConfigUpdate(cfg ofnet.OfnetGlobalConfig) error { if sw.ofnetAgent == nil { return errors.New("no ofnet agent") } return sw.ofnetAgent.GlobalConfigUpdate(cfg) }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "GlobalConfigUpdate", "(", "cfg", "ofnet", ".", "OfnetGlobalConfig", ")", "error", "{", "if", "sw", ".", "ofnetAgent", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "sw", ".", "ofnetAgent", ".", "GlobalConfigUpdate", "(", "cfg", ")", "\n", "}" ]
// GlobalConfigUpdate updates the global configs like arp-mode
[ "GlobalConfigUpdate", "updates", "the", "global", "configs", "like", "arp", "-", "mode" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1073-L1078
8,168
contiv/netplugin
drivers/ovsd/ovsSwitch.go
AddNameServer
func (sw *OvsSwitch) AddNameServer(ns ofnet.NameServer) { if sw.ofnetAgent != nil { sw.ofnetAgent.AddNameServer(ns) } }
go
func (sw *OvsSwitch) AddNameServer(ns ofnet.NameServer) { if sw.ofnetAgent != nil { sw.ofnetAgent.AddNameServer(ns) } }
[ "func", "(", "sw", "*", "OvsSwitch", ")", "AddNameServer", "(", "ns", "ofnet", ".", "NameServer", ")", "{", "if", "sw", ".", "ofnetAgent", "!=", "nil", "{", "sw", ".", "ofnetAgent", ".", "AddNameServer", "(", "ns", ")", "\n", "}", "\n", "}" ]
// AddNameServer returns ofnet state in json form
[ "AddNameServer", "returns", "ofnet", "state", "in", "json", "form" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/drivers/ovsd/ovsSwitch.go#L1081-L1085
8,169
contiv/netplugin
mgmtfn/k8splugin/kubeClient.go
NewAPIClient
func NewAPIClient(serverURL, caFile, keyFile, certFile, authToken string) *APIClient { useClientCerts := true c := APIClient{} c.apiServerPort = 6443 // default port := strings.Split(serverURL, ":") if len(port) > 0 { if v, err := strconv.ParseUint(port[len(port)-1], 10, 16); err == nil { c.apiServerPort = uint16(v) } else { log.Warnf("parse failed: %s, use default api server port: %d", err, c.apiServerPort) } } c.baseURL = serverURL + "/api/v1/namespaces/" c.watchBase = serverURL + "/api/v1/watch/" // Read CA cert ca, err := ioutil.ReadFile(caFile) if err != nil { log.Fatal(err) return nil } caPool := x509.NewCertPool() caPool.AppendCertsFromPEM(ca) // Read client cert cert, err := tls.LoadX509KeyPair(certFile, keyFile) // We need either the client certs or a non-empty authToken to proceed if err != nil { // We cannot use client certs now useClientCerts = false // Check for a non-empty token if len(strings.TrimSpace(authToken)) == 0 { log.Fatalf("Error %s loading the client certificates and missing auth token", err) return nil } } // Setup HTTPS client tlsCfg := &tls.Config{ RootCAs: caPool, } // Setup client cert based authentication if useClientCerts { tlsCfg.Certificates = []tls.Certificate{cert} tlsCfg.BuildNameToCertificate() } transport := &http.Transport{TLSClientConfig: tlsCfg} c.client = &http.Client{Transport: transport} c.authToken = authToken p := &c.podCache p.labels = make(map[string]string) p.nameSpace = "" p.name = "" return &c }
go
func NewAPIClient(serverURL, caFile, keyFile, certFile, authToken string) *APIClient { useClientCerts := true c := APIClient{} c.apiServerPort = 6443 // default port := strings.Split(serverURL, ":") if len(port) > 0 { if v, err := strconv.ParseUint(port[len(port)-1], 10, 16); err == nil { c.apiServerPort = uint16(v) } else { log.Warnf("parse failed: %s, use default api server port: %d", err, c.apiServerPort) } } c.baseURL = serverURL + "/api/v1/namespaces/" c.watchBase = serverURL + "/api/v1/watch/" // Read CA cert ca, err := ioutil.ReadFile(caFile) if err != nil { log.Fatal(err) return nil } caPool := x509.NewCertPool() caPool.AppendCertsFromPEM(ca) // Read client cert cert, err := tls.LoadX509KeyPair(certFile, keyFile) // We need either the client certs or a non-empty authToken to proceed if err != nil { // We cannot use client certs now useClientCerts = false // Check for a non-empty token if len(strings.TrimSpace(authToken)) == 0 { log.Fatalf("Error %s loading the client certificates and missing auth token", err) return nil } } // Setup HTTPS client tlsCfg := &tls.Config{ RootCAs: caPool, } // Setup client cert based authentication if useClientCerts { tlsCfg.Certificates = []tls.Certificate{cert} tlsCfg.BuildNameToCertificate() } transport := &http.Transport{TLSClientConfig: tlsCfg} c.client = &http.Client{Transport: transport} c.authToken = authToken p := &c.podCache p.labels = make(map[string]string) p.nameSpace = "" p.name = "" return &c }
[ "func", "NewAPIClient", "(", "serverURL", ",", "caFile", ",", "keyFile", ",", "certFile", ",", "authToken", "string", ")", "*", "APIClient", "{", "useClientCerts", ":=", "true", "\n", "c", ":=", "APIClient", "{", "}", "\n\n", "c", ".", "apiServerPort", "=", "6443", "// default", "\n", "port", ":=", "strings", ".", "Split", "(", "serverURL", ",", "\"", "\"", ")", "\n", "if", "len", "(", "port", ")", ">", "0", "{", "if", "v", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "port", "[", "len", "(", "port", ")", "-", "1", "]", ",", "10", ",", "16", ")", ";", "err", "==", "nil", "{", "c", ".", "apiServerPort", "=", "uint16", "(", "v", ")", "\n", "}", "else", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "err", ",", "c", ".", "apiServerPort", ")", "\n", "}", "\n", "}", "\n\n", "c", ".", "baseURL", "=", "serverURL", "+", "\"", "\"", "\n", "c", ".", "watchBase", "=", "serverURL", "+", "\"", "\"", "\n\n", "// Read CA cert", "ca", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "caFile", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "caPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "caPool", ".", "AppendCertsFromPEM", "(", "ca", ")", "\n\n", "// Read client cert", "cert", ",", "err", ":=", "tls", ".", "LoadX509KeyPair", "(", "certFile", ",", "keyFile", ")", "\n", "// We need either the client certs or a non-empty authToken to proceed", "if", "err", "!=", "nil", "{", "// We cannot use client certs now", "useClientCerts", "=", "false", "\n", "// Check for a non-empty token", "if", "len", "(", "strings", ".", "TrimSpace", "(", "authToken", ")", ")", "==", "0", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "// Setup HTTPS client", "tlsCfg", ":=", "&", "tls", ".", "Config", "{", "RootCAs", ":", "caPool", ",", "}", "\n", "// Setup client cert based authentication", "if", "useClientCerts", "{", "tlsCfg", ".", "Certificates", "=", "[", "]", "tls", ".", "Certificate", "{", "cert", "}", "\n", "tlsCfg", ".", "BuildNameToCertificate", "(", ")", "\n", "}", "\n", "transport", ":=", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "tlsCfg", "}", "\n", "c", ".", "client", "=", "&", "http", ".", "Client", "{", "Transport", ":", "transport", "}", "\n", "c", ".", "authToken", "=", "authToken", "\n\n", "p", ":=", "&", "c", ".", "podCache", "\n", "p", ".", "labels", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "p", ".", "nameSpace", "=", "\"", "\"", "\n", "p", ".", "name", "=", "\"", "\"", "\n\n", "return", "&", "c", "\n", "}" ]
// NewAPIClient creates an instance of the k8s api client
[ "NewAPIClient", "creates", "an", "instance", "of", "the", "k8s", "api", "client" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/kubeClient.go#L88-L146
8,170
contiv/netplugin
mgmtfn/k8splugin/kubeClient.go
fetchPodLabels
func (c *APIClient) fetchPodLabels(ns, name string) error { var data interface{} // initiate a get request to the api server podURL := c.baseURL + ns + "/pods/" + name req, err := http.NewRequest("GET", podURL, nil) if err != nil { return err } if len(strings.TrimSpace(c.authToken)) > 0 { req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken)) } r, err := c.client.Do(req) if err != nil { return err } defer r.Body.Close() switch { case r.StatusCode == int(404): return fmt.Errorf("page not found") case r.StatusCode == int(403): return fmt.Errorf("access denied") case r.StatusCode != int(200): log.Errorf("GET Status '%s' status code %d \n", r.Status, r.StatusCode) return fmt.Errorf("%s", r.Status) } response, err := ioutil.ReadAll(r.Body) if err != nil { return err } err = json.Unmarshal(response, &data) if err != nil { return err } podSpec := data.(map[string]interface{}) m, ok := podSpec["metadata"] // Treat missing metadata as a fatal error if !ok { return fmt.Errorf("metadata not found in podSpec") } p := &c.podCache p.labelsMutex.Lock() defer p.labelsMutex.Unlock() p.setDefaults(ns, name) meta := m.(map[string]interface{}) l, ok := meta["labels"] if ok { labels := l.(map[string]interface{}) for key, val := range labels { switch valType := val.(type) { case string: p.labels[key] = val.(string) default: log.Infof("Label %s type %v in pod %s.%s ignored", key, valType, ns, name) } } } else { log.Infof("labels not found in podSpec metadata, using defaults") } return nil }
go
func (c *APIClient) fetchPodLabels(ns, name string) error { var data interface{} // initiate a get request to the api server podURL := c.baseURL + ns + "/pods/" + name req, err := http.NewRequest("GET", podURL, nil) if err != nil { return err } if len(strings.TrimSpace(c.authToken)) > 0 { req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken)) } r, err := c.client.Do(req) if err != nil { return err } defer r.Body.Close() switch { case r.StatusCode == int(404): return fmt.Errorf("page not found") case r.StatusCode == int(403): return fmt.Errorf("access denied") case r.StatusCode != int(200): log.Errorf("GET Status '%s' status code %d \n", r.Status, r.StatusCode) return fmt.Errorf("%s", r.Status) } response, err := ioutil.ReadAll(r.Body) if err != nil { return err } err = json.Unmarshal(response, &data) if err != nil { return err } podSpec := data.(map[string]interface{}) m, ok := podSpec["metadata"] // Treat missing metadata as a fatal error if !ok { return fmt.Errorf("metadata not found in podSpec") } p := &c.podCache p.labelsMutex.Lock() defer p.labelsMutex.Unlock() p.setDefaults(ns, name) meta := m.(map[string]interface{}) l, ok := meta["labels"] if ok { labels := l.(map[string]interface{}) for key, val := range labels { switch valType := val.(type) { case string: p.labels[key] = val.(string) default: log.Infof("Label %s type %v in pod %s.%s ignored", key, valType, ns, name) } } } else { log.Infof("labels not found in podSpec metadata, using defaults") } return nil }
[ "func", "(", "c", "*", "APIClient", ")", "fetchPodLabels", "(", "ns", ",", "name", "string", ")", "error", "{", "var", "data", "interface", "{", "}", "\n\n", "// initiate a get request to the api server", "podURL", ":=", "c", ".", "baseURL", "+", "ns", "+", "\"", "\"", "+", "name", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "podURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "strings", ".", "TrimSpace", "(", "c", ".", "authToken", ")", ")", ">", "0", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "authToken", ")", ")", "\n", "}", "\n", "r", ",", "err", ":=", "c", ".", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "switch", "{", "case", "r", ".", "StatusCode", "==", "int", "(", "404", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "r", ".", "StatusCode", "==", "int", "(", "403", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "r", ".", "StatusCode", "!=", "int", "(", "200", ")", ":", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "r", ".", "Status", ",", "r", ".", "StatusCode", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Status", ")", "\n", "}", "\n\n", "response", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "response", ",", "&", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "podSpec", ":=", "data", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "m", ",", "ok", ":=", "podSpec", "[", "\"", "\"", "]", "\n", "// Treat missing metadata as a fatal error", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "p", ":=", "&", "c", ".", "podCache", "\n", "p", ".", "labelsMutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "labelsMutex", ".", "Unlock", "(", ")", "\n", "p", ".", "setDefaults", "(", "ns", ",", "name", ")", "\n\n", "meta", ":=", "m", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "l", ",", "ok", ":=", "meta", "[", "\"", "\"", "]", "\n", "if", "ok", "{", "labels", ":=", "l", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "key", ",", "val", ":=", "range", "labels", "{", "switch", "valType", ":=", "val", ".", "(", "type", ")", "{", "case", "string", ":", "p", ".", "labels", "[", "key", "]", "=", "val", ".", "(", "string", ")", "\n\n", "default", ":", "log", ".", "Infof", "(", "\"", "\"", ",", "key", ",", "valType", ",", "ns", ",", "name", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// fetchPodLabels retrieves the labels from the podspec metadata
[ "fetchPodLabels", "retrieves", "the", "labels", "from", "the", "podspec", "metadata" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/kubeClient.go#L157-L227
8,171
contiv/netplugin
mgmtfn/k8splugin/kubeClient.go
GetPodLabel
func (c *APIClient) GetPodLabel(ns, name, label string) (string, error) { // If cache does not match, fetch if c.podCache.nameSpace != ns || c.podCache.name != name { err := c.fetchPodLabels(ns, name) if err != nil { return "", err } } c.podCache.labelsMutex.Lock() defer c.podCache.labelsMutex.Unlock() res, found := c.podCache.labels[label] if found { return res, nil } log.Infof("label %s not found in podSpec for %s.%s", label, ns, name) return "", nil }
go
func (c *APIClient) GetPodLabel(ns, name, label string) (string, error) { // If cache does not match, fetch if c.podCache.nameSpace != ns || c.podCache.name != name { err := c.fetchPodLabels(ns, name) if err != nil { return "", err } } c.podCache.labelsMutex.Lock() defer c.podCache.labelsMutex.Unlock() res, found := c.podCache.labels[label] if found { return res, nil } log.Infof("label %s not found in podSpec for %s.%s", label, ns, name) return "", nil }
[ "func", "(", "c", "*", "APIClient", ")", "GetPodLabel", "(", "ns", ",", "name", ",", "label", "string", ")", "(", "string", ",", "error", ")", "{", "// If cache does not match, fetch", "if", "c", ".", "podCache", ".", "nameSpace", "!=", "ns", "||", "c", ".", "podCache", ".", "name", "!=", "name", "{", "err", ":=", "c", ".", "fetchPodLabels", "(", "ns", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n\n", "c", ".", "podCache", ".", "labelsMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "podCache", ".", "labelsMutex", ".", "Unlock", "(", ")", "\n\n", "res", ",", "found", ":=", "c", ".", "podCache", ".", "labels", "[", "label", "]", "\n\n", "if", "found", "{", "return", "res", ",", "nil", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "label", ",", "ns", ",", "name", ")", "\n", "return", "\"", "\"", ",", "nil", "\n", "}" ]
// GetPodLabel retrieves the specified label
[ "GetPodLabel", "retrieves", "the", "specified", "label" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/kubeClient.go#L230-L251
8,172
contiv/netplugin
mgmtfn/k8splugin/kubeClient.go
WatchSvcEps
func (c *APIClient) WatchSvcEps(respCh chan EpWatchResp) { ctx, _ := context.WithCancel(context.Background()) go func() { // Make request to Kubernetes API getURL := c.watchBase + "endpoints" req, err := http.NewRequest("GET", getURL, nil) if err != nil { respCh <- EpWatchResp{opcode: "FATAL", errStr: fmt.Sprintf("Req %v", err)} return } req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken)) res, err := ctxhttp.Do(ctx, c.client, req) if err != nil { log.Errorf("EP Watch error: %v", err) respCh <- EpWatchResp{opcode: "FATAL", errStr: fmt.Sprintf("Do %v", err)} return } defer res.Body.Close() var weps watchSvcEpStatus reader := bufio.NewReader(res.Body) // bufio.Reader.ReadBytes is blocking, so we watch for // context timeout or cancellation in a goroutine // and close the response body when see see it. The // response body is also closed via defer when the // request is made, but closing twice is OK. go func() { <-ctx.Done() res.Body.Close() }() for { line, err := reader.ReadBytes('\n') if ctx.Err() != nil { respCh <- EpWatchResp{opcode: "ERROR", errStr: fmt.Sprintf("ctx %v", err)} return } if err != nil { respCh <- EpWatchResp{opcode: "ERROR", errStr: fmt.Sprintf("read %v", err)} return } if err := json.Unmarshal(line, &weps); err != nil { respCh <- EpWatchResp{opcode: "WARN", errStr: fmt.Sprintf("unmarshal %v", err)} continue } if weps.Object.ObjectMeta.Namespace == "kube-system" && (weps.Object.ObjectMeta.Name == "kube-scheduler" || weps.Object.ObjectMeta.Name == "kube-controller-manager") { // Ignoring these frequent updates continue } resp := EpWatchResp{opcode: weps.Type} resp.svcName = weps.Object.ObjectMeta.Name resp.providers = make([]string, 0, 1) for _, subset := range weps.Object.Subsets { // TODO: handle partially ready providers for _, addr := range subset.Addresses { resp.providers = append(resp.providers, addr.IP) } } log.Infof("kube ep watch: %v", resp) respCh <- resp } }() }
go
func (c *APIClient) WatchSvcEps(respCh chan EpWatchResp) { ctx, _ := context.WithCancel(context.Background()) go func() { // Make request to Kubernetes API getURL := c.watchBase + "endpoints" req, err := http.NewRequest("GET", getURL, nil) if err != nil { respCh <- EpWatchResp{opcode: "FATAL", errStr: fmt.Sprintf("Req %v", err)} return } req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken)) res, err := ctxhttp.Do(ctx, c.client, req) if err != nil { log.Errorf("EP Watch error: %v", err) respCh <- EpWatchResp{opcode: "FATAL", errStr: fmt.Sprintf("Do %v", err)} return } defer res.Body.Close() var weps watchSvcEpStatus reader := bufio.NewReader(res.Body) // bufio.Reader.ReadBytes is blocking, so we watch for // context timeout or cancellation in a goroutine // and close the response body when see see it. The // response body is also closed via defer when the // request is made, but closing twice is OK. go func() { <-ctx.Done() res.Body.Close() }() for { line, err := reader.ReadBytes('\n') if ctx.Err() != nil { respCh <- EpWatchResp{opcode: "ERROR", errStr: fmt.Sprintf("ctx %v", err)} return } if err != nil { respCh <- EpWatchResp{opcode: "ERROR", errStr: fmt.Sprintf("read %v", err)} return } if err := json.Unmarshal(line, &weps); err != nil { respCh <- EpWatchResp{opcode: "WARN", errStr: fmt.Sprintf("unmarshal %v", err)} continue } if weps.Object.ObjectMeta.Namespace == "kube-system" && (weps.Object.ObjectMeta.Name == "kube-scheduler" || weps.Object.ObjectMeta.Name == "kube-controller-manager") { // Ignoring these frequent updates continue } resp := EpWatchResp{opcode: weps.Type} resp.svcName = weps.Object.ObjectMeta.Name resp.providers = make([]string, 0, 1) for _, subset := range weps.Object.Subsets { // TODO: handle partially ready providers for _, addr := range subset.Addresses { resp.providers = append(resp.providers, addr.IP) } } log.Infof("kube ep watch: %v", resp) respCh <- resp } }() }
[ "func", "(", "c", "*", "APIClient", ")", "WatchSvcEps", "(", "respCh", "chan", "EpWatchResp", ")", "{", "ctx", ",", "_", ":=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n\n", "go", "func", "(", ")", "{", "// Make request to Kubernetes API", "getURL", ":=", "c", ".", "watchBase", "+", "\"", "\"", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "getURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "respCh", "<-", "EpWatchResp", "{", "opcode", ":", "\"", "\"", ",", "errStr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "}", "\n", "return", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "authToken", ")", ")", "\n", "res", ",", "err", ":=", "ctxhttp", ".", "Do", "(", "ctx", ",", "c", ".", "client", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "respCh", "<-", "EpWatchResp", "{", "opcode", ":", "\"", "\"", ",", "errStr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "}", "\n", "return", "\n", "}", "\n", "defer", "res", ".", "Body", ".", "Close", "(", ")", "\n\n", "var", "weps", "watchSvcEpStatus", "\n", "reader", ":=", "bufio", ".", "NewReader", "(", "res", ".", "Body", ")", "\n\n", "// bufio.Reader.ReadBytes is blocking, so we watch for", "// context timeout or cancellation in a goroutine", "// and close the response body when see see it. The", "// response body is also closed via defer when the", "// request is made, but closing twice is OK.", "go", "func", "(", ")", "{", "<-", "ctx", ".", "Done", "(", ")", "\n", "res", ".", "Body", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n\n", "for", "{", "line", ",", "err", ":=", "reader", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "respCh", "<-", "EpWatchResp", "{", "opcode", ":", "\"", "\"", ",", "errStr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "}", "\n", "return", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "respCh", "<-", "EpWatchResp", "{", "opcode", ":", "\"", "\"", ",", "errStr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "}", "\n", "return", "\n", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "line", ",", "&", "weps", ")", ";", "err", "!=", "nil", "{", "respCh", "<-", "EpWatchResp", "{", "opcode", ":", "\"", "\"", ",", "errStr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "}", "\n", "continue", "\n", "}", "\n\n", "if", "weps", ".", "Object", ".", "ObjectMeta", ".", "Namespace", "==", "\"", "\"", "&&", "(", "weps", ".", "Object", ".", "ObjectMeta", ".", "Name", "==", "\"", "\"", "||", "weps", ".", "Object", ".", "ObjectMeta", ".", "Name", "==", "\"", "\"", ")", "{", "// Ignoring these frequent updates", "continue", "\n", "}", "\n\n", "resp", ":=", "EpWatchResp", "{", "opcode", ":", "weps", ".", "Type", "}", "\n", "resp", ".", "svcName", "=", "weps", ".", "Object", ".", "ObjectMeta", ".", "Name", "\n", "resp", ".", "providers", "=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "for", "_", ",", "subset", ":=", "range", "weps", ".", "Object", ".", "Subsets", "{", "// TODO: handle partially ready providers", "for", "_", ",", "addr", ":=", "range", "subset", ".", "Addresses", "{", "resp", ".", "providers", "=", "append", "(", "resp", ".", "providers", ",", "addr", ".", "IP", ")", "\n", "}", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "resp", ")", "\n", "respCh", "<-", "resp", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// WatchSvcEps watches the service endpoints object
[ "WatchSvcEps", "watches", "the", "service", "endpoints", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/kubeClient.go#L341-L408
8,173
contiv/netplugin
netmaster/mastercfg/policyRuleState.go
ReadAll
func (s *CfgPolicyRule) ReadAll() ([]core.State, error) { return s.StateDriver.ReadAllState(policyRuleConfigPathPrefix, s, json.Unmarshal) }
go
func (s *CfgPolicyRule) ReadAll() ([]core.State, error) { return s.StateDriver.ReadAllState(policyRuleConfigPathPrefix, s, json.Unmarshal) }
[ "func", "(", "s", "*", "CfgPolicyRule", ")", "ReadAll", "(", ")", "(", "[", "]", "core", ".", "State", ",", "error", ")", "{", "return", "s", ".", "StateDriver", ".", "ReadAllState", "(", "policyRuleConfigPathPrefix", ",", "s", ",", "json", ".", "Unmarshal", ")", "\n", "}" ]
// ReadAll reads all state objects for the policy rules.
[ "ReadAll", "reads", "all", "state", "objects", "for", "the", "policy", "rules", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyRuleState.go#L50-L52
8,174
contiv/netplugin
netmaster/mastercfg/policyRuleState.go
WatchAll
func (s *CfgPolicyRule) WatchAll(rsps chan core.WatchState) error { return s.StateDriver.WatchAllState(policyRuleConfigPathPrefix, s, json.Unmarshal, rsps) }
go
func (s *CfgPolicyRule) WatchAll(rsps chan core.WatchState) error { return s.StateDriver.WatchAllState(policyRuleConfigPathPrefix, s, json.Unmarshal, rsps) }
[ "func", "(", "s", "*", "CfgPolicyRule", ")", "WatchAll", "(", "rsps", "chan", "core", ".", "WatchState", ")", "error", "{", "return", "s", ".", "StateDriver", ".", "WatchAllState", "(", "policyRuleConfigPathPrefix", ",", "s", ",", "json", ".", "Unmarshal", ",", "rsps", ")", "\n", "}" ]
// WatchAll fills a channel on each state event related to policy rules.
[ "WatchAll", "fills", "a", "channel", "on", "each", "state", "event", "related", "to", "policy", "rules", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyRuleState.go#L55-L58
8,175
contiv/netplugin
netmaster/mastercfg/policyRuleState.go
addPolicyRuleState
func addPolicyRuleState(ofnetRule *ofnet.OfnetPolicyRule) error { ruleCfg := &CfgPolicyRule{} ruleCfg.StateDriver = stateStore ruleCfg.OfnetPolicyRule = (*ofnetRule) // Save the rule return ruleCfg.Write() }
go
func addPolicyRuleState(ofnetRule *ofnet.OfnetPolicyRule) error { ruleCfg := &CfgPolicyRule{} ruleCfg.StateDriver = stateStore ruleCfg.OfnetPolicyRule = (*ofnetRule) // Save the rule return ruleCfg.Write() }
[ "func", "addPolicyRuleState", "(", "ofnetRule", "*", "ofnet", ".", "OfnetPolicyRule", ")", "error", "{", "ruleCfg", ":=", "&", "CfgPolicyRule", "{", "}", "\n", "ruleCfg", ".", "StateDriver", "=", "stateStore", "\n", "ruleCfg", ".", "OfnetPolicyRule", "=", "(", "*", "ofnetRule", ")", "\n\n", "// Save the rule", "return", "ruleCfg", ".", "Write", "(", ")", "\n", "}" ]
// addPolicyRuleState adds policy rule to state store
[ "addPolicyRuleState", "adds", "policy", "rule", "to", "state", "store" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyRuleState.go#L67-L74
8,176
contiv/netplugin
netmaster/mastercfg/policyRuleState.go
delPolicyRuleState
func delPolicyRuleState(ofnetRule *ofnet.OfnetPolicyRule) error { ruleCfg := &CfgPolicyRule{} ruleCfg.StateDriver = stateStore ruleCfg.OfnetPolicyRule = (*ofnetRule) // Delete the rule return ruleCfg.Clear() }
go
func delPolicyRuleState(ofnetRule *ofnet.OfnetPolicyRule) error { ruleCfg := &CfgPolicyRule{} ruleCfg.StateDriver = stateStore ruleCfg.OfnetPolicyRule = (*ofnetRule) // Delete the rule return ruleCfg.Clear() }
[ "func", "delPolicyRuleState", "(", "ofnetRule", "*", "ofnet", ".", "OfnetPolicyRule", ")", "error", "{", "ruleCfg", ":=", "&", "CfgPolicyRule", "{", "}", "\n", "ruleCfg", ".", "StateDriver", "=", "stateStore", "\n", "ruleCfg", ".", "OfnetPolicyRule", "=", "(", "*", "ofnetRule", ")", "\n\n", "// Delete the rule", "return", "ruleCfg", ".", "Clear", "(", ")", "\n", "}" ]
// delPolicyRuleState deletes policy rule from state store
[ "delPolicyRuleState", "deletes", "policy", "rule", "from", "state", "store" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/mastercfg/policyRuleState.go#L77-L84
8,177
contiv/netplugin
utils/netwrapper.go
ListenWrapper
func ListenWrapper(l net.Listener) net.Listener { return &contivListener{ Listener: l, cond: sync.NewCond(&sync.Mutex{})} }
go
func ListenWrapper(l net.Listener) net.Listener { return &contivListener{ Listener: l, cond: sync.NewCond(&sync.Mutex{})} }
[ "func", "ListenWrapper", "(", "l", "net", ".", "Listener", ")", "net", ".", "Listener", "{", "return", "&", "contivListener", "{", "Listener", ":", "l", ",", "cond", ":", "sync", ".", "NewCond", "(", "&", "sync", ".", "Mutex", "{", "}", ")", "}", "\n", "}" ]
// ListenWrapper is a wrapper over net.Listener
[ "ListenWrapper", "is", "a", "wrapper", "over", "net", ".", "Listener" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netwrapper.go#L24-L28
8,178
contiv/netplugin
utils/netwrapper.go
Accept
func (s *contivListener) Accept() (net.Conn, error) { s.incrementRef() defer s.decrementRef() return s.Listener.Accept() }
go
func (s *contivListener) Accept() (net.Conn, error) { s.incrementRef() defer s.decrementRef() return s.Listener.Accept() }
[ "func", "(", "s", "*", "contivListener", ")", "Accept", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "s", ".", "incrementRef", "(", ")", "\n", "defer", "s", ".", "decrementRef", "(", ")", "\n", "return", "s", ".", "Listener", ".", "Accept", "(", ")", "\n", "}" ]
// Accept is a wrapper over regular Accept call // which also maintains the refCnt
[ "Accept", "is", "a", "wrapper", "over", "regular", "Accept", "call", "which", "also", "maintains", "the", "refCnt" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netwrapper.go#L54-L58
8,179
contiv/netplugin
utils/netwrapper.go
Close
func (s *contivListener) Close() error { if err := s.Listener.Close(); err != nil { return err } s.cond.L.Lock() for s.refCnt > 0 { s.cond.Wait() } s.cond.L.Unlock() return nil }
go
func (s *contivListener) Close() error { if err := s.Listener.Close(); err != nil { return err } s.cond.L.Lock() for s.refCnt > 0 { s.cond.Wait() } s.cond.L.Unlock() return nil }
[ "func", "(", "s", "*", "contivListener", ")", "Close", "(", ")", "error", "{", "if", "err", ":=", "s", ".", "Listener", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "s", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "for", "s", ".", "refCnt", ">", "0", "{", "s", ".", "cond", ".", "Wait", "(", ")", "\n", "}", "\n", "s", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Close closes the contivListener.
[ "Close", "closes", "the", "contivListener", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/utils/netwrapper.go#L61-L72
8,180
contiv/netplugin
mgmtfn/k8splugin/contivk8s/clients/network.go
NewNWClient
func NewNWClient() *NWClient { c := NWClient{} c.baseURL = nwURL transport := &http.Transport{Dial: unixDial} c.client = &http.Client{Transport: transport} return &c }
go
func NewNWClient() *NWClient { c := NWClient{} c.baseURL = nwURL transport := &http.Transport{Dial: unixDial} c.client = &http.Client{Transport: transport} return &c }
[ "func", "NewNWClient", "(", ")", "*", "NWClient", "{", "c", ":=", "NWClient", "{", "}", "\n", "c", ".", "baseURL", "=", "nwURL", "\n\n", "transport", ":=", "&", "http", ".", "Transport", "{", "Dial", ":", "unixDial", "}", "\n", "c", ".", "client", "=", "&", "http", ".", "Client", "{", "Transport", ":", "transport", "}", "\n\n", "return", "&", "c", "\n", "}" ]
// NewNWClient creates an instance of the network driver client
[ "NewNWClient", "creates", "an", "instance", "of", "the", "network", "driver", "client" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/contivk8s/clients/network.go#L46-L54
8,181
contiv/netplugin
mgmtfn/k8splugin/contivk8s/clients/network.go
AddPod
func (c *NWClient) AddPod(podInfo interface{}) (*cniapi.RspAddPod, error) { data := cniapi.RspAddPod{} buf, err := json.Marshal(podInfo) if err != nil { return nil, err } body := bytes.NewBuffer(buf) url := c.baseURL + cniapi.EPAddURL r, err := c.client.Post(url, "application/json", body) if err != nil { return nil, err } defer r.Body.Close() switch { case r.StatusCode == int(404): return nil, fmt.Errorf("page not found") case r.StatusCode == int(403): return nil, fmt.Errorf("access denied") case r.StatusCode == int(500): info, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err } err = json.Unmarshal(info, &data) if err != nil { return nil, err } return &data, fmt.Errorf("internal server error") case r.StatusCode != int(200): log.Errorf("POST Status '%s' status code %d \n", r.Status, r.StatusCode) return nil, fmt.Errorf("%s", r.Status) } response, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err } err = json.Unmarshal(response, &data) if err != nil { return nil, err } return &data, nil }
go
func (c *NWClient) AddPod(podInfo interface{}) (*cniapi.RspAddPod, error) { data := cniapi.RspAddPod{} buf, err := json.Marshal(podInfo) if err != nil { return nil, err } body := bytes.NewBuffer(buf) url := c.baseURL + cniapi.EPAddURL r, err := c.client.Post(url, "application/json", body) if err != nil { return nil, err } defer r.Body.Close() switch { case r.StatusCode == int(404): return nil, fmt.Errorf("page not found") case r.StatusCode == int(403): return nil, fmt.Errorf("access denied") case r.StatusCode == int(500): info, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err } err = json.Unmarshal(info, &data) if err != nil { return nil, err } return &data, fmt.Errorf("internal server error") case r.StatusCode != int(200): log.Errorf("POST Status '%s' status code %d \n", r.Status, r.StatusCode) return nil, fmt.Errorf("%s", r.Status) } response, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err } err = json.Unmarshal(response, &data) if err != nil { return nil, err } return &data, nil }
[ "func", "(", "c", "*", "NWClient", ")", "AddPod", "(", "podInfo", "interface", "{", "}", ")", "(", "*", "cniapi", ".", "RspAddPod", ",", "error", ")", "{", "data", ":=", "cniapi", ".", "RspAddPod", "{", "}", "\n", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "podInfo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "body", ":=", "bytes", ".", "NewBuffer", "(", "buf", ")", "\n", "url", ":=", "c", ".", "baseURL", "+", "cniapi", ".", "EPAddURL", "\n", "r", ",", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "\"", "\"", ",", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n\n", "switch", "{", "case", "r", ".", "StatusCode", "==", "int", "(", "404", ")", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n\n", "case", "r", ".", "StatusCode", "==", "int", "(", "403", ")", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n\n", "case", "r", ".", "StatusCode", "==", "int", "(", "500", ")", ":", "info", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "info", ",", "&", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "data", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n\n", "case", "r", ".", "StatusCode", "!=", "int", "(", "200", ")", ":", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "r", ".", "Status", ",", "r", ".", "StatusCode", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Status", ")", "\n", "}", "\n\n", "response", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "response", ",", "&", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "data", ",", "nil", "\n", "}" ]
// AddPod adds a pod to contiv using the cni api
[ "AddPod", "adds", "a", "pod", "to", "contiv", "using", "the", "cni", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/contivk8s/clients/network.go#L57-L107
8,182
contiv/netplugin
mgmtfn/k8splugin/contivk8s/clients/network.go
DelPod
func (c *NWClient) DelPod(podInfo interface{}) error { buf, err := json.Marshal(podInfo) if err != nil { return err } body := bytes.NewBuffer(buf) url := c.baseURL + cniapi.EPDelURL r, err := c.client.Post(url, "application/json", body) if err != nil { return err } defer r.Body.Close() switch { case r.StatusCode == int(404): return fmt.Errorf("page not found") case r.StatusCode == int(403): return fmt.Errorf("access denied") case r.StatusCode != int(200): log.Errorf("GET Status '%s' status code %d \n", r.Status, r.StatusCode) return fmt.Errorf("%s", r.Status) } return nil }
go
func (c *NWClient) DelPod(podInfo interface{}) error { buf, err := json.Marshal(podInfo) if err != nil { return err } body := bytes.NewBuffer(buf) url := c.baseURL + cniapi.EPDelURL r, err := c.client.Post(url, "application/json", body) if err != nil { return err } defer r.Body.Close() switch { case r.StatusCode == int(404): return fmt.Errorf("page not found") case r.StatusCode == int(403): return fmt.Errorf("access denied") case r.StatusCode != int(200): log.Errorf("GET Status '%s' status code %d \n", r.Status, r.StatusCode) return fmt.Errorf("%s", r.Status) } return nil }
[ "func", "(", "c", "*", "NWClient", ")", "DelPod", "(", "podInfo", "interface", "{", "}", ")", "error", "{", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "podInfo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "body", ":=", "bytes", ".", "NewBuffer", "(", "buf", ")", "\n", "url", ":=", "c", ".", "baseURL", "+", "cniapi", ".", "EPDelURL", "\n", "r", ",", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "\"", "\"", ",", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n\n", "switch", "{", "case", "r", ".", "StatusCode", "==", "int", "(", "404", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "r", ".", "StatusCode", "==", "int", "(", "403", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "r", ".", "StatusCode", "!=", "int", "(", "200", ")", ":", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "r", ".", "Status", ",", "r", ".", "StatusCode", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Status", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DelPod deletes a pod from contiv using the cni api
[ "DelPod", "deletes", "a", "pod", "from", "contiv", "using", "the", "cni", "api" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/mgmtfn/k8splugin/contivk8s/clients/network.go#L110-L136
8,183
contiv/netplugin
netmaster/objApi/apiController.go
NewAPIController
func NewAPIController(router *mux.Router, objdbClient objdb.API, configs *APIControllerConfig) *APIController { ctrler := new(APIController) ctrler.router = router ctrler.objdbClient = objdbClient // init modeldb modeldb.Init(&objdbClient) // initialize the model objects contivModel.Init() // Register Callbacks contivModel.RegisterGlobalCallbacks(ctrler) contivModel.RegisterAppProfileCallbacks(ctrler) contivModel.RegisterEndpointGroupCallbacks(ctrler) contivModel.RegisterNetworkCallbacks(ctrler) contivModel.RegisterPolicyCallbacks(ctrler) contivModel.RegisterRuleCallbacks(ctrler) contivModel.RegisterTenantCallbacks(ctrler) contivModel.RegisterBgpCallbacks(ctrler) contivModel.RegisterServiceLBCallbacks(ctrler) contivModel.RegisterExtContractsGroupCallbacks(ctrler) contivModel.RegisterEndpointCallbacks(ctrler) contivModel.RegisterNetprofileCallbacks(ctrler) contivModel.RegisterAciGwCallbacks(ctrler) // Register routes contivModel.AddRoutes(router) // Init global state from config initGlobalConfigs(configs) // Add default tenant if it doesnt exist tenant := contivModel.FindTenant("default") if tenant == nil { log.Infof("Creating default tenant") err := contivModel.CreateTenant(&contivModel.Tenant{ Key: "default", TenantName: "default", }) if err != nil { log.Fatalf("Error creating default tenant. Err: %v", err) } } return ctrler }
go
func NewAPIController(router *mux.Router, objdbClient objdb.API, configs *APIControllerConfig) *APIController { ctrler := new(APIController) ctrler.router = router ctrler.objdbClient = objdbClient // init modeldb modeldb.Init(&objdbClient) // initialize the model objects contivModel.Init() // Register Callbacks contivModel.RegisterGlobalCallbacks(ctrler) contivModel.RegisterAppProfileCallbacks(ctrler) contivModel.RegisterEndpointGroupCallbacks(ctrler) contivModel.RegisterNetworkCallbacks(ctrler) contivModel.RegisterPolicyCallbacks(ctrler) contivModel.RegisterRuleCallbacks(ctrler) contivModel.RegisterTenantCallbacks(ctrler) contivModel.RegisterBgpCallbacks(ctrler) contivModel.RegisterServiceLBCallbacks(ctrler) contivModel.RegisterExtContractsGroupCallbacks(ctrler) contivModel.RegisterEndpointCallbacks(ctrler) contivModel.RegisterNetprofileCallbacks(ctrler) contivModel.RegisterAciGwCallbacks(ctrler) // Register routes contivModel.AddRoutes(router) // Init global state from config initGlobalConfigs(configs) // Add default tenant if it doesnt exist tenant := contivModel.FindTenant("default") if tenant == nil { log.Infof("Creating default tenant") err := contivModel.CreateTenant(&contivModel.Tenant{ Key: "default", TenantName: "default", }) if err != nil { log.Fatalf("Error creating default tenant. Err: %v", err) } } return ctrler }
[ "func", "NewAPIController", "(", "router", "*", "mux", ".", "Router", ",", "objdbClient", "objdb", ".", "API", ",", "configs", "*", "APIControllerConfig", ")", "*", "APIController", "{", "ctrler", ":=", "new", "(", "APIController", ")", "\n", "ctrler", ".", "router", "=", "router", "\n", "ctrler", ".", "objdbClient", "=", "objdbClient", "\n\n", "// init modeldb", "modeldb", ".", "Init", "(", "&", "objdbClient", ")", "\n\n", "// initialize the model objects", "contivModel", ".", "Init", "(", ")", "\n\n", "// Register Callbacks", "contivModel", ".", "RegisterGlobalCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterAppProfileCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterEndpointGroupCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterNetworkCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterPolicyCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterRuleCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterTenantCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterBgpCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterServiceLBCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterExtContractsGroupCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterEndpointCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterNetprofileCallbacks", "(", "ctrler", ")", "\n", "contivModel", ".", "RegisterAciGwCallbacks", "(", "ctrler", ")", "\n", "// Register routes", "contivModel", ".", "AddRoutes", "(", "router", ")", "\n\n", "// Init global state from config", "initGlobalConfigs", "(", "configs", ")", "\n\n", "// Add default tenant if it doesnt exist", "tenant", ":=", "contivModel", ".", "FindTenant", "(", "\"", "\"", ")", "\n", "if", "tenant", "==", "nil", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "err", ":=", "contivModel", ".", "CreateTenant", "(", "&", "contivModel", ".", "Tenant", "{", "Key", ":", "\"", "\"", ",", "TenantName", ":", "\"", "\"", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "ctrler", "\n", "}" ]
// NewAPIController creates a new controller
[ "NewAPIController", "creates", "a", "new", "controller" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L79-L124
8,184
contiv/netplugin
netmaster/objApi/apiController.go
GlobalGetOper
func (ac *APIController) GlobalGetOper(global *contivModel.GlobalInspect) error { log.Infof("Received GlobalInspect: %+v", global) stateDriver, err := utils.GetStateDriver() if err != nil { return err } gOper := &gstate.Oper{} gOper.StateDriver = stateDriver err = gOper.Read("") if err != nil { log.Errorf("Error obtaining global operational state") return err } global.Oper.DefaultNetwork = gOper.DefaultNetwork global.Oper.FreeVXLANsStart = int(gOper.FreeVXLANsStart) gCfg := &gstate.Cfg{} gCfg.StateDriver = stateDriver numVlans, vlansInUse := gCfg.GetVlansInUse() numVxlans, vxlansInUse := gCfg.GetVxlansInUse() global.Oper.NumNetworks = int(numVlans + numVxlans) global.Oper.VlansInUse = vlansInUse global.Oper.VxlansInUse = vxlansInUse global.Oper.ClusterMode = master.GetClusterMode() return nil }
go
func (ac *APIController) GlobalGetOper(global *contivModel.GlobalInspect) error { log.Infof("Received GlobalInspect: %+v", global) stateDriver, err := utils.GetStateDriver() if err != nil { return err } gOper := &gstate.Oper{} gOper.StateDriver = stateDriver err = gOper.Read("") if err != nil { log.Errorf("Error obtaining global operational state") return err } global.Oper.DefaultNetwork = gOper.DefaultNetwork global.Oper.FreeVXLANsStart = int(gOper.FreeVXLANsStart) gCfg := &gstate.Cfg{} gCfg.StateDriver = stateDriver numVlans, vlansInUse := gCfg.GetVlansInUse() numVxlans, vxlansInUse := gCfg.GetVxlansInUse() global.Oper.NumNetworks = int(numVlans + numVxlans) global.Oper.VlansInUse = vlansInUse global.Oper.VxlansInUse = vxlansInUse global.Oper.ClusterMode = master.GetClusterMode() return nil }
[ "func", "(", "ac", "*", "APIController", ")", "GlobalGetOper", "(", "global", "*", "contivModel", ".", "GlobalInspect", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "global", ")", "\n\n", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "gOper", ":=", "&", "gstate", ".", "Oper", "{", "}", "\n", "gOper", ".", "StateDriver", "=", "stateDriver", "\n", "err", "=", "gOper", ".", "Read", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "err", "\n", "}", "\n\n", "global", ".", "Oper", ".", "DefaultNetwork", "=", "gOper", ".", "DefaultNetwork", "\n", "global", ".", "Oper", ".", "FreeVXLANsStart", "=", "int", "(", "gOper", ".", "FreeVXLANsStart", ")", "\n\n", "gCfg", ":=", "&", "gstate", ".", "Cfg", "{", "}", "\n", "gCfg", ".", "StateDriver", "=", "stateDriver", "\n", "numVlans", ",", "vlansInUse", ":=", "gCfg", ".", "GetVlansInUse", "(", ")", "\n", "numVxlans", ",", "vxlansInUse", ":=", "gCfg", ".", "GetVxlansInUse", "(", ")", "\n\n", "global", ".", "Oper", ".", "NumNetworks", "=", "int", "(", "numVlans", "+", "numVxlans", ")", "\n", "global", ".", "Oper", ".", "VlansInUse", "=", "vlansInUse", "\n", "global", ".", "Oper", ".", "VxlansInUse", "=", "vxlansInUse", "\n", "global", ".", "Oper", ".", "ClusterMode", "=", "master", ".", "GetClusterMode", "(", ")", "\n", "return", "nil", "\n", "}" ]
// GlobalGetOper retrieves glboal operational information
[ "GlobalGetOper", "retrieves", "glboal", "operational", "information" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L169-L198
8,185
contiv/netplugin
netmaster/objApi/apiController.go
GlobalCreate
func (ac *APIController) GlobalCreate(global *contivModel.Global) error { log.Infof("Received GlobalCreate: %+v", global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Build global config gCfg := intent.ConfigGlobal{ NwInfraType: global.NetworkInfraType, VLANs: global.Vlans, VXLANs: global.Vxlans, FwdMode: global.FwdMode, ArpMode: global.ArpMode, PvtSubnet: global.PvtSubnet, } // Create the object err = master.CreateGlobal(stateDriver, &gCfg) if err != nil { log.Errorf("Error creating global config {%+v}. Err: %v", global, err) return err } return nil }
go
func (ac *APIController) GlobalCreate(global *contivModel.Global) error { log.Infof("Received GlobalCreate: %+v", global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Build global config gCfg := intent.ConfigGlobal{ NwInfraType: global.NetworkInfraType, VLANs: global.Vlans, VXLANs: global.Vxlans, FwdMode: global.FwdMode, ArpMode: global.ArpMode, PvtSubnet: global.PvtSubnet, } // Create the object err = master.CreateGlobal(stateDriver, &gCfg) if err != nil { log.Errorf("Error creating global config {%+v}. Err: %v", global, err) return err } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "GlobalCreate", "(", "global", "*", "contivModel", ".", "Global", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "global", ")", "\n\n", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Build global config", "gCfg", ":=", "intent", ".", "ConfigGlobal", "{", "NwInfraType", ":", "global", ".", "NetworkInfraType", ",", "VLANs", ":", "global", ".", "Vlans", ",", "VXLANs", ":", "global", ".", "Vxlans", ",", "FwdMode", ":", "global", ".", "FwdMode", ",", "ArpMode", ":", "global", ".", "ArpMode", ",", "PvtSubnet", ":", "global", ".", "PvtSubnet", ",", "}", "\n\n", "// Create the object", "err", "=", "master", ".", "CreateGlobal", "(", "stateDriver", ",", "&", "gCfg", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "global", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GlobalCreate creates global state
[ "GlobalCreate", "creates", "global", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L201-L228
8,186
contiv/netplugin
netmaster/objApi/apiController.go
GlobalUpdate
func (ac *APIController) GlobalUpdate(global, params *contivModel.Global) error { log.Infof("Received GlobalUpdate: %+v. Old: %+v", params, global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } gCfg := &gstate.Cfg{} gCfg.StateDriver = stateDriver numVlans, _ := gCfg.GetVlansInUse() numVxlans, _ := gCfg.GetVxlansInUse() // Build global config globalCfg := intent.ConfigGlobal{} // Generate helpful error message when networks exist errExistingNetworks := func(optionLabel string) error { msgs := []string{} if numVlans > 0 { msgs = append(msgs, fmt.Sprintf("%d vlans", numVlans)) } if numVxlans > 0 { msgs = append(msgs, fmt.Sprintf("%d vxlans", numVxlans)) } msg := fmt.Sprintf("Unable to update %s due to existing %s", optionLabel, strings.Join(msgs, " and ")) log.Errorf(msg) return fmt.Errorf(msg) } //check for change in forwarding mode if global.FwdMode != params.FwdMode { //check if there exists any non default network and tenants if numVlans+numVxlans > 0 { return errExistingNetworks("forwarding mode") } if global.FwdMode == "routing" { //check if any bgp configurations exists. bgpCfgs := &mastercfg.CfgBgpState{} bgpCfgs.StateDriver = stateDriver cfgs, _ := bgpCfgs.ReadAll() if len(cfgs) != 0 { log.Errorf("Unable to change the forwarding mode due to existing bgp configs") return fmt.Errorf("please delete existing Bgp configs") } } globalCfg.FwdMode = params.FwdMode } if global.ArpMode != params.ArpMode { globalCfg.ArpMode = params.ArpMode } if global.Vlans != params.Vlans { globalCfg.VLANs = params.Vlans } if global.Vxlans != params.Vxlans { globalCfg.VXLANs = params.Vxlans } if global.NetworkInfraType != params.NetworkInfraType { globalCfg.NwInfraType = params.NetworkInfraType } if global.PvtSubnet != params.PvtSubnet { if (global.PvtSubnet != "" || params.PvtSubnet != defaultHostPvtNet) && numVlans+numVxlans > 0 { return errExistingNetworks("private subnet") } globalCfg.PvtSubnet = params.PvtSubnet } // Create the object err = master.UpdateGlobal(stateDriver, &globalCfg) if err != nil { log.Errorf("Error creating global config {%+v}. Err: %v", global, err) return err } global.NetworkInfraType = params.NetworkInfraType global.Vlans = params.Vlans global.Vxlans = params.Vxlans global.FwdMode = params.FwdMode global.ArpMode = params.ArpMode global.PvtSubnet = params.PvtSubnet return nil }
go
func (ac *APIController) GlobalUpdate(global, params *contivModel.Global) error { log.Infof("Received GlobalUpdate: %+v. Old: %+v", params, global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } gCfg := &gstate.Cfg{} gCfg.StateDriver = stateDriver numVlans, _ := gCfg.GetVlansInUse() numVxlans, _ := gCfg.GetVxlansInUse() // Build global config globalCfg := intent.ConfigGlobal{} // Generate helpful error message when networks exist errExistingNetworks := func(optionLabel string) error { msgs := []string{} if numVlans > 0 { msgs = append(msgs, fmt.Sprintf("%d vlans", numVlans)) } if numVxlans > 0 { msgs = append(msgs, fmt.Sprintf("%d vxlans", numVxlans)) } msg := fmt.Sprintf("Unable to update %s due to existing %s", optionLabel, strings.Join(msgs, " and ")) log.Errorf(msg) return fmt.Errorf(msg) } //check for change in forwarding mode if global.FwdMode != params.FwdMode { //check if there exists any non default network and tenants if numVlans+numVxlans > 0 { return errExistingNetworks("forwarding mode") } if global.FwdMode == "routing" { //check if any bgp configurations exists. bgpCfgs := &mastercfg.CfgBgpState{} bgpCfgs.StateDriver = stateDriver cfgs, _ := bgpCfgs.ReadAll() if len(cfgs) != 0 { log.Errorf("Unable to change the forwarding mode due to existing bgp configs") return fmt.Errorf("please delete existing Bgp configs") } } globalCfg.FwdMode = params.FwdMode } if global.ArpMode != params.ArpMode { globalCfg.ArpMode = params.ArpMode } if global.Vlans != params.Vlans { globalCfg.VLANs = params.Vlans } if global.Vxlans != params.Vxlans { globalCfg.VXLANs = params.Vxlans } if global.NetworkInfraType != params.NetworkInfraType { globalCfg.NwInfraType = params.NetworkInfraType } if global.PvtSubnet != params.PvtSubnet { if (global.PvtSubnet != "" || params.PvtSubnet != defaultHostPvtNet) && numVlans+numVxlans > 0 { return errExistingNetworks("private subnet") } globalCfg.PvtSubnet = params.PvtSubnet } // Create the object err = master.UpdateGlobal(stateDriver, &globalCfg) if err != nil { log.Errorf("Error creating global config {%+v}. Err: %v", global, err) return err } global.NetworkInfraType = params.NetworkInfraType global.Vlans = params.Vlans global.Vxlans = params.Vxlans global.FwdMode = params.FwdMode global.ArpMode = params.ArpMode global.PvtSubnet = params.PvtSubnet return nil }
[ "func", "(", "ac", "*", "APIController", ")", "GlobalUpdate", "(", "global", ",", "params", "*", "contivModel", ".", "Global", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "params", ",", "global", ")", "\n\n", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "gCfg", ":=", "&", "gstate", ".", "Cfg", "{", "}", "\n", "gCfg", ".", "StateDriver", "=", "stateDriver", "\n", "numVlans", ",", "_", ":=", "gCfg", ".", "GetVlansInUse", "(", ")", "\n", "numVxlans", ",", "_", ":=", "gCfg", ".", "GetVxlansInUse", "(", ")", "\n\n", "// Build global config", "globalCfg", ":=", "intent", ".", "ConfigGlobal", "{", "}", "\n\n", "// Generate helpful error message when networks exist", "errExistingNetworks", ":=", "func", "(", "optionLabel", "string", ")", "error", "{", "msgs", ":=", "[", "]", "string", "{", "}", "\n", "if", "numVlans", ">", "0", "{", "msgs", "=", "append", "(", "msgs", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "numVlans", ")", ")", "\n", "}", "\n", "if", "numVxlans", ">", "0", "{", "msgs", "=", "append", "(", "msgs", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "numVxlans", ")", ")", "\n", "}", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "optionLabel", ",", "strings", ".", "Join", "(", "msgs", ",", "\"", "\"", ")", ")", "\n", "log", ".", "Errorf", "(", "msg", ")", "\n", "return", "fmt", ".", "Errorf", "(", "msg", ")", "\n", "}", "\n\n", "//check for change in forwarding mode", "if", "global", ".", "FwdMode", "!=", "params", ".", "FwdMode", "{", "//check if there exists any non default network and tenants", "if", "numVlans", "+", "numVxlans", ">", "0", "{", "return", "errExistingNetworks", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "global", ".", "FwdMode", "==", "\"", "\"", "{", "//check if any bgp configurations exists.", "bgpCfgs", ":=", "&", "mastercfg", ".", "CfgBgpState", "{", "}", "\n", "bgpCfgs", ".", "StateDriver", "=", "stateDriver", "\n", "cfgs", ",", "_", ":=", "bgpCfgs", ".", "ReadAll", "(", ")", "\n", "if", "len", "(", "cfgs", ")", "!=", "0", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "globalCfg", ".", "FwdMode", "=", "params", ".", "FwdMode", "\n", "}", "\n", "if", "global", ".", "ArpMode", "!=", "params", ".", "ArpMode", "{", "globalCfg", ".", "ArpMode", "=", "params", ".", "ArpMode", "\n", "}", "\n", "if", "global", ".", "Vlans", "!=", "params", ".", "Vlans", "{", "globalCfg", ".", "VLANs", "=", "params", ".", "Vlans", "\n", "}", "\n", "if", "global", ".", "Vxlans", "!=", "params", ".", "Vxlans", "{", "globalCfg", ".", "VXLANs", "=", "params", ".", "Vxlans", "\n", "}", "\n", "if", "global", ".", "NetworkInfraType", "!=", "params", ".", "NetworkInfraType", "{", "globalCfg", ".", "NwInfraType", "=", "params", ".", "NetworkInfraType", "\n", "}", "\n", "if", "global", ".", "PvtSubnet", "!=", "params", ".", "PvtSubnet", "{", "if", "(", "global", ".", "PvtSubnet", "!=", "\"", "\"", "||", "params", ".", "PvtSubnet", "!=", "defaultHostPvtNet", ")", "&&", "numVlans", "+", "numVxlans", ">", "0", "{", "return", "errExistingNetworks", "(", "\"", "\"", ")", "\n", "}", "\n", "globalCfg", ".", "PvtSubnet", "=", "params", ".", "PvtSubnet", "\n", "}", "\n\n", "// Create the object", "err", "=", "master", ".", "UpdateGlobal", "(", "stateDriver", ",", "&", "globalCfg", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "global", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "global", ".", "NetworkInfraType", "=", "params", ".", "NetworkInfraType", "\n", "global", ".", "Vlans", "=", "params", ".", "Vlans", "\n", "global", ".", "Vxlans", "=", "params", ".", "Vxlans", "\n", "global", ".", "FwdMode", "=", "params", ".", "FwdMode", "\n", "global", ".", "ArpMode", "=", "params", ".", "ArpMode", "\n", "global", ".", "PvtSubnet", "=", "params", ".", "PvtSubnet", "\n\n", "return", "nil", "\n", "}" ]
// GlobalUpdate updates global state
[ "GlobalUpdate", "updates", "global", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L231-L315
8,187
contiv/netplugin
netmaster/objApi/apiController.go
GlobalDelete
func (ac *APIController) GlobalDelete(global *contivModel.Global) error { log.Infof("Received GlobalDelete: %+v", global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Delete global state err = master.DeleteGlobal(stateDriver) if err != nil { log.Errorf("Error deleting global config. Err: %v", err) return err } return nil }
go
func (ac *APIController) GlobalDelete(global *contivModel.Global) error { log.Infof("Received GlobalDelete: %+v", global) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Delete global state err = master.DeleteGlobal(stateDriver) if err != nil { log.Errorf("Error deleting global config. Err: %v", err) return err } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "GlobalDelete", "(", "global", "*", "contivModel", ".", "Global", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "global", ")", "\n\n", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Delete global state", "err", "=", "master", ".", "DeleteGlobal", "(", "stateDriver", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GlobalDelete is not supported
[ "GlobalDelete", "is", "not", "supported" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L318-L334
8,188
contiv/netplugin
netmaster/objApi/apiController.go
AciGwCreate
func (ac *APIController) AciGwCreate(aci *contivModel.AciGw) error { log.Infof("Received AciGwCreate: %+v", aci) // Fail the create if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { log.Warnf("AciGwCreate: %d existing App-Profiles found.", profCount) } return nil }
go
func (ac *APIController) AciGwCreate(aci *contivModel.AciGw) error { log.Infof("Received AciGwCreate: %+v", aci) // Fail the create if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { log.Warnf("AciGwCreate: %d existing App-Profiles found.", profCount) } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "AciGwCreate", "(", "aci", "*", "contivModel", ".", "AciGw", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "aci", ")", "\n", "// Fail the create if app profiles exist", "profCount", ":=", "contivModel", ".", "GetAppProfileCount", "(", ")", "\n", "if", "profCount", "!=", "0", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "profCount", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AciGwCreate creates aci state
[ "AciGwCreate", "creates", "aci", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L337-L347
8,189
contiv/netplugin
netmaster/objApi/apiController.go
AciGwUpdate
func (ac *APIController) AciGwUpdate(aci, params *contivModel.AciGw) error { log.Infof("Received AciGwUpdate: %+v", params) // Fail the update if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { log.Warnf("AciGwUpdate: %d existing App-Profiles found.", profCount) } aci.EnforcePolicies = params.EnforcePolicies aci.IncludeCommonTenant = params.IncludeCommonTenant aci.NodeBindings = params.NodeBindings aci.PathBindings = params.PathBindings aci.PhysicalDomain = params.PhysicalDomain return nil }
go
func (ac *APIController) AciGwUpdate(aci, params *contivModel.AciGw) error { log.Infof("Received AciGwUpdate: %+v", params) // Fail the update if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { log.Warnf("AciGwUpdate: %d existing App-Profiles found.", profCount) } aci.EnforcePolicies = params.EnforcePolicies aci.IncludeCommonTenant = params.IncludeCommonTenant aci.NodeBindings = params.NodeBindings aci.PathBindings = params.PathBindings aci.PhysicalDomain = params.PhysicalDomain return nil }
[ "func", "(", "ac", "*", "APIController", ")", "AciGwUpdate", "(", "aci", ",", "params", "*", "contivModel", ".", "AciGw", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "params", ")", "\n", "// Fail the update if app profiles exist", "profCount", ":=", "contivModel", ".", "GetAppProfileCount", "(", ")", "\n", "if", "profCount", "!=", "0", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "profCount", ")", "\n", "}", "\n\n", "aci", ".", "EnforcePolicies", "=", "params", ".", "EnforcePolicies", "\n", "aci", ".", "IncludeCommonTenant", "=", "params", ".", "IncludeCommonTenant", "\n", "aci", ".", "NodeBindings", "=", "params", ".", "NodeBindings", "\n", "aci", ".", "PathBindings", "=", "params", ".", "PathBindings", "\n", "aci", ".", "PhysicalDomain", "=", "params", ".", "PhysicalDomain", "\n", "return", "nil", "\n", "}" ]
// AciGwUpdate updates aci state
[ "AciGwUpdate", "updates", "aci", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L350-L365
8,190
contiv/netplugin
netmaster/objApi/apiController.go
AciGwDelete
func (ac *APIController) AciGwDelete(aci *contivModel.AciGw) error { log.Infof("Received AciGwDelete") // Fail the delete if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { return core.Errorf("%d App-Profiles found. Delete them first", profCount) } return nil }
go
func (ac *APIController) AciGwDelete(aci *contivModel.AciGw) error { log.Infof("Received AciGwDelete") // Fail the delete if app profiles exist profCount := contivModel.GetAppProfileCount() if profCount != 0 { return core.Errorf("%d App-Profiles found. Delete them first", profCount) } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "AciGwDelete", "(", "aci", "*", "contivModel", ".", "AciGw", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "// Fail the delete if app profiles exist", "profCount", ":=", "contivModel", ".", "GetAppProfileCount", "(", ")", "\n", "if", "profCount", "!=", "0", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "profCount", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AciGwDelete deletes aci state
[ "AciGwDelete", "deletes", "aci", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L368-L378
8,191
contiv/netplugin
netmaster/objApi/apiController.go
AciGwGetOper
func (ac *APIController) AciGwGetOper(op *contivModel.AciGwInspect) error { op.Oper.NumAppProfiles = contivModel.GetAppProfileCount() return nil }
go
func (ac *APIController) AciGwGetOper(op *contivModel.AciGwInspect) error { op.Oper.NumAppProfiles = contivModel.GetAppProfileCount() return nil }
[ "func", "(", "ac", "*", "APIController", ")", "AciGwGetOper", "(", "op", "*", "contivModel", ".", "AciGwInspect", ")", "error", "{", "op", ".", "Oper", ".", "NumAppProfiles", "=", "contivModel", ".", "GetAppProfileCount", "(", ")", "\n", "return", "nil", "\n", "}" ]
// AciGwGetOper provides operational info for the aci object
[ "AciGwGetOper", "provides", "operational", "info", "for", "the", "aci", "object" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L381-L384
8,192
contiv/netplugin
netmaster/objApi/apiController.go
AppProfileCreate
func (ac *APIController) AppProfileCreate(prof *contivModel.AppProfile) error { log.Infof("Received AppProfileCreate: %+v", prof) // Make sure tenant exists if prof.TenantName == "" { return core.Errorf("Invalid tenant name") } tenant := contivModel.FindTenant(prof.TenantName) if tenant == nil { return core.Errorf("Tenant %s not found", prof.TenantName) } for _, epg := range prof.EndpointGroups { epgKey := prof.TenantName + ":" + epg epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.AddLinkSet(&prof.LinkSets.EndpointGroups, epgObj) modeldb.AddLink(&epgObj.Links.AppProfile, prof) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } } // Setup links modeldb.AddLink(&prof.Links.Tenant, tenant) modeldb.AddLinkSet(&tenant.LinkSets.AppProfiles, prof) err := tenant.Write() if err != nil { log.Errorf("Error updating tenant state(%+v). Err: %v", tenant, err) return err } err = CreateAppNw(prof) return err }
go
func (ac *APIController) AppProfileCreate(prof *contivModel.AppProfile) error { log.Infof("Received AppProfileCreate: %+v", prof) // Make sure tenant exists if prof.TenantName == "" { return core.Errorf("Invalid tenant name") } tenant := contivModel.FindTenant(prof.TenantName) if tenant == nil { return core.Errorf("Tenant %s not found", prof.TenantName) } for _, epg := range prof.EndpointGroups { epgKey := prof.TenantName + ":" + epg epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.AddLinkSet(&prof.LinkSets.EndpointGroups, epgObj) modeldb.AddLink(&epgObj.Links.AppProfile, prof) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } } // Setup links modeldb.AddLink(&prof.Links.Tenant, tenant) modeldb.AddLinkSet(&tenant.LinkSets.AppProfiles, prof) err := tenant.Write() if err != nil { log.Errorf("Error updating tenant state(%+v). Err: %v", tenant, err) return err } err = CreateAppNw(prof) return err }
[ "func", "(", "ac", "*", "APIController", ")", "AppProfileCreate", "(", "prof", "*", "contivModel", ".", "AppProfile", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "prof", ")", "\n\n", "// Make sure tenant exists", "if", "prof", ".", "TenantName", "==", "\"", "\"", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenant", ":=", "contivModel", ".", "FindTenant", "(", "prof", ".", "TenantName", ")", "\n", "if", "tenant", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "prof", ".", "TenantName", ")", "\n", "}", "\n\n", "for", "_", ",", "epg", ":=", "range", "prof", ".", "EndpointGroups", "{", "epgKey", ":=", "prof", ".", "TenantName", "+", "\"", "\"", "+", "epg", "\n", "epgObj", ":=", "contivModel", ".", "FindEndpointGroup", "(", "epgKey", ")", "\n", "if", "epgObj", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "epgKey", ")", "\n", "}", "\n", "modeldb", ".", "AddLinkSet", "(", "&", "prof", ".", "LinkSets", ".", "EndpointGroups", ",", "epgObj", ")", "\n", "modeldb", ".", "AddLink", "(", "&", "epgObj", ".", "Links", ".", "AppProfile", ",", "prof", ")", "\n", "err", ":=", "epgObj", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgObj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Setup links", "modeldb", ".", "AddLink", "(", "&", "prof", ".", "Links", ".", "Tenant", ",", "tenant", ")", "\n", "modeldb", ".", "AddLinkSet", "(", "&", "tenant", ".", "LinkSets", ".", "AppProfiles", ",", "prof", ")", "\n\n", "err", ":=", "tenant", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "tenant", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "err", "=", "CreateAppNw", "(", "prof", ")", "\n", "return", "err", "\n", "}" ]
// AppProfileCreate creates app profile state
[ "AppProfileCreate", "creates", "app", "profile", "state" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L387-L427
8,193
contiv/netplugin
netmaster/objApi/apiController.go
AppProfileUpdate
func (ac *APIController) AppProfileUpdate(oldProf, newProf *contivModel.AppProfile) error { log.Infof("Received AppProfileUpdate: %+v, newProf: %+v", oldProf, newProf) // handle any epg addition for _, epg := range newProf.EndpointGroups { epgKey := newProf.TenantName + ":" + epg log.Infof("Add %s to %s", epgKey, newProf.AppProfileName) epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.AddLinkSet(&newProf.LinkSets.EndpointGroups, epgObj) // workaround for objdb update problem modeldb.AddLinkSet(&oldProf.LinkSets.EndpointGroups, epgObj) modeldb.AddLink(&epgObj.Links.AppProfile, newProf) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } } // handle any epg removal for _, epg := range oldProf.EndpointGroups { if !stringInSlice(epg, newProf.EndpointGroups) { epgKey := newProf.TenantName + ":" + epg log.Infof("Remove %s from %s", epgKey, newProf.AppProfileName) epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.RemoveLink(&epgObj.Links.AppProfile, oldProf) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } // workaround for objdb update problem modeldb.RemoveLinkSet(&oldProf.LinkSets.EndpointGroups, epgObj) } } // workaround for objdb update problem -- should fix model oldProf.EndpointGroups = newProf.EndpointGroups // update the app nw DeleteAppNw(oldProf) lErr := CreateAppNw(oldProf) return lErr }
go
func (ac *APIController) AppProfileUpdate(oldProf, newProf *contivModel.AppProfile) error { log.Infof("Received AppProfileUpdate: %+v, newProf: %+v", oldProf, newProf) // handle any epg addition for _, epg := range newProf.EndpointGroups { epgKey := newProf.TenantName + ":" + epg log.Infof("Add %s to %s", epgKey, newProf.AppProfileName) epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.AddLinkSet(&newProf.LinkSets.EndpointGroups, epgObj) // workaround for objdb update problem modeldb.AddLinkSet(&oldProf.LinkSets.EndpointGroups, epgObj) modeldb.AddLink(&epgObj.Links.AppProfile, newProf) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } } // handle any epg removal for _, epg := range oldProf.EndpointGroups { if !stringInSlice(epg, newProf.EndpointGroups) { epgKey := newProf.TenantName + ":" + epg log.Infof("Remove %s from %s", epgKey, newProf.AppProfileName) epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { return core.Errorf("EndpointGroup %s not found", epgKey) } modeldb.RemoveLink(&epgObj.Links.AppProfile, oldProf) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) return err } // workaround for objdb update problem modeldb.RemoveLinkSet(&oldProf.LinkSets.EndpointGroups, epgObj) } } // workaround for objdb update problem -- should fix model oldProf.EndpointGroups = newProf.EndpointGroups // update the app nw DeleteAppNw(oldProf) lErr := CreateAppNw(oldProf) return lErr }
[ "func", "(", "ac", "*", "APIController", ")", "AppProfileUpdate", "(", "oldProf", ",", "newProf", "*", "contivModel", ".", "AppProfile", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "oldProf", ",", "newProf", ")", "\n\n", "// handle any epg addition", "for", "_", ",", "epg", ":=", "range", "newProf", ".", "EndpointGroups", "{", "epgKey", ":=", "newProf", ".", "TenantName", "+", "\"", "\"", "+", "epg", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "epgKey", ",", "newProf", ".", "AppProfileName", ")", "\n", "epgObj", ":=", "contivModel", ".", "FindEndpointGroup", "(", "epgKey", ")", "\n", "if", "epgObj", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "epgKey", ")", "\n", "}", "\n", "modeldb", ".", "AddLinkSet", "(", "&", "newProf", ".", "LinkSets", ".", "EndpointGroups", ",", "epgObj", ")", "\n\n", "// workaround for objdb update problem", "modeldb", ".", "AddLinkSet", "(", "&", "oldProf", ".", "LinkSets", ".", "EndpointGroups", ",", "epgObj", ")", "\n\n", "modeldb", ".", "AddLink", "(", "&", "epgObj", ".", "Links", ".", "AppProfile", ",", "newProf", ")", "\n", "err", ":=", "epgObj", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgObj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// handle any epg removal", "for", "_", ",", "epg", ":=", "range", "oldProf", ".", "EndpointGroups", "{", "if", "!", "stringInSlice", "(", "epg", ",", "newProf", ".", "EndpointGroups", ")", "{", "epgKey", ":=", "newProf", ".", "TenantName", "+", "\"", "\"", "+", "epg", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "epgKey", ",", "newProf", ".", "AppProfileName", ")", "\n", "epgObj", ":=", "contivModel", ".", "FindEndpointGroup", "(", "epgKey", ")", "\n", "if", "epgObj", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "epgKey", ")", "\n", "}", "\n", "modeldb", ".", "RemoveLink", "(", "&", "epgObj", ".", "Links", ".", "AppProfile", ",", "oldProf", ")", "\n", "err", ":=", "epgObj", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgObj", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// workaround for objdb update problem", "modeldb", ".", "RemoveLinkSet", "(", "&", "oldProf", ".", "LinkSets", ".", "EndpointGroups", ",", "epgObj", ")", "\n", "}", "\n", "}", "\n\n", "// workaround for objdb update problem -- should fix model", "oldProf", ".", "EndpointGroups", "=", "newProf", ".", "EndpointGroups", "\n\n", "// update the app nw", "DeleteAppNw", "(", "oldProf", ")", "\n", "lErr", ":=", "CreateAppNw", "(", "oldProf", ")", "\n", "return", "lErr", "\n", "}" ]
// AppProfileUpdate updates app
[ "AppProfileUpdate", "updates", "app" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L430-L483
8,194
contiv/netplugin
netmaster/objApi/apiController.go
AppProfileDelete
func (ac *APIController) AppProfileDelete(prof *contivModel.AppProfile) error { log.Infof("Received AppProfileDelete: %+v", prof) tenant := contivModel.FindTenant(prof.TenantName) if tenant == nil { return core.Errorf("Tenant %s not found", prof.TenantName) } DeleteAppNw(prof) // remove all links for _, epg := range prof.EndpointGroups { epgKey := prof.TenantName + ":" + epg epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { log.Errorf("EndpointGroup %s not found", epgKey) continue } modeldb.RemoveLink(&epgObj.Links.AppProfile, prof) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) } } modeldb.RemoveLinkSet(&tenant.LinkSets.AppProfiles, prof) tenant.Write() return nil }
go
func (ac *APIController) AppProfileDelete(prof *contivModel.AppProfile) error { log.Infof("Received AppProfileDelete: %+v", prof) tenant := contivModel.FindTenant(prof.TenantName) if tenant == nil { return core.Errorf("Tenant %s not found", prof.TenantName) } DeleteAppNw(prof) // remove all links for _, epg := range prof.EndpointGroups { epgKey := prof.TenantName + ":" + epg epgObj := contivModel.FindEndpointGroup(epgKey) if epgObj == nil { log.Errorf("EndpointGroup %s not found", epgKey) continue } modeldb.RemoveLink(&epgObj.Links.AppProfile, prof) err := epgObj.Write() if err != nil { log.Errorf("Error updating epg state(%+v). Err: %v", epgObj, err) } } modeldb.RemoveLinkSet(&tenant.LinkSets.AppProfiles, prof) tenant.Write() return nil }
[ "func", "(", "ac", "*", "APIController", ")", "AppProfileDelete", "(", "prof", "*", "contivModel", ".", "AppProfile", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "prof", ")", "\n\n", "tenant", ":=", "contivModel", ".", "FindTenant", "(", "prof", ".", "TenantName", ")", "\n", "if", "tenant", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "prof", ".", "TenantName", ")", "\n", "}", "\n\n", "DeleteAppNw", "(", "prof", ")", "\n\n", "// remove all links", "for", "_", ",", "epg", ":=", "range", "prof", ".", "EndpointGroups", "{", "epgKey", ":=", "prof", ".", "TenantName", "+", "\"", "\"", "+", "epg", "\n", "epgObj", ":=", "contivModel", ".", "FindEndpointGroup", "(", "epgKey", ")", "\n", "if", "epgObj", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgKey", ")", "\n", "continue", "\n", "}", "\n", "modeldb", ".", "RemoveLink", "(", "&", "epgObj", ".", "Links", ".", "AppProfile", ",", "prof", ")", "\n", "err", ":=", "epgObj", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgObj", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "modeldb", ".", "RemoveLinkSet", "(", "&", "tenant", ".", "LinkSets", ".", "AppProfiles", ",", "prof", ")", "\n", "tenant", ".", "Write", "(", ")", "\n", "return", "nil", "\n", "}" ]
// AppProfileDelete delete the app
[ "AppProfileDelete", "delete", "the", "app" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L486-L514
8,195
contiv/netplugin
netmaster/objApi/apiController.go
EndpointGetOper
func (ac *APIController) EndpointGetOper(endpoint *contivModel.EndpointInspect) error { log.Infof("Received EndpointInspect: %+v", endpoint) stateDriver, err := utils.GetStateDriver() if err != nil { return err } readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = stateDriver // TODO avoid linear read epCfgs, err := readEp.ReadAll() if err == nil { for _, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) if strings.Contains(ep.EndpointID, endpoint.Oper.Key) || strings.Contains(ep.ContainerID, endpoint.Oper.Key) || strings.Contains(ep.EPCommonName, endpoint.Oper.Key) { endpoint.Oper.Network = ep.NetID endpoint.Oper.EndpointID = ep.EndpointID endpoint.Oper.ServiceName = ep.ServiceName endpoint.Oper.EndpointGroupID = ep.EndpointGroupID endpoint.Oper.EndpointGroupKey = ep.EndpointGroupKey endpoint.Oper.IpAddress = []string{ep.IPAddress, ep.IPv6Address} endpoint.Oper.MacAddress = ep.MacAddress endpoint.Oper.HomingHost = ep.HomingHost endpoint.Oper.IntfName = ep.IntfName endpoint.Oper.VtepIP = ep.VtepIP endpoint.Oper.Labels = fmt.Sprintf("%s", ep.Labels) endpoint.Oper.ContainerID = ep.ContainerID endpoint.Oper.ContainerName = ep.EPCommonName epOper := &drivers.OperEndpointState{} epOper.StateDriver = stateDriver err := epOper.Read(ep.NetID + "-" + ep.EndpointID) if err == nil { endpoint.Oper.VirtualPort = "v" + epOper.PortName } return nil } } } return fmt.Errorf("endpoint not found") }
go
func (ac *APIController) EndpointGetOper(endpoint *contivModel.EndpointInspect) error { log.Infof("Received EndpointInspect: %+v", endpoint) stateDriver, err := utils.GetStateDriver() if err != nil { return err } readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = stateDriver // TODO avoid linear read epCfgs, err := readEp.ReadAll() if err == nil { for _, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) if strings.Contains(ep.EndpointID, endpoint.Oper.Key) || strings.Contains(ep.ContainerID, endpoint.Oper.Key) || strings.Contains(ep.EPCommonName, endpoint.Oper.Key) { endpoint.Oper.Network = ep.NetID endpoint.Oper.EndpointID = ep.EndpointID endpoint.Oper.ServiceName = ep.ServiceName endpoint.Oper.EndpointGroupID = ep.EndpointGroupID endpoint.Oper.EndpointGroupKey = ep.EndpointGroupKey endpoint.Oper.IpAddress = []string{ep.IPAddress, ep.IPv6Address} endpoint.Oper.MacAddress = ep.MacAddress endpoint.Oper.HomingHost = ep.HomingHost endpoint.Oper.IntfName = ep.IntfName endpoint.Oper.VtepIP = ep.VtepIP endpoint.Oper.Labels = fmt.Sprintf("%s", ep.Labels) endpoint.Oper.ContainerID = ep.ContainerID endpoint.Oper.ContainerName = ep.EPCommonName epOper := &drivers.OperEndpointState{} epOper.StateDriver = stateDriver err := epOper.Read(ep.NetID + "-" + ep.EndpointID) if err == nil { endpoint.Oper.VirtualPort = "v" + epOper.PortName } return nil } } } return fmt.Errorf("endpoint not found") }
[ "func", "(", "ac", "*", "APIController", ")", "EndpointGetOper", "(", "endpoint", "*", "contivModel", ".", "EndpointInspect", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "endpoint", ")", "\n\n", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "readEp", ":=", "&", "mastercfg", ".", "CfgEndpointState", "{", "}", "\n", "readEp", ".", "StateDriver", "=", "stateDriver", "\n", "// TODO avoid linear read", "epCfgs", ",", "err", ":=", "readEp", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "_", ",", "epCfg", ":=", "range", "epCfgs", "{", "ep", ":=", "epCfg", ".", "(", "*", "mastercfg", ".", "CfgEndpointState", ")", "\n", "if", "strings", ".", "Contains", "(", "ep", ".", "EndpointID", ",", "endpoint", ".", "Oper", ".", "Key", ")", "||", "strings", ".", "Contains", "(", "ep", ".", "ContainerID", ",", "endpoint", ".", "Oper", ".", "Key", ")", "||", "strings", ".", "Contains", "(", "ep", ".", "EPCommonName", ",", "endpoint", ".", "Oper", ".", "Key", ")", "{", "endpoint", ".", "Oper", ".", "Network", "=", "ep", ".", "NetID", "\n", "endpoint", ".", "Oper", ".", "EndpointID", "=", "ep", ".", "EndpointID", "\n", "endpoint", ".", "Oper", ".", "ServiceName", "=", "ep", ".", "ServiceName", "\n", "endpoint", ".", "Oper", ".", "EndpointGroupID", "=", "ep", ".", "EndpointGroupID", "\n", "endpoint", ".", "Oper", ".", "EndpointGroupKey", "=", "ep", ".", "EndpointGroupKey", "\n", "endpoint", ".", "Oper", ".", "IpAddress", "=", "[", "]", "string", "{", "ep", ".", "IPAddress", ",", "ep", ".", "IPv6Address", "}", "\n", "endpoint", ".", "Oper", ".", "MacAddress", "=", "ep", ".", "MacAddress", "\n", "endpoint", ".", "Oper", ".", "HomingHost", "=", "ep", ".", "HomingHost", "\n", "endpoint", ".", "Oper", ".", "IntfName", "=", "ep", ".", "IntfName", "\n", "endpoint", ".", "Oper", ".", "VtepIP", "=", "ep", ".", "VtepIP", "\n", "endpoint", ".", "Oper", ".", "Labels", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ep", ".", "Labels", ")", "\n", "endpoint", ".", "Oper", ".", "ContainerID", "=", "ep", ".", "ContainerID", "\n", "endpoint", ".", "Oper", ".", "ContainerName", "=", "ep", ".", "EPCommonName", "\n\n", "epOper", ":=", "&", "drivers", ".", "OperEndpointState", "{", "}", "\n", "epOper", ".", "StateDriver", "=", "stateDriver", "\n", "err", ":=", "epOper", ".", "Read", "(", "ep", ".", "NetID", "+", "\"", "\"", "+", "ep", ".", "EndpointID", ")", "\n", "if", "err", "==", "nil", "{", "endpoint", ".", "Oper", ".", "VirtualPort", "=", "\"", "\"", "+", "epOper", ".", "PortName", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// EndpointGetOper retrieves glboal operational information
[ "EndpointGetOper", "retrieves", "glboal", "operational", "information" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L517-L562
8,196
contiv/netplugin
netmaster/objApi/apiController.go
endpointGroupCleanup
func endpointGroupCleanup(endpointGroup *contivModel.EndpointGroup) error { // delete the endpoint group state err := master.DeleteEndpointGroup(endpointGroup.TenantName, endpointGroup.GroupName) if err != nil { log.Errorf("Error deleting endpoint group %+v. Err: %v", endpointGroup, err) return err } // Detach the endpoint group from the Policies for _, policyName := range endpointGroup.Policies { policyKey := GetpolicyKey(endpointGroup.TenantName, policyName) // find the policy policy := contivModel.FindPolicy(policyKey) if policy == nil { log.Errorf("Could not find policy %s", policyName) continue } // detach policy to epg err := master.PolicyDetach(endpointGroup, policy) if err != nil && err != master.EpgPolicyExists { log.Errorf("Error detaching policy %s from epg %s", policyName, endpointGroup.Key) } // Remove links modeldb.RemoveLinkSet(&policy.LinkSets.EndpointGroups, endpointGroup) modeldb.RemoveLinkSet(&endpointGroup.LinkSets.Policies, policy) policy.Write() } // Cleanup any external contracts err = cleanupExternalContracts(endpointGroup) if err != nil { log.Errorf("Error cleaning up external contracts for epg %s", endpointGroup.Key) } // Remove the endpoint group from network and tenant link sets. nwObjKey := endpointGroup.TenantName + ":" + endpointGroup.NetworkName network := contivModel.FindNetwork(nwObjKey) if network != nil { modeldb.RemoveLinkSet(&network.LinkSets.EndpointGroups, endpointGroup) network.Write() } tenant := contivModel.FindTenant(endpointGroup.TenantName) if tenant != nil { modeldb.RemoveLinkSet(&tenant.LinkSets.EndpointGroups, endpointGroup) tenant.Write() } return nil }
go
func endpointGroupCleanup(endpointGroup *contivModel.EndpointGroup) error { // delete the endpoint group state err := master.DeleteEndpointGroup(endpointGroup.TenantName, endpointGroup.GroupName) if err != nil { log.Errorf("Error deleting endpoint group %+v. Err: %v", endpointGroup, err) return err } // Detach the endpoint group from the Policies for _, policyName := range endpointGroup.Policies { policyKey := GetpolicyKey(endpointGroup.TenantName, policyName) // find the policy policy := contivModel.FindPolicy(policyKey) if policy == nil { log.Errorf("Could not find policy %s", policyName) continue } // detach policy to epg err := master.PolicyDetach(endpointGroup, policy) if err != nil && err != master.EpgPolicyExists { log.Errorf("Error detaching policy %s from epg %s", policyName, endpointGroup.Key) } // Remove links modeldb.RemoveLinkSet(&policy.LinkSets.EndpointGroups, endpointGroup) modeldb.RemoveLinkSet(&endpointGroup.LinkSets.Policies, policy) policy.Write() } // Cleanup any external contracts err = cleanupExternalContracts(endpointGroup) if err != nil { log.Errorf("Error cleaning up external contracts for epg %s", endpointGroup.Key) } // Remove the endpoint group from network and tenant link sets. nwObjKey := endpointGroup.TenantName + ":" + endpointGroup.NetworkName network := contivModel.FindNetwork(nwObjKey) if network != nil { modeldb.RemoveLinkSet(&network.LinkSets.EndpointGroups, endpointGroup) network.Write() } tenant := contivModel.FindTenant(endpointGroup.TenantName) if tenant != nil { modeldb.RemoveLinkSet(&tenant.LinkSets.EndpointGroups, endpointGroup) tenant.Write() } return nil }
[ "func", "endpointGroupCleanup", "(", "endpointGroup", "*", "contivModel", ".", "EndpointGroup", ")", "error", "{", "// delete the endpoint group state", "err", ":=", "master", ".", "DeleteEndpointGroup", "(", "endpointGroup", ".", "TenantName", ",", "endpointGroup", ".", "GroupName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "endpointGroup", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Detach the endpoint group from the Policies", "for", "_", ",", "policyName", ":=", "range", "endpointGroup", ".", "Policies", "{", "policyKey", ":=", "GetpolicyKey", "(", "endpointGroup", ".", "TenantName", ",", "policyName", ")", "\n\n", "// find the policy", "policy", ":=", "contivModel", ".", "FindPolicy", "(", "policyKey", ")", "\n", "if", "policy", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "policyName", ")", "\n", "continue", "\n", "}", "\n\n", "// detach policy to epg", "err", ":=", "master", ".", "PolicyDetach", "(", "endpointGroup", ",", "policy", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "master", ".", "EpgPolicyExists", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "policyName", ",", "endpointGroup", ".", "Key", ")", "\n", "}", "\n\n", "// Remove links", "modeldb", ".", "RemoveLinkSet", "(", "&", "policy", ".", "LinkSets", ".", "EndpointGroups", ",", "endpointGroup", ")", "\n", "modeldb", ".", "RemoveLinkSet", "(", "&", "endpointGroup", ".", "LinkSets", ".", "Policies", ",", "policy", ")", "\n", "policy", ".", "Write", "(", ")", "\n", "}", "\n\n", "// Cleanup any external contracts", "err", "=", "cleanupExternalContracts", "(", "endpointGroup", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "endpointGroup", ".", "Key", ")", "\n", "}", "\n\n", "// Remove the endpoint group from network and tenant link sets.", "nwObjKey", ":=", "endpointGroup", ".", "TenantName", "+", "\"", "\"", "+", "endpointGroup", ".", "NetworkName", "\n", "network", ":=", "contivModel", ".", "FindNetwork", "(", "nwObjKey", ")", "\n", "if", "network", "!=", "nil", "{", "modeldb", ".", "RemoveLinkSet", "(", "&", "network", ".", "LinkSets", ".", "EndpointGroups", ",", "endpointGroup", ")", "\n", "network", ".", "Write", "(", ")", "\n", "}", "\n", "tenant", ":=", "contivModel", ".", "FindTenant", "(", "endpointGroup", ".", "TenantName", ")", "\n", "if", "tenant", "!=", "nil", "{", "modeldb", ".", "RemoveLinkSet", "(", "&", "tenant", ".", "LinkSets", ".", "EndpointGroups", ",", "endpointGroup", ")", "\n", "tenant", ".", "Write", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Cleans up state off endpointGroup and related objects.
[ "Cleans", "up", "state", "off", "endpointGroup", "and", "related", "objects", "." ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L579-L630
8,197
contiv/netplugin
netmaster/objApi/apiController.go
EndpointGroupGetOper
func (ac *APIController) EndpointGroupGetOper(endpointGroup *contivModel.EndpointGroupInspect) error { log.Infof("Received EndpointGroupInspect: %+v", endpointGroup) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } epgCfg := &mastercfg.EndpointGroupState{} epgCfg.StateDriver = stateDriver epgID := endpointGroup.Config.GroupName + ":" + endpointGroup.Config.TenantName if err := epgCfg.Read(epgID); err != nil { log.Errorf("Error fetching endpointGroup from mastercfg: %s", epgID) return err } nwName := epgCfg.NetworkName + "." + epgCfg.TenantName nwCfg := &mastercfg.CfgNetworkState{} nwCfg.StateDriver = stateDriver if err := nwCfg.Read(nwName); err != nil { log.Errorf("Error fetching network config %s", nwName) return err } endpointGroup.Oper.ExternalPktTag = epgCfg.ExtPktTag endpointGroup.Oper.PktTag = epgCfg.PktTag endpointGroup.Oper.NumEndpoints = epgCfg.EpCount endpointGroup.Oper.AvailableIPAddresses = netutils.ListAvailableIPs(epgCfg.EPGIPAllocMap, nwCfg.SubnetIP, nwCfg.SubnetLen) endpointGroup.Oper.AllocatedIPAddresses = netutils.ListAllocatedIPs(epgCfg.EPGIPAllocMap, epgCfg.IPPool, nwCfg.SubnetIP, nwCfg.SubnetLen) endpointGroup.Oper.GroupTag = epgCfg.GroupTag readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = stateDriver epCfgs, err := readEp.ReadAll() if err == nil { for _, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) if ep.EndpointGroupKey == epgID { epOper := contivModel.EndpointOper{} epOper.Network = ep.NetID epOper.EndpointID = ep.EndpointID epOper.ServiceName = ep.ServiceName epOper.EndpointGroupID = ep.EndpointGroupID epOper.EndpointGroupKey = ep.EndpointGroupKey epOper.IpAddress = []string{ep.IPAddress, ep.IPv6Address} epOper.MacAddress = ep.MacAddress epOper.HomingHost = ep.HomingHost epOper.IntfName = ep.IntfName epOper.VtepIP = ep.VtepIP epOper.Labels = fmt.Sprintf("%s", ep.Labels) epOper.ContainerID = ep.ContainerID epOper.ContainerName = ep.EPCommonName endpointGroup.Oper.Endpoints = append(endpointGroup.Oper.Endpoints, epOper) } } } return nil }
go
func (ac *APIController) EndpointGroupGetOper(endpointGroup *contivModel.EndpointGroupInspect) error { log.Infof("Received EndpointGroupInspect: %+v", endpointGroup) // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } epgCfg := &mastercfg.EndpointGroupState{} epgCfg.StateDriver = stateDriver epgID := endpointGroup.Config.GroupName + ":" + endpointGroup.Config.TenantName if err := epgCfg.Read(epgID); err != nil { log.Errorf("Error fetching endpointGroup from mastercfg: %s", epgID) return err } nwName := epgCfg.NetworkName + "." + epgCfg.TenantName nwCfg := &mastercfg.CfgNetworkState{} nwCfg.StateDriver = stateDriver if err := nwCfg.Read(nwName); err != nil { log.Errorf("Error fetching network config %s", nwName) return err } endpointGroup.Oper.ExternalPktTag = epgCfg.ExtPktTag endpointGroup.Oper.PktTag = epgCfg.PktTag endpointGroup.Oper.NumEndpoints = epgCfg.EpCount endpointGroup.Oper.AvailableIPAddresses = netutils.ListAvailableIPs(epgCfg.EPGIPAllocMap, nwCfg.SubnetIP, nwCfg.SubnetLen) endpointGroup.Oper.AllocatedIPAddresses = netutils.ListAllocatedIPs(epgCfg.EPGIPAllocMap, epgCfg.IPPool, nwCfg.SubnetIP, nwCfg.SubnetLen) endpointGroup.Oper.GroupTag = epgCfg.GroupTag readEp := &mastercfg.CfgEndpointState{} readEp.StateDriver = stateDriver epCfgs, err := readEp.ReadAll() if err == nil { for _, epCfg := range epCfgs { ep := epCfg.(*mastercfg.CfgEndpointState) if ep.EndpointGroupKey == epgID { epOper := contivModel.EndpointOper{} epOper.Network = ep.NetID epOper.EndpointID = ep.EndpointID epOper.ServiceName = ep.ServiceName epOper.EndpointGroupID = ep.EndpointGroupID epOper.EndpointGroupKey = ep.EndpointGroupKey epOper.IpAddress = []string{ep.IPAddress, ep.IPv6Address} epOper.MacAddress = ep.MacAddress epOper.HomingHost = ep.HomingHost epOper.IntfName = ep.IntfName epOper.VtepIP = ep.VtepIP epOper.Labels = fmt.Sprintf("%s", ep.Labels) epOper.ContainerID = ep.ContainerID epOper.ContainerName = ep.EPCommonName endpointGroup.Oper.Endpoints = append(endpointGroup.Oper.Endpoints, epOper) } } } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "EndpointGroupGetOper", "(", "endpointGroup", "*", "contivModel", ".", "EndpointGroupInspect", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "endpointGroup", ")", "\n\n", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "epgCfg", ":=", "&", "mastercfg", ".", "EndpointGroupState", "{", "}", "\n", "epgCfg", ".", "StateDriver", "=", "stateDriver", "\n", "epgID", ":=", "endpointGroup", ".", "Config", ".", "GroupName", "+", "\"", "\"", "+", "endpointGroup", ".", "Config", ".", "TenantName", "\n", "if", "err", ":=", "epgCfg", ".", "Read", "(", "epgID", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "epgID", ")", "\n", "return", "err", "\n", "}", "\n\n", "nwName", ":=", "epgCfg", ".", "NetworkName", "+", "\"", "\"", "+", "epgCfg", ".", "TenantName", "\n", "nwCfg", ":=", "&", "mastercfg", ".", "CfgNetworkState", "{", "}", "\n", "nwCfg", ".", "StateDriver", "=", "stateDriver", "\n", "if", "err", ":=", "nwCfg", ".", "Read", "(", "nwName", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "nwName", ")", "\n", "return", "err", "\n", "}", "\n\n", "endpointGroup", ".", "Oper", ".", "ExternalPktTag", "=", "epgCfg", ".", "ExtPktTag", "\n", "endpointGroup", ".", "Oper", ".", "PktTag", "=", "epgCfg", ".", "PktTag", "\n", "endpointGroup", ".", "Oper", ".", "NumEndpoints", "=", "epgCfg", ".", "EpCount", "\n", "endpointGroup", ".", "Oper", ".", "AvailableIPAddresses", "=", "netutils", ".", "ListAvailableIPs", "(", "epgCfg", ".", "EPGIPAllocMap", ",", "nwCfg", ".", "SubnetIP", ",", "nwCfg", ".", "SubnetLen", ")", "\n", "endpointGroup", ".", "Oper", ".", "AllocatedIPAddresses", "=", "netutils", ".", "ListAllocatedIPs", "(", "epgCfg", ".", "EPGIPAllocMap", ",", "epgCfg", ".", "IPPool", ",", "nwCfg", ".", "SubnetIP", ",", "nwCfg", ".", "SubnetLen", ")", "\n", "endpointGroup", ".", "Oper", ".", "GroupTag", "=", "epgCfg", ".", "GroupTag", "\n\n", "readEp", ":=", "&", "mastercfg", ".", "CfgEndpointState", "{", "}", "\n", "readEp", ".", "StateDriver", "=", "stateDriver", "\n", "epCfgs", ",", "err", ":=", "readEp", ".", "ReadAll", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "_", ",", "epCfg", ":=", "range", "epCfgs", "{", "ep", ":=", "epCfg", ".", "(", "*", "mastercfg", ".", "CfgEndpointState", ")", "\n", "if", "ep", ".", "EndpointGroupKey", "==", "epgID", "{", "epOper", ":=", "contivModel", ".", "EndpointOper", "{", "}", "\n", "epOper", ".", "Network", "=", "ep", ".", "NetID", "\n", "epOper", ".", "EndpointID", "=", "ep", ".", "EndpointID", "\n", "epOper", ".", "ServiceName", "=", "ep", ".", "ServiceName", "\n", "epOper", ".", "EndpointGroupID", "=", "ep", ".", "EndpointGroupID", "\n", "epOper", ".", "EndpointGroupKey", "=", "ep", ".", "EndpointGroupKey", "\n", "epOper", ".", "IpAddress", "=", "[", "]", "string", "{", "ep", ".", "IPAddress", ",", "ep", ".", "IPv6Address", "}", "\n", "epOper", ".", "MacAddress", "=", "ep", ".", "MacAddress", "\n", "epOper", ".", "HomingHost", "=", "ep", ".", "HomingHost", "\n", "epOper", ".", "IntfName", "=", "ep", ".", "IntfName", "\n", "epOper", ".", "VtepIP", "=", "ep", ".", "VtepIP", "\n", "epOper", ".", "Labels", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ep", ".", "Labels", ")", "\n", "epOper", ".", "ContainerID", "=", "ep", ".", "ContainerID", "\n", "epOper", ".", "ContainerName", "=", "ep", ".", "EPCommonName", "\n", "endpointGroup", ".", "Oper", ".", "Endpoints", "=", "append", "(", "endpointGroup", ".", "Oper", ".", "Endpoints", ",", "epOper", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// EndpointGroupGetOper inspects endpointGroup
[ "EndpointGroupGetOper", "inspects", "endpointGroup" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L942-L1003
8,198
contiv/netplugin
netmaster/objApi/apiController.go
EndpointGroupDelete
func (ac *APIController) EndpointGroupDelete(endpointGroup *contivModel.EndpointGroup) error { log.Infof("Received EndpointGroupDelete: %+v", endpointGroup) // if this is associated with an app profile, reject the delete if endpointGroup.Links.AppProfile.ObjKey != "" { return core.Errorf("Cannot delete %s, associated to appProfile %s", endpointGroup.GroupName, endpointGroup.Links.AppProfile.ObjKey) } // In swarm-mode work-flow, if epg is mapped to a docker network, reject the delete if master.GetClusterMode() == core.SwarmMode { dnet, err := docknet.GetDocknetState(endpointGroup.TenantName, endpointGroup.NetworkName, endpointGroup.GroupName) if err == nil { return fmt.Errorf("cannot delete group %s mapped to docker network %s", endpointGroup.GroupName, dnet.DocknetUUID) } if !strings.Contains(strings.ToLower(err.Error()), "key not found") { log.Errorf("Error getting docknet state for %s.%s. (retval = %s)", endpointGroup.TenantName, endpointGroup.GroupName, err.Error()) return err } log.Infof("No docknet state for %s.%s. (retval = %s)", endpointGroup.TenantName, endpointGroup.GroupName, err.Error()) } // get the netprofile structure by finding the netprofile profileKey := GetNetprofileKey(endpointGroup.TenantName, endpointGroup.NetProfile) netprofile := contivModel.FindNetprofile(profileKey) if netprofile != nil { // Remove linksets from netprofile. modeldb.RemoveLinkSet(&netprofile.LinkSets.EndpointGroups, endpointGroup) } err := endpointGroupCleanup(endpointGroup) if err != nil { log.Errorf("EPG cleanup failed: %+v", err) } return err }
go
func (ac *APIController) EndpointGroupDelete(endpointGroup *contivModel.EndpointGroup) error { log.Infof("Received EndpointGroupDelete: %+v", endpointGroup) // if this is associated with an app profile, reject the delete if endpointGroup.Links.AppProfile.ObjKey != "" { return core.Errorf("Cannot delete %s, associated to appProfile %s", endpointGroup.GroupName, endpointGroup.Links.AppProfile.ObjKey) } // In swarm-mode work-flow, if epg is mapped to a docker network, reject the delete if master.GetClusterMode() == core.SwarmMode { dnet, err := docknet.GetDocknetState(endpointGroup.TenantName, endpointGroup.NetworkName, endpointGroup.GroupName) if err == nil { return fmt.Errorf("cannot delete group %s mapped to docker network %s", endpointGroup.GroupName, dnet.DocknetUUID) } if !strings.Contains(strings.ToLower(err.Error()), "key not found") { log.Errorf("Error getting docknet state for %s.%s. (retval = %s)", endpointGroup.TenantName, endpointGroup.GroupName, err.Error()) return err } log.Infof("No docknet state for %s.%s. (retval = %s)", endpointGroup.TenantName, endpointGroup.GroupName, err.Error()) } // get the netprofile structure by finding the netprofile profileKey := GetNetprofileKey(endpointGroup.TenantName, endpointGroup.NetProfile) netprofile := contivModel.FindNetprofile(profileKey) if netprofile != nil { // Remove linksets from netprofile. modeldb.RemoveLinkSet(&netprofile.LinkSets.EndpointGroups, endpointGroup) } err := endpointGroupCleanup(endpointGroup) if err != nil { log.Errorf("EPG cleanup failed: %+v", err) } return err }
[ "func", "(", "ac", "*", "APIController", ")", "EndpointGroupDelete", "(", "endpointGroup", "*", "contivModel", ".", "EndpointGroup", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "endpointGroup", ")", "\n\n", "// if this is associated with an app profile, reject the delete", "if", "endpointGroup", ".", "Links", ".", "AppProfile", ".", "ObjKey", "!=", "\"", "\"", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "endpointGroup", ".", "GroupName", ",", "endpointGroup", ".", "Links", ".", "AppProfile", ".", "ObjKey", ")", "\n", "}", "\n\n", "// In swarm-mode work-flow, if epg is mapped to a docker network, reject the delete", "if", "master", ".", "GetClusterMode", "(", ")", "==", "core", ".", "SwarmMode", "{", "dnet", ",", "err", ":=", "docknet", ".", "GetDocknetState", "(", "endpointGroup", ".", "TenantName", ",", "endpointGroup", ".", "NetworkName", ",", "endpointGroup", ".", "GroupName", ")", "\n", "if", "err", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "endpointGroup", ".", "GroupName", ",", "dnet", ".", "DocknetUUID", ")", "\n", "}", "\n", "if", "!", "strings", ".", "Contains", "(", "strings", ".", "ToLower", "(", "err", ".", "Error", "(", ")", ")", ",", "\"", "\"", ")", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "endpointGroup", ".", "TenantName", ",", "endpointGroup", ".", "GroupName", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "err", "\n", "}", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "endpointGroup", ".", "TenantName", ",", "endpointGroup", ".", "GroupName", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "// get the netprofile structure by finding the netprofile", "profileKey", ":=", "GetNetprofileKey", "(", "endpointGroup", ".", "TenantName", ",", "endpointGroup", ".", "NetProfile", ")", "\n", "netprofile", ":=", "contivModel", ".", "FindNetprofile", "(", "profileKey", ")", "\n\n", "if", "netprofile", "!=", "nil", "{", "// Remove linksets from netprofile.", "modeldb", ".", "RemoveLinkSet", "(", "&", "netprofile", ".", "LinkSets", ".", "EndpointGroups", ",", "endpointGroup", ")", "\n", "}", "\n\n", "err", ":=", "endpointGroupCleanup", "(", "endpointGroup", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "err", "\n\n", "}" ]
// EndpointGroupDelete deletes end point group
[ "EndpointGroupDelete", "deletes", "end", "point", "group" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L1006-L1047
8,199
contiv/netplugin
netmaster/objApi/apiController.go
NetworkCreate
func (ac *APIController) NetworkCreate(network *contivModel.Network) error { log.Infof("Received NetworkCreate: %+v", network) // Make sure global settings is valid if err := validateGlobalConfig(network.Encap); err != nil { return fmt.Errorf("Global configuration is not ready: %v", err.Error()) } // Make sure tenant exists if network.TenantName == "" { return core.Errorf("Invalid tenant name") } tenant := contivModel.FindTenant(network.TenantName) if tenant == nil { return core.Errorf("Tenant not found") } for key := range tenant.LinkSets.Networks { networkDetail := contivModel.FindNetwork(key) if networkDetail == nil { log.Errorf("Network key %s not found", key) return fmt.Errorf("network key %s not found", key) } // Check for overlapping subnetv6 if existing and current subnetv6 is non-empty if network.Ipv6Subnet != "" && networkDetail.Ipv6Subnet != "" { flagv6 := netutils.IsOverlappingSubnetv6(network.Ipv6Subnet, networkDetail.Ipv6Subnet) if flagv6 == true { log.Errorf("Overlapping of Subnetv6 Networks") return errors.New("network " + networkDetail.NetworkName + " conflicts with subnetv6 " + network.Ipv6Subnet) } } // Check for overlapping subnet if existing and current subnet is non-empty if network.Subnet != "" && networkDetail.Subnet != "" { flag := netutils.IsOverlappingSubnet(network.Subnet, networkDetail.Subnet) if flag == true { log.Errorf("Overlapping of Networks") return errors.New("network " + networkDetail.NetworkName + " conflicts with subnet " + network.Subnet) } } } // If there is an EndpointGroup with the same name as this network, reject. nameClash := contivModel.FindEndpointGroup(network.Key) if nameClash != nil { return core.Errorf("EndpointGroup %s conflicts with the network name", nameClash.GroupName) } // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Build network config networkCfg := intent.ConfigNetwork{ Name: network.NetworkName, NwType: network.NwType, PktTagType: network.Encap, PktTag: network.PktTag, SubnetCIDR: network.Subnet, Gateway: network.Gateway, IPv6SubnetCIDR: network.Ipv6Subnet, IPv6Gateway: network.Ipv6Gateway, CfgdTag: network.CfgdTag, } // Create the network err = master.CreateNetwork(networkCfg, stateDriver, network.TenantName) if err != nil { log.Errorf("Error creating network {%+v}. Err: %v", network, err) return err } // Setup links modeldb.AddLink(&network.Links.Tenant, tenant) modeldb.AddLinkSet(&tenant.LinkSets.Networks, network) // Save the tenant too since we added the links err = tenant.Write() if err != nil { log.Errorf("Error updating tenant state(%+v). Err: %v", tenant, err) return err } return nil }
go
func (ac *APIController) NetworkCreate(network *contivModel.Network) error { log.Infof("Received NetworkCreate: %+v", network) // Make sure global settings is valid if err := validateGlobalConfig(network.Encap); err != nil { return fmt.Errorf("Global configuration is not ready: %v", err.Error()) } // Make sure tenant exists if network.TenantName == "" { return core.Errorf("Invalid tenant name") } tenant := contivModel.FindTenant(network.TenantName) if tenant == nil { return core.Errorf("Tenant not found") } for key := range tenant.LinkSets.Networks { networkDetail := contivModel.FindNetwork(key) if networkDetail == nil { log.Errorf("Network key %s not found", key) return fmt.Errorf("network key %s not found", key) } // Check for overlapping subnetv6 if existing and current subnetv6 is non-empty if network.Ipv6Subnet != "" && networkDetail.Ipv6Subnet != "" { flagv6 := netutils.IsOverlappingSubnetv6(network.Ipv6Subnet, networkDetail.Ipv6Subnet) if flagv6 == true { log.Errorf("Overlapping of Subnetv6 Networks") return errors.New("network " + networkDetail.NetworkName + " conflicts with subnetv6 " + network.Ipv6Subnet) } } // Check for overlapping subnet if existing and current subnet is non-empty if network.Subnet != "" && networkDetail.Subnet != "" { flag := netutils.IsOverlappingSubnet(network.Subnet, networkDetail.Subnet) if flag == true { log.Errorf("Overlapping of Networks") return errors.New("network " + networkDetail.NetworkName + " conflicts with subnet " + network.Subnet) } } } // If there is an EndpointGroup with the same name as this network, reject. nameClash := contivModel.FindEndpointGroup(network.Key) if nameClash != nil { return core.Errorf("EndpointGroup %s conflicts with the network name", nameClash.GroupName) } // Get the state driver stateDriver, err := utils.GetStateDriver() if err != nil { return err } // Build network config networkCfg := intent.ConfigNetwork{ Name: network.NetworkName, NwType: network.NwType, PktTagType: network.Encap, PktTag: network.PktTag, SubnetCIDR: network.Subnet, Gateway: network.Gateway, IPv6SubnetCIDR: network.Ipv6Subnet, IPv6Gateway: network.Ipv6Gateway, CfgdTag: network.CfgdTag, } // Create the network err = master.CreateNetwork(networkCfg, stateDriver, network.TenantName) if err != nil { log.Errorf("Error creating network {%+v}. Err: %v", network, err) return err } // Setup links modeldb.AddLink(&network.Links.Tenant, tenant) modeldb.AddLinkSet(&tenant.LinkSets.Networks, network) // Save the tenant too since we added the links err = tenant.Write() if err != nil { log.Errorf("Error updating tenant state(%+v). Err: %v", tenant, err) return err } return nil }
[ "func", "(", "ac", "*", "APIController", ")", "NetworkCreate", "(", "network", "*", "contivModel", ".", "Network", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "network", ")", "\n\n", "// Make sure global settings is valid", "if", "err", ":=", "validateGlobalConfig", "(", "network", ".", "Encap", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "// Make sure tenant exists", "if", "network", ".", "TenantName", "==", "\"", "\"", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tenant", ":=", "contivModel", ".", "FindTenant", "(", "network", ".", "TenantName", ")", "\n", "if", "tenant", "==", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "key", ":=", "range", "tenant", ".", "LinkSets", ".", "Networks", "{", "networkDetail", ":=", "contivModel", ".", "FindNetwork", "(", "key", ")", "\n", "if", "networkDetail", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n\n", "// Check for overlapping subnetv6 if existing and current subnetv6 is non-empty", "if", "network", ".", "Ipv6Subnet", "!=", "\"", "\"", "&&", "networkDetail", ".", "Ipv6Subnet", "!=", "\"", "\"", "{", "flagv6", ":=", "netutils", ".", "IsOverlappingSubnetv6", "(", "network", ".", "Ipv6Subnet", ",", "networkDetail", ".", "Ipv6Subnet", ")", "\n", "if", "flagv6", "==", "true", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", "+", "networkDetail", ".", "NetworkName", "+", "\"", "\"", "+", "network", ".", "Ipv6Subnet", ")", "\n", "}", "\n", "}", "\n\n", "// Check for overlapping subnet if existing and current subnet is non-empty", "if", "network", ".", "Subnet", "!=", "\"", "\"", "&&", "networkDetail", ".", "Subnet", "!=", "\"", "\"", "{", "flag", ":=", "netutils", ".", "IsOverlappingSubnet", "(", "network", ".", "Subnet", ",", "networkDetail", ".", "Subnet", ")", "\n", "if", "flag", "==", "true", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", "+", "networkDetail", ".", "NetworkName", "+", "\"", "\"", "+", "network", ".", "Subnet", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// If there is an EndpointGroup with the same name as this network, reject.", "nameClash", ":=", "contivModel", ".", "FindEndpointGroup", "(", "network", ".", "Key", ")", "\n", "if", "nameClash", "!=", "nil", "{", "return", "core", ".", "Errorf", "(", "\"", "\"", ",", "nameClash", ".", "GroupName", ")", "\n", "}", "\n\n", "// Get the state driver", "stateDriver", ",", "err", ":=", "utils", ".", "GetStateDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Build network config", "networkCfg", ":=", "intent", ".", "ConfigNetwork", "{", "Name", ":", "network", ".", "NetworkName", ",", "NwType", ":", "network", ".", "NwType", ",", "PktTagType", ":", "network", ".", "Encap", ",", "PktTag", ":", "network", ".", "PktTag", ",", "SubnetCIDR", ":", "network", ".", "Subnet", ",", "Gateway", ":", "network", ".", "Gateway", ",", "IPv6SubnetCIDR", ":", "network", ".", "Ipv6Subnet", ",", "IPv6Gateway", ":", "network", ".", "Ipv6Gateway", ",", "CfgdTag", ":", "network", ".", "CfgdTag", ",", "}", "\n\n", "// Create the network", "err", "=", "master", ".", "CreateNetwork", "(", "networkCfg", ",", "stateDriver", ",", "network", ".", "TenantName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "network", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Setup links", "modeldb", ".", "AddLink", "(", "&", "network", ".", "Links", ".", "Tenant", ",", "tenant", ")", "\n", "modeldb", ".", "AddLinkSet", "(", "&", "tenant", ".", "LinkSets", ".", "Networks", ",", "network", ")", "\n\n", "// Save the tenant too since we added the links", "err", "=", "tenant", ".", "Write", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "tenant", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// NetworkCreate creates network
[ "NetworkCreate", "creates", "network" ]
965773066d2b8ebed3514979949061a03d46fd20
https://github.com/contiv/netplugin/blob/965773066d2b8ebed3514979949061a03d46fd20/netmaster/objApi/apiController.go#L1050-L1139