From 329b7ed08bfc2732c49a29b1e029b42b8f2e685a Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Thu, 7 Sep 2023 23:19:32 +0300 Subject: [PATCH] feat(evpn): replace cloud with evpn APIs Signed-off-by: Boris Glimcher --- pydpu/cli.py | 27 +++++++++++++++++++++++--- pydpu/evpn.py | 48 ++++++++++++++++++++++++++++++++++++++++------- tests/test_cli.py | 22 ++++++++++++++++++++-- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/pydpu/cli.py b/pydpu/cli.py index 5dd9e2e..54b365f 100644 --- a/pydpu/cli.py +++ b/pydpu/cli.py @@ -2,7 +2,7 @@ import click import grpc -from .evpn import evpn_configure +from .evpn import bridge_create, port_create, svi_create, vrf_create from .inventory import get_inventory from .ipsec import create_new_tunnel, get_stats from .storage import NvmeController, NvmeNamespace, NvmeSubsystem @@ -40,8 +40,29 @@ def evpn(ctx): @evpn.command() @click.pass_context -def iface(ctx): - evpn_configure(ctx.obj["ADDRESS"]) +def bridge(ctx): + bridge_create(ctx.obj["ADDRESS"]) + click.echo("work in progress") + + +@evpn.command() +@click.pass_context +def port(ctx): + port_create(ctx.obj["ADDRESS"]) + click.echo("work in progress") + + +@evpn.command() +@click.pass_context +def vrf(ctx): + vrf_create(ctx.obj["ADDRESS"]) + click.echo("work in progress") + + +@evpn.command() +@click.pass_context +def svi(ctx): + svi_create(ctx.obj["ADDRESS"]) click.echo("work in progress") diff --git a/pydpu/evpn.py b/pydpu/evpn.py index 19bb3f4..cc69c22 100644 --- a/pydpu/evpn.py +++ b/pydpu/evpn.py @@ -3,19 +3,53 @@ import grpc -from .proto.v1 import ( # , interface_pb2, interface_pb2_grpc - cloudrpc_pb2, - cloudrpc_pb2_grpc, +from .proto.v1 import ( + l2_xpu_infra_mgr_pb2, + l2_xpu_infra_mgr_pb2_grpc, + l3_xpu_infra_mgr_pb2, + l3_xpu_infra_mgr_pb2_grpc, ) -# TODO: replace interface with evpn + +def bridge_create(address): + try: + with grpc.insecure_channel(address) as channel: + stub = l2_xpu_infra_mgr_pb2_grpc.LogicalBridgeServiceStub(channel) + res = stub.CreateLogicalBridge( + request=l2_xpu_infra_mgr_pb2.CreateLogicalBridgeRequest() + ) + return res + except grpc.RpcError as e: + print(e) + + +def port_create(address): + try: + with grpc.insecure_channel(address) as channel: + stub = l2_xpu_infra_mgr_pb2_grpc.BridgePortServiceStub(channel) + res = stub.CreateBridgePort( + request=l2_xpu_infra_mgr_pb2.CreateBridgePortRequest() + ) + return res + except grpc.RpcError as e: + print(e) + + +def vrf_create(address): + try: + with grpc.insecure_channel(address) as channel: + stub = l3_xpu_infra_mgr_pb2_grpc.VrfServiceStub(channel) + res = stub.CreateVrf(request=l3_xpu_infra_mgr_pb2.CreateVrfRequest()) + return res + except grpc.RpcError as e: + print(e) -def evpn_configure(address): +def svi_create(address): try: with grpc.insecure_channel(address) as channel: - stub = cloudrpc_pb2_grpc.CloudInfraServiceStub(channel) - res = stub.CreateInterface(request=cloudrpc_pb2.CreateInterfaceRequest()) + stub = l3_xpu_infra_mgr_pb2_grpc.SviServiceStub(channel) + res = stub.CreateSvi(request=l3_xpu_infra_mgr_pb2.CreateSviRequest()) return res except grpc.RpcError as e: print(e) diff --git a/tests/test_cli.py b/tests/test_cli.py index 914ce15..cb1448b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -26,9 +26,27 @@ def test_cli_inventory_get(runner): assert result.exit_code == 0 -def test_cli_evpn_iface(runner): +def test_cli_evpn_bridge(runner): """Test `dpu evpn interface`""" - result = runner.invoke(cli.main, ("--address", "localhost:50001", "evpn", "iface")) + result = runner.invoke(cli.main, ("--address", "localhost:50001", "evpn", "bridge")) + assert result.exit_code == 0 + + +def test_cli_evpn_port(runner): + """Test `dpu evpn interface`""" + result = runner.invoke(cli.main, ("--address", "localhost:50001", "evpn", "port")) + assert result.exit_code == 0 + + +def test_cli_evpn_vrf(runner): + """Test `dpu evpn interface`""" + result = runner.invoke(cli.main, ("--address", "localhost:50001", "evpn", "vrf")) + assert result.exit_code == 0 + + +def test_cli_evpn_svi(runner): + """Test `dpu evpn interface`""" + result = runner.invoke(cli.main, ("--address", "localhost:50001", "evpn", "svi")) assert result.exit_code == 0