@@ -41,6 +41,7 @@ func NewStackitClient(serviceAccountKey string) (*SdkStackitClient, error) {
4141var (
4242 // ErrServerNotFound indicates the server was not found (404)
4343 ErrServerNotFound = errors .New ("server not found" )
44+ ErrNicNotFound = errors .New ("nic not found" )
4445)
4546
4647// createIAASClient creates a new STACKIT SDK IAAS API client
@@ -320,6 +321,36 @@ func (c *SdkStackitClient) GetNICsForServer(ctx context.Context, projectID, regi
320321 return nics , nil
321322}
322323
324+ func (c * SdkStackitClient ) ListNICs (ctx context.Context , projectID , region , networkID string ) ([]* NIC , error ) {
325+ res , err := c .iaasClient .ListNics (ctx , projectID , region , networkID ).Execute ()
326+ if err != nil {
327+ return nil , fmt .Errorf ("SDK ListServerNICs failed: %w" , err )
328+ }
329+
330+ if res .Items == nil {
331+ return []* NIC {}, nil
332+ }
333+
334+ nics := make ([]* NIC , 0 )
335+ for _ , nic := range * res .Items {
336+ nics = append (nics , convertSDKNICtoNIC (& nic ))
337+ }
338+
339+ return nics , nil
340+ }
341+
342+ func (c * SdkStackitClient ) DeleteNIC (ctx context.Context , projectID , region , networkID , nicID string ) error {
343+ err := c .iaasClient .DeleteNic (ctx , projectID , region , networkID , nicID ).Execute ()
344+ if err != nil {
345+ // Check if error is 404 Not Found - this is OK (idempotent)
346+ if isNotFoundError (err ) {
347+ return fmt .Errorf ("%w: %v" , ErrNicNotFound , err )
348+ }
349+ return fmt .Errorf ("SDK DeleteNic failed: %w" , err )
350+ }
351+ return nil
352+ }
353+
323354func (c * SdkStackitClient ) UpdateNIC (ctx context.Context , projectID , region , networkID , nicID string , allowedAddresses []string ) (* NIC , error ) {
324355 addresses := make ([]iaas.AllowedAddressesInner , len (allowedAddresses ))
325356
@@ -361,6 +392,7 @@ func convertSDKNICtoNIC(nic *iaas.NIC) *NIC {
361392 ID : getStringValue (nic .Id ),
362393 NetworkID : getStringValue (nic .NetworkId ),
363394 AllowedAddresses : addresses ,
395+ Name : getStringValue (nic .Name ),
364396 }
365397}
366398
0 commit comments