Created
November 19, 2023 10:57
-
-
Save EcmaXp/c52b69bfb03d8660360cdcedd6502021 to your computer and use it in GitHub Desktop.
OVN + IPv4 + IPv6 + DHCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fish | |
set CIDR_V4 10.0.0.0/16 | |
set CIDR_V6 fdec::0/64 | |
set CIDR_PREFIX_V6 fdec:0:0:0:: | |
set EXCLUDE_IPS_V4 10.0.0.1..10.0.0.10 | |
set SWITCH OVN-TEST-SW | |
set SWITCH_PORT OVN-TEST-SW-PORT | |
set ROUTER OVN-TEST-LR | |
set ROUTER_PORT OVN-TEST-LR-PORT | |
set ROUTER_IP_V4 10.0.0.1 | |
set ROUTER_CIDR_V4 10.0.0.1/16 | |
set ROUTER_IP_V6 fd00::1 | |
set ROUTER_CIDR_V6 fd00::1/64 | |
set ROUTER_MAC 00:00:00:00:00:01 | |
set DHCP_LEASE_TIME 3600 | |
# ovn-nbctl dhcp-options-list | xargs -i sudo microovn.ovn-nbctl dhcp-options-del {} | |
# ovn-nbctl ls-del $SWITCH | |
# ovn-nbctl lr-del $ROUTER | |
# ovn-nbctl lsp-del $HOST | |
# ovs-vsctl del-port br-int $HOST | |
ovn-nbctl ls-add $SWITCH | |
ovn-nbctl set logical_switch $SWITCH \ | |
other_config:subnet=$CIDR_V4 \ | |
other_config:ipv6_prefix=$CIDR_V6 \ | |
other_config:exclude_ips=$EXCLUDE_IPS_V4 | |
# other_config:exclude_ips=\"$EXCLUDE_IPS_V4,$EXCLUDE_IPS_V6\" | |
ovn-nbctl lr-add $ROUTER | |
ovn-nbctl lrp-add $ROUTER $ROUTER_PORT $ROUTER_MAC $ROUTER_CIDR_V4 $ROUTER_CIDR_V6 | |
ovn-nbctl lsp-add $SWITCH $SWITCH_PORT | |
ovn-nbctl lsp-set-type $SWITCH_PORT router | |
ovn-nbctl lsp-set-addresses $SWITCH_PORT router | |
ovn-nbctl lsp-set-options $SWITCH_PORT router-port=$ROUTER_PORT | |
# ovn-nbctl dhcp-options-list | xargs -i sudo microovn.ovn-nbctl dhcp-options-del {} | |
ovn-nbctl dhcp-options-create $CIDR_V4 | |
set CIDR_UUID_V4 (ovn-nbctl --bare --columns=_uuid find dhcp_options cidr=$CIDR_V4) | |
ovn-nbctl dhcp-options-set-options $CIDR_UUID_V4 \ | |
lease_time=$DHCP_LEASE_TIME \ | |
router=$ROUTER_IP_V4 \ | |
server_id=$ROUTER_IP_V4 \ | |
server_mac=$ROUTER_MAC | |
ovn-nbctl dhcp-options-create $CIDR_V6 | |
set CIDR_UUID_V6 (ovn-nbctl --bare --columns=_uuid find dhcp_options cidr=(echo $CIDR_V6 | sed 's/\:/\\\:/g')) | |
ovn-nbctl dhcp-options-set-options $CIDR_UUID_V6 \ | |
lease_time=$LEASE_TIME \ | |
server_id=$ROUTER_MAC | |
set HOST example-host | |
set HOST_MAC 00:00:00:00:00:02 | |
# ovn-nbctl lsp-del $HOST | |
ovn-nbctl lsp-add $SWITCH $HOST | |
ovn-nbctl lsp-set-addresses $HOST "$HOST_MAC dynamic" | |
ovn-nbctl lsp-set-dhcpv4-options $HOST $CIDR_UUID_V4 | |
ovn-nbctl lsp-set-dhcpv6-options $HOST $CIDR_UUID_V6 | |
# ovs-vsctl del-port br-int $HOST | |
ovs-vsctl add-port br-int $HOST -- \ | |
set Interface $HOST \ | |
type=internal \ | |
mac=\"$HOST_MAC\" \ | |
external-ids:iface-id=$HOST | |
ovn-nbctl list logical_switch_port | |
dhclient -4 -i $HOST -v | |
dhclient -6 -i $HOST -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment