Skip to content

Commit f5d4a38

Browse files
[NX-OS] Allow to configure spanning-tree-port-type on Interfaces
1 parent 9f49b03 commit f5d4a38

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

internal/provider/cisco/nxos/intf.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var (
2222
_ gnmiext.Configurable = (*PhysIfOperItems)(nil)
2323
_ gnmiext.Configurable = (*VrfMember)(nil)
2424
_ gnmiext.Configurable = (*SpanningTree)(nil)
25-
_ gnmiext.Defaultable = (*SpanningTree)(nil)
2625
_ gnmiext.Configurable = (*PortChannel)(nil)
2726
_ gnmiext.Configurable = (*PortChannelOperItems)(nil)
2827
_ gnmiext.Configurable = (*SwitchVirtualInterface)(nil)
@@ -132,9 +131,8 @@ func NewVrfMember(ifName, vrfName string) *VrfMember {
132131

133132
// SpanningTree represents the spanning tree configuration for an interface.
134133
type SpanningTree struct {
135-
AdminSt AdminSt `json:"adminSt"`
136-
Mode SpanningTreeMode `json:"mode"`
137-
IfName string `json:"-"`
134+
Mode SpanningTreeMode `json:"mode"`
135+
IfName string `json:"-"`
138136
}
139137

140138
func (*SpanningTree) IsListItem() {}
@@ -144,7 +142,6 @@ func (s *SpanningTree) XPath() string {
144142
}
145143

146144
func (s *SpanningTree) Default() {
147-
s.AdminSt = AdminStDisabled
148145
s.Mode = SpanningTreeModeDefault
149146
}
150147

@@ -460,6 +457,15 @@ const (
460457
SpanningTreeModeTrunk SpanningTreeMode = "trunk"
461458
)
462459

460+
func (s SpanningTreeMode) IsValid() bool {
461+
switch s {
462+
case SpanningTreeModeDefault, SpanningTreeModeEdge, SpanningTreeModeNetwork, SpanningTreeModeTrunk:
463+
return true
464+
default:
465+
return false
466+
}
467+
}
468+
463469
type PortChannelMode string
464470

465471
const (

internal/provider/cisco/nxos/provider.go

Lines changed: 15 additions & 0 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)
@@ -802,6 +804,19 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
802804
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
803805
}
804806

807+
if (req.Interface.Spec.Type == v1alpha1.InterfaceTypePhysical && req.IPv4 == nil) || req.Interface.Spec.Type == v1alpha1.InterfaceTypeAggregate {
808+
stp := new(SpanningTree)
809+
stp.IfName = name
810+
stp.Mode = SpanningTreeModeDefault
811+
812+
m, ok := req.Interface.GetAnnotations()[SpanningTreePortTypeAnnotation]
813+
if mode := SpanningTreeMode(m); ok && mode.IsValid() {
814+
stp.Mode = mode
815+
}
816+
817+
conf = append(conf, stp)
818+
}
819+
805820
// Add the address items last, as they depend on the interface being created first.
806821
if addr != nil {
807822
conf = append(conf, addr)

0 commit comments

Comments
 (0)