Skip to content

Commit 3323346

Browse files
authored
Merge pull request #28 from stackhpc/feat/create-network
Allow caas to create networks itself
2 parents c5de8a7 + beb917d commit 3323346

File tree

4 files changed

+169
-15
lines changed

4 files changed

+169
-15
lines changed

group_vars/cluster.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vault_openhpc_mungekey: "{{ hostvars[groups['control'][0]].ansible_local.openhpc
1515
appliances_local_users_podman_enable: "{{ groups.get('podman', []) | length > 0 }}"
1616

1717
# The server name for Open OnDemand depends on whether Zenith is enabled or not
18-
openondemand_servername_default: "{{ hostvars[groups['openstack'][0]].cluster_floating_ip_address | replace('.', '-') ~ '.sslip.io' }}"
18+
openondemand_servername_default: "{{ hostvars[groups['openstack'][0]].cluster_gateway_ip | replace('.', '-') ~ '.sslip.io' }}"
1919
openondemand_servername: "{{ zenith_fqdn_ood | default(openondemand_servername_default) }}"
2020

2121
appliances_state_dir: /var/lib/state

roles/cluster_infra/templates/outputs.tf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "cluster_gateway_ip" {
22
description = "The IP address of the gateway used to contact the cluster nodes"
3-
value = "{{ cluster_floating_ip_address }}"
3+
value = openstack_compute_floatingip_associate_v2.login_floatingip_assoc.floating_ip
44
}
55

