Skip to content

Demo layout #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added common/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions src/client.py → common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import httpx
from pydantic import BaseModel
from pydantic_eda.core import (
from pydantic_eda.core.v25_4_1.models import (
GroupVersionKind,
NsCrGvkName,
Transaction,
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(self, base_url: str):
self.transaction: Optional[Transaction] = None
self.transaction_endpoint: str = self.base_url.join("/core/transaction/v1")

super().__init__(headers=self.headers, verify=False)
super().__init__(headers=self.headers, verify=False, timeout=300)

# acquire the token during initialization
self.auth()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions examples/005-banner/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import sys

sys.path.append(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
)

import pydantic_eda.apps.siteinfo.v1alpha1.models as siteinfo

from common.client import EDAClient
from common.logging import setup_logging

setup_logging()

NS = "eda"


def main():
eda = EDAClient(base_url="https://devbox.netdevops.me:9444")

my_banner = siteinfo.Banner(
apiVersion="siteinfo.eda.nokia.com/v1alpha1",
kind="Banner",
metadata=siteinfo.BannerMetadata(
namespace=NS,
name="my-banner",
),
spec=siteinfo.BannerSpec(
loginBanner="Pydantic EDA says Hi",
nodes=["leaf1"],
),
)

eda.add_to_transaction_create(my_banner)
_ = eda.commit_transaction()


if __name__ == "__main__":
main()
32 changes: 32 additions & 0 deletions examples/020-many-vnets/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import sys

sys.path.append(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
)

from vnet import virtualnetwork

from common.client import EDAClient
from common.logging import setup_logging

setup_logging()

NS = "eda"


def main():
num_vnets = 100

eda = EDAClient(base_url="https://1.dev.srexperts.net:9443")

for i in range(num_vnets):
my_vnet = virtualnetwork(ns=NS, id=i)

eda.add_to_transaction_create(my_vnet)

_ = eda.commit_transaction()


if __name__ == "__main__":
main()
82 changes: 82 additions & 0 deletions examples/020-many-vnets/vnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pydantic_eda.apps.services.v1alpha1.models as service


def virtualnetwork(ns: str, id: int) -> service.VirtualNetwork:
router = service.VirtualNetworkSpecRouter(
name=f"vnet-router-{id}",
spec=service.VirtualNetworkSpecRouterSpec(
eviPool="evi-pool",
tunnelIndexPool="tunnel-index-pool",
type="EVPNVXLAN",
vniPool="vni-pool",
),
)

bd = service.VirtualNetworkSpecBridgeDomain(
name=f"vnet-bridge-domain-{id}",
spec=service.VirtualNetworkSpecBridgeDomainSpec(
eviPool="evi-pool",
tunnelIndexPool="tunnel-index-pool",
type="EVPNVXLAN",
vniPool="vni-pool",
),
)

vlan = service.VirtualNetworkSpecVlan(
name=f"vnet-vlan-{id}",
spec=service.VirtualNetworkSpecVlanSpec(
bridgeDomain=bd.name,
interfaceSelector=["edge-type=compute"],
uplink=service.VirtualNetworkSpecVlanSpecUplink(uplinkVLANID="pool"),
vlanID=str(300 + id),
),
)

irb = service.VirtualNetworkSpecIrbInterface(
name=f"vnet-irb-{id}",
spec=service.VirtualNetworkSpecIrbInterfaceSpec(
bridgeDomain=bd.name,
hostRoutePopulate=service.VirtualNetworkSpecIrbInterfaceSpecHostRoutePopulate(
dynamic=True, static=True
),
ipAddresses=[
service.VirtualNetworkSpecIrbInterfaceSpecIpAddress(
ipv4Address=service.VirtualNetworkSpecIrbInterfaceSpecIpAddressIpv4Address(
ipPrefix="10.30.0.1/24", primary=True
)
),
service.VirtualNetworkSpecIrbInterfaceSpecIpAddress(
ipv6Address=service.VirtualNetworkSpecIrbInterfaceSpecIpAddressIpv6Address(
ipPrefix="fd00:fdfd:0:3000::1/64", primary=True
)
),
],
router=router.name,
),
)

vnet = service.VirtualNetwork(
apiVersion="services.eda.nokia.com/v1alpha1",
kind="VirtualNetwork",
metadata=service.VirtualNetworkMetadata(
name=f"vnet-api-example-{id}",
namespace=ns,
labels={"role": "pydantic-example"},
),
spec=service.VirtualNetworkSpec(
routers=[
router,
],
bridgeDomains=[
bd,
],
vlans=[
vlan,
],
irbInterfaces=[
irb,
],
),
)

return vnet
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ dependencies = [

[tool.uv.sources]
pydantic-eda = { git = "https://github.com/eda-labs/pydantic-eda" }

[tool.ruff.lint]
# do not warn about imports not at the top
# as we do have to modify the sys path for the exercises
ignore = ["E402"]
40 changes: 20 additions & 20 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.