2.5. Automated pre-configuration

If you installed Virtual Service Router as a new system, it includes a Day-1 configuration mechanism that starts a DHCP client on the first interface and enables a SSH server on it, so that the user can remotely access the console. This mechanism relies on cloud-init and can be customized as described in the following sections.

2.5.1. Day-1 configuration

At Virtual Service Router startup, the Day-1 configuration is applied if one of the following file is present on the system:

  • /etc/init-config.cli: this file can contain a list of CLI commands to be executed at startup.

  • /etc/init-config.json: this file can contain a configuration in JSON format.

On success, the configuration is copied to the startup configuration and becomes persistent.

Note

If both files are present, /etc/init-config.cli is applied first, then /etc/init-config.json.

2.5.2. Cloud-init for baremetal and VNF

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

See also

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

Customizing the Virtual Service Router configuration files via cloud-init is possible only at first boot.

2.5.3. Cloud-Init for VNF using 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.

    cat << EOF > /tmp/user-data
    #cloud-config
    chpasswd:
      list: |
        root:myrootpassword
    EOF
    
    cat << EOF > meta-data
    instance-id: vsr-vm
    local-hostname: vsr-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-variant ubuntu18.04 --cpu host --network=default,model=e1000 \
                 --ram 8192 --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.5.4. Cloud-Init for VNF using OpenStack

Cloud-init is integrated within OpenStack.

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

    cat << EOF > /tmp/user-data
    #cloud-config
    chpasswd:
      list: |
        root:myrootpassword
    EOF
    
  2. Start the VM with the additional parameter --user-data.

    openstack server create --flavor vsr \
                            --image vsr \
                            --user-data /tmp/user-data \
                            vsr_vm
    

2.5.5. Initial configuration for CNF using Docker

To specify an initial configuration file to the Virtual Service Router container with docker, use the following argument:

-v /path/to/local/init-config.cli:/etc/init-config.cli:ro

2.5.6. Initial configuration for CNF using Kubernetes

To pass an initial configuration file to the container in Kubernetes, you can use a ConfigMap.

Add the following content to the deployment file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: vsr-init-config
data:
  vsr_init_config: |
    / system license online serial xxx
    / vrf main ssh-server enabled true
---
(...)
      volumeMounts:
       - mountPath: /etc/init-config.cli
         subPath: vsr_init_config
         name: init-config
(...)
    volumes:
    - name: init-config
      configMap:
        name: vsr-init-config
        defaultMode: 0400
(...)

An alternative is to use an Init Container to generate the /etc/init-config.cli or /etc/init-config.json file inside the container. This option is more powerful because it is possible to generate a different configuration for each pod.

2.5.7. Examples of Cloud-Init configuration for the VNF

Here are cloud-init user-data examples, where we upload a startup configuration.

Example in text format (/etc/init-config.cli)

#cloud-config
write_files:
- path: /etc/init-config.cli
  content: |
      / vrf main interface physical pub1 port pci-b0s5
      / vrf main interface physical pub1 ipv4 dhcp enabled
      / system fast-path port pci-b0s5
      / system license online serial xxx

Example in JSON format (/etc/init-config.json)

#cloud-config
write_files:
- path: /etc/init-config.json
  content: |
      {
         "vrouter:config": {
            "vrf": [
               {
                  "name": "main",
                  "vrouter-interface:interface": {
                     "physical": [
                        {
                           "name": "pub1",
                           "port": "pci-b0s5",
                           "ipv4": {
                              "dhcp": {
                                 "enabled": true
                               }
                            }
                         }
                      ]
                   }
                }
             ],
             "vrouter-system:system": {
                "vrouter-fast-path:fast-path": {
                   "port": [
                      "pci-b0s5"
                   ]
                },
                "vrouter-license:license": {
                   "online": {
                      "serial": "xxx"
                   }
                }
             }
          }
       }

2.5.8. Examples of Day-1 configuration for the CNF

Here are examples of files that can be provided to the Virtual Service Router container to provide the initial configuration.

Example in text format (/etc/init-config.cli)

/ vrf main interface physical pub1 port pci-b0s5
/ vrf main interface physical pub1 ipv4 dhcp enabled
/ system fast-path port pci-b0s5
/ system license online serial xxx

Example in JSON format (/etc/init-config.json)

{
   "vrouter:config": {
      "vrf": [
         {
            "name": "main",
            "vrouter-interface:interface": {
               "physical": [
                  {
                     "name": "pub1",
                     "port": "pci-b0s5",
                     "ipv4": {
                        "dhcp": {
                           "enabled": true
                         }
                      }
                   }
                ]
             }
          }
       ],
       "vrouter-system:system": {
          "vrouter-fast-path:fast-path": {
             "port": [
                "pci-b0s5"
             ]
          },
          "vrouter-license:license": {
             "online": {
                "serial": "xxx"
             }
          }
       }
    }
 }