def start(self): # use parent class start() function super(VMX_vcp, self).start() # add interface to internal control plane bridge if not self.install_mode: vrnetlab.run_command(["brctl", "addif", "int_cp", "vcp-int"]) vrnetlab.run_command(["ip", "link", "set", "vcp-int", "up"])
def __init__(self, username, password): for e in os.listdir("/"): if re.search(".qcow2$", e): disk_image = "/" + e self.ram = 16384 self.vcpu = 6 self.disk_size = '40G' super(simulator_VM, self).__init__(username, password, disk_image=disk_image, ram=self.ram) self.num_nics = 14 self.wait_time = 30 self.nic_type = 'virtio-net-pci' vrnetlab.run_command([ "qemu-img", "create", "-f", "qcow2", "DataDisk.qcow2", self.disk_size ]) self.qemu_args.extend([ "-smp", str(self.vcpu), "-cpu", "host", "-drive", "if=virtio,format=qcow2,file=DataDisk.qcow2" ]) self.qemu_args.extend(["-D", "/var/log/qemu.log"])
def __init__(self, username, password, num_nics): super(SROS, self).__init__(username, password) # move files into place for e in os.listdir("/"): if re.search("\.qcow2$", e): os.rename("/" + e, "/sros.qcow2") if re.search("\.license$", e): os.rename("/" + e, "/tftpboot/license.txt") self.license = False if os.path.isfile("/tftpboot/license.txt"): self.logger.info("License found") self.license = True self.logger.info("Number of NICS: " + str(num_nics)) # if we have more than 5 NICs we use distributed VSR-SIM if num_nics > 5: if not self.license: self.logger.error("More than 5 NICs require distributed VSR which requires a license but no license is found") sys.exit(1) num_lc = math.ceil(num_nics / 6) self.logger.info("Number of linecards: " + str(num_lc)) self.vms = [ SROS_cp(username, password, num_lc=num_lc) ] for i in range(1, num_lc+1): self.vms.append(SROS_lc(i)) else: # 5 ports or less means integrated VSR-SIM self.vms = [ SROS_integrated(username, password) ] # set up bridge for connecting CP with LCs vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def start(self): # use parent class start() function super(VMX_vcp, self).start() # add interface to internal control plane bridge if not self.install_mode: vrnetlab.run_command(["brctl", "addif", "int_cp", "vcp-int"]) vrnetlab.run_command(["ip", "link", "set", "vcp-int", "up"])
def __init__(self, username, password): super(VQFX, self).__init__(username, password) self.vms = [ VQFX_vcp(username, password), VQFX_vpfe() ] # set up bridge for connecting VCP with vFPC vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def insert_extra_config(self): extra_config = os.getenv('EXTRA_CONFIG') if extra_config: self.logger.debug('extra_config = ' + extra_config) vrnetlab.run_command(["mount", "-o", "loop", self._metadata_usb, "/mnt"]) with open('/mnt/extra-config.conf', 'w') as f: f.write(extra_config) vrnetlab.run_command(["umount", "/mnt"])
def start(self): # use parent class start() function super(SROS_lc, self).start() # add interface to internal control plane bridge vrnetlab.run_command( ["brctl", "addif", "int_cp", "vfpc{}-int".format(self.slot)]) vrnetlab.run_command( ["ip", "link", "set", "vfpc{}-int".format(self.slot), "up"])
def __init__(self, username, password): super(VQFX, self).__init__(username, password) self.vms = [VQFX_vcp(username, password), VQFX_vpfe()] # set up bridge for connecting VCP with vFPC vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def __init__(self, username, password): 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), VMX_vfpc(self.version) ] # set up bridge for connecting VCP with vFPC vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def __init__(self, username, password): for e in os.listdir("/"): if re.search("-re-.*.vmdk", e): vrnetlab.run_command([ "qemu-img", "create", "-b", "/" + e, "-f", "qcow", "/vcp.qcow2" ]) super(VQFX_vcp, self).__init__(username, password, disk_image="/vcp.qcow2", ram=1024) self.num_nics = 12
def __init__(self, username, password): 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), VMX_vfpc(self.version) ] # set up bridge for connecting VCP with vFPC vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def __init__(self): for e in os.listdir("/"): if re.search("-pfe-.*.vmdk", e): vrnetlab.run_command([ "qemu-img", "create", "-b", "/" + e, "-f", "qcow", "/vpfe.qcow2" ]) super(VQFX_vpfe, self).__init__(None, None, disk_image="/vpfe.qcow2", num=1, ram=2048) self.num_nics = 0
def gen_mgmt(self): """ Augment the parent class function to add gNMI port forwarding """ # call parent function to generate first mgmt interface (e1000) res = super(XRV_vm, self).gen_mgmt() # append gNMI forwarding if it was not added by common lib if "hostfwd=tcp::57400-10.0.0.15:57400" not in res[-1]: res[-1] = res[-1] + ",hostfwd=tcp::17400-10.0.0.15:57400" vrnetlab.run_command( ["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"], background=True, ) return res
def gen_mgmt(self): """Generate mgmt interface(s) We override the default function since we want a fake NIC in there """ # call parent function to generate first mgmt interface (e1000) res = super(SROS_integrated, self).gen_mgmt() # append gNMI forwarding if it was not added by common lib if "hostfwd=tcp::57400-10.0.0.15:57400" not in res[-1]: res[-1] = res[-1] + ",hostfwd=tcp::17400-10.0.0.15:57400" vrnetlab.run_command( ["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"], background=True, ) return res
def create_overlay_image(self): self.overlay_image = re.sub(r'(\.[^.]+$)', r'-overlay\1', self.image) extended_args = ['-nographic', '-bios', self.bios, '-smp', '2'] # remove previously old overlay image, otherwise boot fails if os.path.exists(self.overlay_image): os.remove(self.overlay_image) # now re-create it! super().create_overlay_image() # use SATA driver for disk and set to drive 0 extended_args.extend(['-device', 'ahci,id=ahci0,bus=pci.0', '-drive', 'if=none,file=%s,id=drive-sata-disk0,format=qcow2' % self.overlay_image, '-device', 'ide-drive,bus=ahci0.0,drive=drive-sata-disk0,id=drive-sata-disk0']) # create initial config and load it vrnetlab.run_command(['genisoimage', '-o', '/cfg.iso', '-l', '--iso-level', '2', 'nxos_config.txt']) extended_args.extend(['-drive', 'file=cfg.iso,media=cdrom']) return extended_args
def __init__(self, username, password, num_nics, mode): super(SROS, self).__init__(username, password) major_release = 0 # move files into place for e in os.listdir("/"): match = re.match(r'[^0-9]+([0-9]+)\S+\.qcow2$', e) if match: major_release = int(match.group(1)) if re.search("\.qcow2$", e): os.rename("/" + e, "/sros.qcow2") if re.search("\.license$", e): os.rename("/" + e, "/tftpboot/license.txt") self.license = False if os.path.isfile("/tftpboot/license.txt"): self.logger.info("License found") self.license = True self.logger.info("Number of NICS: " + str(num_nics)) self.logger.info("Mode: " + str(mode)) # if we have more than 5 NICs or version is 19 or higher we use distributed VSR-SIM if num_nics > 5 or major_release >= 19: if not self.license: self.logger.error( "More than 5 NICs require distributed VSR which requires a license but no license is found" ) sys.exit(1) num_lc = math.ceil(num_nics / 6) self.logger.info("Number of linecards: " + str(num_lc)) self.vms = [ SROS_cp(username, password, mode, major_release, num_lc=num_lc) ] for i in range(1, num_lc + 1): self.vms.append(SROS_lc(i)) else: # 5 ports or less means integrated VSR-SIM self.vms = [SROS_integrated(username, password, mode)] # set up bridge for connecting CP with LCs vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def __init__(self, username, password, dual_re=False): self.version = None self.version_info = [] self.read_version() self.dual_re = dual_re super(VMX, self).__init__(username, password) if not dual_re: self.vms = [ VMX_vcp(username, password, self.vcp_image, self.version), VMX_vfpc(self.version) ] else: self.vms = [ VMX_vcp(username, password, self.vcp_image, self.version, dual_re=True, re_instance=0), VMX_vcp(username, password, self.vcp_image, self.version, dual_re=True, re_instance=1), VMX_vfpc(self.version) ] # set up bridge for connecting VCP with vFPC vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def gen_mgmt(self): """ Augment base gen_mgmt function to add gnmi and socat forwarding """ res = [] # vEOS-lab requires its Ma1 interface to be the first in the bus, so let's hardcode it (addr 0x2) res.append("-device") res.append(self.nic_type + f",netdev=p00,mac={vrnetlab.gen_mac(0)},bus=pci.1,addr=0x2") res.append("-netdev") res.append( "user,id=p00,net=10.0.0.0/24,tftp=/tftpboot,hostfwd=tcp::2022-10.0.0.15:22,hostfwd=udp::2161-10.0.0.15:161,hostfwd=tcp::2830-10.0.0.15:830,hostfwd=tcp::2080-10.0.0.15:80,hostfwd=tcp::2443-10.0.0.15:443,hostfwd=tcp::16030-10.0.0.15:6030" ) vrnetlab.run_command( ["socat", "TCP-LISTEN:6030,fork", "TCP:127.0.0.1:16030"], background=True, ) return res
def start(self): # use parent class start() function super(SROS_cp, self).start() # add interface to internal control plane bridge vrnetlab.run_command(["brctl", "addif", "int_cp", "vcp-int"]) vrnetlab.run_command(["ip", "link", "set", "vcp-int", "up"]) vrnetlab.run_command(["ip", "link", "set", "dev", "vcp-int", "mtu", "10000"])
def gen_mgmt(self): """Generate qemu args for the mgmt interface(s)""" res = [] # mgmt interface res.extend( ["-device", "virtio-net-pci,netdev=mgmt,mac=%s" % vrnetlab.gen_mac(0)] ) res.extend( [ "-netdev", "user,id=mgmt,net=10.0.0.0/24,tftp=/tftpboot,hostfwd=tcp::2022-10.0.0.15:22,hostfwd=udp::2161-10.0.0.15:161,hostfwd=tcp::2830-10.0.0.15:830,hostfwd=tcp::17400-10.0.0.15:57400", ] ) # dummy interface for xrv9k ctrl interface res.extend( [ "-device", "virtio-net-pci,netdev=ctrl-dummy,id=ctrl-dummy,mac=%s" % vrnetlab.gen_mac(0), "-netdev", "tap,ifname=ctrl-dummy,id=ctrl-dummy,script=no,downscript=no", ] ) # dummy interface for xrv9k dev interface res.extend( [ "-device", "virtio-net-pci,netdev=dev-dummy,id=dev-dummy,mac=%s" % vrnetlab.gen_mac(0), "-netdev", "tap,ifname=dev-dummy,id=dev-dummy,script=no,downscript=no", ] ) # add socat for gNMI port we added on L76, since it's not part of vrnetlab core lib vrnetlab.run_command( ["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"], background=True, ) return res
def start(self): # use parent class start() function super(SROS_lc, self).start() # add interface to internal control plane bridge vrnetlab.run_command(["brctl", "addif", "int_cp", "vfpc{}-int".format(self.slot)]) vrnetlab.run_command(["ip", "link", "set", "vfpc{}-int".format(self.slot), "up"]) vrnetlab.run_command(["ip", "link", "set", "dev", "vfpc{}-int".format(self.slot), "mtu", "10000"])
def __init__(self, username, password, num_nics, chassis): super(SROS, self).__init__(username, password) # move files into place for e in os.listdir("/"): if re.search("\.qcow2$", e): os.rename("/" + e, "/sros.qcow2") if re.search("\.license$", e): os.rename("/" + e, "/tftpboot/license.txt") self.license = False if os.path.isfile("/tftpboot/license.txt"): self.logger.info("License found") self.license = True self.logger.info("Number of NICS: " + str(num_nics)) # if we have more than 5 NICs we use distributed VSR-SIM if num_nics > 5 or chassis in ['SR-7s', 'SR-14s']: if not self.license: self.logger.error( "More than 5 NICs require distributed VSR which requires a license but no license is found" ) sys.exit(1) num_lc = math.ceil(num_nics / 6) self.logger.info("Number of linecards: " + str(num_lc)) self.vms = [ SROS_cp(username, password, num_lc=num_lc, chassis=chassis) ] for i in range(1, num_lc + 1): self.vms.append(SROS_lc(i, chassis=chassis)) else: # 5 ports or less means integrated VSR-SIM self.vms = [SROS_integrated(username, password, chassis=chassis)] # set up bridge for connecting CP with LCs vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"])
def gen_mgmt(self): """Generate mgmt interface(s) We override the default function since we want a virtio NIC to the vFPC """ # call parent function to generate first mgmt interface (e1000) res = super(VMX_vcp, self).gen_mgmt() if not self.install_mode: # append gNMI forwarding if it was not added by common lib if "hostfwd=tcp::57400-10.0.0.15:57400" not in res[-1]: res[-1] = res[-1] + ",hostfwd=tcp::17400-10.0.0.15:57400" vrnetlab.run_command( ["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"], background=True, ) # add virtio NIC for internal control plane interface to vFPC res.append("-device") res.append("virtio-net-pci,netdev=vcp-int,mac=%s" % vrnetlab.gen_mac(1)) res.append("-netdev") res.append("tap,ifname=vcp-int,id=vcp-int,script=no,downscript=no") return res
def start(self): # use parent class start() function super(VQFX_vpfe, self).start() # add interface to internal control plane bridge vrnetlab.run_command(["brctl", "addif", "int_cp", "vpfe-int"]) vrnetlab.run_command(["ip", "link", "set", "vpfe-int", "up"])
def __init__(self): for e in os.listdir("/"): if re.search("-pfe-.*.vmdk", e): vrnetlab.run_command(["qemu-img", "create", "-b", "/" + e, "-f", "qcow", "/vpfe.qcow2"]) super(VQFX_vpfe, self).__init__(None, None, disk_image="/vpfe.qcow2", num=1, ram=2048) self.num_nics = 0
def __init__(self, hostname, username, password, mode, variant_name, conn_mode): super(SROS, self).__init__(username, password) if variant_name.lower() in SROS_VARIANTS: variant = SROS_VARIANTS[variant_name.lower()] else: variant = parse_custom_variant(self, variant_name) major_release = 0 # move files into place for e in os.listdir("/"): match = re.match(r"[^0-9]+([0-9]+)\S+\.qcow2$", e) if match: major_release = int(match.group(1)) self.qcow_name = match.group(0) if re.search(r"\.qcow2$", e): os.rename("/" + e, "/sros.qcow2") if re.search(r"\.license$", e): os.rename("/" + e, "/tftpboot/license.txt") self.license = False if os.path.isfile("/tftpboot/license.txt"): self.logger.info("License found") self.license = True else: self.logger.error( "License is missing! Provide a license file with a {}.license name next to the qcow2 image.".format( self.qcow_name ) ) sys.exit(1) self.logger.info("SR OS Variant: " + variant_name) self.logger.info(f"Number of NICs: {variant['max_nics']}") self.logger.info("Configuration mode: " + str(mode)) # set up bridge for management interface to a localhost self.logger.info("Creating br-mgmt bridge for management interface") # This is to whitlist all bridges vrnetlab.run_command(["mkdir", "-p", "/etc/qemu"]) vrnetlab.run_command(["echo 'allow all' > /etc/qemu/bridge.conf"], shell=True) vrnetlab.run_command(["brctl", "addbr", "br-mgmt"]) vrnetlab.run_command( ["echo 16384 > /sys/class/net/br-mgmt/bridge/group_fwd_mask"], shell=True, ) vrnetlab.run_command(["ip", "link", "set", "br-mgmt", "up"]) vrnetlab.run_command( ["ip", "addr", "add", "dev", "br-mgmt", f"{BRIDGE_ADDR}/{PREFIX_LENGTH}"] ) if variant["deployment_model"] == "distributed": self.vms = [ SROS_cp( hostname, username, password, mode, major_release, variant, conn_mode, ), SROS_lc(variant, conn_mode, variant["max_nics"]), ] # set up bridge for connecting CP with LCs vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"]) # integrated mode else: self.vms = [ SROS_integrated( hostname, username, password, mode, variant["max_nics"], variant, conn_mode=conn_mode, ) ]
def start(self): # use parent class start() function super(VQFX_vpfe, self).start() # add interface to internal control plane bridge vrnetlab.run_command(["brctl", "addif", "int_cp", "vpfe-int"]) vrnetlab.run_command(["ip", "link", "set", "vpfe-int", "up"])
def start(self): for i in range(10): net = "net%d" % (i + 1) tap = "tap%d" % i bridge = "%s_%s" % (net, tap) vrnetlab.run_command( ["ip", "link", "add", bridge, "type", "bridge"]) vrnetlab.run_command(["ip", "addr", "flush", "dev", net]) vrnetlab.run_command(["ip", "link", "set", net, "master", bridge]) vrnetlab.run_command( ["ip", "tuntap", "add", "dev", tap, "mode", "tap"]) # vrnetlab.run_command(["ip", "link", "set", tap, "promisc", "on"]) vrnetlab.run_command(["ip", "link", "set", tap, "master", bridge]) vrnetlab.run_command(["ip", "link", "set", bridge, "up"]) vrnetlab.run_command(["ip", "link", "set", tap, "up"]) # use parent class start() function super(VQFX_vcp, self).start() # add interface to internal control plane bridge vrnetlab.run_command(["brctl", "addif", "int_cp", "vcp-int"]) vrnetlab.run_command(["ip", "link", "set", "vcp-int", "up"])
def insert_bootstrap_config(self): vrnetlab.run_command(["mount", "-o", "loop", self._metadata_usb, "/mnt"]) vrnetlab.run_command(["mkdir", "/tmp/vmm-config"]) vrnetlab.run_command(["tar", "-xzvf", "/mnt/vmm-config.tgz", "-C", "/tmp/vmm-config"]) vrnetlab.run_command(["mkdir", "/tmp/vmm-config/config"]) vrnetlab.run_command(["cp", "/juniper.conf", "/tmp/vmm-config/config/"]) vrnetlab.run_command(["tar", "zcf", "vmm-config.tgz", "-C", "/tmp/vmm-config", "."]) vrnetlab.run_command(["cp", "vmm-config.tgz", "/mnt/vmm-config.tgz"]) vrnetlab.run_command(["umount", "/mnt"])
def __init__(self, hostname, username, password, num_nics, mode, variant_name, conn_mode): super(SROS, self).__init__(username, password) variant = SROS_VARIANTS[variant_name] major_release = 0 # move files into place for e in os.listdir("/"): match = re.match(r"[^0-9]+([0-9]+)\S+\.qcow2$", e) if match: major_release = int(match.group(1)) self.qcow_name = match.group(0) if re.search("\.qcow2$", e): os.rename("/" + e, "/sros.qcow2") if re.search("\.license$", e): os.rename("/" + e, "/tftpboot/license.txt") self.license = False if os.path.isfile("/tftpboot/license.txt"): self.logger.info("License found") self.license = True else: self.logger.error( "License is missing! Provide a license file with a {}.license name next to the qcow2 image." .format(self.qcow_name)) sys.exit(1) if num_nics > variant["max_nics"]: self.logger.error( "Requested number of nics '{}' exceeds the capacity of the '{}' variant: {} nics" .format(num_nics, variant_name, variant["max_nics"])) sys.exit(1) self.logger.info("SR OS Variant: " + variant_name) self.logger.info("Number of NICs: " + str(num_nics)) self.logger.info("Configuration mode: " + str(mode)) if variant["deployment_model"] == "distributed": self.vms = [ SROS_cp( hostname, username, password, mode, major_release, variant, conn_mode, ), SROS_lc(variant, conn_mode, num_nics), ] # set up bridge for connecting CP with LCs vrnetlab.run_command(["brctl", "addbr", "int_cp"]) vrnetlab.run_command(["ip", "link", "set", "int_cp", "up"]) # integrated mode else: self.vms = [ SROS_integrated( hostname, username, password, mode, num_nics, variant, conn_mode=conn_mode, ) ]
def __init__(self, username, password): for e in os.listdir("/"): if re.search("-re-.*.vmdk", e): vrnetlab.run_command(["qemu-img", "create", "-b", "/" + e, "-f", "qcow", "/vcp.qcow2"]) super(VQFX_vcp, self).__init__(username, password, disk_image="/vcp.qcow2", ram=2048) self.num_nics = 12
LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s" logging.basicConfig(format=LOG_FORMAT) logger = logging.getLogger() logger.setLevel(logging.DEBUG) if args.trace: logger.setLevel(1) vrnetlab.run_command( [ "in.tftpd", "--listen", "--user", "tftp", "-a", "0.0.0.0:69", "-s", "-c", "-v", "/tftpboot", ] ) # make tftpboot writable for saving SR OS config vrnetlab.run_command(["chmod", "-R", "777", "/tftpboot"]) # kill origin socats since we use bridge interface # for SR OS management interface # thus we need to forward connections to a different address vrnetlab.run_command(["pkill", "socat"])