Skip to content
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

add host-ubuntu initial version #25

Merged
merged 21 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/container_build_host_ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Create Ubuntu host container image

on:
push:
branches: ['**'] # branches will be filtered in the jobs
paths:
- .github/workflows/container_build_host_ubuntu.yml
- .github/workflows/container_build_child.yml
- containers/host-ubuntu/**
workflow_dispatch:
branches: ['**'] # branches will be filtered in the jobs

jobs:
build-demo-container:
# fork - build container from any branch for testing
# parent repo - build on main branch only
if: github.repository != 'aristanetworks/acLabs' || github.ref == 'refs/heads/main'
uses: ./.github/workflows/container_build_child.yml
with:
container_name: "host-ubuntu"
image_tags: "latest"
from_image: "ubuntu"
from_variant: "24.04"
username: "admin"
user_id: "1001"
group_id: "1001"
54 changes: 54 additions & 0 deletions containers/host-ubuntu/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ARG FROM_IMAGE
ARG FROM_VARIANT

FROM ${FROM_IMAGE}:${FROM_VARIANT}

ARG USERNAME

# Install essential tools.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
make \
curl \
git-all \
python3 \
python3-pip \
sudo \
wget \
# TODO: have to review the bottom part later
ca-certificates \
cdpr \
dnsutils \
dsniff \
ipcalc \
iperf \
iperf3 \
fping \
gnupg \
gsutil \
ifenslave \
inetutils-traceroute \
iputils-* \
libkrb5-dev \
lldpd \
locales \
mtr \
nano \
net-tools \
netplan.io \
openssh-server \
snapd \
tzdata \
# ufw \
vim
# no need to reduce the image size for now
# && rm -rf /var/lib/apt/lists/* \
# && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
# && apt-get clean

COPY ./entrypoint.sh /bin/entrypoint.sh
RUN chmod +x /bin/entrypoint.sh

USER ${USERNAME}

ENTRYPOINT [ "/bin/entrypoint.sh" ]
32 changes: 32 additions & 0 deletions containers/host-ubuntu/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"build": {
"dockerfile": "./Dockerfile",
"context": ".",
"args": {
"FROM_IMAGE": "${localEnv:FROM_IMAGE}",
"FROM_VARIANT": "${localEnv:FROM_VARIANT}",
"USERNAME": "${localEnv:USERNAME}",
"UID": "${localEnv:UID}",
"GID": "${localEnv:GID}"
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2":{
"installZsh": true,
"installOhMyZsh": true,
"configureZshAsDefaultShell": true,
"username": "${localEnv:USERNAME}",
"userUid": "${localEnv:UID}",
"userGid": "${localEnv:GID}",
// do not update packages to reduce build time
"upgradePackages": "false"
}
// Add sshd
// "ghcr.io/devcontainers/features/sshd:1": {
// "version": "latest"
// }
},

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "${localEnv:USERNAME}"
}
110 changes: 110 additions & 0 deletions containers/host-ubuntu/.devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

# preserve environment variables
if [ "$(id -u)" != "0" ]; then
exec sudo --preserve-env=TMODE,TACTIVE,TBACKUP,SSH_PASSWORD,IPV4,IPV6,GW,STATIC_ROUTE "$0" "$@"
fi

# set admin password for SSH access
if [ -z "${SSH_PASSWORD}" ]; then
SSH_PASSWORD='admin'
fi

echo "admin:${SSH_PASSWORD}" | sudo chpasswd

# start SSH server
sudo service ssh start

UPLINK='eth1'

# TMODE is expected to be set via the containerlab topology file prior to deployment
# Expected values are "lacp" or "static" or "active-backup" which will bond eth1 and eth2
if [ -z "$TMODE" ]; then
TMODE='none'
fi

# TACTIVE and TBACKUP to be set via the containerlab topology file for active-backup runner
# expected values are "eth1" or "eth2" default is "eth1" active and "eth2" backup
if [ -z "$TACTIVE" ]; then
TACTIVE='eth1'
TBACKUP='eth2'
elif [ "$TACTIVE" == 'eth1' ]; then
TBACKUP='eth2'
elif [ "$TACTIVE" == 'eth2' ]; then
TBACKUP='eth1'
fi

if [ "$TMODE" == 'lacp' ]; then

UPLINK='bond0'

sudo ip link set eth1 down
sudo ip link set eth2 down

sudo ip link add ${UPLINK} type bond mode 802.3ad

sudo ip link set eth1 master ${UPLINK}
sudo ip link set eth2 master ${UPLINK}

if [ -z "$UPLINK_MAC" ]; then
UPLINK_MAC="c0:d6:82:00:$(openssl rand -hex 1):$(openssl rand -hex 1)"
fi
sudo ip link set dev ${UPLINK} address "${UPLINK_MAC}"
sudo ip link set ${UPLINK} up

elif ! [ -z "${PHONE}" ] ; then

UPLINK='br0'

# Create br0
sudo ip link add name br0 type bridge

if [ -z "$UPLINK_MAC" ]; then
UPLINK_MAC="30:86:2d:00:$(openssl rand -hex 1):$(openssl rand -hex 1)"
fi
sudo ip link set dev ${UPLINK} address "${UPLINK_MAC}"

# Disable STP, provide add'l visibility
sudo ip link set ${UPLINK} type bridge stp_state 0
sudo ip link set ${UPLINK} type bridge vlan_stats_per_port 1

# Bring up Bridge Interface and add eth1 & eth2 (Note: eths must be UP to add)
sudo ip link set dev ${UPLINK} up
sudo ip link set eth1 master ${UPLINK}
sudo ip link set eth2 master ${UPLINK}

# Add Simple Multicast Support
#sysctl net.ipv4.conf.br0.mc_forwarding=1
#sysctl net.ipv6.conf.br0.mc_forwarding=1
sudo ip link set ${UPLINK} type bridge mcast_stats_enabled 1

# Customize LLDP
# lldpcli configure ports eth1,eth2,br0 lldp status rx-only
fi

# configure IP addresses and routes
if ! [ -z "${IPV4}" ]; then
sudo ip addr add ${IPV4} dev ${UPLINK}
fi

if ! [ -z "${IPV6}" ]; then
sudo ip -6 addr add ${IPV6} dev ${UPLINK}
fi

if ! [ -z "${GW}" ]; then
# add static routes
sudo ip route add ${STATIC_ROUTE} via ${GW} dev ${UPLINK}
sudo ip route add 224.0.0.0/4 via ${GW} dev ${UPLINK}
fi

# Execute command from docker cli if any.
if [ ${@+True} ]; then
exec "$@"
# Otherwise just enter sh or zsh.
else
if [ -f "/bin/zsh" ]; then
exec zsh
else
exec sh
fi
fi
38 changes: 37 additions & 1 deletion labs/techlib-vxlan-domain-a/clab/topology.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ topology:
ceos:
image: arista/ceos:4.32.1F
linux:
image: ghcr.io/aristanetworks/aclabs/host-alpine:latest
image: ghcr.io/aristanetworks/aclabs/host-ubuntu:latest

nodes:
###############################################################
Expand Down Expand Up @@ -112,36 +112,72 @@ topology:
HostA1:
kind: linux
mgmt-ipv4: 172.100.100.201
env:
TMODE: lacp
IPV4: 10.10.10.101/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.10.10.1
IPV6: 2001:db8:10:10::101/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -b -i4 10.10.10.101/24 -i6 2001:db8:10:10::101/64 -g 10.10.10.1

HostA2:
kind: linux
mgmt-ipv4: 172.100.100.202
env:
TMODE: lacp
IPV4: 10.30.30.101/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.30.30.1
IPV6: 2001:db8:30:30::101/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -b -i4 10.30.30.101/24 -i6 2001:db8:30:30::101/64 -g 10.30.30.1

HostA3:
kind: linux
mgmt-ipv4: 172.100.100.203
env:
TMODE: lacp
IPV4: 10.50.50.101/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.50.50.1
IPV6: 2001:db8:50:50::101/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -i4 10.50.50.101/24 -i6 2001:db8:50:50::101/64 -g 10.50.50.1

HostA4:
kind: linux
mgmt-ipv4: 172.100.100.204
env:
TMODE: lacp
IPV4: 10.10.10.102/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.10.10.1
IPV6: 2001:db8:10:10::102/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -b -i4 10.10.10.102/24 -i6 2001:db8:10:10::102/64 -g 10.10.10.1

HostA5:
kind: linux
mgmt-ipv4: 172.100.100.205
env:
TMODE: lacp
IPV4: 10.30.30.102/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.30.30.1
IPV6: 2001:db8:30:30::102/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -i4 10.30.30.102/24 -i6 2001:db8:30:30::102/64 -g 10.30.30.1

HostA6:
kind: linux
mgmt-ipv4: 172.100.100.206
env:
TMODE: lacp
IPV4: 10.70.70.101/24
STATIC_ROUTE: 10.0.0.0/8
GW: 10.70.70.1
IPV6: 2001:db8:70:70::101/64
# exec:
# - bash /usr/local/bin/hostnetconfig.sh -b -i4 10.70.70.101/24 -i6 2001:db8:70:70::101/64 -g 10.70.70.1

Expand Down
Loading