Dynamic cloudinit network config [FEATURE REQUEST]
-
We can create multiple VMs from cloud image template by dynamically setting hostnames
BUT how do we also apply setting synamic IP addresses to these VMs???
so that way can have something like this
test-1 -> static ipv4 192.168.1.5
test-2 -> static ipv4 192.168.1.6
test-3 -> static ipv4 192.168.1.7in xen-orchestra we only can apply dynamic hostnames, but we can not apply dynamic static ip
-
-
FWIW: I know I have done this from cli using xo-cli in a bash script.
I don't have all that code handy at the moment, but here is a hack from memory as an example:
#! /bin/bash while IFS=',' read -r name_c1 ip_c2 do file=v1-$ip_c2.yaml cat >> "$file" << EOF network: version: 1 config: - type: physical name: eth0 subnets: - type: static address: $ip_c2/24 gateway: 192.168.0.1 - type: nameserver address: - 192.168.0.10 - 192.168.23.50 search: - example.tld EOF xo-cli vm.create bootAfterCreate=true cloudConfig="$(cat /root/user.yaml)" networkConfig="$(cat $file)" clone=true name_label="$name_c1" template=0856a8d6-7761-f39d-f968-290b18a1bd42 VIFs='json:[{"network":"ca96456f-3843-26f5-7075-1e54xxxx121xxf97"}]' hvmBootFirmware=bios copyHostBiosStrings=true rm $file done < prov-list exit
prov-list example:
Bookworm,192.168.0.217 Noble1,192.168.0.218 Jammy1,192.168.0.219 Oracle9,192.168.0.222 Rocky9,192.168.0.223 Fedora40,192.168.0.224
If you wanted to do different networks, that is a bit more complicated, but just need a variable to render.
Sorry on my tablet and I don't have a better example handy. But this should get you close, and can be handy when you need to stand up a few dozen VM's.
-
@dj423 really cool
for now i decided to create one at a time
but when i get some will look into what you have abovethanks again!!!
-
@julien-f I think we isolated Cloudinit variable from XO variable so we couldn't use XO variable in Cloudinit to do numbering, right?
-
@olivierlambert It's still possible to use the VM number in the cloud-init template:
{index}
since XO 5.100 (%
before)See the changelog.
-
So it could be a solution
-
Would that be something like this for a dynamic network config as an example?
network: version: 1 config: - type: physical name: enX0 subnets: - type: static address: 192.168.99.{index}/24 gateway: 192.168.99.1 - type: nameserver address: - 172.31.31.1 - 192.168.45.11 search: - example.tld
I plan to test this at some point, but I don't do a whole lot of bulk provisioning myself. Just curious.