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

Set random UUIDs per default, override via cli #258

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/vrnetlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import telnetlib
import time
import uuid

MAX_RETRIES=60

Expand Down Expand Up @@ -38,6 +39,12 @@ def run_command(cmd, cwd=None, background=False):



def argparse_type_uuid(arg_value):
uuid.UUID(str(arg_value))
return arg_value



class VM:
def __str__(self):
return self.__class__.__name__
Expand Down Expand Up @@ -91,6 +98,8 @@ def start(self):
# uuid
if self.uuid:
cmd.extend(["-uuid", self.uuid])
else:
cmd.extend(["-uuid", str(uuid.uuid4())])

# do we have a fake start date?
if self.fake_start_date:
Expand Down
16 changes: 10 additions & 6 deletions vmx/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def trace(self, message, *args, **kws):


class VMX_vcp(vrnetlab.VM):
def __init__(self, username, password, image, version, install_mode=False):
def __init__(self, username, password, uuid, image, version, install_mode=False):
super(VMX_vcp, self).__init__(username, password, disk_image=image, ram=2048)
self.install_mode = install_mode
self.num_nics = 0
if uuid:
self.uuid = uuid
self.qemu_args.extend(["-drive", "if=ide,file=/vmx/vmxhdd.img"])
self.smbios = ["type=0,vendor=Juniper",
"type=1,manufacturer=Juniper,product=VM-vcp_vmx2-161-re-0,version=0.1.0"]
Expand Down Expand Up @@ -243,14 +245,14 @@ class VMX(vrnetlab.VR):
""" Juniper vMX router
"""

def __init__(self, username, password):
def __init__(self, username, password, uuid):
self.version = None
self.version_info = []
self.read_version()

super(VMX, self).__init__(username, password)

self.vms = [ VMX_vcp(username, password, "/vmx/" + self.vcp_image, self.version), VMX_vfpc(self.version) ]
self.vms = [ VMX_vcp(username, password, uuid, "/vmx/" + self.vcp_image, self.version), VMX_vfpc(self.version) ]

# set up bridge for connecting VCP with vFPC
vrnetlab.run_command(["brctl", "addbr", "int_cp"])
Expand Down Expand Up @@ -280,9 +282,9 @@ def __init__(self, username, password):
self.version_info = []
self.read_version()

super().__init__(username, password)
super().__init__(username, password, None)

self.vms = [ VMX_vcp(username, password, "/vmx/" + self.vcp_image, self.version, install_mode=True) ]
self.vms = [ VMX_vcp(username, password, None, "/vmx/" + self.vcp_image, self.version, install_mode=True) ]

def install(self):
self.logger.info("Installing VMX")
Expand Down Expand Up @@ -324,6 +326,8 @@ def install(self):
parser.add_argument('--password', default='VR-netlab9', help='Password')
parser.add_argument('--install', action='store_true', help='Install vMX')
parser.add_argument('--num-nics', type=int, default=96, help='Number of NICs, this parameter is IGNORED, only added to be compatible with other platforms')
parser.add_argument('--uuid', type=vrnetlab.argparse_type_uuid, help='UUID')

args = parser.parse_args()

LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s"
Expand All @@ -338,5 +342,5 @@ def install(self):
vr = VMX_installer(args.username, args.password)
vr.install()
else:
vr = VMX(args.username, args.password)
vr = VMX(args.username, args.password, args.uuid)
vr.start()