| Ilya Bumarskov | 54f2ffb | 2025-10-14 13:29:14 +0200 | [diff] [blame^] | 1 | heat_template_version: queens |
| 2 | |
| 3 | parameters: |
| 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 |
| 21 | default: 450 |
| 22 | 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 |
| 31 | |
| 32 | resources: |
| 33 | |
| 34 | pxe_network_port: |
| 35 | type: OS::Neutron::Port |
| 36 | properties: |
| 37 | network: { get_param: pxe_network } |
| 38 | port_security_enabled: false |
| 39 | fixed_ips: |
| 40 | - subnet: { get_param: pxe_subnet } |
| 41 | |
| 42 | ip_addr_pxe: |
| 43 | type: OS::Heat::Value |
| 44 | properties: |
| 45 | type: string |
| 46 | value: { get_attr: [ pxe_network_port, fixed_ips, 0, ip_address ] } |
| 47 | |
| 48 | ip_mask_pxe: |
| 49 | type: OS::Heat::Value |
| 50 | properties: |
| 51 | type: string |
| 52 | value: { str_split: [ '/', { get_attr: [ pxe_network_port, subnets, 0, cidr ] }, 1 ] } |
| 53 | |
| 54 | k8s_network_port: |
| 55 | type: OS::Neutron::Port |
| 56 | properties: |
| 57 | network: { get_param: k8s_network } |
| 58 | port_security_enabled: false |
| 59 | fixed_ips: |
| 60 | - subnet: { get_param: k8s_subnet_id } |
| 61 | |
| 62 | floating_ip_k8s_net: |
| 63 | type: OS::Neutron::FloatingIP |
| 64 | properties: |
| 65 | floating_network_id: { get_param: public_net_id } |
| 66 | port_id: { get_resource: k8s_network_port } |
| 67 | |
| 68 | wait_handle: |
| 69 | type: OS::Heat::WaitConditionHandle |
| 70 | |
| 71 | wait_condition: |
| 72 | type: OS::Heat::WaitCondition |
| 73 | properties: |
| 74 | handle: { get_resource: wait_handle } |
| 75 | timeout: { get_param: boot_timeout } |
| 76 | |
| 77 | server_init: |
| 78 | type: OS::Heat::CloudConfig |
| 79 | properties: |
| 80 | cloud_config: |
| 81 | password: 'r00tme' |
| 82 | chpasswd: |
| 83 | expire: false |
| 84 | ssh_pwauth: true |
| 85 | packages: |
| 86 | - bridge-utils |
| 87 | - cpu-checker |
| 88 | - libvirt-clients |
| 89 | - libvirt-daemon |
| 90 | - libvirt-daemon-system |
| 91 | - qemu-kvm |
| 92 | - virt-manager |
| 93 | - virtinst |
| 94 | - python3-virtualbmc |
| 95 | - ipmitool |
| 96 | write_files: |
| 97 | - path: /etc/systemd/system/virtualbmc.service |
| 98 | content: | |
| 99 | [Unit] |
| 100 | Description=Virtual BMC Service |
| 101 | After=network.target libvirtd.service |
| 102 | [Service] |
| 103 | Type=simple |
| 104 | ExecStart=/usr/bin/vbmcd --foreground |
| 105 | ExecStop=/bin/kill -HUP $MAINPID |
| 106 | User=root |
| 107 | Group=root |
| 108 | [Install] |
| 109 | WantedBy=multi-user.target |
| 110 | - path: /etc/netplan/99-custom-bridge.yaml |
| 111 | content: |
| 112 | str_replace: |
| 113 | template: | |
| 114 | network: |
| 115 | version: 2 |
| 116 | bridges: |
| 117 | br_pxe: |
| 118 | interfaces: [ens4] |
| 119 | addresses: [ip_addr/ip_mask] |
| 120 | params: |
| 121 | ip_addr: { get_attr: [ ip_addr_pxe, value ] } |
| 122 | ip_mask: { get_attr: [ ip_mask_pxe, value ] } |
| 123 | runcmd: |
| 124 | - str_replace: |
| 125 | template: | |
| 126 | #!/bin/bash |
| 127 | set +x |
| 128 | netplan apply |
| 129 | sudo ip addr flush dev ens4 |
| 130 | systemctl enable --now virtualbmc.service |
| 131 | # Run instances with vBMC |
| 132 | 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 |
| 133 | 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 |
| 134 | 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 |
| 135 | vbmc add child-control-1 --port 6231 --username engineer --password password && vbmc start child-control-1 |
| 136 | vbmc add child-control-2 --port 6232 --username engineer --password password && vbmc start child-control-2 |
| 137 | vbmc add child-control-3 --port 6233 --username engineer --password password && vbmc start child-control-3 |
| 138 | # Collect VM data |
| 139 | mac1=$(virsh domiflist child-control-1 | grep 'br_pxe' | awk '{print $5}') |
| 140 | mac2=$(virsh domiflist child-control-2 | grep 'br_pxe' | awk '{print $5}') |
| 141 | mac3=$(virsh domiflist child-control-3 | grep 'br_pxe' | awk '{print $5}') |
| 142 | # Simple success signal |
| 143 | wc_notify --data-binary '{"status": "SUCCESS", "data": {"vnodes": [{"mac": "'${mac1}'", "port": "6231"}, {"mac": "'${mac2}'", "port": "6232"}, {"mac": "'${mac3}'", "port": "6233"}]}}' |
| 144 | params: |
| 145 | wc_notify: { get_attr: [ wait_handle, curl_cli ] } |
| 146 | |
| 147 | server: |
| 148 | type: OS::Nova::Server |
| 149 | properties: |
| 150 | availability_zone: { get_param: availability_zone } |
| 151 | image: { get_param: image } |
| 152 | flavor: { get_param: flavor } |
| 153 | key_name: { get_param: key_name } |
| 154 | networks: |
| 155 | - port: { get_resource: k8s_network_port } |
| 156 | - port: { get_resource: pxe_network_port } |
| 157 | user_data_format: RAW |
| 158 | user_data: { get_resource: server_init } |
| 159 | |
| 160 | outputs: |
| 161 | server_public_ip: |
| 162 | description: Floating IP address of server in public network |
| 163 | value: { get_attr: [ floating_ip_k8s_net, floating_ip_address ] } |
| 164 | vbmc_ip: |
| 165 | description: IP address of interface in PXE network (virtual BMC) |
| 166 | value: { get_attr: [ ip_addr_pxe, value ] } |
| 167 | vnodes_data: |
| 168 | description: Virtual nodes data (mac addresses and vbmc ports) |
| 169 | value: { get_attr: [ wait_condition, data ] } |