Skip to content

Commit 3e5e70f

Browse files
committed
added version detection for vqfx
1 parent 711de56 commit 3e5e70f

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

vqfx/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ docker-pre-build:
2828
# mostly copied from makefile.include, i wish this was easier to change
2929
docker-build-common: docker-clean-build docker-pre-build
3030
@if [ -z "$$IMAGE" ]; then echo "ERROR: No IMAGE specified"; exit 1; fi
31-
@if [ "$(IMAGE)" = "$(VERSION)" ]; then echo "ERROR: Incorrect version string ($(IMAGE)). The regexp for extracting version information is likely incorrect, check the regexp in the Makefile or open an issue at https://github.com/plajjan/vrnetlab/issues/new including the image file name you are using."; exit 1; fi
31+
@if [ "$(IMAGE)" = "$(VERSION)" ]; then echo "ERROR: Incorrect version string ($(IMAGE)). The regexp for extracting version information is likely incorrect, check the regexp in the Makefile or open an issue at https://github.com/hellt/vrnetlab/issues/new including the image file name you are using."; exit 1; fi
3232
@echo "Building docker image using $(IMAGE) as $(REGISTRY)vr-$(VR_NAME):$(VERSION)"
3333
cp ../common/* docker/
3434
$(MAKE) IMAGE=$$IMAGE docker-build-image-copy

vqfx/docker/Dockerfile

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
FROM ubuntu:20.04
2-
MAINTAINER Kristian Larsson <[email protected]>
3-
42
ENV DEBIAN_FRONTEND=noninteractive
53

64
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-
procps \
15-
tcpdump \
16-
openvswitch-switch \
17-
&& rm -rf /var/lib/apt/lists/*
5+
&& apt-get upgrade -qy \
6+
&& apt-get install -y \
7+
bridge-utils \
8+
iproute2 \
9+
python3-ipy \
10+
socat \
11+
qemu-kvm \
12+
procps \
13+
tcpdump \
14+
&& rm -rf /var/lib/apt/lists/*
1815

1916
ARG RE_IMAGE
2017
ARG PFE_IMAGE
2118

2219
COPY $RE_IMAGE /
2320
COPY $PFE_IMAGE /
2421

25-
RUN echo $RE_IMAGE > /re_image
26-
RUN echo $PFE_IMAGE > /pfe_image
27-
2822
COPY healthcheck.py /
2923
COPY vrnetlab.py /
3024
COPY launch.py /

vqfx/docker/launch.py

+40-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import signal
77
import sys
8+
import re
89

910
import vrnetlab
1011

@@ -37,14 +38,14 @@ def trace(self, message, *args, **kws):
3738

3839

3940
class VQFX_vcp(vrnetlab.VM):
40-
def __init__(self, hostname, username, password, conn_mode):
41-
re_image_name = open("/re_image").read().strip()
41+
def __init__(self, hostname, username, password, conn_mode, version, disk_image):
4242
super(VQFX_vcp, self).__init__(
43-
username, password, disk_image=re_image_name, ram=2048
43+
username, password, disk_image=disk_image, ram=2048
4444
)
4545
self.num_nics = 12
4646
self.conn_mode = conn_mode
4747
self.hostname = hostname
48+
self.version = version
4849

4950
def start(self):
5051
# use parent class start() function
@@ -89,12 +90,21 @@ def bootstrap_spin(self):
8990
self.spins = 0
9091
return
9192

92-
(ridx, match, res) = self.tn.expect([b"login:", b"root@vqfx-re:RE:0%"], 1)
93+
# logged_in_prompt prompt for v20+ versions
94+
logged_in_prompt = b"root@:RE:0%"
95+
96+
if self.version["major"] < 20:
97+
logged_in_prompt = b"root@vqfx-re:RE:0%"
98+
99+
(ridx, match, res) = self.tn.expect([b"login:", logged_in_prompt], 1)
93100
if match: # got a match!
94101
if ridx == 0: # matched login prompt, so should login
95102
self.logger.info("matched login prompt")
96103
self.wait_write("root", wait=None)
97-
self.wait_write("Juniper", wait="Password:")
104+
105+
# v19 has Juniper password for root login
106+
if self.version["major"] < 20:
107+
self.wait_write("Juniper", wait="Password:")
98108
if ridx == 1:
99109
# run main config!
100110
self.bootstrap_config()
@@ -186,10 +196,9 @@ def wait_write(self, cmd, wait="#", timeout=None):
186196

187197

188198
class VQFX_vpfe(vrnetlab.VM):
189-
def __init__(self):
190-
pfe_image_name = open("/pfe_image").read().strip()
199+
def __init__(self, disk_image):
191200
super(VQFX_vpfe, self).__init__(
192-
None, None, disk_image=pfe_image_name, num=1, ram=2048
201+
None, None, disk_image=disk_image, num=1, ram=2048
193202
)
194203
self.num_nics = 0
195204

@@ -232,12 +241,34 @@ class VQFX(vrnetlab.VR):
232241
def __init__(self, hostname, username, password, conn_mode):
233242
super(VQFX, self).__init__(username, password)
234243

235-
self.vms = [VQFX_vcp(hostname, username, password, conn_mode), VQFX_vpfe()]
244+
self.read_version()
245+
246+
self.vms = [
247+
VQFX_vcp(
248+
hostname, username, password, conn_mode, self.ver, self.vcp_qcow_name
249+
),
250+
VQFX_vpfe(self.pfe_qcow_name),
251+
]
236252

237253
# set up bridge for connecting VCP with vFPC
238254
vrnetlab.run_command(["brctl", "addbr", "int_cp"])
239255
vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
240256

257+
def read_version(self):
258+
for e in os.listdir("/"):
259+
vcp_match = re.match(r"vqfx-(\d+)\.(\w+)\.(\w+)\S+re\S+\.qcow2", e)
260+
if vcp_match:
261+
self.ver = {
262+
"major": int(vcp_match.group(1)),
263+
"minor": vcp_match.group(2),
264+
}
265+
self.vcp_qcow_name = vcp_match.group(0)
266+
267+
# https://regex101.com/r/4ByEhT/1
268+
pfe_match = re.match(r"vqfx-(\d+)\.(\w+)\S+-pfe.+qcow2?", e)
269+
if pfe_match:
270+
self.pfe_qcow_name = pfe_match.group(0)
271+
241272

242273
if __name__ == "__main__":
243274
import argparse
@@ -249,7 +280,6 @@ def __init__(self, hostname, username, password, conn_mode):
249280
parser.add_argument("--hostname", default="vr-vqfx", help="QFX hostname")
250281
parser.add_argument("--username", default="vrnetlab", help="Username")
251282
parser.add_argument("--password", default="VR-netlab9", help="Password")
252-
parser.add_argument("--install", action="store_true", help="Install vQFX")
253283
parser.add_argument(
254284
"--connection-mode",
255285
default="tc",

0 commit comments

Comments
 (0)