forked from vrnetlab/vrnetlab
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from dteslya/add-freebsd
Add FreeBSD support
- Loading branch information
Showing
8 changed files
with
425 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
VENDOR=FreeBSD | ||
NAME=FreeBSD | ||
IMAGE_FORMAT=qcow2 | ||
IMAGE_GLOB=*.qcow2 | ||
|
||
# match versions like: | ||
# freebsd-13.2-zfs-2023-04-21.qcow2 | ||
VERSION=$(shell echo $(IMAGE) | sed -e 's/freebsd-\([0-9]\+\.[0-9]\)-.*/\1/') | ||
|
||
-include ../makefile-sanity.include | ||
-include ../makefile.include | ||
|
||
download: | ||
/bin/bash download.sh | ||
|
||
build: download | ||
$(MAKE) docker-image |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# vrnetlab / FreeBSD | ||
|
||
This is the vrnetlab docker image for FreeBSD. | ||
|
||
This docker image requires a custom-built FreeBSD image with pre-installed [cloud-init](https://cloudinit.readthedocs.io/en/latest/). You can download such images from https://bsd-cloud-image.org/. | ||
|
||
## Building the docker image | ||
|
||
Run `make download`. It will try to download the latest FreeBSD release from https://bsd-cloud-image.org/ to this directory. Then run `make` to build a docker image. | ||
|
||
If for some reasons you can't obtain an image from https://bsd-cloud-image.org/, you can build it yourself with the script from [this repository](https://github.com/goneri/pcib). | ||
|
||
It's been tested to boot, respond to SSH and have correct interface mapping | ||
with the following images: | ||
|
||
* freebsd-13.2-zfs-2023-04-21.qcow2 | ||
|
||
## Usage | ||
|
||
``` | ||
docker run -d --privileged --name <container_name> vrnetlab/vr-freebsd:<tag> --username <username> --password <password> | ||
``` | ||
|
||
Where: | ||
|
||
* `container_name` - name of the created container. | ||
* `tag`- FreeBSD release version (e.g., 13.2). | ||
* `username`, `password` - FreeBSD VM credentials. | ||
|
||
Example: | ||
|
||
``` | ||
docker run -d --privileged --name my-obsd-router vrnetlab/vr-freebsd:13.2 --username admin --password admin | ||
``` | ||
|
||
It will take about 1 minute for the container to boot. After that, you can try to ssh to the container's IP or telnet to port 5000 for console access. | ||
|
||
To obtain the container's IP run: | ||
|
||
``` | ||
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name> | ||
``` | ||
|
||
## Interface mapping | ||
|
||
Interface `vtnet0` is always configured as a management interface. Interfaces `vtnet1` to `vio16` can be used for data plane. | ||
|
||
## System requirements | ||
|
||
CPU: 1 core | ||
RAM: 512MB | ||
DISK: 4.0GB |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM debian:bookworm-slim | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
ARG DISK_SIZE=4G | ||
|
||
RUN apt-get update -qy \ | ||
&& apt-get upgrade -qy \ | ||
&& apt-get install -y \ | ||
bridge-utils \ | ||
iproute2 \ | ||
python3-ipy \ | ||
socat \ | ||
qemu-kvm \ | ||
tcpdump \ | ||
ssh \ | ||
inetutils-ping \ | ||
dnsutils \ | ||
iptables \ | ||
nftables \ | ||
telnet \ | ||
cloud-utils \ | ||
sshpass \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG IMAGE | ||
COPY $IMAGE* / | ||
COPY *.py / | ||
COPY --chmod=0755 backup.sh / | ||
|
||
RUN qemu-img resize /${IMAGE} ${DISK_SIZE} | ||
|
||
EXPOSE 22 5000 10000-10099 | ||
HEALTHCHECK CMD ["/healthcheck.py"] | ||
ENTRYPOINT ["/launch.py"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
|
||
DEFAULT_USER="admin" | ||
DEFAULT_PASSWORD="admin" | ||
BACKUP_FILE="backup.tar.gz" | ||
BACKUP_PATH=/config/$BACKUP_FILE | ||
REMOTE_BACKUP_PATH=/tmp/$BACKUP_FILE | ||
|
||
handle_args() { | ||
# Parse options | ||
while getopts 'u:p:' OPTION; do | ||
case "$OPTION" in | ||
u) | ||
user="$OPTARG" | ||
;; | ||
p) | ||
password="$OPTARG" | ||
;; | ||
?) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift "$(($OPTIND -1))" | ||
|
||
# Assign defaults if options weren't provided | ||
if [ -z "$user" ] ; then | ||
user=$DEFAULT_USER | ||
fi | ||
if [ -z "$password" ] ; then | ||
password=$DEFAULT_PASSWORD | ||
fi | ||
|
||
SSH_CMD="sshpass -p $password ssh -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p2022" | ||
SCP_CMD="sshpass -p $password scp -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P2022" | ||
HOST="$user@localhost" | ||
|
||
# Parse commands | ||
case $1 in | ||
|
||
backup) | ||
backup | ||
;; | ||
|
||
restore) | ||
restore | ||
;; | ||
|
||
*) | ||
usage | ||
;; | ||
esac | ||
} | ||
|
||
usage() { | ||
echo "Usage: $(basename $0) [-u USERNAME] [-p PASSWORD] COMMAND" | ||
echo "Options:" | ||
echo " -u USERNAME VM SSH username (default: admin)" | ||
echo " -p PASSWORD VM SSH password (default: admin)" | ||
echo | ||
echo "Commands:" | ||
echo " backup Backup VM /etc directory to $BACKUP_PATH" | ||
echo " restore Restore VM /etc directory from $BACKUP_PATH" | ||
exit 0; | ||
} | ||
|
||
backup() { | ||
echo "Backing up..." | ||
$SSH_CMD $HOST "sudo tar zcf $REMOTE_BACKUP_PATH /etc > & /dev/null" | ||
$SCP_CMD $HOST:$REMOTE_BACKUP_PATH $BACKUP_PATH | ||
} | ||
|
||
restore() { | ||
if [ -f "$BACKUP_PATH" ]; then | ||
echo "Restoring from backup..." | ||
# Put backup file to VM, untar, and reboot. | ||
$SCP_CMD $BACKUP_PATH $HOST:$REMOTE_BACKUP_PATH && $SSH_CMD $HOST "sudo tar xzf $REMOTE_BACKUP_PATH -C /" && $SSH_CMD $HOST "sudo shutdown -r now || true" | ||
else | ||
echo "$BACKUP_PATH not found. Nothing to restore." | ||
fi | ||
} | ||
|
||
handle_args "$@" |
Oops, something went wrong.