Skip to content

Commit cb86bf5

Browse files
committed
[NXOS] Add annotation to force members on interface aggregates
Use `nx.cisco.networking.metal.ironcore.dev/channel-group-force` to tag an interface of type `Aggregate` on a Cisco NX device and force the addition of member interfaces to the port-channel. The value of the annotation is ignored.
1 parent ec6685e commit cb86bf5

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

internal/provider/cisco/nxos/intf.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ func NewVrfMember(ifName, vrfName string) *VrfMember {
130130

131131
// SpanningTree represents the spanning tree configuration for an interface.
132132
type SpanningTree struct {
133-
Mode SpanningTreeMode `json:"mode"`
134-
IfName string `json:"-"`
135-
Bridge Option[BridgeControl] `json:"bridge"`
133+
Mode SpanningTreeMode `json:"mode"`
134+
IfName string `json:"-"`
136135
}
137136

138137
func (*SpanningTree) IsListItem() {}
@@ -145,22 +144,6 @@ func (s *SpanningTree) Default() {
145144
s.Mode = SpanningTreeModeDefault
146145
}
147146

148-
type BridgeControl string
149-
150-
const (
151-
BridgeControlEnabled BridgeControl = "enabled"
152-
BridgeControlDisabled BridgeControl = "disabled"
153-
)
154-
155-
func (b BridgeControl) IsValid() bool {
156-
switch b {
157-
case BridgeControlEnabled, BridgeControlDisabled:
158-
return true
159-
default:
160-
return false
161-
}
162-
}
163-
164147
// PortChannel represents a port-channel (LAG) interface on a NX-OS device.
165148
type PortChannel struct {
166149
AccessVlan string `json:"accessVlan"`
@@ -184,11 +167,21 @@ type PortChannelMember struct {
184167
Force bool `json:"isMbrForce,omitempty"`
185168
}
186169

187-
func NewPortChannelMember(name string) *PortChannelMember {
188-
return &PortChannelMember{
170+
type PortChannelMemberOption func(*PortChannelMember)
171+
172+
func WithForce(force bool) PortChannelMemberOption {
173+
return func(m *PortChannelMember) { m.Force = force }
174+
}
175+
176+
func NewPortChannelMember(name string, opts ...PortChannelMemberOption) *PortChannelMember {
177+
m := &PortChannelMember{
189178
TDn: fmt.Sprintf("/System/intf-items/phys-items/PhysIf-list[id='%s']", name),
190179
Force: false,
191180
}
181+
for _, o := range opts {
182+
o(m)
183+
}
184+
return m
192185
}
193186

194187
func (m *PortChannelMember) Key() string { return m.TDn }

internal/provider/cisco/nxos/provider.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
const (
3333
SpanningTreePortTypeAnnotation = "nx.cisco.networking.metal.ironcore.dev/spanning-tree-port-type"
34+
ChannelGroupForceAnnotation = "nx.cisco.networking.metal.ironcore.dev/channel-group-force"
3435
)
3536

3637
var (
@@ -740,12 +741,13 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
740741
}
741742
}
742743

744+
_, force := req.Interface.GetAnnotations()[ChannelGroupForceAnnotation]
743745
for _, member := range req.Members {
744746
n, err := ShortNamePhysicalInterface(member.Spec.Name)
745747
if err != nil {
746748
return err
747749
}
748-
pc.RsmbrIfsItems.RsMbrIfsList.Set(NewPortChannelMember(n))
750+
pc.RsmbrIfsItems.RsMbrIfsList.Set(NewPortChannelMember(n, WithForce(force)))
749751
}
750752

751753
v := new(VPCIfItems)

0 commit comments

Comments
 (0)