-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add network interface capability #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
cdd8ef2
f59fbf6
7b06a2d
19a450e
b654131
441f270
607756e
0e4ba2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2025 Dell Inc, or its subsidiaries. | ||
|
||
// Package netintf implements the network interface related CLI commands | ||
package netintf | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/opiproject/godpu/cmd/common" | ||
network "github.com/opiproject/godpu/network" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
) | ||
|
||
// ListNetworkInterfaces lists all Network Interface details from OPI server | ||
func ListNetworkInterfaces() *cobra.Command { | ||
var pageSize int32 | ||
var pageToken string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "list-net-interfaces", | ||
Short: "List the network interfaces", | ||
Run: func(c *cobra.Command, _ []string) { | ||
addr, err := c.Flags().GetString(common.AddrCmdLineArg) | ||
cobra.CheckErr(err) | ||
|
||
timeout, err := c.Flags().GetDuration(common.TimeoutCmdLineArg) | ||
cobra.CheckErr(err) | ||
|
||
tlsFiles, err := c.Flags().GetString(common.TLSFiles) | ||
cobra.CheckErr(err) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
|
||
netifClient, err := network.NewNetInterface(addr, tlsFiles) | ||
if err != nil { | ||
log.Fatalf("could not create gRPC client: %v", err) | ||
} | ||
defer cancel() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look at this one to determine if it needs to move or change in future addition. |
||
|
||
for { | ||
resp, err := netifClient.ListNetInterfaces(ctx, pageSize, pageToken) | ||
if err != nil { | ||
log.Fatalf("Failed to get items: %v", err) | ||
} | ||
|
||
// Process the response | ||
log.Println("List Network Interfaces:") | ||
for _, lif := range resp.NetInterfaces { | ||
log.Println("Interface with: ") | ||
common.PrintResponse(protojson.Format(lif)) | ||
} | ||
|
||
// Are there more pages | ||
if resp.NextPageToken == "" { | ||
// if no then break | ||
break | ||
} | ||
// update to next token | ||
pageToken = resp.NextPageToken | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().Int32VarP(&pageSize, "pagesize", "s", 0, "Specify page size") | ||
cmd.Flags().StringVarP(&pageToken, "pagetoken", "t", "", "Specify the token") | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. | ||
// Copyright (c) 2024 Dell Inc, or its subsidiaries. | ||
|
||
// Package network implements the network related CLI commands | ||
package network | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/opiproject/godpu/cmd/common" | ||
"github.com/opiproject/godpu/cmd/network/evpn" | ||
"github.com/opiproject/godpu/cmd/network/netintf" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewNetworkCommand tests the Network functionality command | ||
func NewNetworkCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "network", | ||
Aliases: []string{"g"}, | ||
Short: "Tests DPU networking functionality", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
err := cmd.Help() | ||
if err != nil { | ||
log.Fatalf("[ERROR] %s", err.Error()) | ||
} | ||
}, | ||
} | ||
|
||
flags := cmd.PersistentFlags() | ||
flags.Duration(common.TimeoutCmdLineArg, 10*time.Second, "timeout for a cmd") | ||
|
||
cmd.AddCommand(NewEvpnCommand()) | ||
cmd.AddCommand(NewNetIntfCommand()) | ||
|
||
return cmd | ||
} | ||
|
||
// NewNetIntfCommand tests the Network functionality command | ||
func NewNetIntfCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "intf", | ||
Aliases: []string{"g"}, | ||
Short: "Tests DPU network interface functionality", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
err := cmd.Help() | ||
if err != nil { | ||
log.Fatalf("[ERROR] %s", err.Error()) | ||
} | ||
}, | ||
} | ||
|
||
flags := cmd.PersistentFlags() | ||
flags.Duration(common.TimeoutCmdLineArg, 10*time.Second, "timeout for a cmd") | ||
|
||
cmd.AddCommand(netintf.ListNetworkInterfaces()) | ||
|
||
return cmd | ||
} | ||
|
||
// NewEvpnCommand tests the EVPN functionality command | ||
func NewEvpnCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "evpn", | ||
Aliases: []string{"g"}, | ||
Short: "Tests DPU evpn functionality", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
err := cmd.Help() | ||
if err != nil { | ||
log.Fatalf("[ERROR] %s", err.Error()) | ||
} | ||
}, | ||
} | ||
// Bridge cli's | ||
cmd.AddCommand(evpn.CreateLogicalBridge()) | ||
cmd.AddCommand(evpn.DeleteLogicalBridge()) | ||
cmd.AddCommand(evpn.GetLogicalBridge()) | ||
cmd.AddCommand(evpn.ListLogicalBridges()) | ||
cmd.AddCommand(evpn.UpdateLogicalBridge()) | ||
// Port cli's | ||
cmd.AddCommand(evpn.CreateBridgePort()) | ||
cmd.AddCommand(evpn.DeleteBridgePort()) | ||
cmd.AddCommand(evpn.GetBridgePort()) | ||
cmd.AddCommand(evpn.ListBridgePorts()) | ||
cmd.AddCommand(evpn.UpdateBridgePort()) | ||
// VRF cli's | ||
cmd.AddCommand(evpn.CreateVRF()) | ||
cmd.AddCommand(evpn.DeleteVRF()) | ||
cmd.AddCommand(evpn.GetVRF()) | ||
cmd.AddCommand(evpn.ListVRFs()) | ||
cmd.AddCommand(evpn.UpdateVRF()) | ||
// SVI cli's | ||
cmd.AddCommand(evpn.CreateSVI()) | ||
cmd.AddCommand(evpn.DeleteSVI()) | ||
cmd.AddCommand(evpn.GetSVI()) | ||
cmd.AddCommand(evpn.ListSVIs()) | ||
cmd.AddCommand(evpn.UpdateSVI()) | ||
|
||
return cmd | ||
} |
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium