Skip to content
Merged
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
34 changes: 34 additions & 0 deletions ocp_resources/network_attachment_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,37 @@ def to_dict(self):
@property
def resource_name(self):
return f"ovs-cni.network.kubevirt.io/{self.bridge_name}"


class OVNOverlayNetworkAttachmentDefinition(NetworkAttachmentDefinition):
def __init__(
self,
network_name=None,
**kwargs,
):
"""
Create and manage an OVN k8s overlay NetworkAttachmentDefinition (a switched, layer 2, topology network).

API reference:
https://docs.openshift.com/container-platform/4.13/networking/multiple_networks/configuring-additional-network.html#configuration-ovnk-network-plugin-json-object_configuring-additional-network

Args:
network_name (str): The name of the network. This field is mandatory when not using yaml
file.
"""
super().__init__(
cni_type="ovn-k8s-cni-overlay",
**kwargs,
)
self.network_name = network_name

def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not self.network_name:
raise ValueError("network_name is required")
spec_config = self.res["spec"]["config"]
spec_config["name"] = self.network_name
spec_config["netAttachDefName"] = f"{self.namespace}/{self.name}"
spec_config["topology"] = "layer2"
self.res["spec"]["config"] = json.dumps(spec_config)