-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network configuration using netplan for Ubuntu versions greater than 16.04 #141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you think about moving the netplan-specific code in to two helper functions:
is_netplan
setup_networking_netplan
the setup_networking
function is quite large, and I'm a bit afraid of letting it grow too much more.
cat >/etc/netplan/${TINKERBELL_NETWORK_INTERFACE}.yaml <<EOF | ||
--- | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
$TINKERBELL_NETWORK_INTERFACE: | ||
addresses: | ||
- $TINKERBELL_HOST_IP/$cidr | ||
- $TINKERBELL_NGINX_IP/$cidr | ||
EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating YAML on the fly with bash feels a bit scary. In particular, magic values can turn in to other things like "no" being a bool, and 1.10
being just 1.1
. What would you think about using (and installing if it isn't yet available) jq
for this? Using jq guarantees the output will be correct and that we didn't make an error in indentation, whitespace, and also makes sure that all of the values are properly quoted.
Here is an example of what that would look like:
TINKERBELL_NETWORK_INTERFACE=10.5.3.1
TINKERBELL_HOST_IP=10.5.3.2
TINKERBELL_NGINX_IP=10.5.3.3
cidr=24
jq -n \
--arg interface "$TINKERBELL_NETWORK_INTERFACE" \
--arg cidr "$cidr" \
--arg host_ip "$TINKERBELL_HOST_IP" \
--arg nginx_ip "$TINKERBELL_NGINX_IP" \
'{
network: "hi",
renderer: "networkd",
ethernets: {
($interface): {
addresses: [
"\($host_ip)/\($cidr)",
"\($nginx_ip)/\($cidr)"
]
}
}
}'
This prints:
{
"network": "hi",
"renderer": "networkd",
"ethernets": {
"10.5.3.1": {
"addresses": [
"10.5.3.2/24",
"10.5.3.3/24"
]
}
}
}
since JSON is valid YAML, this output works directly with netplan.
v16=16.04 | ||
version=$(. /etc/os-release && echo "$VERSION_ID") | ||
if (( $(echo "$version > $v16" | bc -l) )); then | ||
echo "$INFO found Ubuntu $version, using 'netplan' for network configuration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like 17.10 is the first release to use netplan by default. Maybe we should change this to >= 17.10
?
ip link set $TINKERBELL_NETWORK_INTERFACE nomaster | ||
netplan apply | ||
echo "$INFO waiting for the network configuration to be applied by systemd-networkd" | ||
sleep 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if netplan creates a systemd unit we could wait for, like this:
while ! systemctl is-active netplan-something-or-other; do
sleep 1
done
Oops, I meant to also say -- looks pretty good! |
Signed-off-by: Gaurav Gahlot <[email protected]>
These commits were included in #147 |
Signed-off-by: Gaurav Gahlot [email protected]