Skip to content
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

Add Layer2 topology class #2145

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 18 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
63 changes: 63 additions & 0 deletions ocp_resources/user_defined_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Any, Dict, Optional
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError
from typing import List


class UserDefinedNetwork(NamespacedResource):
Expand Down Expand Up @@ -66,3 +67,65 @@ def to_dict(self) -> None:
_spec["localNet"] = self.local_net

# End of generated code


LAYER2: str = "Layer2"


class Layer2UserDefinedNetwork(UserDefinedNetwork):
"""
UserDefinedNetwork layer2 object.

API reference:
https://ovn-kubernetes.io/api-reference/userdefinednetwork-api-spec/#layer2config
"""

def __init__(
self,
role: Optional[str] = None,
mtu: Optional[int] = None,
subnets: Optional[List[str]] = None,
join_subnets: Optional[List[str]] = None,
ipam_lifecycle: Optional[str] = None,
**kwargs,
):
"""
Create and manage UserDefinedNetwork with layer2 configuration

Args:
role (Optional[str]): role describes the network role in the pod.
mtu (Optional[int]): mtu is the maximum transmission unit for a network.
subnets (Optional[List[str]]): subnets are used for the pod network across the cluster.
join_subnets (Optional[List[str]]): join_subnets are used inside the OVN network topology.
ipam_lifecycle (Optional[str]): ipam_lifecycle controls IP addresses management lifecycle.
"""
super().__init__(
topology=LAYER2,
**kwargs,
)
self.role = role
self.mtu = mtu
self.subnets = subnets
self.join_subnets = join_subnets
self.ipam_lifecycle = ipam_lifecycle
sbahar619 marked this conversation as resolved.
Show resolved Hide resolved

def to_dict(self) -> None:
super().to_dict()
if not self.kind_dict and not self.yaml_file:
self.res["spec"][LAYER2.lower()] = {}
_layer2 = self.res["spec"][LAYER2.lower()]

if self.role:
sbahar619 marked this conversation as resolved.
Show resolved Hide resolved
_layer2["role"] = self.role

if self.mtu:
_layer2["mtu"] = self.mtu

if self.subnets:
_layer2["subnets"] = self.subnets

if self.join_subnets:
_layer2["joinSubnets"] = self.join_subnets

if self.ipam_lifecycle:
_layer2["ipamLifecycle"] = self.ipam_lifecycle