@@ -2,7 +2,9 @@ package iosxr
22
33import (
44 "context"
5+ "errors"
56 "fmt"
7+ "strconv"
68
79 "github.com/ironcore-dev/network-operator/internal/deviceutil"
810 "github.com/ironcore-dev/network-operator/internal/provider"
@@ -43,21 +45,22 @@ func (p *Provider) Disconnect(ctx context.Context, conn *deviceutil.Connection)
4345
4446func (p * Provider ) EnsureInterface (ctx context.Context , req * provider.InterfaceRequest ) error {
4547 if p .client == nil {
46- return fmt . Errorf ("client is not connected" )
48+ return errors . New ("client is not connected" )
4749 }
48- var name string = req .Interface .Spec .Name
50+ var name = req .Interface .Spec .Name
4951
50- var physif * PhisIf = NewIface (name )
52+ var physif = NewIface (name )
5153
5254 physif .Name = req .Interface .Spec .Name
5355 physif .Description = req .Interface .Spec .Description
5456
5557 physif .Statistics .LoadInterval = 30
5658 owner , err := ExractMTUOwnerFromIfaceName (name )
5759 if err != nil {
58- return fmt .Errorf ("failed to extract MTU owner from interface name %s: %w" , name , err )
60+ message := "failed to extract MTU owner from interface name" + name
61+ return errors .New (message )
5962 }
60- physif .MTUs = MTUs {MTU : []MTU {{MTU : uint16 ( req .Interface .Spec .MTU ) , Owner : string (owner )}}}
63+ physif .MTUs = MTUs {MTU : []MTU {{MTU : req .Interface .Spec .MTU , Owner : string (owner )}}}
6164
6265 // (fixme): for the moment it is enought to keep this static
6366 // option1: extend existing interface spec
@@ -66,31 +69,30 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.InterfaceR
6669 physif .Statistics .LoadInterval = uint8 (30 )
6770
6871 if len (req .Interface .Spec .IPv4 .Addresses ) == 0 {
69- return fmt .Errorf ("no IPv4 address configured for interface %s" , name )
72+ message := "no IPv4 address configured for interface " + name
73+ return errors .New (message )
7074 }
7175
7276 if len (req .Interface .Spec .IPv4 .Addresses ) > 1 {
73- return fmt .Errorf ("only a single primary IPv4 address is supported for interface %s" , name )
77+ message := "multiple IPv4 addresses configured for interface " + name
78+ return errors .New (message )
7479 }
7580
7681 // (fixme): support IPv6 addresses, IPv6 neighbor config
77- ip := req .Interface .Spec .IPv4 .Addresses [0 ].Prefix .Addr ().String ()
78- ipNet := req .Interface .Spec .IPv4 .Addresses [0 ].Prefix .Bits ()
79- if err != nil {
80- return fmt .Errorf ("failed to parse IPv4 address %s: %w" , req .Interface .Spec .IPv4 .Addresses [0 ], err )
81- }
82+ ip := req .Interface .Spec .IPv4 .Addresses [0 ].Addr ().String ()
83+ ipNet := req .Interface .Spec .IPv4 .Addresses [0 ].Bits ()
8284
8385 physif .IPv4Network = IPv4Network {
8486 Addresses : AddressesIPv4 {
8587 Primary : Primary {
8688 Address : ip ,
87- Netmask : fmt . Sprintf ( "%d" , ipNet ),
89+ Netmask : strconv . Itoa ( ipNet ),
8890 },
8991 },
9092 }
9193
9294 // Check if interface exists otherwise patch will fail
93- var tmpiFace * PhisIf = NewIface (name )
95+ var tmpiFace = NewIface (name )
9496 err = p .client .GetConfig (ctx , tmpiFace )
9597 if err != nil {
9698 // Interface does not exist, create it
@@ -114,7 +116,7 @@ func (p *Provider) DeleteInterface(ctx context.Context, req *provider.InterfaceR
114116 var iFace = NewIface (req .Interface .Spec .Name )
115117
116118 if p .client == nil {
117- return fmt . Errorf ("client is not connected" )
119+ return errors . New ("client is not connected" )
118120 }
119121
120122 err := p .client .Delete (ctx , iFace )
@@ -129,7 +131,7 @@ func (p *Provider) GetInterfaceStatus(ctx context.Context, req *provider.Interfa
129131 state .Name = req .Interface .Spec .Name
130132
131133 if p .client == nil {
132- return provider.InterfaceStatus {}, fmt . Errorf ("client is not connected" )
134+ return provider.InterfaceStatus {}, errors . New ("client is not connected" )
133135 }
134136
135137 err := p .client .GetState (ctx , state )
0 commit comments