#!/bin/bash

cat netplan.yaml \
	| relpipe-in-yamltable \
		--relation 'nic' \
			--records '/yaml/network/ethernets/*|/yaml/network/bridges/*' \
			--attribute 'name'         string    'name()' \
			--attribute 'type'         string    'name(..)' \
			--attribute 'dhcp4'        boolean   'dhcp4' \
			--attribute 'dhcp6'        boolean   'dhcp6' \
			--attribute 'accept-ra'    boolean   'accept-ra' \
		--relation 'bridge' \
			--records '/yaml/network/bridges/*' \
			--attribute 'name'         string    'name()' \
			--attribute 'gateway4'     string    'gateway4' \
			--attribute 'mtu'          string    'mtu' \
		--relation 'bridge_interface' \
			--records '/yaml/network/bridges/*/interfaces' \
			--attribute 'bridge'       string    'name(..)' \
			--attribute 'interface'    string    '.' \
		--relation 'ip' \
			--records '/yaml/network/bridges/*/addresses' \
			--attribute 'address'      string    'substring-before(., "/")' \
			--attribute 'mask'         string    'substring-after(., "/")' \
			--attribute 'interface'    string    'name(..)' \
	| relpipe-out-tabular

# an early draft of the relational mapping
