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
9 changes: 7 additions & 2 deletions ocp_resources/network_attachment_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,31 +201,36 @@ class OVNOverlayNetworkAttachmentDefinition(NetworkAttachmentDefinition):
def __init__(
self,
network_name=None,
topology=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
https://docs.openshift.com/container-platform/4.14/networking/multiple_networks/configuring-additional-network.html#configuration-ovnk-additional-networks_configuring-additional-network

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

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