@@ -673,7 +673,9 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
673673 p .AccessVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .AccessVlan )
674674 case v1alpha1 .SwitchportModeTrunk :
675675 p .Mode = SwitchportModeTrunk
676- p .NativeVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .NativeVlan )
676+ if req .Interface .Spec .Switchport .NativeVlan != 0 {
677+ p .NativeVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .NativeVlan )
678+ }
677679 if len (req .Interface .Spec .Switchport .AllowedVlans ) > 0 {
678680 p .TrunkVlans = Range (req .Interface .Spec .Switchport .AllowedVlans )
679681 }
@@ -751,13 +753,32 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
751753 pc .AccessVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .AccessVlan )
752754 case v1alpha1 .SwitchportModeTrunk :
753755 pc .Mode = SwitchportModeTrunk
754- pc .NativeVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .NativeVlan )
756+ if req .Interface .Spec .Switchport .NativeVlan != 0 {
757+ pc .NativeVlan = fmt .Sprintf ("vlan-%d" , req .Interface .Spec .Switchport .NativeVlan )
758+ }
755759 if len (req .Interface .Spec .Switchport .AllowedVlans ) > 0 {
756760 pc .TrunkVlans = Range (req .Interface .Spec .Switchport .AllowedVlans )
757761 }
758762 default :
759763 return fmt .Errorf ("invalid switchport mode: %s" , req .Interface .Spec .Switchport .Mode )
760764 }
765+
766+ if req .Interface .Spec .Switchport .SpanningTreeMode != nil {
767+ stp := new (SpanningTree )
768+ switch * req .Interface .Spec .Switchport .SpanningTreeMode {
769+ case v1alpha1 .SpanningTreeModeEdge :
770+ stp .Mode = SpanningTreeModeEdge
771+ case v1alpha1 .SpanningTreeModeNetwork :
772+ stp .Mode = SpanningTreeModeNetwork
773+ case v1alpha1 .SpanningTreeModeTrunk :
774+ stp .Mode = SpanningTreeModeTrunk
775+ case v1alpha1 .SpanningTreeModeDefault :
776+ stp .Mode = SpanningTreeModeDefault
777+ default :
778+ return fmt .Errorf ("invalid spanning tree mode: %v" , * req .Interface .Spec .Switchport .SpanningTreeMode )
779+ }
780+ conf = append (conf , stp )
781+ }
761782 }
762783
763784 for _ , member := range req .Members {
@@ -774,9 +795,9 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
774795 }
775796
776797 // Delete the existing VPC interface entry if the MultiChassisID has changed or got removed.
777- if vpc := v .GetListItemByInterface (name ); vpc != nil {
778- if req .MultiChassisID == nil || int (* req .MultiChassisID ) != vpc .ID {
779- if err := p .client .Delete (ctx , vpc ); err != nil {
798+ if vpcdomain := v .GetListItemByInterface (name ); vpcdomain != nil {
799+ if req .MultiChassisID == nil || int (* req .MultiChassisID ) != vpcdomain .ID {
800+ if err := p .client .Delete (ctx , vpcdomain ); err != nil {
780801 return err
781802 }
782803 }
@@ -936,8 +957,8 @@ func (p *Provider) DeleteInterface(ctx context.Context, req *provider.InterfaceR
936957 }
937958
938959 // Make sure to delete any associated VPC interface.
939- if vpc := v .GetListItemByInterface (name ); vpc != nil {
940- conf = append (conf , vpc )
960+ if vpcdomain := v .GetListItemByInterface (name ); vpcdomain != nil {
961+ conf = append (conf , vpcdomain )
941962 }
942963
943964 case v1alpha1 .InterfaceTypeRoutedVLAN :
@@ -2141,8 +2162,8 @@ func (p *Provider) ResetSystemSettings(ctx context.Context) error {
21412162 )
21422163}
21432164
2144- // VPCStatus represents the operational status of a vPC configuration on the device.
2145- type VPCStatus struct {
2165+ // VPCDomainStatus represents the operational status of a vPC configuration on the device.
2166+ type VPCDomainStatus struct {
21462167 // KeepAliveStatus indicates whether the keepalive link is operationally up (true) or down (false).
21472168 KeepAliveStatus bool
21482169 // KeepAliveStatusMessage provides additional human-readable information returned by the device
@@ -2166,10 +2187,10 @@ func (p *Provider) EnsureVPCDomain(ctx context.Context, vpcdomain *nxv1alpha1.VP
21662187 f .Name = "vpc"
21672188 f .AdminSt = AdminStEnabled
21682189
2169- v := new (VPC )
2170- v .Id = vpc .Spec .DomainID
2190+ v := new (VPCDomain )
2191+ v .Id = vpcdomain .Spec .DomainID
21712192
2172- switch vpc .Spec .AdminState {
2193+ switch vpcdomain .Spec .AdminState {
21732194 case "enabled" :
21742195 v .AdminSt = NewOption (AdminStEnabled )
21752196 case "disabled" :
@@ -2199,7 +2220,7 @@ func (p *Provider) EnsureVPCDomain(ctx context.Context, vpcdomain *nxv1alpha1.VP
21992220 v .FastConvergence = NewOption (AdminStEnabled )
22002221 }
22012222
2202- peer := vpc .Spec .Peer
2223+ peer := vpcdomain .Spec .Peer
22032224
22042225 v .PeerSwitch = AdminStDisabled
22052226 if peer .Switch .Enabled {
@@ -2224,13 +2245,13 @@ func (p *Provider) EnsureVPCDomain(ctx context.Context, vpcdomain *nxv1alpha1.VP
22242245
22252246 ipaddr := net .ParseIP (peer .KeepAlive .Destination )
22262247 if ipaddr == nil {
2227- return fmt .Errorf ("nxos-vpc: invalid keep-alive destination IP address %q" , peer .KeepAlive .Destination )
2248+ return fmt .Errorf ("invalid keep-alive destination IP address %q" , peer .KeepAlive .Destination )
22282249 }
22292250 v .KeepAliveItems .DestIP = peer .KeepAlive .Destination
22302251
22312252 ipaddr = net .ParseIP (peer .KeepAlive .Source )
22322253 if ipaddr == nil {
2233- return fmt .Errorf ("nxos-vpc: invalid keep-alive source IP address %q" , peer .KeepAlive .Source )
2254+ return fmt .Errorf ("invalid keep-alive source IP address %q" , peer .KeepAlive .Source )
22342255 }
22352256 v .KeepAliveItems .SrcIP = peer .KeepAlive .Source
22362257
@@ -2247,16 +2268,16 @@ func (p *Provider) EnsureVPCDomain(ctx context.Context, vpcdomain *nxv1alpha1.VP
22472268 return p .client .Patch (ctx , f , v )
22482269}
22492270
2250- func (p * Provider ) DeleteVPC (ctx context.Context ) error {
2251- v := new (VPC )
2271+ func (p * Provider ) DeleteVPCDomain (ctx context.Context ) error {
2272+ v := new (VPCDomain )
22522273 return p .client .Delete (ctx , v )
22532274}
22542275
22552276// GetStatusVPC retrieves the current status of the vPC configuration on the device.
2256- func (p * Provider ) GetStatusVPC (ctx context.Context ) (VPCStatus , error ) {
2257- vpcOper := new (VPCOper )
2258- if err := p .client .GetState (ctx , vpcOper ); err != nil && ! errors .Is (err , gnmiext .ErrNil ) {
2259- return VPCStatus {}, err
2277+ func (p * Provider ) GetStatusVPCDomain (ctx context.Context ) (VPCDomainStatus , error ) {
2278+ vdOper := new (VPCDomainOper )
2279+ if err := p .client .GetState (ctx , vdOper ); err != nil && ! errors .Is (err , gnmiext .ErrNil ) {
2280+ return VPCDomainStatus {}, err
22602281 }
22612282
22622283 vpcSt := VPCDomainStatus {}
@@ -2284,15 +2305,15 @@ func (p *Provider) GetStatusVPC(ctx context.Context) (VPCStatus, error) {
22842305 case vpcRoleElectionNotDone :
22852306 vpcSt .Role = nxv1alpha1 .VPCDomainRoleUnknown
22862307 case vpcRolePrimary :
2287- vpcSt .Role = nxv1alpha1 .VPCRolePrimary
2308+ vpcSt .Role = nxv1alpha1 .VPCDomainRolePrimary
22882309 case vpcRoleSecondary :
2289- vpcSt .Role = nxv1alpha1 .VPCRoleSecondary
2310+ vpcSt .Role = nxv1alpha1 .VPCDomainRoleSecondary
22902311 case vpcRolePrimaryOperationalSecondary :
2291- vpcSt .Role = nxv1alpha1 .VPCRolePrimaryOperationalSecondary
2312+ vpcSt .Role = nxv1alpha1 .VPCDomainRolePrimaryOperationalSecondary
22922313 case vpcRoleSecondaryOperationalPrimary :
2293- vpcSt .Role = nxv1alpha1 .VPCRoleSecondaryOperationalPrimary
2314+ vpcSt .Role = nxv1alpha1 .VPCDomainRoleSecondaryOperationalPrimary
22942315 default :
2295- vpcSt .Role = nxv1alpha1 .VPCRoleUnknown
2316+ vpcSt .Role = nxv1alpha1 .VPCDomainRoleUnknown
22962317 }
22972318 return vpcSt , nil
22982319}
0 commit comments