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

Open
wants to merge 17 commits into
base: scrapli-dev
Choose a base branch
from
Open
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
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
8 changes: 6 additions & 2 deletions aoscx/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:bullseye
FROM public.ecr.aws/docker/library/debian:bookworm-slim
MAINTAINER Stefano Sasso <[email protected]>

ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -19,7 +19,11 @@ RUN apt-get update -qy \
ftp \
qemu-system-x86=1:5.2+dfsg-11+deb11u2 \
qemu-utils=1:5.2+dfsg-11+deb11u2 \
&& rm -rf /var/lib/apt/lists/*
git \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

RUN pip install git+https://github.com/carlmontanari/scrapli

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.

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.
8 changes: 6 additions & 2 deletions asav/docker/Dockerfile → cisco/asav/docker/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM public.ecr.aws/docker/library/debian:bookworm-slim
MAINTAINER Kristian Larsson <[email protected]>

ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -17,7 +17,11 @@ RUN apt-get update -qy \
dnsutils \
telnet \
genisoimage \
&& rm -rf /var/lib/apt/lists/*
git \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

RUN pip install git+https://github.com/carlmontanari/scrapli --break-system-packages

ARG VERSION
ENV VERSION=${VERSION}
Expand Down
34 changes: 20 additions & 14 deletions asav/docker/launch.py → cisco/asav/docker/launch.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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
Expand All @@ -47,6 +47,7 @@ def __init__(self, username, password, install_mode=False):
)
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 +59,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 +86,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 +104,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 +114,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 +125,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 +157,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 +173,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.
7 changes: 6 additions & 1 deletion c8000v/docker/Dockerfile → cisco/c8000v/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ FROM public.ecr.aws/docker/library/debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -qy \
&& apt-get install -y \
&& apt-get install -y --no-install-recommends \
bridge-utils \
iproute2 \
socat \
qemu-kvm \
qemu-utils \
tcpdump \
inetutils-ping \
ssh \
telnet \
procps \
genisoimage \
git \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

RUN pip install git+https://github.com/carlmontanari/scrapli --break-system-packages

ARG VERSION
ENV VERSION=${VERSION}
ARG IMAGE
Expand Down
Loading