Skip to content

Commit

Permalink
add cloud-init gateway setup for compute nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpb committed Jan 16, 2025
1 parent c9fd09a commit eb2e92c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module "compute" {
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
extra_volumes = lookup(each.value, "extra_volumes", {})
gateway_nmcli_connection = lookup(each.value, "gateway_nmcli_connection", "")
gateway_ip = lookup(each.value, "gateway_ip", "")

compute_init_enable = lookup(each.value, "compute_init_enable", [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ resource "openstack_compute_instance_v2" "compute" {
user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
runcmd:
%{ if var.gateway_nmcli_connection == "dummy0" ~}
- nmcli connection add type dummy ifname dummy0 con-name dummy0
- nmcli connection modify dummy0 ipv4.address ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.gateway ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.route-metric 1000 ipv4.method manual
%{ endif ~}
%{ if (var.gateway_nmcli_connection != "") && (var.gateway_nmcli_connection != "dummy0") ~}
- nmcli connection modify '${var.gateway_nmcli_connection}' ipv4.address ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.gateway ${var.gateway_ip}
%{ endif ~}
%{ if var.gateway_nmcli_connection != "" }
- nmcli connection up '${var.gateway_nmcli_connection}'
%{ endif ~}
EOF

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ variable "compute_init_enable" {
type = list(string)
description = "Groups to activate for ansible-init compute rebuilds"
default = []
}
}

variable "gateway_nmcli_connection" {
description = "Name of nmcli connection for default gateway, '' for none or 'dummy0' to create a dummy interface"
type = string
default = ""
}

variable "gateway_ip" {
description = "IP of default gateway. Ignored when gateway_nmcli_connection == 'dummy0'"
type = string
default = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ variable "compute" {
Values are a mapping with:
size: Size of volume in GB
**NB**: The order in /dev is not guaranteed to match the mapping
gateway_nmcli_connection: Name of nmcli connection to set a default
route on via cloud-init, e.g. "System eth0"
or "Bond bond0". Use "dummy0" to create
a dummy interface with dummy route.
gateway_ip: IP of default gateway. Ignored when gateway_nmcli_connection == "dummy0".
EOF
}

Expand Down

0 comments on commit eb2e92c

Please sign in to comment.