本文整理汇总了Golang中github.com/contiv/netplugin/netmaster/mastercfg.CfgNetworkState.Read方法的典型用法代码示例。如果您正苦于以下问题:Golang CfgNetworkState.Read方法的具体用法?Golang CfgNetworkState.Read怎么用?Golang CfgNetworkState.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/netplugin/netmaster/mastercfg.CfgNetworkState
的用法示例。
在下文中一共展示了CfgNetworkState.Read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteEndpoint
// DeleteEndpoint deletes an endpoint by named identifier.
func (d *OvsDriver) DeleteEndpoint(id string) (err error) {
epOper := OvsOperEndpointState{}
epOper.StateDriver = d.oper.StateDriver
err = epOper.Read(id)
if err != nil {
return err
}
defer func() {
epOper.Clear()
}()
// Get the network state
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err = cfgNw.Read(epOper.NetID)
if err != nil {
return err
}
// Find the switch based on network type
var sw *OvsSwitch
if cfgNw.PktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
err = sw.DeletePort(&epOper)
if err != nil {
log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err)
}
return nil
}
示例2: networks
// XXX: This function should be returning logical state instead of driver state
func (d *daemon) networks(id string) ([]core.State, error) {
var (
err error
nw *mastercfg.CfgNetworkState
)
nw = &mastercfg.CfgNetworkState{}
if nw.StateDriver, err = utils.GetStateDriver(); err != nil {
return nil, err
}
if id == "all" {
return nw.ReadAll()
} else if err := nw.Read(id); err == nil {
return []core.State{core.State(nw)}, nil
}
return nil, core.Errorf("Unexpected code path")
}
示例3: CreateNetwork
// CreateNetwork creates a network by named identifier
func (d *OvsDriver) CreateNetwork(id string) error {
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err := cfgNw.Read(id)
if err != nil {
log.Errorf("Failed to read net %s \n", cfgNw.ID)
return err
}
log.Infof("create net %+v \n", cfgNw)
// Find the switch based on network type
var sw *OvsSwitch
if cfgNw.PktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
return sw.CreateNetwork(uint16(cfgNw.PktTag), uint32(cfgNw.ExtPktTag), cfgNw.Gateway, cfgNw.Tenant)
}
示例4: DeleteEndpoint
// DeleteEndpoint deletes an endpoint by named identifier.
func (d *OvsDriver) DeleteEndpoint(id string) error {
epOper := OvsOperEndpointState{}
epOper.StateDriver = d.oper.StateDriver
err := epOper.Read(id)
if err != nil {
return err
}
defer func() {
epOper.Clear()
}()
// Get the network state
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err = cfgNw.Read(epOper.NetID)
if err != nil {
return err
}
// Find the switch based on network type
var sw *OvsSwitch
if cfgNw.PktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
skipVethPair := (cfgNw.NwType == "infra")
err = sw.DeletePort(&epOper, skipVethPair)
if err != nil {
log.Errorf("Error deleting endpoint: %+v. Err: %v", epOper, err)
}
d.oper.localEpInfoMutex.Lock()
delete(d.oper.LocalEpInfo, id)
d.oper.localEpInfoMutex.Unlock()
return nil
}
示例5: CreateEndpoint
// CreateEndpoint creates an endpoint by named identifier
func (d *OvsDriver) CreateEndpoint(id string) error {
var (
err error
intfName string
epgKey string
epgBandwidth int64
dscp int
)
cfgEp := &mastercfg.CfgEndpointState{}
cfgEp.StateDriver = d.oper.StateDriver
err = cfgEp.Read(id)
if err != nil {
return err
}
// Get the nw config.
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err = cfgNw.Read(cfgEp.NetID)
if err != nil {
log.Errorf("Unable to get network %s. Err: %v", cfgEp.NetID, err)
return err
}
pktTagType := cfgNw.PktTagType
pktTag := cfgNw.PktTag
cfgEpGroup := &mastercfg.EndpointGroupState{}
// Read pkt tags from endpoint group if available
if cfgEp.EndpointGroupKey != "" {
cfgEpGroup.StateDriver = d.oper.StateDriver
err = cfgEpGroup.Read(cfgEp.EndpointGroupKey)
if err == nil {
log.Debugf("pktTag: %v ", cfgEpGroup.PktTag)
pktTagType = cfgEpGroup.PktTagType
pktTag = cfgEpGroup.PktTag
epgKey = cfgEp.EndpointGroupKey
dscp = cfgEpGroup.DSCP
log.Infof("Received endpoint create with bandwidth:%s", cfgEpGroup.Bandwidth)
if cfgEpGroup.Bandwidth != "" {
epgBandwidth = netutils.ConvertBandwidth(cfgEpGroup.Bandwidth)
}
} else if core.ErrIfKeyExists(err) == nil {
log.Infof("EPG %s not found: %v. will use network based tag ", cfgEp.EndpointGroupKey, err)
} else {
return err
}
}
// Find the switch based on network type
var sw *OvsSwitch
if pktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
// Skip Veth pair creation for infra nw endpoints
skipVethPair := (cfgNw.NwType == "infra")
operEp := &OvsOperEndpointState{}
operEp.StateDriver = d.oper.StateDriver
err = operEp.Read(id)
if core.ErrIfKeyExists(err) != nil {
return err
} else if err == nil {
// check if oper state matches cfg state. In case of mismatch cleanup
// up the EP and continue add new one. In case of match just return.
if operEp.Matches(cfgEp) {
log.Printf("Found matching oper state for ep %s, noop", id)
// Ask the switch to update the port
err = sw.UpdatePort(operEp.PortName, cfgEp, pktTag, cfgNw.PktTag, dscp, skipVethPair)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
}
return nil
}
log.Printf("Found mismatching oper state for Ep, cleaning it. Config: %+v, Oper: %+v",
cfgEp, operEp)
d.DeleteEndpoint(operEp.ID)
}
if cfgNw.NwType == "infra" {
// For infra nw, port name is network name
intfName = cfgNw.NetworkName
} else {
// Get the interface name to use
intfName, err = d.getIntfName()
if err != nil {
return err
}
}
// Get OVS port name
//.........这里部分代码省略.........
示例6: CreateEndpoint
// CreateEndpoint creates an endpoint by named identifier
func (d *OvsDriver) CreateEndpoint(id string) error {
var (
err error
intfName string
)
cfgEp := &mastercfg.CfgEndpointState{}
cfgEp.StateDriver = d.oper.StateDriver
err = cfgEp.Read(id)
if err != nil {
return err
}
// Ignore VTEP endpoints and uplink endpoints
// FIXME: we need to stop publiching these from netmaster
if cfgEp.VtepIP != "" {
return nil
}
if cfgEp.IntfName != "" {
return nil
}
cfgEpGroup := &mastercfg.EndpointGroupState{}
cfgEpGroup.StateDriver = d.oper.StateDriver
err = cfgEpGroup.Read(strconv.Itoa(cfgEp.EndpointGroupID))
if err == nil {
log.Debugf("pktTag: %v ", cfgEpGroup.PktTag)
} else if core.ErrIfKeyExists(err) == nil {
// FIXME: this should be deprecated once we remove old style intent
// In case EpGroup is not specified, get the tag from nw.
// this is mainly for the intent based system tests
log.Warnf("%v will use network based tag ", err)
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err1 := cfgNw.Read(cfgEp.NetID)
if err1 != nil {
log.Errorf("Unable to get tag neither epg nor nw")
return err1
}
cfgEpGroup.PktTagType = cfgNw.PktTagType
cfgEpGroup.PktTag = cfgNw.PktTag
} else {
return err
}
// Find the switch based on network type
var sw *OvsSwitch
if cfgEpGroup.PktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
operEp := &OvsOperEndpointState{}
operEp.StateDriver = d.oper.StateDriver
err = operEp.Read(id)
if core.ErrIfKeyExists(err) != nil {
return err
} else if err == nil {
// check if oper state matches cfg state. In case of mismatch cleanup
// up the EP and continue add new one. In case of match just return.
if operEp.Matches(cfgEp) {
log.Printf("Found matching oper state for ep %s, noop", id)
// Ask the switch to update the port
err = sw.UpdatePort(operEp.PortName, cfgEp, cfgEpGroup.PktTag)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
}
return nil
}
log.Printf("Found mismatching oper state for Ep, cleaning it. Config: %+v, Oper: %+v",
cfgEp, operEp)
d.DeleteEndpoint(operEp.ID)
}
// add an internal ovs port with vlan-tag information from the state
// XXX: revisit, the port name might need to come from user. Also revisit
// the algorithm to take care of port being deleted and reuse unused port
// numbers
d.oper.CurrPortNum++
err = d.oper.Write()
if err != nil {
return err
}
intfName = d.getIntfName()
// Ask the switch to create the port
err = sw.CreatePort(intfName, cfgEp, cfgEpGroup.PktTag)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
}
// Save the oper state
//.........这里部分代码省略.........
示例7: CreateEndpoint
// CreateEndpoint creates an endpoint by named identifier
func (d *OvsDriver) CreateEndpoint(id string) error {
var (
err error
intfName string
)
cfgEp := &mastercfg.CfgEndpointState{}
cfgEp.StateDriver = d.oper.StateDriver
err = cfgEp.Read(id)
if err != nil {
return err
}
// Get the nw config.
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err = cfgNw.Read(cfgEp.NetID)
if err != nil {
log.Errorf("Unable to get network %s. Err: %v", cfgEp.NetID, err)
return err
}
cfgEpGroup := &mastercfg.EndpointGroupState{}
cfgEpGroup.StateDriver = d.oper.StateDriver
err = cfgEpGroup.Read(strconv.Itoa(cfgEp.EndpointGroupID))
if err == nil {
log.Debugf("pktTag: %v ", cfgEpGroup.PktTag)
} else if core.ErrIfKeyExists(err) == nil {
log.Infof("%v will use network based tag ", err)
cfgEpGroup.PktTagType = cfgNw.PktTagType
cfgEpGroup.PktTag = cfgNw.PktTag
} else {
return err
}
// Find the switch based on network type
var sw *OvsSwitch
if cfgEpGroup.PktTagType == "vxlan" {
sw = d.switchDb["vxlan"]
} else {
sw = d.switchDb["vlan"]
}
operEp := &OvsOperEndpointState{}
operEp.StateDriver = d.oper.StateDriver
err = operEp.Read(id)
if core.ErrIfKeyExists(err) != nil {
return err
} else if err == nil {
// check if oper state matches cfg state. In case of mismatch cleanup
// up the EP and continue add new one. In case of match just return.
if operEp.Matches(cfgEp) {
log.Printf("Found matching oper state for ep %s, noop", id)
// Ask the switch to update the port
err = sw.UpdatePort(operEp.PortName, cfgEp, cfgEpGroup.PktTag)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
}
return nil
}
log.Printf("Found mismatching oper state for Ep, cleaning it. Config: %+v, Oper: %+v",
cfgEp, operEp)
d.DeleteEndpoint(operEp.ID)
}
// Get the interface name to use
intfName, err = d.getIntfName()
if err != nil {
return err
}
// Ask the switch to create the port
err = sw.CreatePort(intfName, cfgEp, cfgEpGroup.PktTag, cfgNw.PktTag)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
}
// Save the oper state
operEp = &OvsOperEndpointState{
NetID: cfgEp.NetID,
AttachUUID: cfgEp.AttachUUID,
ContName: cfgEp.ContName,
ServiceName: cfgEp.ServiceName,
IPAddress: cfgEp.IPAddress,
MacAddress: cfgEp.MacAddress,
IntfName: cfgEp.IntfName,
PortName: intfName,
HomingHost: cfgEp.HomingHost,
VtepIP: cfgEp.VtepIP}
operEp.StateDriver = d.oper.StateDriver
operEp.ID = id
err = operEp.Write()
if err != nil {
return err
}
//.........这里部分代码省略.........