Examples

Linux bridge on top of default gw NIC with DHCP

policy


capture:
  default-gw: routes.running.destination=="0.0.0.0/0"
  base-iface: interfaces.name==capture.default-gw.routes.running.0.next-hop-interface
desiredState:
  interfaces:
  - name: br1
    description: DHCP aware Linux bridge to connect a nic that is referenced by a default gateway
    type: linux-bridge
    state: up
    mac-address: "{{ capture.base-iface.interfaces.0.mac-address }}"
    ipv4:
      dhcp: true
      enabled: true
    bridge:
      options:
        stp:
          enabled: false
        port:
        - name: "{{ capture.base-iface.interfaces.0.name }}"


current state

routes:
  running:
  - destination: 0.0.0.0/0
    next-hop-address: 192.168.100.1
    next-hop-interface: eth1
    table-id: 254
  - destination: 1.1.1.0/24
    next-hop-address: 192.168.100.1
    next-hop-interface: eth1
    table-id: 254
interfaces:
- name: eth1
  type: ethernet
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    address:
    - ip: 10.244.0.1
      prefix-length: 24
    - ip: 169.254.1.0
      prefix-length: 16
    dhcp: true
    enabled: true

generated state

interfaces:
- name: br1
  description: DHCP aware Linux bridge to connect a nic that is referenced by a default gateway
  type: linux-bridge
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    dhcp: true
    enabled: true
  bridge:
    options:
      stp:
        enabled: false
      port:
      - name: eth1

captured states

base-iface:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: eth1
      type: ethernet
      state: up
      mac-address: 00:00:5E:00:00:01
      ipv4:
        address:
        - ip: 10.244.0.1
          prefix-length: 24
        - ip: 169.254.1.0
          prefix-length: 16
        dhcp: true
        enabled: true
default-gw:
  metaInfo:
     time: "2021-12-15T13:45:40Z"
     version: "0"
  state:
    routes:
      running:
      - destination: 0.0.0.0/0
        next-hop-address: 192.168.100.1
        next-hop-interface: eth1
        table-id: 254

Linux bridge on top of default gw NIC without DHCP

policy


capture:
  default-gw: routes.running.destination=="0.0.0.0/0"
  base-iface: interfaces.name==capture.default-gw.routes.running.0.next-hop-interface
  base-iface-routes: routes.running.next-hop-interface==capture.base-iface.interfaces.0.name
  bridge-routes: capture.base-iface-routes | routes.running.next-hop-interface:="br1"
desiredState:
  interfaces:
  - name: br1
    description: Linux bridge with base interface as a port
    type: linux-bridge
    state: up
    mac-address: "{{ capture.base-iface.interfaces.0.mac-address }}"
    ipv4: "{{ capture.base-iface.interfaces.0.ipv4 }}"
    bridge:
      options:
        stp:
          enabled: false
        port:
        - name: "{{ capture.base-iface.interfaces.0.name }}"
  routes:
    config: "{{ capture.bridge-routes.routes.running }}"


current state

routes:
  running:
  - destination: 0.0.0.0/0
    next-hop-address: 192.168.100.1
    next-hop-interface: eth1
    table-id: 254
  - destination: 1.1.1.0/24
    next-hop-address: 192.168.100.1
    next-hop-interface: eth1
    table-id: 254
interfaces:
- name: eth1
  type: ethernet
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    address:
    - ip: 10.244.0.1
      prefix-length: 24
    - ip: 169.254.1.0
      prefix-length: 16
    dhcp: false
    enabled: true

generated state

interfaces:
- name: br1
  description: Linux bridge with base interface as a port
  type: linux-bridge
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    address:
    - ip: 10.244.0.1
      prefix-length: 24
    - ip: 169.254.1.0
      prefix-length: 16
    dhcp: false
    enabled: true
  bridge:
    options:
      stp:
        enabled: false
      port:
      - name: eth1
routes:
  config:
  - destination: 0.0.0.0/0
    next-hop-address: 192.168.100.1
    next-hop-interface: br1
    table-id: 254
  - destination: 1.1.1.0/24
    next-hop-address: 192.168.100.1
    next-hop-interface: br1 
    table-id: 254


captured states

base-iface:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: eth1
      type: ethernet
      state: up
      mac-address: 00:00:5E:00:00:01
      ipv4:
        address:
        - ip: 10.244.0.1
          prefix-length: 24
        - ip: 169.254.1.0
          prefix-length: 16
        dhcp: false
        enabled: true
