### Install virl2_client from a local wheel file Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install the virl2_client package directly from a downloaded wheel file. Ensure to use the correct filename that includes version and build information. ```bash pip3 install ./virl2_client-*.whl ``` -------------------------------- ### Install full pyATS library Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install the complete pyATS library, including features like Genie, in a subsequent step after installing virl2_client. This is for users requiring the full pyATS functionality. ```bash pip3 install "pyats[full]" ``` -------------------------------- ### Install virl2_client using pip Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install the virl2_client package from PyPI. This is the standard method for obtaining the library. ```bash pip3 install virl2_client ``` -------------------------------- ### Install virl2_client with pyATS support Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install the virl2_client along with pyATS for device interaction. This installs the necessary dependencies for pyATS integration. ```bash pip3 install "virl2_client[pyats]" ``` -------------------------------- ### Create and Manage a Lab Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Demonstrates creating a lab, adding nodes with configurations, creating interfaces, linking them, starting the lab, monitoring node/interface states, and finally stopping, wiping, and removing the lab and its nodes. ```python lab = client.create_lab() r1 = lab.create_node("r1", "iosv", 50, 100) r1.config = "hostname router1" r2 = lab.create_node("r2", "iosv", 50, 200) r2.config = "hostname router2" # create a link between r1 and r2 r1_i1 = r1.create_interface() r2_i1 = r2.create_interface() lab.create_link(r1_i1, r2_i1) # alternatively, use this convenience function: lab.connect_two_nodes(r1, r2) # start the lab lab.start() # print nodes and interfaces states: for node in lab.nodes(): print(node, node.state, node.cpu_usage) for interface in node.interfaces(): print(interface, interface.readpackets, interface.writepackets) lab.stop() lab.wipe() lab.remove_node(r2) lab.remove() ``` -------------------------------- ### Install virl2_client with version constraint Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install a version of virl2_client that is compatible with a specific CML controller version, for example, installing a version less than 2.3.0 for a 2.2.x controller. ```bash pip3 install "virl2-client<2.3.0" ``` -------------------------------- ### Install a specific version of virl2_client Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/intro.md Install a specific version of the virl2_client to ensure compatibility with your CML controller version. This is useful when the latest version is not compatible. ```bash pip3 install virl2_client-2.0.0b10-py3-none-any.whl ``` -------------------------------- ### Find and Join Lab, then Condition Link Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md This example demonstrates how to find a lab by its title, join it if it's unique, list its links, and then set or remove conditioning on a selected link. It handles user input for link selection and conditioning parameters. ```python import re from virl2_client.client import Client from virl2_client.exceptions import HTTPError # Assume client and LAB_NAME are defined elsewhere # client = Client(config='~/.virl2/virl2.conf') # LAB_NAME = "MyTestLab" # Find the lab by title and join it as long as it's the only # lab with that title. lbs = client.find_labs_by_title(LAB_NAME) if not lbs or len(lbs) != 1: print("ERROR: Unable to find a unique lab named {}".format(LAB_NAME)) exit(1) lobj = client.join_existing_lab(lbs[0].id) if not lobj: print("ERROR: Failed to join lab {}".format(LAB_NAME)) exit(1) # Print all links in the lab and ask which link to condition. i = 1 liobjs = [] for link in lobj.links(): print( "{}. {}[{}] <-> {}[{}]" .format( i, link.interface_a.node.label, link.interface_a.label, link.interface_b.node.label, link.interface_b.label, ) ) liobjs.append(lobj.get_link_by_interfaces(link.interface_a, link.interface_b)) i += 1 print() lnum = 0 while lnum < 1 or lnum > i-1: lnum = input("enter link number to condition (1-{})".format(i-1)) try: lnum = int(lnum) except ValueError: lnum = 0 # Print the selected link's current conditioning (if any). link = liobs[lnum-1] print("Current condition is {}".format(link.get_condition())) # Request the new conditoning for bandwidth, latency, jitter, and loss. # Bandwidth is an integer between 0-10000000 kbps # Bandwidth of 0 is "no bandwidth restriction" # Latency is an integer between 0-10000 ms # Jitter is an integer between 0-10000 ms # Loss is a float between 0-100% new_cond = input( "enter new condition in format 'BANDWIDTH, " "LATENCY, JITTER, LOSS' or 'None' to disable: " ) # If "None" is provided disable any conditioning on the link. if new_cond.lower() == "none": link.remove_condition() print("Link conditioning has been disabled.") else: try: # Set the current conditioning based on the provided values. cond_list = re.split(r"\s*,\s*", new_cond) bw = int(cond_list[0]) # Bandwidth is an int latency = int(cond_list[1]) # Latency is an int jitter = int(cond_list[2]) # Jitter is an int loss = float(cond_list[3]) # Loss is a float link.set_condition(bw, latency, jitter, loss) print("Link conditioning set.") except HTTPError as exc: print("ERROR: Failed to set link conditioning: {}", format(exc)) exit(1) ``` -------------------------------- ### Create and Get Lab ID Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Create a new lab environment using the initialized client and print its unique identifier. This is the first step in building a network topology. ```python lab = client.create_lab() print(lab.id) ``` -------------------------------- ### Get All Lab Names Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Retrieves a list of titles for all labs owned by the current user. ```python all_labs_names = [lab.title for lab in client.all_labs()] ``` -------------------------------- ### Integrate VIRL2 Client with Netmiko Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Combines the VIRL2 client with Netmiko to connect to a specific node within a lab. This example demonstrates how to establish a console connection via a terminal server and execute Cisco IOS commands, including interactive ones like generating crypto keys. ```python import getpass import netmiko from virl2_client import ClientLibrary LAB_USERNAME = 'cisco' LAB_PASSWORD = 'cisco' VIRL_CONTROLLER = 'cml2-controller' VIRL_USERNAME = input('username: ') VIRL_PASSWORD = getpass.getpass('password: ') client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False) # this assumes that there's exactly one lab with this title our_lab = client.find_labs_by_title('my_lab')[0] iosv_node = our_lab.get_node_by_label('iosv-0') # open the Netmiko connection via the terminal server # (SSH to the controller connects to the terminal server) c = netmiko.ConnectHandler(device_type='terminal_server', host=VIRL_CONTROLLER, username=VIRL_USERNAME, password=VIRL_PASSWORD) # send CR, get a prompt on terminal server c.write_channel('\r') # open the connection to the console c.write_channel(f'open /{our_lab.title}/{iosv_node.label}/0\r') # router login # this makes an assumption that it's required to login c.write_channel('\r') c.write_channel(LAB_USERNAME + '\r') c.write_channel(LAB_PASSWORD + '\r') # switch to Cisco IOS mode netmiko.redispatch(c, device_type='cisco_ios') c.find_prompt() # get the list of interfaces result = c.send_command('show ip int brief') print(result) # create the keys c.write_channel('enable\r') c.write_channel('configure terminal\r') result = c.send_command('crypto key generate rsa', expect_string='How many bits in the modulus [512]\\: ') print(result) # send the key length c.write_channel('2048\n') # retrieve the result c.write_channel('exit\r') c.write_channel('disable\r') result = c.send_command_timing('show crypto key mypubkey rsa', last_read=2.0) print(result) ``` -------------------------------- ### Initialize VIRL 2 Client Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Basic client initialization with controller URL, username, and password. Environment variables can be used if arguments are omitted. ```python from virl2_client import ClientLibrary client = ClientLibrary("https://192.168.1.1", "username", "password") ``` -------------------------------- ### Initialize VIRL 2 Client Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Instantiate the ClientLibrary to connect to the VIRL server. Ensure to provide the correct server URL and credentials. SSL verification can be disabled if necessary for testing environments. ```python from virl2_client import ClientLibrary client = ClientLibrary("https://192.168.1.1", "virl2", "virl2", ssl_verify=False) ``` -------------------------------- ### Initialize Client with Custom SSL Certificate Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Initialize the client, providing a custom SSL certificate bundle for verification. This is useful for self-signed certificates. ```python client = ClientLibrary("https://192.168.1.1", "username", "password", ssl_verify="./cert.pem") ``` -------------------------------- ### Apply and Retrieve System License Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Applies a license to the system using a token and retrieves licensing status and features. Requires controller details, username, password, a smart license token, and product configuration. ```python import getpass import json from virl2_client import ClientLibrary VIRL_CONTROLLER = "cml2-controller" VIRL_USERNAME = input("username: ") VIRL_PASSWORD = getpass.getpass("password: ") SL_TOKEN = input("smart license token: ") PRODUCT_CONFIG = input("product configuration: ") client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False) # Get the licensing handle from the client as a property licensing = client.licensing # Set the product configuration licensing.set_product_license(PRODUCT_CONFIG) # Setup default license transport (i.e., directly connected to the external # Smart License server) licensing.set_default_transport() # Register with the Smart License server. # Wait for registration and authorization to complete. result = licensing.register_wait(SL_TOKEN) if not result: result = licensing.get_reservation_return_code() print( "ERROR: Failed to register with Smart License server: {}!".format(result) ) exit(1) # Get the current registration status. # This returns a JSON blob with license status and authorization details. status = licensing.status() # Get the current list of licensed features. # This returns a JSON blob with licensed features. features = licensing.features() print(json.dumps(status, indent=2)) print(json.dumps(features, indent=2)) ``` ```json { "registration": { "status": "COMPLETED", "expires": "2021-06-10 20:17:39", "smart_account": "Foo", "virtual_account": "Bar", "instance_name": "cml-controller.cml.lab", "register_time": { "succeeded": null, "attempted": "2020-06-10 20:22:33", "scheduled": null, "status": null, "failure": "OK", "success": "SUCCESS" }, "renew_time": { "succeeded": null, "attempted": null, "scheduled": "2020-12-07 20:22:40", "status": null, "failure": null, "success": "FAILED" } }, "authorization": { "status": "IN_COMPLIANCE", "renew_time": { "succeeded": null, "attempted": "2020-07-25 16:44:09", "scheduled": "2020-08-24 16:44:08", "status": "SUCCEEDED", "failure": null, "success": "SUCCESS" }, "expires": "2020-10-23 16:39:07" }, "features": [ { "name": "CML - Enterprise License", "description": "Cisco Modeling Labs - Enterprise License with 20 nodes capacity included", "in_use": 1, "status": "IN_COMPLIANCE", "version": "1.0" }, { "name": "CML \u2013 Expansion Nodes", "description": "Cisco Modeling Labs - Expansion node capacity for CML Enterprise Servers", "in_use": 50, "status": "IN_COMPLIANCE", "version": "1.0" } ], "reservation_mode": false, "transport": { "ssms": "https://smartreceiver.cisco.com/licservice/license", "proxy": { "server": null, "port": null }, "default_ssms": "https://smartreceiver.cisco.com/licservice/license" }, "udi": { "hostname": "cml2-controller", "product_uuid": "00000000-0000-4000-a000-000000000000" }, "product_license": { "active": "CML_Personal", "is_enterprise": False } } ``` ```json [ { "id": "regid.2019-10.com.cisco.CML_ENT_BASE,1.0_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "name": "CML - Enterprise License", "description": "Cisco Modeling Labs - Enterprise License with 20 nodes capacity included", "in_use": 1, "status": "IN_COMPLIANCE", "version": "1.0", "min": 0, "max": 1 }, { "id": "regid.2019-10.com.cisco.CML_NODE_COUNT,1.0_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "name": "CML \u2013 Expansion Nodes", "description": "Cisco Modeling Labs - Expansion node capacity for CML Enterprise Servers", "in_use": 50, "status": "IN_COMPLIANCE", "version": "1.0", "min": 0, "max": 300 } ] ``` -------------------------------- ### Initialize Client with SSL Verification Disabled Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Initialize the client with SSL certificate verification disabled. This is not recommended for production environments due to security risks. ```python client = ClientLibrary("https://192.168.1.1", "username", "password", ssl_verify=False) ``` -------------------------------- ### Create Node Interfaces Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Create network interfaces for a given node. Each node can have multiple interfaces, which are necessary for establishing connections. ```python r1_i1 = r1.create_interface() r1_i2 = r1.create_interface() ``` ```python r2_i1 = r2.create_interface() r2_i2 = r2.create_interface() ``` ```python r3_i1 = r3.create_interface() r3_i2 = r3.create_interface() ``` -------------------------------- ### Stop, Wipe, and Remove All Labs Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Loops through all labs, stopping, wiping, and then removing each one from the controller. ```python lab_list = client.get_lab_list() for lab_id in lab_list: lab = client.join_existing_lab(lab_id) lab.stop() lab.wipe() client.remove_lab(lab_id) ``` -------------------------------- ### Apply Link Conditioning to a Link Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Applies link conditioning to a specified link within a lab. Requires controller details, username, password, and lab name. It lists links, shows current conditions, and allows setting new conditions or removing them. ```python import getpass import re from requests.exceptions import HTTPError from virl2_client import ClientLibrary VIRL_CONTROLLER = "cml2-controller" VIRL_USERNAME = input("username: ") VIRL_PASSWORD = getpass.getpass("password: ") LAB_NAME = input("enter lab name: ") client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False) ``` -------------------------------- ### Create Network Node Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Add a network node to the lab. Specify the node name, image type, and its position within the lab canvas. Multiple nodes can be added to form a network. ```python r1 = lab.create_node("r1", "iosv", 50, 100) ``` ```python r2 = lab.create_node("r2", "iosv", 302, 201) ``` ```python r3 = lab.create_node("r3", "iosv", 200, 400) ``` -------------------------------- ### Create Network Link Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Establish a connection between two network interfaces. This function takes two interface objects as arguments to create a link. ```python link_1 = lab.create_link(r1_i1, r2_i1) ``` ```python link_2 = lab.create_link(r2_i2, r3_i1) ``` ```python link_3 = lab.create_link(r3_i2, r1_i2) ``` -------------------------------- ### Upload Image Disk File Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Uploads a local disk image file to the controller. The uploaded file can then be used to create image definitions for node types. ```python filename = "/Users/username/Desktop/vios-adventerprisek9-m.spa.158-3.m2.qcow2" client_library.definitions.upload_image_file(filename, rename="iosv-test.qcow2") ``` -------------------------------- ### Stop All Labs Source: https://github.com/ciscodevnet/virl2-client/blob/main/docs/source/examples.md Iterates through all available labs managed by the client and stops each one. ```python for lab in client.all_labs(): lab.stop() ``` -------------------------------- ### Remove Entire Lab Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Deletes the entire lab environment and all its components. This is a destructive operation that should be used when the lab is no longer needed. ```python lab.remove() ``` -------------------------------- ### Remove Network Node Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Delete a node from the lab environment. This action also removes all interfaces and links associated with the node. ```python lab.remove_node(r1) ``` ```python lab.remove_node(r2) ``` ```python lab.remove_node(r3) ``` -------------------------------- ### Remove Node Interface Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Delete a specific interface from a node. This action removes the interface and any associated links. ```python lab.remove_interface(r1_i2) ``` -------------------------------- ### Remove Network Link Source: https://github.com/ciscodevnet/virl2-client/blob/main/examples/demo.ipynb Delete a previously created link between network interfaces. This is useful for reconfiguring the network topology dynamically. ```python lab.remove_link(link_1) ``` ```python lab.remove_link(link_2) ``` ```python lab.remove_link(link_3) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.