Skip to content

Commit

Permalink
feat(evpn): replace cloud with evpn APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Sep 7, 2023
1 parent 9461bf7 commit a6080cf
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 12 deletions.
27 changes: 24 additions & 3 deletions pydpu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")


Expand Down
48 changes: 41 additions & 7 deletions pydpu/evpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
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

Check warning on line 21 in pydpu/evpn.py

View check run for this annotation

Codecov / codecov/patch

pydpu/evpn.py#L21

Added line #L21 was not covered by tests
except grpc.RpcError as e:
print(e)


def port_create(address):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
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

Check warning on line 33 in pydpu/evpn.py

View check run for this annotation

Codecov / codecov/patch

pydpu/evpn.py#L33

Added line #L33 was not covered by tests
except grpc.RpcError as e:
print(e)


def vrf_create(address):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
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

Check warning on line 43 in pydpu/evpn.py

View check run for this annotation

Codecov / codecov/patch

pydpu/evpn.py#L43

Added line #L43 was not covered by tests
except grpc.RpcError as e:
print(e)


def evpn_configure(address):
def svi_create(address):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
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)
22 changes: 20 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit a6080cf

Please sign in to comment.