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 Ability to perform Node operation on IBM Cloud IPI deployment #9402

Merged
merged 11 commits into from
Oct 1, 2024
Merged
2 changes: 2 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
STATUS_WAITFORUSERTOCLEANUP = "WaitOnUserToCleanUp"
STATUS_POWERON = "ON"
STATUS_POWEROFF = "OFF"
STATUS_STOPPED = "stopped"
STATUS_STOPPING = "stopping"

# NooBaa statuses
BS_AUTH_FAILED = "AUTH_FAILED"
Expand Down
113 changes: 113 additions & 0 deletions ocs_ci/ocs/platform_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
get_node_objs,
get_typed_worker_nodes,
get_nodes,
get_worker_nodes,
)
from ocs_ci.ocs.resources.pvc import get_deviceset_pvs
from ocs_ci.ocs.resources import pod
Expand Down Expand Up @@ -99,6 +100,7 @@ def __init__(self):
"fusion_aas": AWSNodes,
"hci_baremetal": IBMCloudBMNodes,
"kubevirt_vm": KubevirtVMNodes,
"ibm_cloud_ipi": IBMCloudIPI,
}

def get_nodes_platform(self):
Expand All @@ -117,6 +119,9 @@ def get_nodes_platform(self):
):
platform = "kubevirt_vm"

if config.ENV_DATA["platform"] == constants.IBMCLOUD_PLATFORM:
if config.ENV_DATA["deployment_type"] == "ipi":
platform += "_ipi"
return self.cls_map[platform]()


Expand Down Expand Up @@ -3345,3 +3350,111 @@ def terminate_nodes(self, nodes, wait=True):

"""
raise NotImplementedError("Terminate nodes functionality not implemented")


class IBMCloudIPI(object):
"""
An IBM Cloud IPI class for node related operations
Should be inherited by specific platform classes
"""

def __init__(self):
from ocs_ci.utility import ibmcloud

super(IBMCloudIPI, self).__init__()
self.ibmcloud_ipi = ibmcloud.IBMCloudIPI()

def get_data_volumes(self):
pvs = get_deviceset_pvs()
s = [
pv.get().get("spec").get("csi").get("volumeAttributes").get("volumeId")
for pv in pvs
]
logger.info(s)
return s

def get_node_by_attached_volume(self, volume):
volume_kube_path = f"kubernetes.io/csi/vpc.block.csi.ibm.io^{volume}"
all_nodes = get_node_objs(get_worker_nodes())
for node in all_nodes:
for volume in node.data["status"]["volumesAttached"]:
if volume_kube_path in volume.values():
return node

def stop_nodes(self, nodes, force=True):
self.ibmcloud_ipi.stop_nodes(nodes=nodes, force=force)

def start_nodes(self, nodes):
self.ibmcloud_ipi.start_nodes(nodes=nodes)

def restart_nodes(self, nodes, wait=True):
self.ibmcloud_ipi.restart_nodes(nodes=nodes, wait=wait)

def restart_nodes_by_stop_and_start(self, nodes, force=True):
self.ibmcloud_ipi.restart_nodes_by_stop_and_start(nodes=nodes, force=force)

def detach_volume(self, volume, node=None, delete_from_backend=True):
self.ibmcloud_ipi.detach_volume(volume=volume, node=node)

def attach_volume(self, volume, node):
self.ibmcloud_ipi.attach_volume(volume=volume, node=node)

def wait_for_volume_attach(self, volume):
self.ibmcloud_ipi.wait_for_volume_attach(volume=volume)

def restart_nodes_by_stop_and_start_teardown(self):
self.ibmcloud_ipi.restart_nodes_by_stop_and_start_force()

def create_and_attach_nodes_to_cluster(self, node_conf, node_type, num_nodes):
"""
Create nodes and attach them to cluster
Use this function if you want to do both creation/attachment in
a single call
Args:
node_conf (dict): of node configuration
node_type (str): type of node to be created RHCOS/RHEL
num_nodes (int): Number of node instances to be created
"""
node_list = self.create_nodes(node_conf, node_type, num_nodes)
self.attach_nodes_to_cluster(node_list)

def create_nodes(self, node_conf, node_type, num_nodes):
raise NotImplementedError("Create nodes functionality not implemented")

def attach_nodes_to_cluster(self, node_list):
raise NotImplementedError(
"attach nodes to cluster functionality is not implemented"
)

def read_default_config(self, default_config_path):
"""
Commonly used function to read default config
Args:
default_config_path (str): Path to default config file
Returns:
dict: of default config loaded
"""
assert os.path.exists(default_config_path), "Config file doesnt exists"

with open(default_config_path) as f:
default_config_dict = yaml.safe_load(f)

return default_config_dict

def terminate_nodes(self, nodes, wait=True):
self.ibmcloud_ipi.terminate_nodes(nodes=nodes, wait=wait)

def wait_for_nodes_to_stop(self, nodes):
raise NotImplementedError(
"wait for nodes to stop functionality is not implemented"
)

def wait_for_nodes_to_terminate(self, nodes):
raise NotImplementedError(
"wait for nodes to terminate functionality is not implemented"
)

def wait_for_nodes_to_stop_or_terminate(self, nodes):
raise NotImplementedError(
"wait for nodes to stop or terminate functionality is not implemented"
)
Loading
Loading