diff --git a/cmd/network/evpn-logical-brige.go b/cmd/network/evpn-logical-brige.go index eb1645f..ffc0ade 100644 --- a/cmd/network/evpn-logical-brige.go +++ b/cmd/network/evpn-logical-brige.go @@ -192,6 +192,7 @@ func ListLogicalBridges() *cobra.Command { func UpdateLogicalBridge() *cobra.Command { var addr string var name string + var allowMissing bool var updateMask []string cmd := &cobra.Command{ Use: "update-lb", @@ -204,7 +205,7 @@ func UpdateLogicalBridge() *cobra.Command { } defer cancel() - lb, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask) + lb, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask, allowMissing) if err != nil { log.Fatalf("failed to update logical bridge: %v", err) } @@ -215,6 +216,7 @@ func UpdateLogicalBridge() *cobra.Command { cmd.Flags().StringVar(&name, "name", "", "name of the logical bridge") cmd.Flags().StringSliceVar(&updateMask, "update-mask", nil, "update mask") cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server") + cmd.Flags().BoolVarP(&allowMissing, "allowMissing", "a", false, "Specify allow missing") return cmd } diff --git a/network/bridge_port.go b/network/bridge_port.go index 6269291..6202396 100644 --- a/network/bridge_port.go +++ b/network/bridge_port.go @@ -7,6 +7,7 @@ package network import ( "context" + "errors" "fmt" "log" "net" @@ -25,7 +26,9 @@ func (c evpnClientImpl) CreateBridgePort(ctx context.Context, name string, mac s return nil, err } defer closer() - + if mac == "" || bridgePortType == "" { + return nil, errors.New("required parameter [mac, bridgePortType] wasn't passed ") + } client := c.getEvpnBridgePortClient(conn) macBytes, err := net.ParseMAC(mac) if err != nil { @@ -67,6 +70,9 @@ func (c evpnClientImpl) DeleteBridgePort(ctx context.Context, name string, allow } defer closer() + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } client := c.getEvpnBridgePortClient(conn) data, err := client.DeleteBridgePort(ctx, &pb.DeleteBridgePortRequest{ Name: resourceIDToFullName("ports", name), @@ -89,6 +95,10 @@ func (c evpnClientImpl) GetBridgePort(ctx context.Context, name string) (*pb.Bri } defer closer() + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } + client := c.getEvpnBridgePortClient(conn) data, err := client.GetBridgePort(ctx, &pb.GetBridgePortRequest{ Name: resourceIDToFullName("ports", name), diff --git a/network/evpn.go b/network/evpn.go index ce7672b..bbdeb44 100644 --- a/network/evpn.go +++ b/network/evpn.go @@ -45,7 +45,7 @@ type EvpnClient interface { DeleteLogicalBridge(ctx context.Context, name string, allowMissing bool) (*emptypb.Empty, error) GetLogicalBridge(ctx context.Context, name string) (*pb.LogicalBridge, error) ListLogicalBridges(ctx context.Context, pageSize int32, pageToken string) (*pb.ListLogicalBridgesResponse, error) - UpdateLogicalBridge(ctx context.Context, name string, updateMask []string) (*pb.LogicalBridge, error) + UpdateLogicalBridge(ctx context.Context, name string, updateMask []string, allowMissing bool) (*pb.LogicalBridge, error) // Bridge Port Interfaces CreateBridgePort(ctx context.Context, name string, mac string, bridgePortType string, logicalBridges []string) (*pb.BridgePort, error) diff --git a/network/logical_bridge.go b/network/logical_bridge.go index 64aee26..97f2755 100644 --- a/network/logical_bridge.go +++ b/network/logical_bridge.go @@ -67,6 +67,9 @@ func (c evpnClientImpl) DeleteLogicalBridge(ctx context.Context, name string, al } defer closer() + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } client := c.getEvpnLogicalBridgeClient(conn) data, err := client.DeleteLogicalBridge(ctx, &pb.DeleteLogicalBridgeRequest{ @@ -90,6 +93,9 @@ func (c evpnClientImpl) GetLogicalBridge(ctx context.Context, name string) (*pb. } defer closer() + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } client := c.getEvpnLogicalBridgeClient(conn) data, err := client.GetLogicalBridge(ctx, &pb.GetLogicalBridgeRequest{ @@ -127,7 +133,7 @@ func (c evpnClientImpl) ListLogicalBridges(ctx context.Context, pageSize int32, } // UpdateLogicalBridge update Logical Bridge on OPI server -func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, updateMask []string) (*pb.LogicalBridge, error) { +func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, updateMask []string, allowMissing bool) (*pb.LogicalBridge, error) { conn, closer, err := c.NewConn() if err != nil { log.Printf("error creating connection: %s\n", err) @@ -142,6 +148,7 @@ func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, up data, err := client.UpdateLogicalBridge(ctx, &pb.UpdateLogicalBridgeRequest{ LogicalBridge: Bridge, UpdateMask: &fieldmaskpb.FieldMask{Paths: updateMask}, + AllowMissing: allowMissing, }) if err != nil { log.Printf("error Update logical bridge: %s\n", err) diff --git a/network/logical_bridge_test.go b/network/logical_bridge_test.go index 0c9a0c0..7488e7f 100644 --- a/network/logical_bridge_test.go +++ b/network/logical_bridge_test.go @@ -407,7 +407,7 @@ func TestUpdateLogicalBridge(t *testing.T) { }, ) - response, err := c.UpdateLogicalBridge(context.Background(), name, updateMask) + response, err := c.UpdateLogicalBridge(context.Background(), name, updateMask, allowMissing) assert.Equal(t, tt.wantErr, err) assert.Equal(t, tt.wantConnClosed, connClosed) diff --git a/network/svi.go b/network/svi.go index 4de9628..0cb4013 100644 --- a/network/svi.go +++ b/network/svi.go @@ -7,6 +7,7 @@ package network import ( "context" + "errors" "fmt" "log" "net" @@ -27,6 +28,10 @@ func (c evpnClientImpl) CreateSvi(ctx context.Context, name string, vrf string, client := c.getEvpnSVIClient(conn) + if vrf == "" || mac == "" || len(gwIPs) == 0 { + return nil, errors.New("one of the required together parameter [vrf, mac, gwIPs] wasn't passed ") + } + gwPrefixes, err := parseIPPrefixes(gwIPs) if err != nil { log.Printf("error parsing GwIPs: %s\n", err) @@ -66,6 +71,11 @@ func (c evpnClientImpl) DeleteSvi(ctx context.Context, name string, allowMissing return nil, err } defer closer() + + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } + client := c.getEvpnSVIClient(conn) data, err := client.DeleteSvi(ctx, &pb.DeleteSviRequest{ Name: resourceIDToFullName("svis", name), @@ -87,6 +97,11 @@ func (c evpnClientImpl) GetSvi(ctx context.Context, name string) (*pb.Svi, error return nil, err } defer closer() + + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } + client := c.getEvpnSVIClient(conn) data, err := client.GetSvi(ctx, &pb.GetSviRequest{ Name: resourceIDToFullName("svis", name), diff --git a/network/vrf.go b/network/vrf.go index 146c006..8672d33 100644 --- a/network/vrf.go +++ b/network/vrf.go @@ -27,15 +27,14 @@ func (c evpnClientImpl) CreateVrf(ctx context.Context, name string, vni *uint32, defer closer() client := c.getEvpnVRFClient(conn) + if loopbackIP == "" { + return nil, errors.New("required together parameter [loopbackIP] wasn't passed ") + } ipLoopback, err := parseIPAndPrefix(loopbackIP) if err != nil { log.Printf("parseIPAndPrefix: error creating vrf: %s\n", err) return nil, err } - if (vni == nil && vtepIP != "") || (vni != nil && vtepIP == "") { - return nil, errors.New("one of the required together parameter [vni, vtep] wasn't passed ") - } - if vni != nil && vtepIP != "" { ipVtep, err = parseIPAndPrefix(vtepIP) if err != nil { @@ -69,6 +68,11 @@ func (c evpnClientImpl) DeleteVrf(ctx context.Context, name string, allowMissing return nil, err } defer closer() + + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } + client := c.getEvpnVRFClient(conn) data, err := client.DeleteVrf(ctx, &pb.DeleteVrfRequest{ Name: resourceIDToFullName("vrfs", name), @@ -90,6 +94,11 @@ func (c evpnClientImpl) GetVrf(ctx context.Context, name string) (*pb.Vrf, error return nil, err } defer closer() + + if name == "" { + return nil, errors.New("required parameter [name] wasn't passed ") + } + client := c.getEvpnVRFClient(conn) data, err := client.GetVrf(ctx, &pb.GetVrfRequest{ Name: resourceIDToFullName("vrfs", name),