Skip to content

Commit 441f270

Browse files
committed
feat(interface): add list interface function
Signed-off-by: Mark Sanders <[email protected]>
1 parent b654131 commit 441f270

File tree

12 files changed

+138
-69
lines changed

12 files changed

+138
-69
lines changed

.golangci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ run:
77
# output configuration options
88
output:
99
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
10-
format: colored-line-number
10+
formats: colored-line-number
1111

1212
linters-settings:
1313
funlen:
@@ -17,13 +17,18 @@ linters-settings:
1717
threshold: 200
1818
gocognit:
1919
min-complexity: 32
20+
gosec:
21+
excludes:
22+
# TODO: Re-enable the checks when fixes to gosec for false positives are done.
23+
# The issue began in gosec 2.21.0 and its inclusion in golangci-lint
24+
- G115 # Potential integer overflow when converting between integer types
2025

2126
linters:
2227
enable:
2328
- bodyclose
2429
- dogsled
2530
- errcheck
26-
- exportloopref
31+
- copyloopvar
2732
- funlen
2833
- gochecknoinits
2934
- gocognit

cmd/network/evpn/evpn-utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
44
// Copyright (c) 2024 Ericsson AB.
55

6-
// Package network implements the network related CLI commands
6+
// Package evpn implements the evpn related CLI commands
77
package evpn
88

99
import (

cmd/network/netintf/netintf.go

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,71 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (c) 2025 Dell Inc, or its subsidiaries.
33

4-
// Package network implements the network related CLI commands
4+
// Package netintf implements the network interface related CLI commands
55
package netintf
66

77
import (
8-
// "log"
9-
// "time"
8+
"context"
9+
"log"
1010

11-
// "github.com/opiproject/godpu/cmd/common"
11+
"github.com/opiproject/godpu/cmd/common"
12+
network "github.com/opiproject/godpu/network"
1213
"github.com/spf13/cobra"
14+
"google.golang.org/protobuf/encoding/protojson"
1315
)
1416

15-
16-
// ListNetInterfaces lists all Network Interface details from OPI server
17-
func ListNetInterfaces() *cobra.Command {
17+
// ListNetworkInterfaces lists all Network Interface details from OPI server
18+
func ListNetworkInterfaces() *cobra.Command {
1819
var pageSize int32
1920
var pageToken string
2021

2122
cmd := &cobra.Command{
2223
Use: "list-net-interfaces",
2324
Short: "List the network interfaces",
2425
Run: func(c *cobra.Command, _ []string) {
25-
// TODO: Add processing for Network Interface List
26-
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
26+
addr, err := c.Flags().GetString(common.AddrCmdLineArg)
27+
cobra.CheckErr(err)
28+
29+
timeout, err := c.Flags().GetDuration(common.TimeoutCmdLineArg)
30+
cobra.CheckErr(err)
31+
32+
tlsFiles, err := c.Flags().GetString(common.TLSFiles)
33+
cobra.CheckErr(err)
2734

28-
// tlsFiles, err := c.Flags().GetString(common.TLSFiles)
29-
// cobra.CheckErr(err)
35+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
3036

31-
// addr, err := c.Flags().GetString(common.AddrCmdLineArg)
32-
// cobra.CheckErr(err)
37+
netifClient, err := network.NewNetInterface(addr, tlsFiles)
38+
if err != nil {
39+
log.Fatalf("could not create gRPC client: %v", err)
40+
}
41+
defer cancel()
3342

34-
// evpnClient, err := network.NewLogicalBridge(addr, tlsFiles)
35-
// if err != nil {
36-
// log.Fatalf("could not create gRPC client: %v", err)
37-
// }
38-
// defer cancel()
43+
for {
44+
resp, err := netifClient.ListNetInterfaces(ctx, pageSize, pageToken)
45+
if err != nil {
46+
log.Fatalf("Failed to get items: %v", err)
47+
}
3948

40-
// for {
41-
// resp, err := evpnClient.ListLogicalBridges(ctx, pageSize, pageToken)
42-
// if err != nil {
43-
// log.Fatalf("Failed to get items: %v", err)
44-
// }
45-
// Process the server response
46-
// log.Println("List Network Interfaces:")
47-
// for _, lb := range resp.NetInterfaces {
48-
// log.Println("Interface with: ")
49-
// PrintLB(lb)
50-
// }
49+
// Process the response
50+
log.Println("List Network Interfaces:")
51+
for _, lif := range resp.NetInterfaces {
52+
log.Println("Interface with: ")
53+
common.PrintResponse(protojson.Format(lif))
54+
}
5155

52-
// Check if there are more pages to retrieve
53-
// if resp.NextPageToken == "" {
54-
// No more pages, break the loop
55-
// break
56-
// }
57-
// Update the page token for the next request
58-
// pageToken = resp.NextPageToken
59-
// }
56+
// Are there more pages
57+
if resp.NextPageToken == "" {
58+
// if no then break
59+
break
60+
}
61+
// update to next token
62+
pageToken = resp.NextPageToken
63+
}
6064
},
6165
}
6266

6367
cmd.Flags().Int32VarP(&pageSize, "pagesize", "s", 0, "Specify page size")
6468
cmd.Flags().StringVarP(&pageToken, "pagetoken", "t", "", "Specify the token")
6569

6670
return cmd
67-
}
71+
}

cmd/network/network.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"time"
1111

1212
"github.com/opiproject/godpu/cmd/common"
13-
"github.com/opiproject/godpu/cmd/network/netintf"
1413
"github.com/opiproject/godpu/cmd/network/evpn"
14+
"github.com/opiproject/godpu/cmd/network/netintf"
1515
"github.com/spf13/cobra"
1616
)
1717

