Skip to content

Commit

Permalink
Changes for route creation (#509)
Browse files Browse the repository at this point in the history
* Route related changes

Signed-off-by: Jayesh-Kumar3 <Jayesh.Kumar3@ibm.com>

* Changed the condition for route creation

Signed-off-by: Jayesh-Kumar3 <Jayesh.Kumar3@ibm.com>

---------

Signed-off-by: Jayesh-Kumar3 <Jayesh.Kumar3@ibm.com>
Co-authored-by: Jayesh-Kumar3 <Jayesh.Kumar3@ibm.com>
  • Loading branch information
jayeshh123 and Jayesh-Kumar3 authored Apr 24, 2024
1 parent 5c5603f commit 0703ffe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 53 deletions.
34 changes: 14 additions & 20 deletions ibmcloud_scale_templates/sub_modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ module "protocol_reserved_ip" {
protocol_dns_zone_id = var.vpc_protocol_cluster_dns_zone_id
}

module "routing_table_routes" {
source = "../../../resources/ibmcloud/network/routing_table_routes"
scale_ces_enabled = local.scale_ces_enabled
total_vsis = var.total_protocol_cluster_instances
vpc_id = var.vpc_id
routing_table = data.ibm_is_vpc.vpc_rt_id.default_routing_table
zone = [var.vpc_availability_zones[0]]
action = "deliver"
next_hop = values(one(module.protocol_cluster_instances[*].secondary_interface_name_ip_map))
priority = 2
dest_ip = values(one(module.protocol_reserved_ip[*].instance_name_ip_map))
depends_on = [module.protocol_cluster_instances, module.storage_cluster_instances, module.protocol_reserved_ip, module.client_cluster_instances]
}

module "storage_cluster_instances" {
count = var.storage_type != "persistent" ? 1 : 0
source = "../../../resources/ibmcloud/compute/vsi_multiple_vol"
Expand Down Expand Up @@ -860,26 +874,6 @@ module "combined_cluster_configuration" {
depends_on = [module.ldap_configuration]
}

module "routing_table_routes" {
source = "../../../resources/ibmcloud/network/routing_table_routes"
turn_on = (var.create_separate_namespaces == true) ? true : false
clone_complete = module.prepare_ansible_configuration.clone_complete
create_scale_cluster = var.create_scale_cluster
scale_ces_enabled = local.scale_ces_enabled == true ? true : false
storage_cluster_create_complete = module.storage_cluster_configuration.storage_cluster_create_complete
total_vsis = var.total_protocol_cluster_instances
vpc_id = var.vpc_id
routing_table = data.ibm_is_vpc.vpc_rt_id.default_routing_table
zone = [var.vpc_availability_zones[0]]
action = "deliver"
next_hop = values(one(module.protocol_cluster_instances[*].secondary_interface_name_ip_map))
priority = 2
dest_ip = values(one(module.protocol_reserved_ip[*].instance_name_ip_map))
storage_admin_ip = var.storage_type != "persistent" ? values(one(module.storage_cluster_instances[*].instance_name_ip_map))[0] : values(one(module.storage_cluster_bare_metal_server[*].storage_cluster_instance_name_ip_map))[0]
storage_private_key = format("%s/storage_key/id_rsa", var.scale_ansible_repo_clone_path)
depends_on = [module.protocol_cluster_instances, module.storage_cluster_instances, module.protocol_reserved_ip, module.compute_cluster_configuration, module.storage_cluster_configuration]
}

module "client_configuration" {
source = "../../../resources/common/client_configuration"
turn_on = (var.total_client_cluster_instances > 0 && var.create_separate_namespaces == true && local.scale_ces_enabled == true) ? true : false
Expand Down
11 changes: 8 additions & 3 deletions resources/common/scripts/prepare_scale_inv_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def initialize_cluster_details(scale_version, cluster_name, cluster_type, userna

def get_host_format(node):
""" Return host entries """
host_format = f"{node['ip_addr']} scale_cluster_quorum={node['is_quorum']} scale_cluster_manager={node['is_manager']} scale_cluster_gui={node['is_gui']} scale_zimon_collector={node['is_collector']} is_nsd_server={node['is_nsd']} is_admin_node={node['is_admin']} ansible_user={node['user']} ansible_ssh_private_key_file={node['key_file']} ansible_python_interpreter=/usr/bin/python3 scale_nodeclass={node['class']} scale_daemon_nodename={node['daemon_nodename']} scale_protocol_node={node['scale_protocol_node']}"
host_format = f"{node['ip_addr']} scale_cluster_quorum={node['is_quorum']} scale_cluster_manager={node['is_manager']} scale_cluster_gui={node['is_gui']} scale_zimon_collector={node['is_collector']} is_nsd_server={node['is_nsd']} is_admin_node={node['is_admin']} ansible_user={node['user']} ansible_ssh_private_key_file={node['key_file']} ansible_python_interpreter=/usr/bin/python3 scale_nodeclass={node['class']} scale_daemon_nodename={node['daemon_nodename']} scale_protocol_node={node['scale_protocol_node']}"
return host_format


Expand Down Expand Up @@ -626,7 +626,7 @@ def initialize_scale_storage_details(az_count, fs_mount, block_size, disk_detail
return storage


def initialize_scale_ces_details(smb, nfs, object, export_ip_pool, filesystem, mountpoint, filesets, enable_ces):
def initialize_scale_ces_details(smb, nfs, object, export_ip_pool, filesystem, mountpoint, filesets, protocol_cluster_instance_names, enable_ces):
""" Initialize ces details.
:args: smb (bool), nfs (bool), object (bool),
export_ip_pool (list), filesystem (string), mountpoint (string)
Expand All @@ -637,12 +637,16 @@ def initialize_scale_ces_details(smb, nfs, object, export_ip_pool, filesystem, m
key.split('/')[-1]: value for key, value in filesets.items()}
exports = list(filesets_name_size.keys())

# Creating map of CES nodes and it Ips
export_node_ip_map = [{protocol_cluster_instance_name.split(
'.')[0]: ip} for protocol_cluster_instance_name, ip in zip(protocol_cluster_instance_names, export_ip_pool)]

ces = {
"scale_protocols": {
"nfs": nfs,
"object": object,
"smb": smb,
"export_ip_pool": export_ip_pool,
"export_node_ip_map": export_node_ip_map,
"filesystem": filesystem,
"mountpoint": mountpoint,
"exports": exports
Expand Down Expand Up @@ -979,6 +983,7 @@ def initialize_scale_ces_details(smb, nfs, object, export_ip_pool, filesystem, m
TF['filesystem'],
TF['mountpoint'],
TF['filesets'],
TF['protocol_cluster_instance_names'],
ARGUMENTS.enable_ces)
scale_storage_cluster = {
'scale_protocols': scale_protocols['scale_protocols'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,16 @@ variable "zone" {}
variable "action" {}
variable "next_hop" {}
variable "priority" {}
variable "turn_on" {}
variable "clone_complete" {}
variable "storage_cluster_create_complete" {}
variable "create_scale_cluster" {}
variable "scale_ces_enabled" {}
variable "dest_ip" {}
variable "storage_admin_ip" {}
variable "storage_private_key" {}

data "external" "get_ces_ips" {
count = (tobool(var.turn_on) == true && tobool(var.scale_ces_enabled) == true && tobool(var.clone_complete) == true && tobool(var.storage_cluster_create_complete) == true && tobool(var.create_scale_cluster) == true) ? 1 : 0
program = ["bash", "-c", <<-EOT
remote_command='/usr/lpp/mmfs/bin/mmces address list -Y | tail -n +2 | awk -F: '\''{print $7, $8}'\'' | sort -k2 | awk '\''{print $1}'\'''
ces_ips=$(ssh -i ${var.storage_private_key} root@${var.storage_admin_ip} "$remote_command")
ces_ips_json="{ \"ces_ips\": \"$ces_ips\" }"
echo $ces_ips_json
EOT
]
}

locals {
ces_ips = var.scale_ces_enabled == true && var.create_scale_cluster == true ? split(" ", data.external.get_ces_ips[0].result.ces_ips) : []
destination_ip = var.scale_ces_enabled == true && var.create_scale_cluster == true ? local.ces_ips : var.dest_ip
}

resource "ibm_is_vpc_routing_table_route" "itself" {
for_each = var.scale_ces_enabled == true && var.create_scale_cluster != true ? {} : {
for_each = var.scale_ces_enabled == false ? {} : {
# This assigns a subnet-id to each of the instance
# iteration.
for idx, count_number in range(1, var.total_vsis + 1) : idx => {
sequence_string = tostring(count_number)
destination_ip = element(local.destination_ip, idx)
destination_ip = element(var.dest_ip, idx)
next_hop = element(var.next_hop, idx)
zone = element(var.zone, idx)
}
Expand All @@ -62,15 +40,9 @@ resource "ibm_is_vpc_routing_table_route" "itself" {
action = var.action
next_hop = each.value.next_hop
priority = var.priority
depends_on = [data.external.get_ces_ips]
}

output "route_details" {
value = resource.ibm_is_vpc_routing_table_route.itself
depends_on = [resource.ibm_is_vpc_routing_table_route.itself]
}

output "ansible_ces_ip_result" {
value = local.ces_ips
depends_on = [data.external.get_ces_ips]
}

0 comments on commit 0703ffe

Please sign in to comment.