From 3aa1f03a32232e75da9f98d4513094632bb071aa Mon Sep 17 00:00:00 2001 From: Anat Wax Date: Wed, 2 Aug 2023 12:40:53 +0300 Subject: [PATCH] Add an OVN overlay (flat l2 topology) NAD option Signed-off-by: Anat Wax --- .../network_attachment_definition.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ocp_resources/network_attachment_definition.py b/ocp_resources/network_attachment_definition.py index d5c1b7ca06..8588d4e6f5 100644 --- a/ocp_resources/network_attachment_definition.py +++ b/ocp_resources/network_attachment_definition.py @@ -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)