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

Replace telnetlib with scrapli #279

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e1bf3df
Replace telnetlib with scrapli
kaelemc Nov 7, 2024
7519894
Change QEMU connection error log message to 'error' instead of 'debug'
kaelemc Nov 9, 2024
d5c06fb
Migrate IOS-XE devices to Scrapli driver for bootstrap and startup co…
kaelemc Nov 9, 2024
6d23587
Delete cidfiles
kaelemc Nov 9, 2024
1726fd4
Ignore cidfile
kaelemc Nov 9, 2024
2a21182
Rename XRv9k class names and use context manager for scrapli
kaelemc Nov 9, 2024
decb036
Format environment variables nicely
kaelemc Nov 9, 2024
ad8fdfc
Add XRv 'qemu' node
kaelemc Nov 9, 2024
f5183cc
Alter vrnetlab logging.
kaelemc Nov 9, 2024
a192853
Move environment variable printing to vrnetlab.py
kaelemc Nov 9, 2024
f8bff21
Fix missing space after 'ifeq' in VENDOR_SUBDIR check.
kaelemc Nov 9, 2024
4826cfd
Update gitignore to ignore .qcow and .tgz
kaelemc Nov 9, 2024
54cddd6
Add 'yes' statement after netconf-yang command in CSR config (for IOS…
kaelemc Nov 9, 2024
a2219a5
Bump scrapli operation timeouts for Cisco devices.
kaelemc Nov 9, 2024
5765434
Bump timeout of XE devices to 10 minutes (600 seconds)
kaelemc Nov 10, 2024
e1c71a4
Use env var for IOSXEDriver Scrapli timeout on csr1000v
kaelemc Nov 13, 2024
2b89d11
SROS Fixes
kaelemc Nov 13, 2024
13b3cc6
added vrnetlab base image
hellt Nov 19, 2024
a95ef39
add empty line
hellt Nov 19, 2024
a1f0aa6
added genisoimage
hellt Nov 20, 2024
15e8224
update scrapli
hellt Nov 21, 2024
9ef133f
Update Cisco Dockerfiles to use vrnetlab base img
kaelemc Nov 22, 2024
5dc58c5
Alter log formatting in vrnetlab.py
kaelemc Nov 22, 2024
7b9bada
Imrpove XRv9k install process + use env vars for vcpu, ram.
kaelemc Nov 22, 2024
628fd33
Rename xrv_qemu to xrv_qcow
kaelemc Nov 22, 2024
6249321
Add VCPU, RAM and SCRAPLI_TIMEOUT env vars to cat8k
kaelemc Nov 22, 2024
d09e24d
Update SROS Dockerfile to use vrnetlab-base image
kaelemc Nov 22, 2024
4e483ed
Update Cisco nodes to use env vars for smp/ram
kaelemc Nov 22, 2024
89277f7
Override smp property in XRv9k to set single socket config
kaelemc Nov 22, 2024
9a9bf7e
added scrapli community
hellt Nov 22, 2024
ce49fd9
Update other Dockefiles to use new base image.
kaelemc Nov 22, 2024
e46c174
Allow custom SMP for XRv9k
kaelemc Nov 23, 2024
0710b1d
Set "scrapli" logger to info (instead of root logger)
kaelemc Nov 29, 2024
b181cd4
Fix `makefile-install.include` image naming schema (#283)
kaelemc Nov 19, 2024
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
.idea
venv
*.qcow2
*.qcow
cisco*.bin
*.gz
*.tgz
*.xz
*.vmdk
*.iso
Expand All @@ -24,4 +26,7 @@ cisco*.bin
*.xml

# ignore clab- dirs
clab-*
clab-*

# Ignore container cidfile
**cidfile
23 changes: 1 addition & 22 deletions aoscx/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
FROM debian:bullseye
MAINTAINER Stefano Sasso <[email protected]>

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -qy \
&& apt-get upgrade -qy \
&& apt-get install -y \
bridge-utils \
iproute2 \
python3-ipy \
socat \
tcpdump \
ssh \
inetutils-ping \
dnsutils \
iptables \
telnet \
ftp \
qemu-system-x86=1:5.2+dfsg-11+deb11u2 \
qemu-utils=1:5.2+dfsg-11+deb11u2 \
&& rm -rf /var/lib/apt/lists/*
FROM ghcr.io/srl-labs/vrnetlab-base:0.0.1

ARG IMAGE
COPY $IMAGE* /
Expand Down
6 changes: 3 additions & 3 deletions aoscx/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def bootstrap_spin(self):
self.start()
return

(ridx, match, res) = self.tn.expect([b"switch login:"], 1)
(ridx, match, res) = self.expect([b"switch login:"], 1)
if match: # got a match!
if ridx == 0: # login
self.logger.debug("trying to log in with 'admin'")
Expand Down Expand Up @@ -92,8 +92,8 @@ def bootstrap_spin(self):

# no match, if we saw some output from the router it's probably
# booting, so let's give it some more time
if res != b"":
self.logger.trace("OUTPUT: %s" % res.decode())
if res != "":
self.print(res)
# reset spins if we saw some output
self.spins = 0

Expand Down
12 changes: 0 additions & 12 deletions asav/Makefile

This file was deleted.

30 changes: 0 additions & 30 deletions asav/docker/Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions build-base-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# this script builds the vrnetlab base container image
# that is used in the dockerfiles of the NOS images

set -e

if [ -z "$1" ]; then
echo "Usage: $0 <version>"
exit 1
fi

sudo docker build -t ghcr.io/srl-labs/vrnetlab-base:$1 \
-f vrnetlab-base.dockerfile .
27 changes: 0 additions & 27 deletions c8000v/docker/Dockerfile

This file was deleted.

31 changes: 0 additions & 31 deletions cat9kv/docker/Dockerfile

This file was deleted.

21 changes: 21 additions & 0 deletions cisco/asav/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
VENDOR=cisco
NAME=asav
IMAGE_FORMAT=qcow2
IMAGE_GLOB=*.qcow2
VENDOR_SUBDIR=1

# match versions like:
# asav9-18-2.qcow2
VERSION=$(shell echo $(IMAGE) | sed -e 's/.\+[^0-9]\([0-9]\+\-[0-9]\+\-[0-9]\+[a-z]\?\)\([^0-9].*\|$$\)/\1/')

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

docker-pre-build:
-cat cidfile | xargs --no-run-if-empty docker rm -f
-rm cidfile

docker-build: docker-build-common
docker run --cidfile cidfile --privileged $(REGISTRY)$(VENDOR)_$(NAME):$(VERSION) --trace --install
docker commit --change='ENTRYPOINT ["/launch.py"]' $$(cat cidfile) $(REGISTRY)$(VENDOR)_$(NAME):$(VERSION)
docker rm -f $$(cat cidfile)
File renamed without changes.
11 changes: 11 additions & 0 deletions cisco/asav/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/srl-labs/vrnetlab-base:0.0.1

ARG VERSION
ENV VERSION=${VERSION}
ARG IMAGE
COPY $IMAGE* /
COPY *.py /

EXPOSE 22 161/udp 830 5000 10000-10099
HEALTHCHECK CMD ["/healthcheck.py"]
ENTRYPOINT ["/launch.py"]
39 changes: 24 additions & 15 deletions asav/docker/launch.py → cisco/asav/docker/launch.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import vrnetlab


DEFAULT_SMP = 4
DEFAULT_RAM = 8192 # in MB

def handle_SIGCHLD(signal, frame):
os.waitpid(-1, os.WNOHANG)

Expand All @@ -37,16 +40,17 @@ def trace(self, message, *args, **kws):


class ASAv_vm(vrnetlab.VM):
def __init__(self, username, password, install_mode=False):
def __init__(self, username, password, conn_mode, install_mode=False):
for e in os.listdir("/"):
if re.search(".qcow2$", e):
disk_image = "/" + e

super(ASAv_vm, self).__init__(
username, password, disk_image=disk_image, ram=2048
username, password, disk_image=disk_image, ram=DEFAULT_RAM, smp=f"cores={DEFAULT_SMP},threads=1,sockets=1"
)
self.nic_type = "e1000"
self.install_mode = install_mode
self.conn_mode = conn_mode
self.num_nics = 8

def bootstrap_spin(self):
Expand All @@ -58,18 +62,18 @@ def bootstrap_spin(self):
self.start()
return

(ridx, match, res) = self.tn.expect([b"ciscoasa>"], 1)
(ridx, match, res) = self.expect([b"ciscoasa>"], 1)
if match: # got a match!
if ridx == 0: # login
if self.install_mode:
self.logger.debug("matched, ciscoasa>")
self.logger.info("matched, ciscoasa>")
self.wait_write("", wait=None)
self.wait_write("", None)
self.wait_write("", wait="ciscoasa>")
self.running = True
return

self.logger.debug("matched, ciscoasa>")
self.logger.info("matched, ciscoasa>")
self.wait_write("", wait=None)

# run main config!
Expand All @@ -85,8 +89,8 @@ def bootstrap_spin(self):

# no match, if we saw some output from the router it's probably
# booting, so let's give it some more time
if res != b"":
self.logger.trace("OUTPUT: %s" % res.decode())
if res != "":
self.print(res)
# reset spins if we saw some output
self.spins = 0

Expand All @@ -103,8 +107,7 @@ def bootstrap_config(self):
self.wait_write("VR-netlab9", wait="Repeat Password:")
self.wait_write("", wait="ciscoasa#")
self.wait_write("configure terminal", wait="#")
self.wait_write("N", wait="[Y]es, [N]o, [A]sk later:")
self.wait_write("", wait="(config)#")
self.wait_write("N", wait="[Y]es, [N]o, [A]sk later:", timeout=15)
self.wait_write("aaa authentication ssh console LOCAL")
self.wait_write("aaa authentication enable console LOCAL")
self.wait_write(
Expand All @@ -114,6 +117,7 @@ def bootstrap_config(self):
self.wait_write("nameif management")
self.wait_write("ip address 10.0.0.15 255.255.255.0")
self.wait_write("no shutdown")
self.wait_write("route management 0.0.0.0 0.0.0.0 10.0.0.2")
self.wait_write("ssh 0.0.0.0 0.0.0.0 management")
self.wait_write("ssh version 2")
self.wait_write("ssh key-exchange group dh-group14-sha256")
Expand All @@ -124,17 +128,17 @@ def bootstrap_config(self):


class ASAv(vrnetlab.VR):
def __init__(self, username, password):
def __init__(self, username, password, conn_mode):
super(ASAv, self).__init__(username, password)
self.vms = [ASAv_vm(username, password)]
self.vms = [ASAv_vm(username, password, conn_mode)]


class ASAv_installer(ASAv):
"""ASAv installer"""

def __init__(self, username, password):
def __init__(self, username, password, conn_mode):
super(ASAv, self).__init__(username, password)
self.vms = [ASAv_vm(username, password, install_mode=True)]
self.vms = [ASAv_vm(username, password, conn_mode, install_mode=True)]

def install(self):
self.logger.info("Installing ASAv")
Expand All @@ -156,6 +160,11 @@ def install(self):
parser.add_argument("--username", default="vrnetlab", help="Username")
parser.add_argument("--password", default="VR-netlab9", help="Password")
parser.add_argument("--install", action="store_true", help="Install ASAv")
parser.add_argument(
"--connection-mode",
default="vrxcon",
help="Connection mode to use in the datapath",
)
args = parser.parse_args()

LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s"
Expand All @@ -167,8 +176,8 @@ def install(self):
logger.setLevel(1)

if args.install:
vr = ASAv_installer(args.username, args.password)
vr = ASAv_installer(args.username, args.password, args.connection_mode)
vr.install()
else:
vr = ASAv(args.username, args.password)
vr = ASAv(args.username, args.password, args.connection_mode)
vr.start()
10 changes: 7 additions & 3 deletions c8000v/Makefile → cisco/c8000v/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ VENDOR=cisco
NAME=c8000v
IMAGE_FORMAT=qcow2
IMAGE_GLOB=*.qcow2
VENDOR_SUBDIR=1

# match versions like:
# c8000v-17.11.01a.qcow2
VERSION=$(shell echo $(IMAGE) | sed -e 's/.\+[^0-9]\([0-9]\+\.[0-9]\+\.[0-9]\+[a-z]\?\)\([^0-9].*\|$$\)/\1/')

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

docker-pre-build:
-cat cidfile | xargs --no-run-if-empty docker rm -f
-rm cidfile

docker-build: docker-build-common
docker run --cidfile cidfile --privileged $(REGISTRY)$(VENDOR)_$(NAME):$(VERSION) --trace --install
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions cisco/c8000v/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/srl-labs/vrnetlab-base:0.0.1

ARG VERSION
ENV VERSION=${VERSION}
ARG IMAGE
COPY $IMAGE* /
COPY *.py /

EXPOSE 22 161/udp 830 5000 10000-10099
HEALTHCHECK CMD ["/healthcheck.py"]
ENTRYPOINT ["/launch.py"]
Loading