-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mgmt): adding Mgmt api for opi-evpn-bridge netlink DB dump
Signed-off-by: atulpatel261194 <[email protected]>
- Loading branch information
1 parent
4918e77
commit 38e3d55
Showing
6 changed files
with
170 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. | ||
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries. | ||
// Copyright (c) 2024 Ericsson AB. | ||
|
||
// Package network implements the network related CLI commands | ||
package network | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/opiproject/godpu/cmd/common" | ||
"github.com/opiproject/godpu/network" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DumpNetlinkDatabase Get netlink database details | ||
func DumpNetlinkDatabase() *cobra.Command { | ||
var details bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "dump-netlink-DB", | ||
Short: "Show details of a netlink database", | ||
Long: "Show details of netlink database with current running config", | ||
Run: func(c *cobra.Command, _ []string) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
|
||
tlsFiles, err := c.Flags().GetString(common.TLSFiles) | ||
cobra.CheckErr(err) | ||
|
||
addr, err := c.Flags().GetString(common.AddrCmdLineArg) | ||
cobra.CheckErr(err) | ||
|
||
evpnClient, err := network.NewManagement(addr, tlsFiles) | ||
if err != nil { | ||
log.Fatalf("could not create gRPC client: %v", err) | ||
} | ||
defer cancel() | ||
|
||
// grpc call to create the bridge port | ||
result, err := evpnClient.DumpNetlinkDB(ctx, details) | ||
if err != nil { | ||
log.Fatalf("DumpNetlinkDatabase: Error occurred while dumping the netlink database: %q", err) | ||
} | ||
log.Printf("DumpNetlinkDatabase: %s", result.Details) | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&details, "details", false, "get the dump with details") | ||
|
||
if err := cmd.MarkFlagRequired("details"); err != nil { | ||
log.Fatalf("Error marking flag as required: %v", err) | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. | ||
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries. | ||
|
||
// Package network implements the go library for OPI to be used to establish networking | ||
package network | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
pm "github.com/opiproject/opi-evpn-bridge/pkg/netlink/proto/gen/go" | ||
) | ||
|
||
// DumpNetlinkDb get netlink DB details from OPI server | ||
func (c evpnClientImpl) DumpNetlinkDB(ctx context.Context, details bool) (*pm.DumpNetlinkDbResult, error) { | ||
conn, closer, err := c.NewConn() | ||
if err != nil { | ||
log.Printf("error creating connection: %s\n", err) | ||
return nil, err | ||
} | ||
defer closer() | ||
|
||
client := c.getEvpnMgmtClient(conn) | ||
data, err := client.DumpNetlinkDB(ctx, &pm.DumpNetlinkDbRequest{ | ||
Details: details, | ||
}) | ||
if err != nil { | ||
log.Printf("error getting vrf: %s\n", err) | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} |