From 0ba86ef71eec6fb9bf66c8660875c264b0017807 Mon Sep 17 00:00:00 2001 From: Carlos Nunez Date: Thu, 23 Mar 2023 08:51:16 -0500 Subject: [PATCH 1/5] [vyatta] Update regex for generating networks This will make it easier to create the networks that Vyatta needs for users who wish to use this for creating a Layer 2 network to use Avi with. Signed-off-by: Carlos Nunez --- src/partials/vyatta.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/partials/vyatta.md b/src/partials/vyatta.md index 106512c4..0c688f83 100644 --- a/src/partials/vyatta.md +++ b/src/partials/vyatta.md @@ -37,14 +37,13 @@ while read -r net; \ do \ name="$(awk -F '|' '{print $3}' <<< "$net" | sed 's/management/mgmt/g' | tr -d ' ')"; \ if test "$(wc -c <<< "$name")" -gt 12; then name=$(head -c 10 <<< "$name"); fi; \ - vlan="$(awk -F '|' '{print $4}' <<< "$net" | tr -d ' ')"; \ - cidr="$(awk -F '|' '{print $5}' <<< "$net" | sed -E 's/ +//' | tr -d ' ' | tr '/' '_')"; \ - cmd="govc host.portgroup.add -vswitch vSwitch0 ${name}-${cidr}-${vlan}"; \ + cidr="$(awk -F '|' '{print $4}' <<< "$net" | sed -E 's/ +//' | tr -d ' ' | tr '/' '_')"; \ + cmd="govc host.portgroup.add -vswitch vSwitch0 ${name}-${cidr}"; \ echo "--> $cmd"; \ $cmd; \ - govc host.portgroup.change -allow-promiscuous=true -forged-transmits=true -mac-changes=true "${name}-${cidr}-${vlan}"; \ - govc vm.network.add -vm="$VM_NAME" -net="${name}-${cidr}-${vlan}" -net.adapter=vmxnet3; \ -done < <(grep --color -E 'Network +\|.*_pg +\| [0-9]{4} +\| 172.*' "src/deployment-guides/${DEPLOYMENT_GUIDE}.md") + govc host.portgroup.change -allow-promiscuous=true -forged-transmits=true -mac-changes=true "${name}-${cidr}"; \ + govc vm.network.add -vm="$VM_NAME" -net="${name}-${cidr}" -net.adapter=vmxnet3; \ +done < <(grep -E 'Network {0,}\|.*_pg {0,}\| {0,}[0-9]{3}\..*' "src/deployment-guides/${DEPLOYMENT_GUIDE}.md") ``` > If your VM's NICs are connected to a port group on a distributed virtual @@ -64,12 +63,11 @@ do \ name="$(awk -F '|' '{print $3}' <<< "$net" | sed 's/management/mgmt/g' | tr -d ' ')"; \ if test "$(wc -c <<< "$name")" -gt 12; then name=$(head -c 10 <<< "$name"); fi; \ vlan="$(awk -F '|' '{print $4}' <<< "$net" | tr -d ' ')"; \ - cidr="$(awk -F '|' '{print $5}' <<< "$net" | sed -E 's/ +//' | tr -d ' ' | tr '/' '_')"; \ - cmd="govc dvs.portgroup.add -dvs vSwitch0 ${name}-${cidr}-${vlan}"; \ + cmd="govc dvs.portgroup.add -dvs vSwitch0 ${name}-${vlan}"; \ echo "--> $cmd"; \ $cmd; \ - govc vm.network.add -vm="$VM_NAME" -net="${name}-${cidr}-${vlan}" -net.adapter=vmxnet3; \ -done < <(grep --color -E 'Network +\|.*_pg +\| [0-9]{4} +\| 172.*' "src/deployment-guides/${DEPLOYMENT_GUIDE}.md") + govc vm.network.add -vm="$VM_NAME" -net="${name}-${vlan}" -net.adapter=vmxnet3; \ +done < <(grep -E 'Network {0,}\|.*_pg {0,}\| {0,}[0-9]{3}\..*' "src/deployment-guides/${DEPLOYMENT_GUIDE}.md") ``` Next, go into the vCenter portal and connect to the VM's console. Log in with the username `vyos` and the password `vyos`. From 5ccbaeddd10a2fd16ea1755bd51545fa867b0e87 Mon Sep 17 00:00:00 2001 From: Carlos Nunez Date: Thu, 23 Mar 2023 09:14:48 -0500 Subject: [PATCH 2/5] slashes are urlencoded; replace with underscores Signed-off-by: Carlos Nunez --- src/partials/vyatta.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partials/vyatta.md b/src/partials/vyatta.md index 0c688f83..26e7fb01 100644 --- a/src/partials/vyatta.md +++ b/src/partials/vyatta.md @@ -62,7 +62,7 @@ while read -r net; \ do \ name="$(awk -F '|' '{print $3}' <<< "$net" | sed 's/management/mgmt/g' | tr -d ' ')"; \ if test "$(wc -c <<< "$name")" -gt 12; then name=$(head -c 10 <<< "$name"); fi; \ - vlan="$(awk -F '|' '{print $4}' <<< "$net" | tr -d ' ')"; \ + vlan="$(awk -F '|' '{print $4}' <<< "$net" | tr -d ' ' | tr '/' '_')"; \ cmd="govc dvs.portgroup.add -dvs vSwitch0 ${name}-${vlan}"; \ echo "--> $cmd"; \ $cmd; \ From a5d5b62f19b674897994b2ca7ceea260d4f9133c Mon Sep 17 00:00:00 2001 From: Carlos Nunez Date: Thu, 23 Mar 2023 10:00:24 -0500 Subject: [PATCH 3/5] this should be on one line Signed-off-by: Carlos Nunez --- src/partials/vyatta.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/partials/vyatta.md b/src/partials/vyatta.md index 26e7fb01..7e38290d 100644 --- a/src/partials/vyatta.md +++ b/src/partials/vyatta.md @@ -146,8 +146,8 @@ the block of code above. > ```sh VYOS_IP=10.220.3.252 -ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP - find /sys/class/net -mindepth 1 -maxdepth 1 +ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP \ + find /sys/class/net -mindepth 1 -maxdepth 1 \ -not -name lo -printf "%P: " -execdir 'cat {}/address \;') govc vm.info -json=true $VM_NAME | jq -r '.VirtualMachines[0].Config.Hardware.Device[] | \ From e97adde83c7afa56976a9755cf09c52e244900f9 Mon Sep 17 00:00:00 2001 From: Carlos Nunez Date: Thu, 23 Mar 2023 10:05:06 -0500 Subject: [PATCH 4/5] jq and line length don't play well together Signed-off-by: Carlos Nunez --- src/partials/vyatta.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/partials/vyatta.md b/src/partials/vyatta.md index 7e38290d..09a15a70 100644 --- a/src/partials/vyatta.md +++ b/src/partials/vyatta.md @@ -146,13 +146,9 @@ the block of code above. > ```sh VYOS_IP=10.220.3.252 -ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP \ - find /sys/class/net -mindepth 1 -maxdepth 1 \ - -not -name lo -printf "%P: " -execdir 'cat {}/address \;') +ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP find /sys/class/net -mindepth 1 -maxdepth 1 -not -name lo -printf "%P: " -execdir 'cat {}/address \;') govc vm.info -json=true $VM_NAME | - jq -r '.VirtualMachines[0].Config.Hardware.Device[] | \ -select(.MacAddress != null and .DeviceInfo.Summary != "VM Network") | \ -.MacAddress + ";" + .DeviceInfo.Summary' | + jq -r '.VirtualMachines[0].Config.Hardware.Device[] | select(.MacAddress != null and .DeviceInfo.Summary != "VM Network") | .MacAddress + ";" + .DeviceInfo.Summary' | while read -r line; do mac=$(echo "$line" | cut -f1 -d ';'); From 8ea73a768abd4e75085b16bbb598f3b6bc291873 Mon Sep 17 00:00:00 2001 From: Carlos Nunez Date: Thu, 23 Mar 2023 10:06:29 -0500 Subject: [PATCH 5/5] remove my leaky abstractions Signed-off-by: Carlos Nunez --- src/partials/vyatta.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/partials/vyatta.md b/src/partials/vyatta.md index 09a15a70..15f9dbb7 100644 --- a/src/partials/vyatta.md +++ b/src/partials/vyatta.md @@ -165,21 +165,18 @@ If your NICs are connected to a distributed vSwitch, use this instead: ```sh VYOS_IP=10.220.8.189 >&2 echo '---> Grabbing portgroup names'; -portgroupNamesToKeys=$(h2o_govc find / -type DistributedVirtualPortgroup | \ +portgroupNamesToKeys=$(govc find / -type DistributedVirtualPortgroup | \ while read -r pg; \ do \ - h2o_govc object.collect -json=true "$pg" | jq -r '.[] | + govc object.collect -json=true "$pg" | jq -r '.[] | select(.Name == "config") | .Val.Key + ":" + .Val.Name'; \ done ); >&2 echo '---> Grabbing interfaces'; -ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP find /sys/class/net -mindepth 1 -maxdepth 1 \ - -not -name lo -printf "%P: " -execdir 'cat {}/address \;'); +ifaces=$(sshpass -p vyos ssh vyos@$VYOS_IP find /sys/class/net -mindepth 1 -maxdepth 1 -not -name lo -printf "%P: " -execdir 'cat {}/address \;'); >&2 echo '---> Forming vyos interface commands'; -h2o_govc vm.info -json=true $VM_NAME | - jq -r '.VirtualMachines[0].Config.Hardware.Device[] | -select(.MacAddress != null) | -.MacAddress + ";" + .Backing.Port.PortgroupKey' | +govc vm.info -json=true $VM_NAME | + jq -r '.VirtualMachines[0].Config.Hardware.Device[] | select(.MacAddress != null) | .MacAddress + ";" + .Backing.Port.PortgroupKey' | while read -r line; do mac=$(echo "$line" | cut -f1 -d ';'); @@ -188,8 +185,8 @@ select(.MacAddress != null) | gw=$(echo "$pg" | cut -f2 -d '-' | cut -f1 -d '_'); eth=$(grep "$mac" <<< "$ifaces" | cut -f1 -d ':'); test "$eth" == "eth0" && continue; - echo "set interface ethernet $eth ${gw}/27"; - echo "set interface ethernet description $pg"; + echo "set interface ethernet $eth address ${gw}/27"; + echo "set interface ethernet $eth description $pg"; done ```