mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
cli: Use api struct in VRF commands
Signed-off-by: IWASE Yusuke <[email protected]>
This commit is contained in:
+2
-26
@@ -461,36 +461,12 @@ func (cli *Client) DeletePathByFamily(family bgp.RouteFamily) error {
|
||||
return cli.deletePath(nil, family, "", nil)
|
||||
}
|
||||
|
||||
func (cli *Client) GetVRF() ([]*table.Vrf, error) {
|
||||
func (cli *Client) GetVRF() ([]*api.Vrf, error) {
|
||||
ret, err := cli.cli.GetVrf(context.Background(), &api.GetVrfRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var vrfs []*table.Vrf
|
||||
|
||||
for _, vrf := range ret.Vrfs {
|
||||
rd, err := api.UnmarshalRD(vrf.Rd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
importRT, err := api.UnmarshalRTs(vrf.ImportRt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exportRT, err := api.UnmarshalRTs(vrf.ExportRt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vrfs = append(vrfs, &table.Vrf{
|
||||
Name: vrf.Name,
|
||||
Id: vrf.Id,
|
||||
Rd: rd,
|
||||
ImportRt: importRT,
|
||||
ExportRt: exportRT,
|
||||
})
|
||||
}
|
||||
|
||||
return vrfs, nil
|
||||
return ret.Vrfs, nil
|
||||
}
|
||||
|
||||
func (cli *Client) AddVRF(name string, id int, rd bgp.RouteDistinguisherInterface, im, ex []bgp.ExtendedCommunityInterface) error {
|
||||
|
||||
+3
-4
@@ -29,10 +29,10 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
|
||||
api "github.com/osrg/gobgp/api"
|
||||
cli "github.com/osrg/gobgp/client"
|
||||
"github.com/osrg/gobgp/config"
|
||||
"github.com/osrg/gobgp/packet/bgp"
|
||||
"github.com/osrg/gobgp/table"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -142,9 +142,8 @@ func formatTimedelta(d int64) string {
|
||||
|
||||
if days == 0 {
|
||||
return fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
|
||||
} else {
|
||||
return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
|
||||
}
|
||||
return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
|
||||
}
|
||||
|
||||
func cidr2prefix(cidr string) string {
|
||||
@@ -245,7 +244,7 @@ func (c capabilities) Less(i, j int) bool {
|
||||
return c[i].Code() < c[j].Code()
|
||||
}
|
||||
|
||||
type vrfs []*table.Vrf
|
||||
type vrfs []*api.Vrf
|
||||
|
||||
func (v vrfs) Len() int {
|
||||
return len(v)
|
||||
|
||||
+24
-7
@@ -22,8 +22,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/any"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
api "github.com/osrg/gobgp/api"
|
||||
"github.com/osrg/gobgp/packet/bgp"
|
||||
)
|
||||
|
||||
@@ -56,21 +59,35 @@ func showVrfs() error {
|
||||
lines := make([][]string, 0, len(vrfs))
|
||||
for _, v := range vrfs {
|
||||
name := v.Name
|
||||
rd := v.Rd.String()
|
||||
rd, err := api.UnmarshalRD(v.Rd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rdStr := rd.String()
|
||||
|
||||
f := func(rts []bgp.ExtendedCommunityInterface) (string, error) {
|
||||
f := func(rts []*any.Any) (string, error) {
|
||||
ret := make([]string, 0, len(rts))
|
||||
for _, rt := range rts {
|
||||
for _, an := range rts {
|
||||
rt, err := api.UnmarshalRT(an)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ret = append(ret, rt.String())
|
||||
}
|
||||
return strings.Join(ret, ", "), nil
|
||||
}
|
||||
|
||||
importRts, _ := f(v.ImportRt)
|
||||
exportRts, _ := f(v.ExportRt)
|
||||
lines = append(lines, []string{name, rd, importRts, exportRts, fmt.Sprintf("%d", v.Id)})
|
||||
importRts, err := f(v.ImportRt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exportRts, err := f(v.ExportRt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lines = append(lines, []string{name, rdStr, importRts, exportRts, fmt.Sprintf("%d", v.Id)})
|
||||
|
||||
for i, v := range []int{len(name), len(rd), len(importRts), len(exportRts)} {
|
||||
for i, v := range []int{len(name), len(rdStr), len(importRts), len(exportRts)} {
|
||||
if v > maxLens[i] {
|
||||
maxLens[i] = v + 4
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user