_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q8000 | InspectNameserver | train | func (d *OvsDriver) InspectNameserver() ([]byte, error) {
if d.nameServer == nil {
return []byte{}, nil
}
ns, err := d.nameServer.InspectState()
jsonState, err := json.Marshal(ns)
if err != nil {
log.Errorf("Error encoding nameserver state. Err: %v", err)
return []byte{}, err
}
return jsonState, nil
} | go | {
"resource": ""
} |
q8001 | NewClient | train | func (cp *consulPlugin) NewClient(endpoints []string) (API, error) {
cc := new(ConsulClient)
if len(endpoints) == 0 {
endpoints = []string{"127.0.0.1:8500"}
}
// default consul config
cc.consulConfig = api.Config{Address: strings.TrimPrefix(endpoints[0], "http://")}
// Initialize service DB
cc.serviceDb = m... | go | {
"resource": ""
} |
q8002 | GetObj | train | func (cp *ConsulClient) GetObj(key string, retVal interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
resp, _, err := cp.client.KV().Get(key, &api.QueryOptions{RequireConsistent: true})
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(... | go | {
"resource": ""
} |
q8003 | ListDir | train | func (cp *ConsulClient) ListDir(key string) ([]string, error) {
key = processKey("/contiv.io/obj/" + processKey(key))
kvs, _, err := cp.client.KV().List(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i ... | go | {
"resource": ""
} |
q8004 | SetObj | train | func (cp *ConsulClient) SetObj(key string, value interface{}) error {
key = processKey("/contiv.io/obj/" + processKey(key))
// JSON format the object
jsonVal, err := json.Marshal(value)
if err != nil {
log.Errorf("Json conversion error. Err %v", err)
return err
}
_, err = cp.client.KV().Put(&api.KVPair{Key:... | go | {
"resource": ""
} |
q8005 | DelObj | train | func (cp *ConsulClient) DelObj(key string) error {
key = processKey("/contiv.io/obj/" + processKey(key))
_, err := cp.client.KV().Delete(key, nil)
if err != nil {
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxCons... | go | {
"resource": ""
} |
q8006 | ClearState | train | func (d *ConsulStateDriver) ClearState(key string) error {
key = processKey(key)
_, err := d.Client.KV().Delete(key, nil)
return err
} | go | {
"resource": ""
} |
q8007 | ReadState | train | func (d *ConsulStateDriver) ReadState(key string, value core.State,
unmarshal func([]byte, interface{}) error) error {
key = processKey(key)
encodedState, err := d.Read(key)
if err != nil {
return err
}
return unmarshal(encodedState, value)
} | go | {
"resource": ""
} |
q8008 | ReadAllState | train | func (d *ConsulStateDriver) ReadAllState(baseKey string, sType core.State,
unmarshal func([]byte, interface{}) error) ([]core.State, error) {
baseKey = processKey(baseKey)
return readAllStateCommon(d, baseKey, sType, unmarshal)
} | go | {
"resource": ""
} |
q8009 | AddLink | train | func AddLink(link *Link, obj ModelObj) {
link.ObjType = obj.GetType()
link.ObjKey = obj.GetKey()
} | go | {
"resource": ""
} |
q8010 | AddLinkSet | train | func AddLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// Allocate the linkset if its nil
if *linkSet == nil {
*linkSet = make(map[string]Link)
}
// add the link to map
(*linkSet)[obj.GetKey()] = Link{
ObjType: obj.GetType(),
ObjKey: obj.GetKey(),
}
return nil
} | go | {
"resource": ""
} |
q8011 | RemoveLinkSet | train | func RemoveLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
// check is linkset is nil
if *linkSet == nil {
return nil
}
// remove the link from map
delete(*linkSet, obj.GetKey())
return nil
} | go | {
"resource": ""
} |
q8012 | WriteObj | train | func WriteObj(objType, objKey string, value interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.SetObj(key, value)
if err != nil {
log.Errorf("Error storing object %s. Err: %v", key, err)
return err
}
return nil
} | go | {
"resource": ""
} |
q8013 | ReadObj | train | func ReadObj(objType, objKey string, retVal interface{}) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.GetObj(key, retVal)
if err != nil {
log.Errorf("Error reading object: %s. Err: %v", key, err)
return err
}
return nil
} | go | {
"resource": ""
} |
q8014 | DeleteObj | train | func DeleteObj(objType, objKey string) error {
key := "/modeldb/" + objType + "/" + objKey
err := cdb.DelObj(key)
if err != nil {
log.Errorf("Error deleting object: %s. Err: %v", key, err)
}
return nil
} | go | {
"resource": ""
} |
q8015 | ReadAllObj | train | func ReadAllObj(objType string) ([]string, error) {
key := "/modeldb/" + objType + "/"
return cdb.ListDir(key)
} | go | {
"resource": ""
} |
q8016 | GetEndpointGroupID | train | func GetEndpointGroupID(stateDriver core.StateDriver, groupName, tenantName string) (int, error) {
// If service name is not specified, we are done
if groupName == "" {
return 0, nil
}
epgKey := GetEndpointGroupKey(groupName, tenantName)
cfgEpGroup := &EndpointGroupState{}
cfgEpGroup.StateDriver = stateDriver
... | go | {
"resource": ""
} |
q8017 | getGwCIDR | train | func getGwCIDR(epgObj *contivModel.EndpointGroup, stateDriver core.StateDriver) (string, error) {
// get the subnet info and add it to ans
nwCfg := &mastercfg.CfgNetworkState{}
nwCfg.StateDriver = stateDriver
networkID := epgObj.NetworkName + "." + epgObj.TenantName
nErr := nwCfg.Read(networkID)
if nErr != nil {
... | go | {
"resource": ""
} |
q8018 | addPolicyContracts | train | func addPolicyContracts(csMap map[string]*contrSpec, epg *epgSpec, policy *contivModel.Policy) error {
for ruleName := range policy.LinkSets.Rules {
rule := contivModel.FindRule(ruleName)
if rule == nil {
errStr := fmt.Sprintf("rule %v not found", ruleName)
return errors.New(errStr)
}
if rule.FromIpAdd... | go | {
"resource": ""
} |
q8019 | CreateAppNw | train | func CreateAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
// Get the state driver
stateDriver, uErr := utils.GetState... | go | {
"resource": ""
} |
q8020 | DeleteAppNw | train | func DeleteAppNw(app *contivModel.AppProfile) error {
aciPresent, aErr := master.IsAciConfigured()
if aErr != nil {
log.Errorf("Couldn't read global config %v", aErr)
return aErr
}
if !aciPresent {
log.Debugf("ACI not configured")
return nil
}
ans := &appNwSpec{}
ans.TenantName = app.TenantName
ans.Ap... | go | {
"resource": ""
} |
q8021 | NewLock | train | func (cp *ConsulClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error) {
// Create a lock
return &consulLock{
name: name,
keyName: "contiv.io/lock/" + name,
myID: myID,
ttl: fmt.Sprintf("%ds", ttl),
eventChan: make(chan LockEvent, 1),
stopChan: make(chan struct{}, ... | go | {
"resource": ""
} |
q8022 | IsReleased | train | func (lk *consulLock) IsReleased() bool {
lk.mutex.Lock()
defer lk.mutex.Unlock()
return lk.isReleased
} | go | {
"resource": ""
} |
q8023 | createSession | train | func (lk *consulLock) createSession() error {
// session configuration
sessCfg := api.SessionEntry{
Name: lk.keyName,
Behavior: "delete",
LockDelay: 10 * time.Millisecond,
TTL: lk.ttl,
}
// Create consul session
sessionID, _, err := lk.client.Session().CreateNoChecks(&sessCfg, nil)
if err != ... | go | {
"resource": ""
} |
q8024 | renewSession | train | func (lk *consulLock) renewSession() {
for {
err := lk.client.Session().RenewPeriodic(lk.ttl, lk.sessionID, nil, lk.stopChan)
if err == nil || lk.IsReleased() {
// If lock was released, exit this go routine
return
}
// Create new consul session
err = lk.createSession()
if err != nil {
log.Errorf(... | go | {
"resource": ""
} |
q8025 | GetEndpoint | train | func GetEndpoint(epID string) (*drivers.OperEndpointState, error) {
// Get hold of the state driver
stateDriver, err := GetStateDriver()
if err != nil {
return nil, err
}
operEp := &drivers.OperEndpointState{}
operEp.StateDriver = stateDriver
err = operEp.Read(epID)
if err != nil {
return nil, err
}
ret... | go | {
"resource": ""
} |
q8026 | NewOvsdbDriver | train | func NewOvsdbDriver(bridgeName string, failMode string, vxlanUDPPort int) (*OvsdbDriver, error) {
// Create a new driver instance
d := new(OvsdbDriver)
d.bridgeName = bridgeName
d.vxlanUDPPort = fmt.Sprintf("%d", vxlanUDPPort)
// Connect to OVS
ovs, err := libovsdb.ConnectUnix("")
if err != nil {
log.Fatalf("... | go | {
"resource": ""
} |
q8027 | Update | train | func (d *OvsdbDriver) Update(context interface{}, tableUpdates libovsdb.TableUpdates) {
d.populateCache(tableUpdates)
intfUpds, ok := tableUpdates.Updates["Interface"]
if !ok {
return
}
for _, intfUpd := range intfUpds.Rows {
intf := intfUpd.New.Fields["name"]
oldLacpStatus, ok := intfUpd.Old.Fields["lacp_c... | go | {
"resource": ""
} |
q8028 | createDeleteBridge | train | func (d *OvsdbDriver) createDeleteBridge(bridgeName, failMode string, op oper) error {
namedUUIDStr := "netplugin"
brUUID := []libovsdb.UUID{{GoUuid: namedUUIDStr}}
protocols := []string{"OpenFlow10", "OpenFlow11", "OpenFlow12", "OpenFlow13"}
opStr := "insert"
if op != operCreateBridge {
opStr = "delete"
}
//... | go | {
"resource": ""
} |
q8029 | GetPortOrIntfNameFromID | train | func (d *OvsdbDriver) GetPortOrIntfNameFromID(id string, isPort bool) (string, error) {
table := portTable
if !isPort {
table = interfaceTable
}
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk thru all ports
for _, row := range d.cache[table] {
if extIDs, ok := row.Fields["external_ids"]; ok {
e... | go | {
"resource": ""
} |
q8030 | CreatePort | train | func (d *OvsdbDriver) CreatePort(intfName, intfType, id string, tag, burst int, bandwidth int64) error {
// intfName is assumed to be unique enough to become uuid
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{G... | go | {
"resource": ""
} |
q8031 | GetInterfacesInPort | train | func (d *OvsdbDriver) GetInterfacesInPort(portName string) []string {
var intfList []string
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for _, row := range d.cache["Port"] {
name := row.Fields["name"].(string)
if name == portName {
// Port found
// Iterate over the list of interfaces
switch (row.F... | go | {
"resource": ""
} |
q8032 | GetIntfInfo | train | func (d *OvsdbDriver) GetIntfInfo(uuid libovsdb.UUID) libovsdb.Row {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
for intfUUID, row := range d.cache["Interface"] {
if intfUUID == uuid {
return row
}
}
return libovsdb.Row{}
} | go | {
"resource": ""
} |
q8033 | CreatePortBond | train | func (d *OvsdbDriver) CreatePortBond(intfList []string, bondName string) error {
var err error
var ops []libovsdb.Operation
var intfUUIDList []libovsdb.UUID
opStr := "insert"
// Add all the interfaces to the interface table
for _, intf := range intfList {
intfUUIDStr := fmt.Sprintf("Intf%s", intf)
intfUUID ... | go | {
"resource": ""
} |
q8034 | DeletePortBond | train | func (d *OvsdbDriver) DeletePortBond(bondName string, intfList []string) error {
var ops []libovsdb.Operation
var condition []interface{}
portUUIDStr := bondName
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
opStr := "delete"
for _, intfName := range intfList {
// insert/delete a row in Interface table
... | go | {
"resource": ""
} |
q8035 | UpdatePolicingRate | train | func (d *OvsdbDriver) UpdatePolicingRate(intfName string, burst int, bandwidth int64) error {
bw := int(bandwidth)
intf := make(map[string]interface{})
intf["ingress_policing_rate"] = bw
intf["ingress_policing_burst"] = burst
condition := libovsdb.NewCondition("name", "==", intfName)
if condition == nil {
retu... | go | {
"resource": ""
} |
q8036 | CreateVtep | train | func (d *OvsdbDriver) CreateVtep(intfName string, vtepRemoteIP string) error {
portUUIDStr := intfName
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
portUUID := []libovsdb.UUID{{GoUuid: portUUIDStr}}
intfUUID := []libovsdb.UUID{{GoUuid: intfUUIDStr}}
opStr := "insert"
intfType := "vxlan"
var err error
// inse... | go | {
"resource": ""
} |
q8037 | GetOfpPortNo | train | func (d *OvsdbDriver) GetOfpPortNo(intfName string) (uint32, error) {
retryNo := 0
condition := libovsdb.NewCondition("name", "==", intfName)
selectOp := libovsdb.Operation{
Op: "select",
Table: "Interface",
Where: []interface{}{condition},
}
for {
row, err := d.ovs.Transact(ovsDataBase, selectOp)
i... | go | {
"resource": ""
} |
q8038 | IsVtepPresent | train | func (d *OvsdbDriver) IsVtepPresent(remoteIP string) (bool, string) {
d.cacheLock.RLock()
defer d.cacheLock.RUnlock()
// walk the local cache
for tName, table := range d.cache {
if tName == "Interface" {
for _, row := range table {
options := row.Fields["options"]
switch optMap := options.(type) {
... | go | {
"resource": ""
} |
q8039 | SetClusterMode | train | func SetClusterMode(cm string) error {
switch cm {
case core.Docker, core.Kubernetes, core.SwarmMode:
case core.Test: // internal mode used for integration testing
break
default:
return core.Errorf("%s not a valid cluster mode {%s | %s | %s}",
cm, core.Docker, core.Kubernetes, core.SwarmMode)
}
masterRTCf... | go | {
"resource": ""
} |
q8040 | CreateGlobal | train | func CreateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
log.Infof("Received global create with intent {%v}", gc)
var err error
gcfgUpdateList := []string{}
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
masterGc.Read("global")
gstate.GlobalMutex.Lock()
defer gs... | go | {
"resource": ""
} |
q8041 | DeleteGlobal | train | func DeleteGlobal(stateDriver core.StateDriver) error {
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
err := masterGc.Read("")
if err == nil {
err = masterGc.Clear()
if err != nil {
return err
}
}
// Setup global state
gCfg := &gstate.Cfg{}
gCfg.StateDriver = stateDriver
err ... | go | {
"resource": ""
} |
q8042 | DeleteTenant | train | func DeleteTenant(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
return validateTenantConfig(tenant)
} | go | {
"resource": ""
} |
q8043 | IsAciConfigured | train | func IsAciConfigured() (res bool, err error) {
// Get the state driver
stateDriver, uErr := utils.GetStateDriver()
if uErr != nil {
log.Warnf("Couldn't read global config %v", uErr)
return false, uErr
}
// read global config
masterGc := &mastercfg.GlobConfig{}
masterGc.StateDriver = stateDriver
uErr = mast... | go | {
"resource": ""
} |
q8044 | getVersion | train | func getVersion(w http.ResponseWriter, r *http.Request) {
ver := version.Get()
resp, err := json.Marshal(ver)
if err != nil {
http.Error(w,
core.Errorf("marshaling json failed. Error: %s", err).Error(),
http.StatusInternalServerError)
return
}
w.Write(resp)
return
} | go | {
"resource": ""
} |
q8045 | slaveProxyHandler | train | func slaveProxyHandler(w http.ResponseWriter, r *http.Request) {
log.Infof("proxy handler for %q ", r.URL.Path)
localIP, err := netutils.GetDefaultAddr()
if err != nil {
log.Fatalf("Error getting local IP address. Err: %v", err)
}
// get current holder of master lock
masterNode := leaderLock.GetHolder()
if m... | go | {
"resource": ""
} |
q8046 | ReadAll | train | func (s *CfgEndpointState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(endpointConfigPathPrefix, s, json.Unmarshal)
} | go | {
"resource": ""
} |
q8047 | WatchAll | train | func (s *CfgEndpointState) WatchAll(rsps chan core.WatchState) error {
return s.StateDriver.WatchAllState(endpointConfigPathPrefix, s, json.Unmarshal,
rsps)
} | go | {
"resource": ""
} |
q8048 | Init | train | func (d *MasterDaemon) Init() {
// set cluster mode
err := master.SetClusterMode(d.ClusterMode)
if err != nil {
log.Fatalf("Failed to set cluster-mode %q. Error: %s", d.ClusterMode, err)
}
// initialize state driver
d.stateDriver, err = utils.NewStateDriver(d.ClusterStoreDriver, &core.InstanceInfo{DbURL: d.Clu... | go | {
"resource": ""
} |
q8049 | agentDiscoveryLoop | train | func (d *MasterDaemon) agentDiscoveryLoop() {
// Create channels for watch thread
agentEventCh := make(chan objdb.WatchServiceEvent, 1)
watchStopCh := make(chan bool, 1)
// Start a watch on netplugin service
err := d.objdbClient.WatchService("netplugin", agentEventCh, watchStopCh)
if err != nil {
log.Fatalf("... | go | {
"resource": ""
} |
q8050 | getPluginAddress | train | func (d *MasterDaemon) getPluginAddress(hostName string) (string, error) {
srvList, err := d.objdbClient.GetService("netplugin.vtep")
if err != nil {
log.Errorf("Error getting netplugin nodes. Err: %v", err)
return "", err
}
for _, srv := range srvList {
if srv.Hostname == hostName {
return srv.HostAddr, ... | go | {
"resource": ""
} |
q8051 | ClearEndpoints | train | func (d *MasterDaemon) ClearEndpoints(stateDriver core.StateDriver, epCfgs *[]core.State, id, matchField string) error {
for _, epCfg := range *epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
if (matchField == "net" && ep.NetID == id) ||
(matchField == "group" && ep.ServiceName == id) ||
(matchField == "e... | go | {
"resource": ""
} |
q8052 | runLeader | train | func (d *MasterDaemon) runLeader() {
router := mux.NewRouter()
// Create a new api controller
apiConfig := &objApi.APIControllerConfig{
NetForwardMode: d.NetForwardMode,
NetInfraType: d.NetInfraType,
}
d.apiController = objApi.NewAPIController(router, d.objdbClient, apiConfig)
//Restore state from cluster... | go | {
"resource": ""
} |
q8053 | runFollower | train | func (d *MasterDaemon) runFollower() {
router := mux.NewRouter()
router.PathPrefix("/").HandlerFunc(slaveProxyHandler)
// Register netmaster service
d.registerService()
// just wait on stop channel
log.Infof("Listening in follower mode")
d.startListeners(router, d.stopFollowerChan)
log.Info("Exiting follower... | go | {
"resource": ""
} |
q8054 | becomeLeader | train | func (d *MasterDaemon) becomeLeader() {
// ask listener to stop
d.stopFollowerChan <- true
// set current state
d.currState = "leader"
// Run the HTTP listener
go d.runLeader()
} | go | {
"resource": ""
} |
q8055 | becomeFollower | train | func (d *MasterDaemon) becomeFollower() {
// ask listener to stop
d.stopLeaderChan <- true
time.Sleep(time.Second)
// set current state
d.currState = "follower"
// run follower loop
go d.runFollower()
} | go | {
"resource": ""
} |
q8056 | InitServices | train | func (d *MasterDaemon) InitServices() {
if d.ClusterMode == "kubernetes" {
isLeader := func() bool {
return d.currState == "leader"
}
networkpolicy.InitK8SServiceWatch(d.ControlURL, isLeader)
}
} | go | {
"resource": ""
} |
q8057 | RunMasterFsm | train | func (d *MasterDaemon) RunMasterFsm() {
var err error
masterURL := strings.Split(d.ControlURL, ":")
masterIP, masterPort := masterURL[0], masterURL[1]
if len(masterURL) != 2 {
log.Fatalf("Invalid netmaster URL")
}
// create new ofnet master
d.ofnetMaster = ofnet.NewOfnetMaster(masterIP, ofnet.OFNET_MASTER_PO... | go | {
"resource": ""
} |
q8058 | getMasterInfo | train | func (d *MasterDaemon) getMasterInfo() (map[string]interface{}, error) {
info := make(map[string]interface{})
// get local ip
localIP, err := netutils.GetDefaultAddr()
if err != nil {
return nil, errors.New("error getting local IP address")
}
// get current holder of master lock
leader := leaderLock.GetHolde... | go | {
"resource": ""
} |
q8059 | PolicyAttach | train | func PolicyAttach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// See if it already exists
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp != nil {
log.Errorf("EPG policy %s a... | go | {
"resource": ""
} |
q8060 | PolicyDetach | train | func PolicyDetach(epg *contivModel.EndpointGroup, policy *contivModel.Policy) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
epgpKey := epg.Key + ":" + policy.Key
// find the policy
gp := mastercfg.FindEpgPolicy(epgpKey)
if gp == nil {
log.Errorf("Epg policy %s does not e... | go | {
"resource": ""
} |
q8061 | PolicyAddRule | train | func PolicyAddRule(policy *contivModel.Policy, rule *contivModel.Rule) error {
// Dont install policies in ACI mode
if !isPolicyEnabled() {
return nil
}
// Walk all associated endpoint groups
for epgKey := range policy.LinkSets.EndpointGroups {
gpKey := epgKey + ":" + policy.Key
// Find the epg policy
gp... | go | {
"resource": ""
} |
q8062 | initStateDriver | train | func initStateDriver(clusterStore string) (core.StateDriver, error) {
// parse the state store URL
parts := strings.Split(clusterStore, "://")
if len(parts) < 2 {
return nil, core.Errorf("Invalid state-store URL %q", clusterStore)
}
stateStore := parts[0]
// Make sure we support the statestore type
switch sta... | go | {
"resource": ""
} |
q8063 | parseRange | train | func parseRange(rangeStr string) ([]uint, error) {
var values []uint
if rangeStr == "" {
return []uint{}, nil
}
// split ranges based on "," char
rangeList := strings.Split(rangeStr, ",")
for _, subrange := range rangeList {
minMax := strings.Split(strings.TrimSpace(subrange), "-")
if len(minMax) == 2 {
... | go | {
"resource": ""
} |
q8064 | processResource | train | func processResource(stateDriver core.StateDriver, rsrcName, rsrcVal string) error {
// Read global config
gCfg := gstate.Cfg{}
gCfg.StateDriver = stateDriver
err := gCfg.Read("")
if err != nil {
log.Errorf("error reading tenant cfg state. Error: %s", err)
return err
}
// process resource based on name
if ... | go | {
"resource": ""
} |
q8065 | ipnsExecute | train | func (cniReq *cniServer) ipnsExecute(namespace string, args []string) ([]byte, error) {
ipCmd := "ip"
ipArgs := []string{"netns", "exec", namespace}
ipArgs = append(ipArgs, args...)
cniLog.Infof("processing cmd: %v", ipArgs)
return exec.Command(ipCmd, ipArgs...).CombinedOutput()
} | go | {
"resource": ""
} |
q8066 | ipnsBatchExecute | train | func (cniReq *cniServer) ipnsBatchExecute(namespace string, args [][]string) ([]byte, error) {
for idx, arg1 := range args {
if out, err := cniReq.ipnsExecute(namespace, arg1); err != nil {
cniLog.Errorf("failed to execute [%d] %v %s, %s", idx, err, arg1, string(out))
return out, err
}
}
return nil, nil
... | go | {
"resource": ""
} |
q8067 | setUpAPIClient | train | func setUpAPIClient() *APIClient {
// Read config
err := k8sutils.GetK8SConfig(&contivK8Config)
if err != nil {
log.Errorf("Failed: %v", err)
return nil
}
return NewAPIClient(contivK8Config.K8sAPIServer, contivK8Config.K8sCa,
contivK8Config.K8sKey, contivK8Config.K8sCert, contivK8Config.K8sToken)
} | go | {
"resource": ""
} |
q8068 | InitKubServiceWatch | train | func InitKubServiceWatch(np *plugin.NetPlugin) {
watchClient := setUpAPIClient()
if watchClient == nil {
log.Fatalf("Could not init kubernetes API client")
}
svcCh := make(chan SvcWatchResp, 1)
epCh := make(chan EpWatchResp, 1)
go func() {
for {
select {
case svcEvent := <-svcCh:
switch svcEvent.o... | go | {
"resource": ""
} |
q8069 | InitCNIServer | train | func InitCNIServer(netplugin *plugin.NetPlugin) error {
netPlugin = netplugin
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not retrieve hostname: %v", err)
}
pluginHost = hostname
// Set up the api client instance
kubeAPIClient = setUpAPIClient()
if kubeAPIClient == nil {
log.Fatalf("... | go | {
"resource": ""
} |
q8070 | epCleanUp | train | func epCleanUp(req *epSpec) error {
// first delete from netplugin
// ignore any errors as this is best effort
netID := req.Network + "." + req.Tenant
pluginErr := netPlugin.DeleteEndpoint(netID + "-" + req.EndpointID)
// now delete from master
delReq := master.DeleteEndpointRequest{
TenantName: req.Tenant,
... | go | {
"resource": ""
} |
q8071 | createEP | train | func createEP(req *epSpec) (*epAttr, error) {
// if the ep already exists, treat as error for now.
netID := req.Network + "." + req.Tenant
ep, err := utils.GetEndpoint(netID + "-" + req.EndpointID)
if err == nil {
return nil, fmt.Errorf("the EP %s already exists", req.EndpointID)
}
// Build endpoint request
... | go | {
"resource": ""
} |
q8072 | getLink | train | func getLink(ifname string) (netlink.Link, error) {
// find the link
link, err := netlink.LinkByName(ifname)
if err != nil {
if !strings.Contains(err.Error(), "Link not found") {
log.Errorf("unable to find link %q. Error: %q", ifname, err)
return link, err
}
// try once more as sometimes (somehow) link c... | go | {
"resource": ""
} |
q8073 | nsToPID | train | func nsToPID(ns string) (int, error) {
// Make sure ns is well formed
ok := strings.HasPrefix(ns, "/proc/")
if !ok {
return -1, fmt.Errorf("invalid nw name space: %v", ns)
}
elements := strings.Split(ns, "/")
return strconv.Atoi(elements[2])
} | go | {
"resource": ""
} |
q8074 | setIfAttrs | train | func setIfAttrs(pid int, ifname, cidr, cidr6, newname string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
ipPath, err := osexec.LookPath("ip")
if err != nil {
return err
}
// find the link
link, err := getLink(ifname)
if err != nil {
log.Errorf("unable to find lin... | go | {
"resource": ""
} |
q8075 | setDefGw | train | func setDefGw(pid int, gw, gw6, intfName string) error {
nsenterPath, err := osexec.LookPath("nsenter")
if err != nil {
return err
}
routePath, err := osexec.LookPath("route")
if err != nil {
return err
}
// set default gw
nsPid := fmt.Sprintf("%d", pid)
out, err := osexec.Command(nsenterPath, "-t", nsPid,... | go | {
"resource": ""
} |
q8076 | getEPSpec | train | func getEPSpec(pInfo *cniapi.CNIPodAttr) (*epSpec, error) {
resp := epSpec{}
// Get labels from the kube api server
epg, err := kubeAPIClient.GetPodLabel(pInfo.K8sNameSpace, pInfo.Name,
"io.contiv.net-group")
if err != nil {
log.Errorf("Error getting epg. Err: %v", err)
return &resp, err
}
// Safe to igno... | go | {
"resource": ""
} |
q8077 | deletePod | train | func deletePod(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
resp := cniapi.RspAddPod{}
logEvent("del pod")
content, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Errorf("Failed to read request: %v", err)
return resp, err
}
pInfo := cniapi.CNIPodAttr{}
if err ... | go | {
"resource": ""
} |
q8078 | freeAddrOnErr | train | func freeAddrOnErr(nwCfg *mastercfg.CfgNetworkState, epgCfg *mastercfg.EndpointGroupState,
ipAddress string, pErr *error) {
if *pErr != nil {
log.Infof("Freeing %s on error", ipAddress)
networkReleaseAddress(nwCfg, epgCfg, ipAddress)
}
} | go | {
"resource": ""
} |
q8079 | CreateEndpoints | train | func CreateEndpoints(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
err := validateEndpointConfig(stateDriver, tenant)
if err != nil {
log.Errorf("error validating endpoint config. Error: %s", err)
return err
}
for _, network := range tenant.Networks {
nwCfg := &mastercfg.CfgNetworkState{... | go | {
"resource": ""
} |
q8080 | DeleteEndpoints | train | func DeleteEndpoints(hostAddr string) error {
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
readEp := &mastercfg.CfgEndpointState{}
readEp.StateDriver = stateDriver
epCfgs, err := readEp.ReadAll()
if err != nil {
return err
}
for _, epCfg := range epCfgs... | go | {
"resource": ""
} |
q8081 | DeleteEndpointID | train | func DeleteEndpointID(stateDriver core.StateDriver, epID string) (*mastercfg.CfgEndpointState, error) {
epCfg := &mastercfg.CfgEndpointState{}
var epgCfg *mastercfg.EndpointGroupState
epCfg.StateDriver = stateDriver
err := epCfg.Read(epID)
if err != nil {
return nil, err
}
nwCfg := &mastercfg.CfgNetworkState... | go | {
"resource": ""
} |
q8082 | CreateEpBindings | train | func CreateEpBindings(epBindings *[]intent.ConfigEP) error {
stateDriver, err := utils.GetStateDriver()
if err != nil {
return err
}
err = validateEpBindings(epBindings)
if err != nil {
log.Errorf("error validating the ep bindings. Error: %s", err)
return err
}
readEp := &mastercfg.CfgEndpointState{}
re... | go | {
"resource": ""
} |
q8083 | cleanupExternalContracts | train | func cleanupExternalContracts(endpointGroup *contivModel.EndpointGroup) error {
tenant := endpointGroup.TenantName
for _, contractsGrp := range endpointGroup.ExtContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj := contivModel.FindExtContractsGroup(contractsGrpKey)
if contractsGrpOb... | go | {
"resource": ""
} |
q8084 | setupExternalContracts | train | func setupExternalContracts(endpointGroup *contivModel.EndpointGroup, extContractsGrps []string) error {
// Validate presence and register consumed external contracts
tenant := endpointGroup.TenantName
for _, contractsGrp := range extContractsGrps {
contractsGrpKey := tenant + ":" + contractsGrp
contractsGrpObj ... | go | {
"resource": ""
} |
q8085 | ExtContractsGroupCreate | train | func (ac *APIController) ExtContractsGroupCreate(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupCreate: %+v", contractsGroup)
// Validate contracts type
if contractsGroup.ContractsType != "provided" && contractsGroup.ContractsType != "consumed" {
return core.Errorf("Co... | go | {
"resource": ""
} |
q8086 | ExtContractsGroupUpdate | train | func (ac *APIController) ExtContractsGroupUpdate(contractsGroup, params *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupUpdate: %+v, params: %+v", contractsGroup, params)
log.Errorf("Error: external contracts update not supported: %s", contractsGroup.ContractsGroupName)
return core.Erro... | go | {
"resource": ""
} |
q8087 | ExtContractsGroupDelete | train | func (ac *APIController) ExtContractsGroupDelete(contractsGroup *contivModel.ExtContractsGroup) error {
log.Infof("Received ExtContractsGroupDelete: %+v", contractsGroup)
// At this moment, we let the external contracts to be deleted only
// if there are no consumers of this external contracts group
if isExtContra... | go | {
"resource": ""
} |
q8088 | MakeHTTPHandler | train | func MakeHTTPHandler(handlerFunc httpAPIFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned er... | go | {
"resource": ""
} |
q8089 | UnknownAction | train | func UnknownAction(w http.ResponseWriter, r *http.Request) {
log.Infof("Unknown action at %q", r.URL.Path)
content, _ := ioutil.ReadAll(r.Body)
log.Infof("Body content: %s", string(content))
http.NotFound(w, r)
} | go | {
"resource": ""
} |
q8090 | HTTPPost | train | func HTTPPost(url string, req interface{}, resp interface{}) error {
// Convert the req to json
jsonStr, err := json.Marshal(req)
if err != nil {
log.Errorf("Error converting request data(%#v) to Json. Err: %v", req, err)
return err
}
// Perform HTTP POST operation
res, err := http.Post(url, "application/jso... | go | {
"resource": ""
} |
q8091 | HTTPDel | train | func HTTPDel(url string) error {
req, err := http.NewRequest("DELETE", url, nil)
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
// Check the response code
if res.StatusCode == http.StatusInternalServerError {
eBody, err := ioutil.ReadAll(res.Body)
if err != nil... | go | {
"resource": ""
} |
q8092 | NewContivClient | train | func NewContivClient(baseURL string) (*ContivClient, error) {
ok, err := regexp.Match(`^https?://`, []byte(baseURL))
if !ok {
return nil, errors.New("invalid URL: must begin with http:// or https://")
} else if err != nil {
return nil, err
}
client := ContivClient{
baseURL: baseURL,
customReq... | go | {
"resource": ""
} |
q8093 | SetAuthToken | train | func (c *ContivClient) SetAuthToken(token string) error {
// setting an auth token is only allowed on secure requests.
// if we didn't enforce this, the client could potentially send auth
// tokens in plain text across the network.
if !c.isHTTPS() {
return errors.New("setting auth token requires a https auth_pro... | go | {
"resource": ""
} |
q8094 | Login | train | func (c *ContivClient) Login(username, password string) (*http.Response, []byte, error) {
// login is only allowed over a secure channel
if !c.isHTTPS() {
return nil, nil, errors.New("login requires a https auth_proxy URL")
}
url := c.baseURL + LoginPath
// create the POST payload for login
lp := loginPayloa... | go | {
"resource": ""
} |
q8095 | addCustomRequestHeader | train | func (c *ContivClient) addCustomRequestHeader(name, value string) {
// lowercase the header name so we can easily check for duplicates in other places.
// there can legitimately be many headers with the same name, but in some cases
// (e.g., auth token) we want to enforce that there is only one.
// Go internally c... | go | {
"resource": ""
} |
q8096 | processCustomHeaders | train | func (c *ContivClient) processCustomHeaders(req *http.Request) {
for _, pair := range c.customRequestHeaders {
req.Header.Add(pair[0], pair[1])
}
} | go | {
"resource": ""
} |
q8097 | AciGwPost | train | func (c *ContivClient) AciGwPost(obj *AciGw) error {
// build key and URL
keyStr := obj.Name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http post the object
err := c.httpPost(url, obj)
if err != nil {
log.Debugf("Error creating aciGw %+v. Err: %v", obj, err)
return err
}
return nil
} | go | {
"resource": ""
} |
q8098 | AciGwList | train | func (c *ContivClient) AciGwList() (*[]*AciGw, error) {
// build key and URL
url := c.baseURL + "/api/v1/aciGws/"
// http get the object
var objList []*AciGw
err := c.httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting aciGws. Err: %v", err)
return nil, err
}
return &objList, nil
} | go | {
"resource": ""
} |
q8099 | AciGwDelete | train | func (c *ContivClient) AciGwDelete(name string) error {
// build key and URL
keyStr := name
url := c.baseURL + "/api/v1/aciGws/" + keyStr + "/"
// http get the object
err := c.httpDelete(url)
if err != nil {
log.Debugf("Error deleting aciGw %s. Err: %v", keyStr, err)
return err
}
return nil
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.