Skip to content

Latest commit

 

History

History
197 lines (156 loc) · 5.62 KB

README.md

File metadata and controls

197 lines (156 loc) · 5.62 KB

Convert/Create & serve WeOS .conf over the network

Introduction

The dhcp-boot application is an example of how a container application can create or convert a WeOS configuration file and then serve it to the WeOS host system as the host system itself boots.

In a real-world scenario a non-native configuration file format on USB is converted by the app and served to WeOS in its native format. In our limited example the application only changes the hostname to verify that the WeOS configuration has been received from the application.

The host (WeOS) first acquires a DHCP lease from the app, the lease contains a boot file option and a boot server address to the container application, from where WeOS downloads its running-config using TFTP.

Host            #  DHCP Boot Application
                #  .-------------.  .-------------.
                #  | DHCP-server |  | TFTP-server |
                #  '------+------'  '------+------'
.------------.  #         '------.  .------'
|    cfg     |  #              .-+--+-.
| inet: dhcp |  #              | eth0 |
'------+-----'  #              '--+---'
       |        #                 |
       '--------------------------'

Figure 1: WeOS host system on the left and the app on the right

Setup

The application in this demo creates the WeOS configuration using the script create-config.sh, only the hostname is changed, using a template we create at the very end of this document.

The container application is connected to the host via the VETH pair named cfg <---> eth0, cfg in WeOS and eth0 in the application. The application uses the Open Source program dnsmasq to act as a DHCP and TFTP server.

The application side of the VETH pair (eth0) networking is set up using the Debian/BusyBox ifupdown program. The configuration file is in /etc/network/interfaces. The IP address is set to 10.0.0.1/30 and has to be consistent with option 66 in /etc/dnsmasq.conf in the app:

# /etc/dnsmasq.conf
log-facility=-
no-daemon

enable-tftp
tftp-root=/tmp

interface=eth0
dhcp-option=66,"10.0.0.1"
dhcp-option=67,"config.cfg"

dhcp-range=tag:eth0,10.0.0.2,10.0.0.2,1h

The WeOS host will be handed the IP lease 10.0.0.2/30 with options 66 and 67 set for TFTP server (the container) and the filename to download.

Configuration

Prepare External Media

It is important that the USB media is formatted as ext2, ext3 or ext4. We also need to create two files on the external media:

  • pre-config.cfg: The template config file that the application alters and saves as config.cfg
  • config/net-config.cfg: The custom WeOS bootstrap config that carries the configuration of our application container

pre-config.cfg

Configuration file containing a hostname. E.g.

{
  .
  .
  "system": {
    "hostname": "Host",
    .
    .
    .
  },
  .
  .
}

config.cfg

In our example config.cfg is generated by the application by altering the hostname in the pre-config.cfg.

The file should look something like this after the conversion.

{
  .
  .
  "system": {
    "hostname": "Host_name_from_app",
    .
    .
    .
  },
  .
  .
}

After reboot the container application starts up, the host fetches the new running-config from the container, and that config is applied, resulting in the hostname changing to "Host_name_from_app".

Prepare the external media by creating the net-config.cfg file:

creation of config/net-config.cfg

net-config will be stored on external media.

Configure the app that will host/run the files we have created:

example:/#> configure app cfg dhcp-boot
example:/config/app-cfg/#> share path /usb as /mnt
example:/config/app-cfg/#> end

Along with the app, a VETH pair is created. By default it will have the same name as the app on the host side, and eth0 on the container side. We need to configure DHCP for the host side interface:

example:/#> configure iface cfg
example:/config/iface-cfg/#> inet dhcp
example:/config/iface-cfg/inet-dhcp/#> option 66, 67
example:/config/iface-cfg/inet-dhcp/#> leave

The net-config is now complete. Copy it to the external media and reset the running-config:

example:/#> copy running-config usb://config/net-config.cfg
Copying running-config to /usb/config/net-config.cfg ...
example:/#> Done.
Host:/#> copy factory-config running-config
Applying configuration.

Creation of pre-config.cfg

The pre-config.cfg is stored on USB media, here we create one for demo purposes by setting the hostname to "Host" in the WeOS CLI and then use the cp command save the file to the USB stick. In a real-life example this file already exists (in possibly another format) on the USB stick.

example:/#> configure system
example:/config/system/#> hostname Host
example:/config/system/#> leave
Applying configuration.
Configuration activated.  Remember "copy run start" to save to flash (NVRAM).
Host:/#> cp running-config usb://pre-config.cfg
Copying running-config to /usb/pre-config.cfg ...
Done.

Finally we configure our system to use net-config on external media to boot the system, and reboot:

example:/#> boot
example:/boot/#> config-order ext:net
example:/boot/#> leave
example:/#> reboot

After reboot the container application is started from WeOS net-config where it "converts" the pre-config.cfg to /tmp/config.cfg, simply by setting a new hostname: "Host_name_from_app". The host WeOS system meanwhile acquries a DHCP lease from the container and then fetches its bootfile (config.cfg), and applies as its new running-config. We can verify this by inspecting the new hostname of the host WeOS system.