default-gw:
  metaInfo:
     time: "2021-12-15T13:45:40Z"
     version: "0"
  state:
    routes:
      running:
      - destination: 0.0.0.0/0
        next-hop-address: 192.168.100.1
        next-hop-interface: eth1
        table-id: 254
base-iface-routes:
  metaInfo:
     time: "2021-12-15T13:45:40Z"
     version: "0"
  state:
    routes:
      running:
      - destination: 0.0.0.0/0
        next-hop-address: 192.168.100.1
        next-hop-interface: eth1
        table-id: 254
      - destination: 1.1.1.0/24
        next-hop-address: 192.168.100.1
        next-hop-interface: eth1
        table-id: 254
bridge-routes:
  metaInfo:
     time: "2021-12-15T13:45:40Z"
     version: "0"
  state:
    routes:
      running:
      - destination: 0.0.0.0/0
        next-hop-address: 192.168.100.1
        next-hop-interface: br1
        table-id: 254
      - destination: 1.1.1.0/24
        next-hop-address: 192.168.100.1
        next-hop-interface: br1
        table-id: 254



OVS SLB bond between primary and secondary nics

It uses the description field to filter between primary and secondary NIC.

policy


capture:
  primary-nic: interfaces.description == "primary"
  secondary-nic: interfaces.description == "secondary"
desiredState:
  interfaces:
  - name: br1-iface
    type: ovs-interface
    state: up
    mac-address: "{{ capture.primary-nic.interfaces.0.mac-address }}"
    ipv4: "{{ capture.primary-nic.interfaces.0.ipv4 }}"
  - name: br1
    type: ovs-bridge
    state: up
    bridge:
      options:
        stp: false
        mcast-snooping-enable: false
        rstp: false
      port:
      - name: bond0
        link-aggregation:
          mode: balance-slb
          port:
          - name: "{{ capture.primary-nic.interfaces.0.name }}"
          - name: "{{ capture.secondary-nic.interfaces.0.name }}"
      - name: br1-iface


current state

interfaces:
- name: eth1
  description: primary
  type: ethernet
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    dhcp: true
    enabled: true
- name: eth2
  description: secondary
  type: ethernet
  state: up
  mac-address: 00:00:5E:00:00:02
  ipv4:
    dhcp: true
    enabled: true

generated state

interfaces:
- name: br1-iface
  type: ovs-interface
  state: up
  mac-address: 00:00:5E:00:00:01
  ipv4:
    dhcp: true
    enabled: true
- name: br1
  type: ovs-bridge
  state: up
  bridge:
    options:
      stp: false
      mcast-snooping-enable: false
      rstp: false
    port:
    - name: bond0
      link-aggregation:
        mode: balance-slb
        port:
        - name: eth1
        - name: eth2
    - name: br1-iface

captured states

primary-nic:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: eth1
      description: primary
      type: ethernet
      state: up
      mac-address: 00:00:5E:00:00:01
      ipv4:
        dhcp: true
        enabled: true
secondary-nic:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: eth2
      description: secondary
      type: ethernet
      state: up
      mac-address: 00:00:5E:00:00:02
      ipv4:
        dhcp: true
        enabled: true


Set all linux bridges down

policy


capture:
  linux-bridges: interfaces.type=="linux-bridge" 
  linux-bridges-down: capture.linux-bridges | interfaces.state:="down"

desiredState: 
  interfaces: "{{ capture.linux-bridges-down.interfaces }}"


current state

interfaces:
- name: eth0
  type: ethernet
- name: br1
  type: linux-bridge
  state: up
- name: br2
  type: linux-bridge
  state: up
- name: br3
  type: linux-bridge
  state: up

generated state

interfaces:
- name: br1
  type: linux-bridge
  state: down
- name: br2
  type: linux-bridge
  state: down
- name: br3
  type: linux-bridge
  state: down

captured states

linux-bridges:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: br1
      type: linux-bridge
      state: up 
    - name: br2
      type: linux-bridge
      state: up 
    - name: br3
      type: linux-bridge
      state: up 
linux-bridges-down:
  metaInfo:
    time: "2021-12-15T13:45:40Z"
    version: "0"
  state:
    interfaces:
    - name: br1
      type: linux-bridge
      state: down
    - name: br2
      type: linux-bridge
      state: down
    - name: br3
      type: linux-bridge
      state: down