Skip to content

Commit 5ddf970

Browse files
authored
Merge pull request #151 from dteslya/add-openbsd
Initial OpenBSD support
2 parents cd48109 + f8f9ded commit 5ddf970

File tree

8 files changed

+427
-1
lines changed

8 files changed

+427
-1
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGES_DIR=
2-
VRS = vr-xcon vr-bgp csr nxos routeros sros veos vjunosswitch vmx vsr1000 vqfx vrp xrv xrv9k vsrx
2+
VRS = vr-xcon vr-bgp csr nxos routeros sros veos vjunosswitch vmx vsr1000 vqfx vrp xrv xrv9k vsrx openbsd
33
VRS_PUSH = $(VRS:=-push)
44

55
.PHONY: all $(VRS) $(VRS_PUSH)

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Since the changes we made in this fork are VM specific, we added a few popular r
4949
* Juniper vSRX
5050
* Juniper vJunos-switch
5151
* Nokia SR OS
52+
* OpenBSD
5253

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

Diff for: openbsd/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
VENDOR=OpenBSD
2+
NAME=OpenBSD
3+
IMAGE_FORMAT=qcow2
4+
IMAGE_GLOB=*.qcow2
5+
6+
# match versions like:
7+
# openbsd-7.2-2022-11-06.qcow2
8+
# openbsd-7.3-2023-04-22.qcow2
9+
VERSION=$(shell echo $(IMAGE) | sed -e 's/openbsd-\([0-9]\.[0-9]\)-.*/\1/')
10+
11+
-include ../makefile-sanity.include
12+
-include ../makefile.include
13+
14+
download:
15+
/bin/bash download.sh
16+
17+
build: download
18+
$(MAKE) docker-image

Diff for: openbsd/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vrnetlab / OpenBSD
2+
3+
This is the vrnetlab docker image for OpenBSD.
4+
5+
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/.
6+
7+
## Building the docker image
8+
9+
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.
10+
11+
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).
12+
13+
It's been tested to boot, respond to SSH and have correct interface mapping
14+
with the following images:
15+
16+
* openbsd-7.3-2023-04-22.qcow2
17+
18+
## Usage
19+
20+
```
21+
docker run -d --privileged --name <container_name> vrnetlab/vr-openbsd:<tag> --username <username> --password <password>
22+
```
23+
24+
Where:
25+
26+
* `container_name` - name of the created container.
27+
* `tag`- OpenBSD release version (e.g., 7.3).
28+
* `username`, `password` - OpenBSD VM credentials.
29+
30+
Example:
31+
32+
```
33+
docker run -d --privileged --name my-obsd-router vrnetlab/vr-openbsd:7.3 --username admin --password admin
34+
```
35+
36+
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.
37+
38+
To obtain the container's IP run:
39+
40+
```
41+
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name>
42+
```
43+
44+
## Interface mapping
45+
46+
Interface `vio0` is always configured as a management interface. Interfaces `vio1` to `vio17` can be used for data plane.
47+
48+
## System requirements
49+
50+
CPU: 1 core
51+
RAM: 512MB
52+
DISK: 4.0GB

Diff for: openbsd/docker/Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM debian:bookworm-slim
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG DISK_SIZE=4G
5+
6+
RUN apt-get update -qy \
7+
&& apt-get upgrade -qy \
8+
&& apt-get install -y \
9+
bridge-utils \
10+
iproute2 \
11+
python3-ipy \
12+
socat \
13+
qemu-kvm \
14+
tcpdump \
15+
ssh \
16+
inetutils-ping \
17+
dnsutils \
18+
iptables \
19+
nftables \
20+
telnet \
21+
cloud-utils \
22+
sshpass \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
ARG IMAGE
26+
COPY $IMAGE* /
27+
COPY *.py /
28+
COPY --chmod=0755 backup.sh /
29+
30+
RUN qemu-img resize /${IMAGE} ${DISK_SIZE}
31+
32+
EXPOSE 22 5000 10000-10099
33+
HEALTHCHECK CMD ["/healthcheck.py"]
34+
ENTRYPOINT ["/launch.py"]

Diff for: openbsd/docker/backup.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
DEFAULT_USER="admin"
4+
DEFAULT_PASSWORD="admin"
5+
BACKUP_FILE="backup.tar.gz"
6+
BACKUP_PATH=/config/$BACKUP_FILE
7+
REMOTE_BACKUP_PATH=/tmp/$BACKUP_FILE
8+
9+
handle_args() {
10+
# Parse options
11+
while getopts 'u:p:' OPTION; do
12+
case "$OPTION" in
13+
u)
14+
user="$OPTARG"
15+
;;
16+
p)
17+
password="$OPTARG"
18+
;;
19+
?)
20+
usage
21+
exit 1
22+
;;
23+
esac
24+
done
25+
shift "$(($OPTIND -1))"
26+
27+
# Assign defaults if options weren't provided
28+
if [ -z "$user" ] ; then
29+
user=$DEFAULT_USER
30+
fi
31+
if [ -z "$password" ] ; then
32+
password=$DEFAULT_PASSWORD
33+
fi
34+
35+
SSH_CMD="sshpass -p $password ssh -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p2022"
36+
SCP_CMD="sshpass -p $password scp -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P2022"
37+
HOST="$user@localhost"
38+
39+
# Parse commands
40+
case $1 in
41+
42+
backup)
43+
backup
44+
;;
45+
46+
restore)
47+
restore
48+
;;
49+
50+
*)
51+
usage
52+
;;
53+
esac
54+
}
55+
56+
usage() {
57+
echo "Usage: $(basename $0) [-u USERNAME] [-p PASSWORD] COMMAND"
58+
echo "Options:"
59+
echo " -u USERNAME VM SSH username (default: admin)"
60+
echo " -p PASSWORD VM SSH password (default: admin)"
61+
echo
62+
echo "Commands:"
63+
echo " backup Backup VM /etc directory to $BACKUP_PATH"
64+
echo " restore Restore VM /etc directory from $BACKUP_PATH"
65+
exit 0;
66+
}
67+
68+
backup() {
69+
echo "Backing up..."
70+
$SSH_CMD $HOST "sudo tar zcf $REMOTE_BACKUP_PATH /etc 2>/dev/null"
71+
$SCP_CMD $HOST:$REMOTE_BACKUP_PATH $BACKUP_PATH
72+
}
73+
74+
restore() {
75+
if [ -f "$BACKUP_PATH" ]; then
76+
echo "Restoring from backup..."
77+
# Put backup file to VM, untar, and reboot.
78+
$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"
79+
else
80+
echo "$BACKUP_PATH not found. Nothing to restore."
81+
fi
82+
}
83+
84+
handle_args "$@"

0 commit comments

Comments
 (0)