Skip to content

Commit 2a6a1bb

Browse files
[NX-OS] Allow to configure spanning-tree-port-type on Interfaces
1 parent 45eee47 commit 2a6a1bb

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

@@ -466,6 +463,15 @@ const (
466463
SpanningTreeModeTrunk SpanningTreeMode = "trunk"
467464
)
468465

466+
func (s SpanningTreeMode) IsValid() bool {
467+
switch s {
468+
case SpanningTreeModeDefault, SpanningTreeModeEdge, SpanningTreeModeNetwork, SpanningTreeModeTrunk:
469+
return true
470+
default:
471+
return false
472+
}
473+
}
474+
469475
type PortChannelMode string
470476

471477
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)
@@ -810,6 +812,19 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
810812
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
811813
}
812814

815+
if (req.Interface.Spec.Type == v1alpha1.InterfaceTypePhysical && req.IPv4 == nil) || req.Interface.Spec.Type == v1alpha1.InterfaceTypeAggregate {
816+
stp := new(SpanningTree)
817+
stp.IfName = name
818+
stp.Mode = SpanningTreeModeDefault
819+
820+
m, ok := req.Interface.GetAnnotations()[SpanningTreePortTypeAnnotation]
821+
if mode := SpanningTreeMode(m); ok && mode.IsValid() {
822+
stp.Mode = mode
823+
}
824+
825+
conf = append(conf, stp)
826+
}
827+
813828
// Add the address items last, as they depend on the interface being created first.
814829
if addr != nil {
815830
conf = append(conf, addr)

0 commit comments

Comments
 (0)