Skip to content

Commit

Permalink
fix(evpn): allow passing name instead of full name
Browse files Browse the repository at this point in the history
Signed-off-by: atulpatel261194 <[email protected]>
  • Loading branch information
atulpatel261194 committed Jun 4, 2024
1 parent 9cf56d1 commit ed1e1a6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ const TLSFiles = "tlsfiles"
// PrintResponse prints only response string into stdout without any
// additional information
func PrintResponse(response string) {
fmt.Fprintln(os.Stdout, response)
if _, err := fmt.Fprintln(os.Stdout, response); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write to stdout: %v\n", err)
}
}
13 changes: 12 additions & 1 deletion network/bridge_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,32 @@ import (
// CreateBridgePort creates an Bridge Port an OPI server
func (c evpnClientImpl) CreateBridgePort(ctx context.Context, name string, mac string, bridgePortType string, logicalBridges []string) (*pb.BridgePort, error) {
var typeOfPort pb.BridgePortType

conn, closer, err := c.NewConn()
if err != nil {
log.Printf("error creating connection: %s\n", err)
return nil, err
}
defer closer()

if mac == "" || bridgePortType == "" {
return nil, errors.New("required parameter [mac, bridgePortType] wasn't passed ")
}

var lBridges = make([]string, 0)
for _, lb := range logicalBridges {
str := resourceIDToFullName("bridges", lb)
lBridges = append(lBridges, str)
}

client := c.getEvpnBridgePortClient(conn)

macBytes, err := net.ParseMAC(mac)
if err != nil {
fmt.Println("Error parsing MAC address:", err)
return nil, err
}

switch bridgePortType {
case "access":
typeOfPort = pb.BridgePortType_BRIDGE_PORT_TYPE_ACCESS
Expand All @@ -49,7 +60,7 @@ func (c evpnClientImpl) CreateBridgePort(ctx context.Context, name string, mac s
Spec: &pb.BridgePortSpec{
MacAddress: macBytes,
Ptype: typeOfPort,
LogicalBridges: logicalBridges,
LogicalBridges: lBridges,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion network/bridge_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestCreateBridgePort(t *testing.T) {
Spec: &pb.BridgePortSpec{
MacAddress: macBytes,
Ptype: pb.BridgePortType_BRIDGE_PORT_TYPE_ACCESS,
LogicalBridges: []string{"lb1", "lb2"},
LogicalBridges: []string{"//network.opiproject.org/bridges/lb1", "//network.opiproject.org/bridges/lb2"},
},
}

Expand Down
7 changes: 5 additions & 2 deletions network/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (c evpnClientImpl) CreateSvi(ctx context.Context, name string, vrf string,
if vrf == "" || mac == "" || len(gwIPs) == 0 {
return nil, errors.New("one of the required together parameter [vrf, mac, gwIPs] wasn't passed ")
}
vrfName := resourceIDToFullName("vrfs", vrf)

lBridge := resourceIDToFullName("bridges", logicalBridge)

gwPrefixes, err := parseIPPrefixes(gwIPs)
if err != nil {
Expand All @@ -46,8 +49,8 @@ func (c evpnClientImpl) CreateSvi(ctx context.Context, name string, vrf string,
SviId: name,
Svi: &pb.Svi{
Spec: &pb.SviSpec{
Vrf: vrf,
LogicalBridge: logicalBridge,
Vrf: vrfName,
LogicalBridge: lBridge,
MacAddress: macBytes,
GwIpPrefix: gwPrefixes,
EnableBgp: ebgp,
Expand Down
4 changes: 2 additions & 2 deletions network/svi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestCreateSvi(t *testing.T) {

testSvi := &pb.Svi{
Spec: &pb.SviSpec{
Vrf: "vrf1",
LogicalBridge: "logical1",
Vrf: "//network.opiproject.org/vrfs/vrf1",
LogicalBridge: "//network.opiproject.org/bridges/logical1",
MacAddress: macBytes,
GwIpPrefix: wantGWPrefixes,
EnableBgp: true,
Expand Down

0 comments on commit ed1e1a6

Please sign in to comment.