2.6. Automated pre-configuration using Cloud-init

2.6.1. Cloud-init

Cloud-init is the defacto multi-distribution package that handles early initialization of a cloud instance. Using cloud-init, it is possible to preconfigure Turbo Router.

See also

For more information about Cloud-init, refer to https://cloudinit.readthedocs.io/en/latest/

Customizing the Turbo Router configuration files is possible only at first boot. The turbo service is started sooner in the next boots, before cloud-init.

2.6.2. Libvirt

The simpler way of using cloud-init with libvirt is to create an iso file labelled cidata.

  1. Write a user-data file and a meta-data file. In this example, we setup the root password and upload a license file.

    # cat << EOF > /tmp/user-data
    #cloud-config
    write_files:
     - path: /usr/admin/etc/turbo.lic
       content: |
         LICENSE 6wind turbo-router 01.99.99 permanent uncounted
           hostid=isv=628CE7A75DA9EFB7B3A2D3CDEB566889 customer=yourcompany
           _ck=c082fce984 sig="60PG4527MCR2KEKTD2UP7TRN18G1R6GDJCUM2XH508A03PHQ
    chpasswd:
      list: |
        root:myrootpassword
    EOF
    
    # cat << EOF > meta-data
    instance-id: turbo-vm
    local-hostname: turbo-vm
    EOF
    
  2. Build an iso image with the cidata label containing the user-data and meta-data and put it in the libvirt images directory.

    # apt-get install -y genisoimage
    # genisoimage -output seed.iso -volid cidata \
                             -joliet -rock user-data meta-data
    # cp seed.iso /var/lib/libvirt/images/
    
  3. Add seed.iso as a disk to the virt-install command. For instance, for a VM with virtual NICs.

    # virt-install --name vm1 --vcpus=3,sockets=1,cores=3,threads=1 \
                   --os-type linux --cpu host --network=default,model=e1000 \
                   --ram 6144 --noautoconsole --import \
                   --disk /var/lib/libvirt/images/vm1.qcow2,device=disk,bus=virtio \
                   --disk /var/lib/libvirt/images/seed.iso,device=disk,bus=virtio
    

2.6.3. OpenStack

Cloud-init is integrated within OpenStack.

  1. Write a cloud-init user-data file. In this example, we setup the root password and upload a license file.

    # cat << EOF > /tmp/user-data
    #cloud-config
    write_files:
     - path: /usr/admin/etc/turbo.lic
       content: |
         LICENSE 6wind turbo-router 01.99.99 permanent uncounted
           hostid=isv=628CE7A75DA9EFB7B3A2D3CDEB566889 customer=yourcompany
           _ck=c082fce984 sig="60PG4527MCR2KEKTD2UP7TRN18G1R6GDJCUM2XH508A03PHQ
    chpasswd:
      list: |
        root:myrootpassword
    EOF
    
  2. Start the VM with the additional parameter --user-data.

    # openstack server create --flavor turbo-router \
                              --image turbo-router \
                              --user-data /tmp/user-data \
                              turbo-router_vm
    

2.6.4. Examples

Here are a few user-data samples.

  1. Update the fast-path.env file that takes ens3 out of the fast path ports.

    #cloud-config
    write_files:
     - path: /etc/fast-path.env
       content: |
         FP_PORTS='all -ens3'
    

    Note

    As explained in the Customizing the configuration section, the /etc/fast-path.env file is generated by the fast path configuration wizard. You can export this file out of the Turbo Router and put it in the cloud-init configuration as shown in this example.

  2. Provide a start configuration, where ssh is enabled, and dhcp is enabled on ens3 and ens4 ports, and default route is learnt only on ens3.

    #cloud-config
    write_files:
     - path: /usr/admin/xml/conf/start
       content: |
         <?xml version="1.0"?>
         <configuration name="start">
           <system>
             <timezone>
               <region>GMT</region>
             </timezone>
             <ssh>
               <ssh-enabled/>
             </ssh>
           </system>
           <ports/>
           <interfaces>
             <interface>
               <name>ens3</name>
               <description>Ethernet interface</description>
               <encapsulation>
                 <ethernet-port>ens3</ethernet-port>
               </encapsulation>
               <protocols>
                 <ipv4-dhcp-client>
                   <enable-dhcp/>
                   <request-default-gateway-enabled/>
                   <request-dns-server-enabled/>
                 </ipv4-dhcp-client>
               </protocols>
             </interface>
             <interface>
               <name>ens4</name>
               <description>Ethernet interface</description>
               <encapsulation>
                 <ethernet-port>ens4</ethernet-port>
               </encapsulation>
               <protocols>
                 <ipv4-dhcp-client>
                   <enable-dhcp/>
                 </ipv4-dhcp-client>
               </protocols>
             </interface>
           </interfaces>
         </configuration>
    

    Note

    When a configuration is saved, as described in Networking configuration, it creates a file in the /usr/admin/xml/conf/ directory. The start configuration that you created can hence be found in /usr/admin/xml/conf/start. You can export this file out of the Turbo Router and put it in the cloud-init configuration as shown in this example.

  3. Upload the Turbo Router license file.

    #cloud-config
    write_files:
     - path: /usr/admin/etc/turbo.lic
       content: |
         LICENSE 6wind turbo-router 01.99.99 permanent uncounted
           hostid=isv=628CE7A75DA9EFB7B3A2D3CDEB566889 customer=yourcompany
           _ck=c082fce984 sig="60PG4527MCR2KEKTD2UP7TRN18G1R6GDJCUM2XH508A03PHQ
    
  4. Disable Turbo Router start at boot time.

    #cloud-config
    bootcmd:
     - rm -f /var/lib/cloud/scripts/per-once/50_enable-turbo.sh