Skip to content

Commit

Permalink
Merge pull request #151 from dteslya/add-openbsd
Browse files Browse the repository at this point in the history
Initial OpenBSD support
  • Loading branch information
hellt authored Nov 30, 2023
2 parents cd48109 + f8f9ded commit 5ddf970
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGES_DIR=
VRS = vr-xcon vr-bgp csr nxos routeros sros veos vjunosswitch vmx vsr1000 vqfx vrp xrv xrv9k vsrx
VRS = vr-xcon vr-bgp csr nxos routeros sros veos vjunosswitch vmx vsr1000 vqfx vrp xrv xrv9k vsrx openbsd
VRS_PUSH = $(VRS:=-push)

.PHONY: all $(VRS) $(VRS_PUSH)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Since the changes we made in this fork are VM specific, we added a few popular r
* Juniper vSRX
* Juniper vJunos-switch
* Nokia SR OS
* OpenBSD

The rest are left untouched and can be contributed back by the community.

Expand Down
18 changes: 18 additions & 0 deletions openbsd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
VENDOR=OpenBSD
NAME=OpenBSD
IMAGE_FORMAT=qcow2
IMAGE_GLOB=*.qcow2

# match versions like:
# openbsd-7.2-2022-11-06.qcow2
# openbsd-7.3-2023-04-22.qcow2
VERSION=$(shell echo $(IMAGE) | sed -e 's/openbsd-\([0-9]\.[0-9]\)-.*/\1/')

-include ../makefile-sanity.include
-include ../makefile.include

download:
/bin/bash download.sh

build: download
$(MAKE) docker-image
52 changes: 52 additions & 0 deletions openbsd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# vrnetlab / OpenBSD

This is the vrnetlab docker image for OpenBSD.

This docker image requires a custom-built OpenBSD 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 OpenBSD 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:

* openbsd-7.3-2023-04-22.qcow2

## Usage

```
docker run -d --privileged --name <container_name> vrnetlab/vr-openbsd:<tag> --username <username> --password <password>
```

Where:

* `container_name` - name of the created container.
* `tag`- OpenBSD release version (e.g., 7.3).
* `username`, `password` - OpenBSD VM credentials.

Example:

```
docker run -d --privileged --name my-obsd-router vrnetlab/vr-openbsd:7.3 --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 `vio0` is always configured as a management interface. Interfaces `vio1` to `vio17` can be used for data plane.

## System requirements

CPU: 1 core
RAM: 512MB
DISK: 4.0GB
34 changes: 34 additions & 0 deletions openbsd/docker/Dockerfile
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"]
84 changes: 84 additions & 0 deletions openbsd/docker/backup.sh
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 2>/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 "$@"
Loading

0 comments on commit 5ddf970

Please sign in to comment.