本文整理汇总了Golang中github.com/contiv/netplugin/core.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handlePreCreate
// Check that container is created with a 'netid' label. This helps us map the
// container to a network. This label could be put by one of docker clients (cli,
// compose etc)
func (adptr *PwrStrpAdptr) handlePreCreate(req *powerStripRequest) (*powerStripResponse, error) {
//structure of interesting fields in the create request
type DockerCreateRequest struct {
Labels map[string]string `json:"Labels"`
}
dockerReq := &DockerCreateRequest{}
err := json.Unmarshal([]byte(req.ClientRequest.Body), dockerReq)
if err != nil {
return nil, err
}
if netID, ok := dockerReq.Labels["netid"]; !ok || netID == "" {
return nil, core.Errorf("Container doesn't contain a valid 'netid' label. Labels: %+v Body: %q",
dockerReq, req.ClientRequest.Body)
} else if tenantID, ok := dockerReq.Labels["tenantid"]; !ok || tenantID == "" {
return nil, core.Errorf("Container doesn't contain a valid 'tenantid' label. Labels: %+v Body: %q",
dockerReq, req.ClientRequest.Body)
} else {
// XXX: record the outstanding network for which we are yet to receive a
// corresponding container-id (in server response). This simplifies things
// by assuming that there can't be two outstanding request. Need to revisit
// and handle this correctly.
adptr.outstandingNet = containerNet{tenantID: tenantID, netID: netID}
}
return makeClientRequest(req), nil
}
示例2: GetIPNumber
// GetIPNumber obtains the host id from the host IP. SEe `GetSubnetIP` for more information.
func GetIPNumber(subnetIP string, subnetLen uint, allocSubnetLen uint, hostIP string) (uint, error) {
if subnetLen > 32 || subnetLen < 8 {
return 0, core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return 0, core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
hostIPUint32, err := ipv4ToUint32(hostIP)
if err != nil {
return 0, core.Errorf("unable to convert hostIP %s to uint32", hostIP)
}
subnetIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return 0, core.Errorf("unable to convert subnetIP %s to uint32", subnetIP)
}
hostID := uint((hostIPUint32 - subnetIPUint32) >> (32 - allocSubnetLen))
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return 0, core.Errorf("hostIP %s is exceeding beyond subnet %s/%d, hostID %d",
hostIP, subnetIP, subnetLen, hostID)
}
return uint(hostID), nil
}
示例3: AppCreate
// AppCreate creates app state
func (ac *APIController) AppCreate(app *contivModel.App) error {
log.Infof("Received AppCreate: %+v", app)
// Make sure tenant exists
if app.TenantName == "" {
return core.Errorf("Invalid tenant name")
}
tenant := contivModel.FindTenant(app.TenantName)
if tenant == nil {
return core.Errorf("Tenant not found")
}
// Setup links
modeldb.AddLink(&app.Links.Tenant, tenant)
modeldb.AddLinkSet(&tenant.LinkSets.Apps, app)
// 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
}
CreateAppNw(app)
return nil
}
示例4: GetIPv6HostID
// GetIPv6HostID obtains the host id from the host IP. SEe `GetSubnetIP` for more information.
func GetIPv6HostID(subnetAddr string, subnetLen uint, hostAddr string) (string, error) {
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
// Initialize hostID
hostID := net.IPv6zero
var offset uint
// get the overlapping byte
offset = subnetLen / 8
subnetIP := net.ParseIP(subnetAddr)
if subnetIP == nil {
return "", core.Errorf("Invalid subnetAddr %s ", subnetAddr)
}
s := uint8(subnetIP[offset])
hostIP := net.ParseIP(hostAddr)
if hostIP == nil {
return "", core.Errorf("Invalid hostAddr %s ", hostAddr)
}
h := uint8(hostIP[offset])
hostID[offset] = byte(h - s)
// Copy the rest of the bytes
for i := (offset + 1); i < 16; i++ {
hostID[i] = hostIP[i]
offset++
}
return hostID.String(), nil
}
示例5: validateNetworkConfig
func validateNetworkConfig(tenant *intent.ConfigTenant) error {
var err error
if tenant.Name == "" {
return core.Errorf("null tenant name")
}
for _, network := range tenant.Networks {
if network.Name == "" {
core.Errorf("null network name")
}
err = checkPktTagType(network.PktTagType)
if err != nil {
return err
}
if network.SubnetCIDR != "" {
_, _, err = netutils.ParseCIDR(network.SubnetCIDR)
if err != nil {
return err
}
}
if network.Gateway != "" {
if net.ParseIP(network.Gateway) == nil {
return core.Errorf("invalid IP")
}
}
}
return err
}
示例6: GetSubnetIPv6
// GetSubnetIPv6 given a subnet IP and host identifier, calculates an IPv6 address
// within the subnet for use.
func GetSubnetIPv6(subnetAddr string, subnetLen uint, hostID string) (string, error) {
if subnetAddr == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 128 || subnetLen < 16 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
subnetIP := net.ParseIP(subnetAddr)
hostidIP := net.ParseIP(hostID)
hostIP := net.IPv6zero
var offset int
for offset = 0; offset < int(subnetLen/8); offset++ {
hostIP[offset] = subnetIP[offset]
}
// copy the overlapping byte in subnetIP and hostID
if subnetLen%8 != 0 && subnetIP[offset] != 0 {
if hostidIP[offset]&subnetIP[offset] != 0 {
return "", core.Errorf("host id %s exceeds subnet %s capacity ",
hostID, subnetAddr)
}
hostIP[offset] = hostidIP[offset] | subnetIP[offset]
offset++
}
for ; offset < len(hostidIP); offset++ {
hostIP[offset] = hostidIP[offset]
}
return hostIP.String(), nil
}
示例7: GetSubnetIP
// GetSubnetIP given a subnet IP and host identifier, calculates an IP within
// the subnet for use.
func GetSubnetIP(subnetIP string, subnetLen uint, allocSubnetLen, hostID uint) (string, error) {
if subnetIP == "" {
return "", core.Errorf("null subnet")
}
if subnetLen > 32 || subnetLen < 8 {
return "", core.Errorf("subnet length %d not supported", subnetLen)
}
if subnetLen > allocSubnetLen {
return "", core.Errorf("subnet length %d is bigger than subnet alloc len %d",
subnetLen, allocSubnetLen)
}
maxHosts := uint(1 << (allocSubnetLen - subnetLen))
if hostID >= maxHosts {
return "", core.Errorf("host id %d is beyond subnet's capacity %d",
hostID, maxHosts)
}
hostIPUint32, err := ipv4ToUint32(subnetIP)
if err != nil {
return "", core.Errorf("unable to convert subnet %s to uint32", subnetIP)
}
hostIPUint32 += uint32(hostID << (32 - allocSubnetLen))
return ipv4Uint32ToString(hostIPUint32)
}
示例8: validateEndpointConfig
func validateEndpointConfig(stateDriver core.StateDriver, tenant *intent.ConfigTenant) error {
var err error
if tenant.Name == "" {
return core.Errorf("null tenant name")
}
for _, network := range tenant.Networks {
if network.Name == "" {
core.Errorf("null network name")
}
for _, ep := range network.Endpoints {
if ep.Container == "" {
return core.Errorf("invalid container name for the endpoint")
}
if ep.IPAddress != "" {
if network.SubnetCIDR != "" {
log.Errorf("found ep with ip for auto-allocated net")
return core.Errorf("found ep with ip for auto-allocated net")
}
if net.ParseIP(ep.IPAddress) == nil {
return core.Errorf("invalid ep IP")
}
}
}
}
return err
}
示例9: performOvsdbOps
func (d *OvsdbDriver) performOvsdbOps(ops []libovsdb.Operation) error {
reply, _ := d.ovs.Transact(ovsDataBase, ops...)
if len(reply) < len(ops) {
return core.Errorf("Unexpected number of replies. Expected: %d, Recvd: %d",
len(ops), len(reply))
}
ok := true
errors := []string{}
for i, o := range reply {
if o.Error != "" && i < len(ops) {
errors = append(errors, fmt.Sprintf("%s(%s)", o.Error, o.Details))
ok = false
} else if o.Error != "" {
errors = append(errors, fmt.Sprintf("%s(%s)", o.Error, o.Details))
ok = false
}
}
if ok {
return nil
}
log.Errorf("OVS operation failed for op: %+v: Errors: %v", ops, errors)
return core.Errorf("ovs operation failed. Error(s): %v", errors)
}
示例10: Init
// Init the state from configuration.
func (r *AutoSubnetCfgResource) Init(rsrcCfg interface{}) error {
cfg, ok := rsrcCfg.(*AutoSubnetCfgResource)
if !ok {
return core.Errorf("Invalid type for subnet resource config")
}
r.SubnetPool = cfg.SubnetPool
r.SubnetPoolLen = cfg.SubnetPoolLen
r.AllocSubnetLen = cfg.AllocSubnetLen
if cfg.AllocSubnetLen < cfg.SubnetPoolLen {
return core.Errorf("AllocSubnetLen should be greater than or equal to SubnetPoolLen")
}
err := r.Write()
if err != nil {
return err
}
defer func() {
if err != nil {
r.Clear()
}
}()
allocSubnetSize := r.AllocSubnetLen - r.SubnetPoolLen
oper := &AutoSubnetOperResource{FreeSubnets: netutils.CreateBitset(allocSubnetSize).Complement()}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
err = oper.Write()
if err != nil {
return err
}
return nil
}
示例11: ParseTagRanges
// ParseTagRanges takes a string such as 12-24,48-64 and turns it into a series
// of TagRange.
func ParseTagRanges(ranges string, tagType string) ([]TagRange, error) {
var err error
if ranges == "" {
return []TagRange{{0, 0}}, nil
}
if tagType != "vlan" && tagType != "vxlan" {
return nil, core.Errorf("invalid tag type %s", tagType)
}
rangesStr := strings.Split(ranges, ",")
if len(rangesStr) > 1 && tagType == "vxlan" {
return nil, core.Errorf("do not support more than 2 vxlan tag ranges")
}
tagRanges := make([]TagRange, len(rangesStr), len(rangesStr))
for idx, oneRangeStr := range rangesStr {
oneRangeStr = strings.Trim(oneRangeStr, " ")
tagNums := strings.Split(oneRangeStr, "-")
if len(tagNums) > 2 {
return nil, core.Errorf("invalid tags %s, correct '10-50,70-100'",
oneRangeStr)
}
tagRanges[idx].Min, err = strconv.Atoi(tagNums[0])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Min, err)
}
tagRanges[idx].Max, err = strconv.Atoi(tagNums[1])
if err != nil {
return nil, core.Errorf("invalid integer %d conversion error '%s'",
tagRanges[idx].Max, err)
}
if tagRanges[idx].Min > tagRanges[idx].Max {
return nil, core.Errorf("invalid range %s, min is greater than max",
oneRangeStr)
}
if tagRanges[idx].Min < 1 {
return nil, core.Errorf("invalid range %s, values less than 1",
oneRangeStr)
}
if tagType == "vlan" && tagRanges[idx].Max > 4095 {
return nil, core.Errorf("invalid range %s, vlan values exceed 4095 max allowed",
oneRangeStr)
}
if tagType == "vxlan" && tagRanges[idx].Max > 65535 {
return nil, core.Errorf("invalid range %s, vlan values exceed 65535 max allowed",
oneRangeStr)
}
if tagType == "vxlan" &&
(tagRanges[idx].Max-tagRanges[idx].Min > 16000) {
return nil, core.Errorf("does not allow vxlan range to exceed 16000 range %s",
oneRangeStr)
}
}
return tagRanges, nil
}
示例12: checkErrors
func (gc *Cfg) checkErrors() error {
var err error
if net.ParseIP(gc.Auto.SubnetPool) == nil {
return core.Errorf("invalid ip address pool %s", gc.Auto.SubnetPool)
}
_, err = netutils.ParseTagRanges(gc.Auto.VLANs, "vlan")
if err != nil {
return err
}
_, err = netutils.ParseTagRanges(gc.Auto.VXLANs, "vxlan")
if err != nil {
return err
}
if gc.Deploy.DefaultNetType != "vlan" &&
gc.Deploy.DefaultNetType != "vxlan" {
return core.Errorf("unsupported net type %s", gc.Deploy.DefaultNetType)
}
if gc.Auto.SubnetLen > gc.Auto.AllocSubnetLen {
return core.Errorf("subnet size %d is smaller than subnets (%d) to be allocated from it",
gc.Auto.SubnetLen, gc.Auto.AllocSubnetLen)
}
return err
}
示例13: Allocate
// Allocate allocates a new resource.
func (r *AutoVXLANCfgResource) Allocate() (interface{}, error) {
oper := &AutoVXLANOperResource{}
oper.StateDriver = r.StateDriver
err := oper.Read(r.ID)
if err != nil {
return nil, err
}
vxlan, ok := oper.FreeVXLANs.NextSet(0)
if !ok {
return nil, core.Errorf("no vxlans available.")
}
vlan, ok := oper.FreeLocalVLANs.NextSet(0)
if !ok {
return nil, core.Errorf("no local vlans available.")
}
oper.FreeVXLANs.Clear(vxlan)
oper.FreeLocalVLANs.Clear(vlan)
err = oper.Write()
if err != nil {
return nil, err
}
return VXLANVLANPair{VXLAN: vxlan, VLAN: vlan}, nil
}
示例14: PolicyCreate
// PolicyCreate creates policy
func (ac *APIController) PolicyCreate(policy *contivModel.Policy) error {
log.Infof("Received PolicyCreate: %+v", policy)
// Make sure tenant exists
if policy.TenantName == "" {
return core.Errorf("Invalid tenant name")
}
tenant := contivModel.FindTenant(policy.TenantName)
if tenant == nil {
return core.Errorf("Tenant not found")
}
// Setup links
modeldb.AddLink(&policy.Links.Tenant, tenant)
modeldb.AddLinkSet(&tenant.LinkSets.Policies, policy)
// 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
}
示例15: VolumeCreate
// VolumeCreate creates a volume
func (ac *APIController) VolumeCreate(volume *contivModel.Volume) error {
log.Infof("Received VolumeCreate: %+v", volume)
// Make sure tenant exists
if volume.TenantName == "" {
return core.Errorf("Invalid tenant name")
}
tenant := contivModel.FindTenant(volume.TenantName)
if tenant == nil {
return core.Errorf("Tenant not found")
}
// Setup links
modeldb.AddLink(&volume.Links.Tenant, tenant)
modeldb.AddLinkSet(&tenant.LinkSets.Volumes, volume)
// Save the tenant too since we added the links
err := tenant.Write()
if err != nil {
return err
}
return nil
}