Skip to content

Commit

Permalink
add_route_nad_obj function
Browse files Browse the repository at this point in the history
Signed-off-by: oviner <[email protected]>
  • Loading branch information
OdedViner committed May 30, 2024
1 parent e26902c commit d88b15c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@
MULTUS_CLUSTER_NET_YAML = os.path.join(
TEMPLATE_DEPLOYMENT_DIR, "multus-cluster-net.yaml"
)
NETWORK_ATTACHEMENT_DEFINITION = "network-attachment-definitions.k8s.cni.cncf.io"


OPERATOR_SOURCE_NAME = "ocs-operatorsource"

Expand Down
49 changes: 49 additions & 0 deletions ocs_ci/ocs/resources/storage_cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
StorageCluster related functionalities
"""

import copy
import ipaddress
import logging
Expand Down Expand Up @@ -2728,3 +2729,51 @@ def resize_osd(new_osd_size, check_size=True):
format_type="json",
)
return res


def get_network_attachment_definitions(
nad_name, namespace=config.ENV_DATA["cluster_namespace"]
):
"""
Get network_attachment_definitions obj
Args:
nad_name (str) : network_attachment_definition name
namespace (str): Namespace of the resource
Returns:
network_attachment_definitions (obj) : network_attachment_definitions object
"""
return OCP(
kind=constants.NETWORK_ATTACHEMENT_DEFINITION,
namespace=namespace,
resource_name=nad_name,
)


def add_route_nad_obj(
nad_name,
namespace=config.ENV_DATA["cluster_namespace"],
route_dst="192.168.252.0/24",
):
"""
Add route section to network_attachment_definitions object
Args:
nad_name: network_attachment_definition name
namespace: Namespace of the resource
"""
nad_obj = get_network_attachment_definitions(nad_name=nad_name, namespace=namespace)
nad_config_str = nad_obj.data["spec"]["config"]
nad_config_dict = json.loads(nad_config_str)
nad_config_dict["ipam"]["routes"] = [{"dst": route_dst}]
nad_config_dict_string = json.dumps(nad_config_dict)
params = f"""[{{ "op": "replace", "path": "/spec/config",
"value": {str(nad_config_dict_string)}}}]"""
nad_obj.patch(
resource_name=nad_name,
params=params.strip("\n"),
format_type="json",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: ceph-public-net-shim-worker-node
namespace: openshift-storage
spec:
nodeSelector:
node-role.kubernetes.io/worker: ""
kubernetes.io/hostname: worker-node
desiredState:
interfaces:
- name: odf-pub-shim
description: Shim interface used to connect host to OpenShift Data Foundation public Multus network
type: mac-vlan
state: up
mac-vlan:
base-iface: enp1s0f1
mode: bridge
promiscuous: true
ipv4:
enabled: true
dhcp: false
address:
- ip: 192.168.252.1 # STATIC IP FOR worker node
prefix-length: 24
routes:
config:
- destination: 192.168.20.0/24
next-hop-interface: odf-pub-shim

0 comments on commit d88b15c

Please sign in to comment.