#!/bin/bash

new_veth()
{
    local if_up=${if_up:-yes}
    local nm_managed=${nm_managed:-yes}
    for i in `seq 0 ${1}`; do
        ip link add veth${2}${i} type veth peer name veth${2}${i}_ep
            if [ ${if_up} == 'yes' ]; then
                ip link set veth${2}${i} up
                ip link set veth${2}${i}_ep up
            fi
            if [ ${nm_managed} != 'notouch' ]; then
                nmcli device set veth${2}${i} managed $nm_managed
                nmcli device set veth${2}${i}_ep managed $nm_managed
            fi
    done
}

new_veth 5

set -x
echo 'interfaces:
- name: bond0
  state: up
  type: bond
  ipv4:
    enabled: true
    address:
    - ip: 1.1.1.1
      prefix-length: 24
  ipv6:
    enabled: true
    address:
    - ip: 1::1
      prefix-length: 64
  link-aggregation:
    mode: 802.3ad
    port:
    - veth0
    - veth1
- name: br0
  state: up
  type: linux-bridge
  ipv4:
    enabled: true
    address:
    - ip: 3.3.3.1
      prefix-length: 24
  ipv6:
    enabled: true
    address:
    - ip: 3::1
      prefix-length: 64
  bridge:
    options:
      stp:
        enabled: false
    port:
    - name: veth5
    - name: veth4
- name: bond0.4000
  type: vlan
  state: up
  ipv4:
    enabled: true
    address:
    - ip: 4.4.4.1
      prefix-length: 24
  ipv6:
    enabled: true
    address:
    - ip: 4::1
      prefix-length: 64
  vlan:
    base-iface: bond0
    id: 4000
- name: vrf0
  state: up
  type: vrf
  ipv4:
    enabled: true
    address:
    - ip: 5.5.5.1
      prefix-length: 24
  ipv6:
    enabled: true
    address:
    - ip: 5::1
      prefix-length: 64
  vrf:
    route-table-id: 100
    port:
    - bond0
    - br0
    - bond0.4000' | nmstatectl apply
nmcli con
echo 'interfaces:
- name: vrf0
  state: up
  type: vrf
  vrf:
    route-table-id: 201' | nmstatectl apply
nmcli con
set +x