66
output "cluster_nodes" {

roles/cluster_infra/templates/resources.tf.j2

Lines changed: 165 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,150 @@ resource "openstack_blockstorage_volume_v3" "home" {
8989
{% endif %}
9090
}
9191

92+
######
93+
###### Cluster network
94+
######
95+
96+
# Always get cluster_external_network network and subnet data
97+
data "openstack_networking_network_v2" "cluster_external_network" {
98+
name = "{{ cluster_external_network }}"
99+
}
100+
101+
data "openstack_networking_subnet_ids_v2" "cluster_external_subnets" {
102+
network_id = "${data.openstack_networking_network_v2.cluster_external_network.id}"
103+
}
104+
105+
{% if cluster_network is not defined %}
106+
# Create a new network
107+
resource "openstack_networking_network_v2" "cluster_network" {
108+
name = "{{ cluster_name }}-net"
109+
admin_state_up = "true"
110+
}
111+
112+
resource "openstack_networking_subnet_v2" "cluster_subnet" {
113+
name = "{{ cluster_name }}-subnet"
114+
network_id = "${openstack_networking_network_v2.cluster_network.id}"
115+
cidr = "{{ cluster_cidr | default('192.168.44.0/24') }}"
116+
{% if cluster_nameservers is defined %}
117+
dns_nameservers = [
118+
{% for nameserver in cluster_nameservers %}
119+
"{{ nameserver }}"{{ ',' if not loop.last }}
120+
{% endfor %}
121+
]
122+
{% endif %}
123+
ip_version = 4
124+
}
125+
126+
resource "openstack_networking_router_v2" "cluster_router" {
127+
name = "{{ cluster_name }}-router"
128+
admin_state_up = true
129+
external_network_id = "${data.openstack_networking_network_v2.cluster_external_network.id}"
130+
}
131+
132+
resource "openstack_networking_router_interface_v2" "cluster_router_interface" {
133+
router_id = "${openstack_networking_router_v2.cluster_router.id}"
134+
subnet_id = "${openstack_networking_subnet_v2.cluster_subnet.id}"
135+
}
136+
{% endif %}
137+
138+
# Get existing network resource data by name, from either the created
139+
# network or the network name if supplied
140+
data "openstack_networking_network_v2" "cluster_network" {
141+
{% if cluster_network is not defined %}
142+
network_id = "${openstack_networking_network_v2.cluster_network.id}"
143+
{% else %}
144+
name = "{{ cluster_network }}"
145+
{% endif %}
146+
}
147+
148+
data "openstack_networking_subnet_v2" "cluster_subnet" {
149+
# Get subnet data from the subnet we create, or if it exists already
150+
# get it from the cluster network data above
151+
{% if cluster_network is not defined %}
152+
subnet_id = "${openstack_networking_subnet_v2.cluster_subnet.id}"
153+
{% else %}
154+
network_id = "${data.openstack_networking_network_v2.cluster_network.id}"
155+
{% endif %}
156+
}
157+
158+
#####
159+
##### Cluster ports
160+
#####
161+
162+
resource "openstack_networking_port_v2" "login" {
163+
name = "{{ cluster_name }}-login-0"
164+
network_id = "${data.openstack_networking_network_v2.cluster_network.id}"
165+
admin_state_up = "true"
166+
167+
fixed_ip {
168+
subnet_id = "${data.openstack_networking_subnet_v2.cluster_subnet.id}"
169+
}
170+
171+
security_group_ids = [
172+
"${openstack_networking_secgroup_v2.secgroup_slurm_cluster.id}",
173+
"${openstack_networking_secgroup_v2.secgroup_slurm_login.id}"
174+
]
175+
176+
binding {
177+
vnic_type = "{{ cluster_vnic_type | default('normal') }}"
178+
{% if cluster_vnic_profile is defined %}
179+
profile = <<EOF
180+
{{ cluster_vnic_profile | to_json }}
181+
EOF
182+
{% endif %}
183+
}
184+
}
185+
186+
resource "openstack_networking_port_v2" "control" {
187+
name = "{{ cluster_name }}-control-0"
188+
network_id = "${data.openstack_networking_network_v2.cluster_network.id}"
189+
admin_state_up = "true"
190+
191+
fixed_ip {
192+
subnet_id = "${data.openstack_networking_subnet_v2.cluster_subnet.id}"
193+
}
194+
195+
security_group_ids = [
196+
"${openstack_networking_secgroup_v2.secgroup_slurm_cluster.id}"
197+
]
198+
199+
binding {
200+
vnic_type = "{{ cluster_vnic_type | default('normal') }}"
201+
{% if cluster_vnic_profile is defined %}
202+
profile = <<EOF
203+
{{ cluster_vnic_profile | to_json }}
204+
EOF
205+
{% endif %}
206+
}
207+
}
208+
209+
{% for partition in openhpc_slurm_partitions %}
210+
resource "openstack_networking_port_v2" "{{ partition.name }}" {
211+
count = {{ partition.count }}
212+
name = "{{ cluster_name }}-compute-{{ partition.name }}-${count.index}"
213+
network_id = "${data.openstack_networking_network_v2.cluster_network.id}"
214+
admin_state_up = "true"
215+
216+
fixed_ip {
217+
subnet_id = "${data.openstack_networking_subnet_v2.cluster_subnet.id}"
218+
}
219+
220+
security_group_ids = [
221+
"${openstack_networking_secgroup_v2.secgroup_slurm_cluster.id}"
222+
]
223+
224+
binding {
225+
vnic_type = "{{ cluster_vnic_type | default('normal') }}"
226+
{% if cluster_vnic_profile is defined %}
227+
profile = <<EOF
228+
{{ cluster_vnic_profile | to_json }}
229+
EOF
230+
{% endif %}
231+
}
232+
}
233+
234+
{% endfor %}
235+
92236

93237
#####
94238
##### Cluster nodes
@@ -104,12 +248,9 @@ resource "openstack_compute_instance_v2" "login" {
104248
{% endif %}
105249

106250
network {
107-
name = "{{ cluster_network }}"
251+
port = "${openstack_networking_port_v2.login.id}"
108252
}
109-
security_groups = [
110-
"${openstack_networking_secgroup_v2.secgroup_slurm_cluster.name}",
111-
"${openstack_networking_secgroup_v2.secgroup_slurm_login.name}"
112-
]
253+
113254
# Use cloud-init to inject the SSH keys
114255
user_data = <<-EOF
115256
#cloud-config
@@ -127,11 +268,10 @@ resource "openstack_compute_instance_v2" "control" {
127268
{% else %}
128269
flavor_id = "{{ control_flavor }}"
129270
{% endif %}
130-
271+
131272
network {
132-
name = "{{ cluster_network }}"
273+
port = "${openstack_networking_port_v2.control.id}"
133274
}
134-
security_groups = ["${openstack_networking_secgroup_v2.secgroup_slurm_cluster.name}"]
135275

136276
# root device:
137277
block_device {
@@ -188,10 +328,9 @@ resource "openstack_compute_instance_v2" "{{ partition.name }}" {
188328
flavor_name = "{{ partition.flavor_name }}"
189329

190330
network {
191-
name = "{{ cluster_network }}"
331+
port = openstack_networking_port_v2.{{ partition.name }}[count.index].id
192332
}
193333

194-
security_groups = ["${openstack_networking_secgroup_v2.secgroup_slurm_cluster.name}"]
195334
# Use cloud-init to inject the SSH keys
196335
user_data = <<-EOF
197336
#cloud-config
@@ -205,8 +344,23 @@ resource "openstack_compute_instance_v2" "{{ partition.name }}" {
205344
#####
206345
##### Floating IP association for login node
207346
#####
347+
{% if cluster_floating_ip_address is not defined %}
348+
# Create a new floating IP
349+
resource "openstack_networking_floatingip_v2" "cluster_floating_ip" {
350+
pool = "${data.openstack_networking_network_v2.cluster_external_network.name}"
351+
subnet_ids = "${data.openstack_networking_subnet_ids_v2.cluster_external_subnets.ids}"
352+
}
353+
{% endif %}
354+
355+
data "openstack_networking_floatingip_v2" "cluster_floating_ip" {
356+
{% if cluster_floating_ip_address is not defined %}
357+
address = "${openstack_networking_floatingip_v2.cluster_floating_ip.address}"
358+
{% else %}
359+
address = "{{ cluster_floating_ip_address }}"
360+
{% endif %}
361+
}
208362

209363
resource "openstack_compute_floatingip_associate_v2" "login_floatingip_assoc" {
210-
floating_ip = "{{ cluster_floating_ip_address }}"
364+
floating_ip = "${data.openstack_networking_floatingip_v2.cluster_floating_ip.address}"
211365
instance_id = "${openstack_compute_instance_v2.login.id}"
212366
}

slurm-infra.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@
128128
# so we have to repeat logic here unfortunately
129129
outputs: >-
130130
{{-
131-
{ "cluster_access_ip": hostvars[groups['openstack'][0]].cluster_floating_ip_address } |
131+
{ "cluster_access_ip": hostvars[groups['openstack'][0]].cluster_gateway_ip } |
132132
combine(
133133
{
134-
"openondemand_url": "https://" ~ (hostvars[groups['openstack'][0]].cluster_floating_ip_address | replace('.', '-')) ~ ".sslip.io",
134+
"openondemand_url": "https://" ~ (hostvars[groups['openstack'][0]].cluster_gateway_ip | replace('.', '-')) ~ ".sslip.io",
135135
"azimuth_user_password": hostvars[groups['control'][0]].ansible_local.openhpc_secrets.vault_azimuth_user_password
136136
}
137137
if zenith_fqdn_ood is not defined

0 commit comments

Comments
 (0)