Skip to content

Commit

Permalink
added InterfaceID and VNI to prefix table view, commands are now case…
Browse files Browse the repository at this point in the history
… insensitive
  • Loading branch information
vlorinc authored and guvenc committed Jan 14, 2025
1 parent 1e1c175 commit d11f686
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cli/dpservice-cli/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func Command() *cobra.Command {
cobra.EnableCaseInsensitive = true

dpdkClientOptions := &DPDKClientOptions{}
rendererOptions := &RendererOptions{}

Expand Down
2 changes: 1 addition & 1 deletion cli/dpservice-cli/cmd/create_loadbalancer_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CreateLoadBalancerPrefix(
Short: "Create a loadbalancer prefix",
Example: "dpservice-cli create lbprefix --prefix=10.10.10.0/24 --interface-id=vm1",
Args: cobra.ExactArgs(0),
Aliases: PrefixAliases,
Aliases: LoadBalancerPrefixAliases,
RunE: func(cmd *cobra.Command, args []string) error {

return RunCreateLoadBalancerPrefix(
Expand Down
16 changes: 13 additions & 3 deletions cli/dpservice-cli/cmd/list_loadbalancer_prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,27 @@ func RunListLoadBalancerPrefixes(
}

for _, iface := range ifaces.Items {
prefix, err := client.ListLoadBalancerPrefixes(ctx, iface.ID)
if err != nil && prefix.Status.Code == 0 {
prefixes, err := client.ListLoadBalancerPrefixes(ctx, iface.ID)
if err != nil && prefixes.Status.Code == 0 {
return fmt.Errorf("error getting loadbalancer prefixes: %w", err)
}
prefixList.Items = append(prefixList.Items, prefix.Items...)
for id := range prefixes.Items {
prefixes.Items[id].Vni = iface.Spec.VNI
}
prefixList.Items = append(prefixList.Items, prefixes.Items...)
}
} else {
prefixList, err = client.ListLoadBalancerPrefixes(ctx, opts.InterfaceID)
if err != nil {
return fmt.Errorf("error listing loadbalancer prefixes: %w", err)
}
iface, err := client.GetInterface(ctx, opts.InterfaceID)
if err != nil {
return fmt.Errorf("error getting interface: %w", err)
}
for id := range prefixList.Items {
prefixList.Items[id].Vni = iface.Spec.VNI
}
}

// sort items in list
Expand Down
16 changes: 13 additions & 3 deletions cli/dpservice-cli/cmd/list_prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,27 @@ func RunListPrefixes(
}

for _, iface := range ifaces.Items {
prefix, err := client.ListPrefixes(ctx, iface.ID)
if err != nil && prefix.Status.Code == 0 {
prefixes, err := client.ListPrefixes(ctx, iface.ID)
if err != nil && prefixes.Status.Code == 0 {
return fmt.Errorf("error getting prefixes: %w", err)
}
prefixList.Items = append(prefixList.Items, prefix.Items...)
for id := range prefixes.Items {
prefixes.Items[id].Vni = iface.Spec.VNI
}
prefixList.Items = append(prefixList.Items, prefixes.Items...)
}
} else {
prefixList, err = client.ListPrefixes(ctx, opts.InterfaceID)
if err != nil {
return fmt.Errorf("error listing prefixes: %w", err)
}
iface, err := client.GetInterface(ctx, opts.InterfaceID)
if err != nil {
return fmt.Errorf("error getting interface: %w", err)
}
for id := range prefixList.Items {
prefixList.Items[id].Vni = iface.Spec.VNI
}
}
// sort items in list
prefixes := prefixList.Items
Expand Down
4 changes: 2 additions & 2 deletions cli/dpservice-cli/renderer/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ func (t defaultTableConverter) interfaceTable(ifaces []api.Interface) (*TableDat
}

func (t defaultTableConverter) prefixTable(prefixes []api.Prefix) (*TableData, error) {
headers := []any{"Prefix", "UnderlayRoute"}
headers := []any{"VNI", "Prefix", "UnderlayRoute", "InterfaceID"}

columns := make([][]any, len(prefixes))
for i, prefix := range prefixes {
columns[i] = []any{prefix.Spec.Prefix, prefix.Spec.UnderlayRoute}
columns[i] = []any{prefix.Vni, prefix.Spec.Prefix, prefix.Spec.UnderlayRoute, prefix.InterfaceID}
}

return &TableData{
Expand Down
1 change: 1 addition & 0 deletions go/dpservice-go/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type Prefix struct {

type PrefixMeta struct {
InterfaceID string `json:"interface_id"`
Vni uint32 `json:"vni"`
}

func (m *Prefix) GetName() string {
Expand Down

0 comments on commit d11f686

Please sign in to comment.