XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Dynamic cloudinit network config [FEATURE REQUEST]

    Scheduled Pinned Locked Moved Xen Orchestra
    7 Posts 4 Posters 278 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      encryptblockr
      last edited by encryptblockr

      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.7

      in xen-orchestra we only can apply dynamic hostnames, but we can not apply dynamic static ip

      a908465f-64d6-4a9d-b159-158d1cd19376-image.png

      D 1 Reply Last reply Reply Quote 0
      • E encryptblockr referenced this topic on
      • D Offline
        dj423 @encryptblockr
        last edited by dj423

        @encryptblockr

        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.

        E 1 Reply Last reply Reply Quote 1
        • E Offline
          encryptblockr @dj423
          last edited by

          @dj423 really cool

          for now i decided to create one at a time
          but when i get some will look into what you have above

          thanks again!!!

          1 Reply Last reply Reply Quote 0
          • olivierlambertO Offline
            olivierlambert Vates 🪐 Co-Founder CEO
            last edited by

            @julien-f I think we isolated Cloudinit variable from XO variable so we couldn't use XO variable in Cloudinit to do numbering, right?

            julien-fJ 1 Reply Last reply Reply Quote 0
            • julien-fJ Offline
              julien-f Vates 🪐 Co-Founder XO Team @olivierlambert
              last edited by

              @olivierlambert It's still possible to use the VM number in the cloud-init template: {index} since XO 5.100 (% before)

              See the changelog.

              1 Reply Last reply Reply Quote 1
              • olivierlambertO Offline
                olivierlambert Vates 🪐 Co-Founder CEO
                last edited by

                So it could be a solution 🙂

                D 1 Reply Last reply Reply Quote 1
                • D Offline
                  dj423 @olivierlambert
                  last edited by

                  @julien-f

                  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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post