Skip to content

Commit 1ba9772

Browse files
[NX-OS] Allow to configure spanning-tree-port-type on Interfaces
1 parent c83a19b commit 1ba9772

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

internal/provider/cisco/nxos/intf.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ func NewVrfMember(ifName, vrfName string) *VrfMember {
132132

133133
// SpanningTree represents the spanning tree configuration for an interface.
134134
type SpanningTree struct {
135-
AdminSt AdminSt `json:"adminSt"`
136-
Mode SpanningTreeMode `json:"mode"`
137-
IfName string `json:"-"`
135+
Mode SpanningTreeMode `json:"mode"`
136+
IfName string `json:"-"`
138137
}
139138

140139
func (*SpanningTree) IsListItem() {}
@@ -144,7 +143,6 @@ func (s *SpanningTree) XPath() string {
144143
}
145144

146145
func (s *SpanningTree) Default() {
147-
s.AdminSt = AdminStDisabled
148146
s.Mode = SpanningTreeModeDefault
149147
}
150148

internal/provider/cisco/nxos/provider.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"github.com/ironcore-dev/network-operator/internal/provider/cisco/gnmiext/v2"
2929
)
3030

31+
const SpanningTreePortTypeAnnotation = "nx.cisco.networking.metal.ironcore.dev/spanning-tree-port-type"
32+
3133
var (
3234
_ provider.Provider = (*Provider)(nil)
3335
_ provider.DeviceProvider = (*Provider)(nil)
@@ -790,6 +792,24 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
790792
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
791793
}
792794

795+
if req.Interface.Spec.Type == v1alpha1.InterfaceTypePhysical || req.Interface.Spec.Type == v1alpha1.InterfaceTypeAggregate {
796+
stp := new(SpanningTree)
797+
stp.IfName = name
798+
799+
m, ok := req.Interface.GetAnnotations()[SpanningTreePortTypeAnnotation]
800+
switch {
801+
case ok && slices.Contains([]SpanningTreeMode{SpanningTreeModeDefault, SpanningTreeModeEdge, SpanningTreeModeNetwork, SpanningTreeModeTrunk}, SpanningTreeMode(m)):
802+
stp.Mode = SpanningTreeMode(m)
803+
conf = append(conf, stp)
804+
default:
805+
if err := p.client.GetConfig(ctx, stp); err == nil {
806+
if err := p.client.Delete(ctx, stp); err != nil {
807+
return err
808+
}
809+
}
810+
}
811+
}
812+
793813
// Add the address items last, as they depend on the interface being created first.
794814
if addr != nil {
795815
conf = append(conf, addr)
@@ -821,10 +841,6 @@ func (p *Provider) DeleteInterface(ctx context.Context, req *provider.InterfaceR
821841
p.ID = name
822842
conf = append(conf, p)
823843

824-
stp := new(SpanningTree)
825-
stp.IfName = name
826-
conf = append(conf, stp)
827-
828844
case v1alpha1.InterfaceTypeLoopback:
829845
lb := new(Loopback)
830846
lb.ID = name
@@ -854,6 +870,12 @@ func (p *Provider) DeleteInterface(ctx context.Context, req *provider.InterfaceR
854870
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
855871
}
856872

873+
if req.Interface.Spec.Type == v1alpha1.InterfaceTypePhysical || req.Interface.Spec.Type == v1alpha1.InterfaceTypeAggregate {
874+
stp := new(SpanningTree)
875+
stp.IfName = name
876+
conf = append(conf, stp)
877+
}
878+
857879
return p.client.Delete(ctx, conf...)
858880
}
859881

0 commit comments

Comments
 (0)