@@ -39,7 +39,7 @@ func NewNetworkCommand() *cobra.Command {
3939
return cmd
4040
}
4141

42-
// NewNetworkCommand tests the Network functionality command
42+
// NewNetIntfCommand tests the Network functionality command
4343
func NewNetIntfCommand() *cobra.Command {
4444
cmd := &cobra.Command{
4545
Use: "intf",
@@ -57,7 +57,7 @@ func NewNetIntfCommand() *cobra.Command {
5757
flags := cmd.PersistentFlags()
5858
flags.Duration(common.TimeoutCmdLineArg, 10*time.Second, "timeout for a cmd")
5959

60-
cmd.AddCommand(netintf.ListNetInterfaces())
60+
cmd.AddCommand(netintf.ListNetworkInterfaces())
6161

6262
return cmd
6363
}

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ toolchain go1.23.4
77
require (
88
github.com/PraserX/ipconv v1.2.0
99
github.com/go-chi/chi/v5 v5.2.0
10-
github.com/go-ping/ping v1.2.0
1110
github.com/google/uuid v1.6.0
1211
github.com/lithammer/fuzzysearch v1.1.8
1312
github.com/onsi/ginkgo/v2 v2.22.2
1413
github.com/onsi/gomega v1.36.2
1514
github.com/opiproject/opi-api v0.0.0-20241209203403-595a3a1a838b
15+
github.com/prometheus-community/pro-bing v0.5.0
1616
github.com/spf13/cobra v1.8.1
1717
github.com/stretchr/testify v1.10.0
1818
go.einride.tech/aip v0.68.1
19-
golang.org/x/net v0.33.0
19+
golang.org/x/net v0.34.0
2020
golang.org/x/text v0.21.0
2121
google.golang.org/grpc v1.69.2
2222
google.golang.org/protobuf v1.36.1
@@ -36,8 +36,8 @@ require (
3636
github.com/spf13/pflag v1.0.5 // indirect
3737
github.com/stretchr/objx v0.5.2 // indirect
3838
golang.org/x/sync v0.10.0 // indirect
39-
golang.org/x/sys v0.28.0 // indirect
40-
golang.org/x/tools v0.28.0 // indirect
39+
golang.org/x/sys v0.29.0 // indirect
40+
golang.org/x/tools v0.29.0 // indirect
4141
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d // indirect
4242
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
4343
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
1010
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
1111
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
1212
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
13-
github.com/go-ping/ping v1.2.0 h1:vsJ8slZBZAXNCK4dPcI2PEE9eM9n9RbXbGouVQ/Y4yQ=
14-
github.com/go-ping/ping v1.2.0/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk=
1513
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
1614
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
1715
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
@@ -20,7 +18,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2018
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2119
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
2220
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
23-
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2421
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2522
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2623
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
@@ -41,6 +38,8 @@ github.com/opiproject/opi-api v0.0.0-20241209203403-595a3a1a838b h1:4k7lhYkkjo+j
4138
github.com/opiproject/opi-api v0.0.0-20241209203403-595a3a1a838b/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
4239
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4340
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
41+
github.com/prometheus-community/pro-bing v0.5.0 h1:Fq+4BUXKIvsPtXUY8K+04ud9dkAuFozqGmRAyNUpffY=
42+
github.com/prometheus-community/pro-bing v0.5.0/go.mod h1:1joR9oXdMEAcAJJvhs+8vNDvTg5thfAZcRFhcUozG2g=
4443
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
4544
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
4645
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -71,26 +70,23 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
7170
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
7271
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
7372
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
74-
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
7573
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
7674
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
77-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
78-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
75+
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
76+
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
7977
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
80-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8178
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8279
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8380
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
8481
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
8582
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
8683
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
87-
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8884
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8985
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9086
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9187
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
92-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
93-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
88+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
89+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
9490
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
9591
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
9692
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@@ -105,8 +101,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
105101
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
106102
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
107103
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
108-
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
109-
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
104+
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
105+
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
110106
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
111107
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d h1:H8tOf8XM88HvKqLTxe755haY6r1fqqzLbEnfrmLXlSA=
112108
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d/go.mod h1:2v7Z7gP2ZUOGsaFyxATQSRoBnKygqVq2Cwnvom7QiqY=

grpc/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Connector interface {
3232

3333
// New returns a new gRPC connector for the server at the given address
3434
func New(address string, tlsfile string) (Connector, error) {
35-
return NewWithDialler(address, grpc.Dial, tlsfile)
35+
return NewWithDialler(address, grpc.NewClient, tlsfile)
3636
}
3737

3838
// NewWithDialler returns a new gRPC client for the server at the given address using the gRPC dialler provided

ipsec/ipsec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"log"
1010
"time"
1111

12-
"github.com/go-ping/ping"
1312
pb "github.com/opiproject/opi-api/security/v1/gen/go"
13+
probing "github.com/prometheus-community/pro-bing"
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/credentials/insecure"
1616
)
@@ -175,7 +175,7 @@ func getVersion(ctx context.Context, client pb.IPsecServiceClient) {
175175
func doPing(a string) {
176176
// .NOTE: The container this test runs in is linked to the appropriate
177177
// strongSwan container.
178-
pinger, err := ping.NewPinger(a)
178+
pinger, err := probing.NewPinger(a)
179179
if err != nil {
180180
log.Fatalf("Cannot create Pinger")
181181
}
@@ -236,7 +236,7 @@ func loadConnections(ctx context.Context, client pb.IPsecServiceClient) {
236236

237237
func dialConnection(address string) error {
238238
var err error
239-
conn, err = grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
239+
conn, err = grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
240240
if err != nil {
241241
log.Printf("Failed to connect: %v", err)
242242
return err

network/netinterface.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2025 Dell Inc, or its subsidiaries.
3+
4+
// Package network implements the go library for OPI network functions
5+
package network
6+
7+
import (
8+
"context"
9+
"log"
10+
11+
grpcOpi "github.com/opiproject/godpu/grpc"
12+
pb "github.com/opiproject/opi-api/network/opinetcommon/v1alpha1/gen/go"
13+
"google.golang.org/grpc"
14+
)
15+
16+
// CreateNetInterfaceClient defines the function type used to retrieve NetInterfaceServiceClient
17+
type CreateNetInterfaceClient func(cc grpc.ClientConnInterface) pb.NetInterfaceServiceClient
18+
19+
// NetIntfClient is used for managing network interfaces on OPI server
20+
type NetIntfClient struct {
21+
c grpcOpi.Connector
22+
createNetInterfaceClient CreateNetInterfaceClient
23+
}
24+
25+
// NewNetInterface creates a network interface client for use with OPI server at the given address
26+
func NewNetInterface(addr string, tls string) (*NetIntfClient, error) {
27+
c, err := grpcOpi.New(addr, tls)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
return NewNetInterfaceWithArgs(c, pb.NewNetInterfaceServiceClient)
33+
}
34+
35+
// NewNetInterfaceWithArgs creates a new instance of the network interface client with non-default members
36+
func NewNetInterfaceWithArgs(connector grpcOpi.Connector, createNetInterfaceClient CreateNetInterfaceClient) (*NetIntfClient, error) {
37+
return &NetIntfClient{
38+
c: connector,
39+
createNetInterfaceClient: createNetInterfaceClient,
40+
}, nil
41+
}
42+
43+
// ListNetInterfaces retrieves a list of all network interface details from OPI server
44+
func (c NetIntfClient) ListNetInterfaces(ctx context.Context, pageSize int32, pageToken string) (*pb.ListNetInterfacesResponse, error) {
45+
conn, closer, err := c.c.NewConn()
46+
if err != nil {
47+
log.Printf("error creating connection: %s\n", err)
48+
return nil, err
49+
}
50+
defer closer()
51+
52+
client := c.createNetInterfaceClient(conn)
53+
54+
data, err := client.ListNetInterfaces(ctx, &pb.ListNetInterfacesRequest{
55+
PageSize: pageSize,
56+
PageToken: pageToken,
57+
})
58+
if err != nil {
59+
log.Printf("error List Network Interfaces: %s\n", err)
60+
return nil, err
61+
}
62+
63+
return data, nil
64+
}

storage/goopicsi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func GenerateHostNQN() string {
340340

341341
func dialConnection() error {
342342
var err error
343-
conn, err = grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
343+
conn, err = grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
344344
if err != nil {
345345
log.Printf("Failed to connect: %v", err)
346346
return err

0 commit comments

Comments
 (0)