Skip to content

Commit

Permalink
[agent] Add custom handler PortChannel enforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymatov authored and Frostman committed Mar 1, 2024
1 parent db3e0fa commit 926e59d
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions pkg/agent/dozer/bcm/spec_pc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,43 @@ var specPortChannelConfigsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecPort
}

var specPortChannelConfigEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel Config %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]",
Summary: "PortChannel Config %s",
CustomHandler: func(basePath string, key string, actual, desired *dozer.SpecPortChannelConfig, actions *ActionQueue) error {
if desired.SystemMAC != nil {
if err := specPortChannelConfigSystemMACEnforcer.Handle(basePath, key, actual, desired, actions); err != nil {
return errors.Wrap(err, "failed to handle system mac")
}
}

if err := specPortChannelConfigFallbackEnforcer.Handle(basePath, key, actual, desired, actions); err != nil {
return errors.Wrap(err, "failed to handle fallback")
}

return nil
},
}

var specPortChannelConfigSystemMACEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel System MAC %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/system_mac",
UpdateWeight: ActionWeightPortChannelConfigUpdate,
DeleteWeight: ActionWeightPortChannelConfigDelete,
Marshal: func(key string, value *dozer.SpecPortChannelConfig) (ygot.ValidatedGoStruct, error) {
ret := &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{}
if value.SystemMAC != nil {
ret.SystemMac = value.SystemMAC
}
ret.Fallback = value.Fallback
return ret, nil
return &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{
SystemMac: value.SystemMAC,
}, nil
},
}

var specPortChannelConfigFallbackEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel Fallback %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/fallback",
UpdateWeight: ActionWeightPortChannelConfigUpdate,
DeleteWeight: ActionWeightPortChannelConfigDelete,
Marshal: func(key string, value *dozer.SpecPortChannelConfig) (ygot.ValidatedGoStruct, error) {
return &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{
Fallback: value.Fallback,
}, nil
},
}

Expand Down

0 comments on commit 926e59d

Please sign in to comment.