blob: e7f44c8057ff8893f2835b16a1f6d473308f4e8a [file] [log] [blame]
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +02001heat_template_version: queens
2
3parameters:
4
5 k8s_network:
6 type: string
7 k8s_subnet_id:
8 type: string
9 public_net_id:
10 type: string
11 pxe_network:
12 type: string
13 pxe_subnet:
14 type: string
15 availability_zone:
16 type: string
17 default: nova
18 boot_timeout:
19 type: number
20 description: Boot timeout for instance
Ilya Bumarskovd668fb72025-11-18 16:09:34 +010021 default: 600
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +020022 image:
23 type: string
24 description: Name of image to use for servers
25 flavor:
26 type: string
27 description: Flavor to use for servers
28 key_name:
29 type: string
30 description: Name of keypair to assign to servers
Ilya Bumarskovd668fb72025-11-18 16:09:34 +010031 k8s_vip:
32 type: string
33 description: VIP of kubernetes (child cluster)
34 k8s_svc_network_cidr:
35 type: string
36 description: CIDR of kubernetes service network
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +020037
38resources:
39
40 pxe_network_port:
41 type: OS::Neutron::Port
42 properties:
43 network: { get_param: pxe_network }
44 port_security_enabled: false
45 fixed_ips:
46 - subnet: { get_param: pxe_subnet }
47
48 ip_addr_pxe:
49 type: OS::Heat::Value
50 properties:
51 type: string
52 value: { get_attr: [ pxe_network_port, fixed_ips, 0, ip_address ] }
53
54 ip_mask_pxe:
55 type: OS::Heat::Value
56 properties:
57 type: string
58 value: { str_split: [ '/', { get_attr: [ pxe_network_port, subnets, 0, cidr ] }, 1 ] }
59
60 k8s_network_port:
61 type: OS::Neutron::Port
62 properties:
63 network: { get_param: k8s_network }
64 port_security_enabled: false
65 fixed_ips:
66 - subnet: { get_param: k8s_subnet_id }
67
68 floating_ip_k8s_net:
69 type: OS::Neutron::FloatingIP
70 properties:
71 floating_network_id: { get_param: public_net_id }
72 port_id: { get_resource: k8s_network_port }
73
74 wait_handle:
75 type: OS::Heat::WaitConditionHandle
76
77 wait_condition:
78 type: OS::Heat::WaitCondition
79 properties:
80 handle: { get_resource: wait_handle }
81 timeout: { get_param: boot_timeout }
82
83 server_init:
84 type: OS::Heat::CloudConfig
85 properties:
86 cloud_config:
87 password: 'r00tme'
88 chpasswd:
89 expire: false
90 ssh_pwauth: true
91 packages:
92 - bridge-utils
93 - cpu-checker
94 - libvirt-clients
95 - libvirt-daemon
96 - libvirt-daemon-system
97 - qemu-kvm
98 - virt-manager
99 - virtinst
100 - python3-virtualbmc
101 - ipmitool
Ilya Bumarskovd668fb72025-11-18 16:09:34 +0100102 - docker.io
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +0200103 write_files:
104 - path: /etc/systemd/system/virtualbmc.service
105 content: |
106 [Unit]
107 Description=Virtual BMC Service
108 After=network.target libvirtd.service
109 [Service]
110 Type=simple
111 ExecStart=/usr/bin/vbmcd --foreground
112 ExecStop=/bin/kill -HUP $MAINPID
113 User=root
114 Group=root
115 [Install]
116 WantedBy=multi-user.target
117 - path: /etc/netplan/99-custom-bridge.yaml
118 content:
119 str_replace:
120 template: |
121 network:
122 version: 2
123 bridges:
124 br_pxe:
125 interfaces: [ens4]
126 addresses: [ip_addr/ip_mask]
Ilya Bumarskovd668fb72025-11-18 16:09:34 +0100127 routes:
128 - to: k8s_svc_network_cidr
129 via: k8s_vip
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +0200130 params:
131 ip_addr: { get_attr: [ ip_addr_pxe, value ] }
132 ip_mask: { get_attr: [ ip_mask_pxe, value ] }
Ilya Bumarskovd668fb72025-11-18 16:09:34 +0100133 k8s_vip: { get_param: k8s_vip }
134 k8s_svc_network_cidr: { get_param: k8s_svc_network_cidr }
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +0200135 runcmd:
136 - str_replace:
137 template: |
138 #!/bin/bash
139 set +x
140 netplan apply
141 sudo ip addr flush dev ens4
142 systemctl enable --now virtualbmc.service
143 # Run instances with vBMC
144 virt-install --name child-control-1 --ram 8192 --vcpus 4 --disk size=20,bus=scsi --os-variant generic --network bridge=br_pxe,model=virtio --graphics vnc,listen=0.0.0.0 --boot network --pxe --noautoconsole
145 virt-install --name child-control-2 --ram 8192 --vcpus 4 --disk size=20,bus=scsi --os-variant generic --network bridge=br_pxe,model=virtio --graphics vnc,listen=0.0.0.0 --boot network --pxe --noautoconsole
146 virt-install --name child-control-3 --ram 8192 --vcpus 4 --disk size=20,bus=scsi --os-variant generic --network bridge=br_pxe,model=virtio --graphics vnc,listen=0.0.0.0 --boot network --pxe --noautoconsole
147 vbmc add child-control-1 --port 6231 --username engineer --password password && vbmc start child-control-1
148 vbmc add child-control-2 --port 6232 --username engineer --password password && vbmc start child-control-2
149 vbmc add child-control-3 --port 6233 --username engineer --password password && vbmc start child-control-3
150 # Collect VM data
151 mac1=$(virsh domiflist child-control-1 | grep 'br_pxe' | awk '{print $5}')
152 mac2=$(virsh domiflist child-control-2 | grep 'br_pxe' | awk '{print $5}')
153 mac3=$(virsh domiflist child-control-3 | grep 'br_pxe' | awk '{print $5}')
154 # Simple success signal
155 wc_notify --data-binary '{"status": "SUCCESS", "data": {"vnodes": [{"mac": "'${mac1}'", "port": "6231"}, {"mac": "'${mac2}'", "port": "6232"}, {"mac": "'${mac3}'", "port": "6233"}]}}'
156 params:
157 wc_notify: { get_attr: [ wait_handle, curl_cli ] }
158
159 server:
Ilya Bumarskovd668fb72025-11-18 16:09:34 +0100160 # TODO: set attribute no_fixed_ips: https://bugs.launchpad.net/ubuntu/+source/heat/+bug/2085409
Ilya Bumarskov54f2ffb2025-10-14 13:29:14 +0200161 type: OS::Nova::Server
162 properties:
163 availability_zone: { get_param: availability_zone }
164 image: { get_param: image }
165 flavor: { get_param: flavor }
166 key_name: { get_param: key_name }
167 networks:
168 - port: { get_resource: k8s_network_port }
169 - port: { get_resource: pxe_network_port }
170 user_data_format: RAW
171 user_data: { get_resource: server_init }
172
173outputs:
174 server_public_ip:
175 description: Floating IP address of server in public network
176 value: { get_attr: [ floating_ip_k8s_net, floating_ip_address ] }
177 vbmc_ip:
178 description: IP address of interface in PXE network (virtual BMC)
179 value: { get_attr: [ ip_addr_pxe, value ] }
180 vnodes_data:
181 description: Virtual nodes data (mac addresses and vbmc ports)
182 value: { get_attr: [ wait_condition, data ] }