VIRL 2 API Client

Subpackages

Exceptions

exception virl2_client.exceptions.InterfaceNotFound

Bases: Exception

exception virl2_client.exceptions.LabNotFound

Bases: Exception

exception virl2_client.exceptions.LinkNotFound

Bases: Exception

exception virl2_client.exceptions.NodeNotFound

Bases: Exception

Utils

exception virl2_client.utils.TextFsmNotInstalled

Bases: Exception

class virl2_client.utils.TextFsmTemplateHelper

Bases: object

__init__()
add_line(line)
add_numeric_token(name)
add_token(name, pattern)
clear()
render()
virl2_client.utils.get_offsets_for_keywords(title)
virl2_client.utils.parse_interfaces(get_offsets_for_keywords, parse_line, result)
virl2_client.utils.parse_line(line, keys, offsets)
virl2_client.utils.parse_ping(result)
virl2_client.utils.parse_with_textfsm_template(template, cli_result)
virl2_client.utils.splice_interface_ip_into_config(config, remote, ip_address, netmask)

ClientLibrary

exception virl2_client.virl2_client.InitializationError

Bases: Exception

class virl2_client.virl2_client.ClientLibrary(url=None, username=None, password=None, ssl_verify=True, raise_for_auth_failure=False, allow_http=False)

Bases: object

Initializes a ClientLibrary instance. Note that ssl_verify can also be a string that points to a cert (see class documentation).

Parameters:
  • url (str) – URL of controller. It’s also possible to pass the URL via the VIRL2_URL environment variable. If no protocol scheme is provided, “https:” is used.

  • username (str) – Username of the user to authenticate

  • password (str) – Password of the user to authenticate

  • ssl_verify (bool) – SSL controller certificate verification

  • raise_for_auth_failure (bool) – Raise an exception if unable to connect to server (use for scripting scenarios)

  • allow_http (bool) – If set, a https URL will not be enforced

Raises:

InitializationError – If no URL is provided or authentication fails or host can’t be reasched

__init__(url=None, username=None, password=None, ssl_verify=True, raise_for_auth_failure=False, allow_http=False)

Constructor method

all_labs(show_all=False)

Retrieves a list of all defined labs.

Parameters:

show_all (bool) – Whether to get only labs owned by the admin or all user labs

Returns:

A list of lab objects

Return type:

list[models.Lab]

check_controller_version(controller_version=None)

Checks remote controller version against current client version (specified in self.VERSION) and against controller version blacklist (specified in self.INCOMPATIBLE_CONTROLLER_VERSIONST) and raises exception if version are incompatible or prints warning if version are not in exact match.

Return type:

None

create_lab(title=None)

Creates an empty lab with the given name. If no name is given, then the created lab ID is set as the name.

Note that the lab will be auto-syncing according to the Client Librarie’s auto-sync setting when created. The lab has a property to override this on a per-lab basis.

Example:

lab = client_library.create_lab()
print(lab.id)
lab.create_node("r1", "iosv", 50, 100)
Parameters:

title (str) – The Lab name (or title)

Returns:

A Lab instance

Return type:

models.Lab

find_labs_by_title(title)

Return a list of labs which match the given title

Parameters:

title (str) – The title to search for

Returns:

A list of lab objects which match the title specified

Return type:

list[models.Lab]

get_diagnostics()

Returns the controller diagnostic data as JSON

Returns:

diagnostic data

Return type:

str

get_host()

Returns the hostname of the session to the controller.

Returns:

A hostname

Return type:

str

get_lab_list(show_all=False)

Returns list of all lab IDs.

Parameters:

show_all (bool) – Whether to get only labs owned by the admin or all user labs

Returns:

a list of Lab IDs

Return type:

list[str]

get_local_lab(lab_id)
import_lab(topology, title, offline=False)

Imports an existing topology from a string.

Parameters:
  • topology (str) – Topology representation as a string

  • title (str) – Title of the lab

  • offline (bool) – whether the ClientLibrary should import the lab locally. The topology parameter has to be a JSON string in this case. This can not be XML or YAML representation of the lab. Compatible JSON from GET /labs/{lab_id}/topology.

Returns:

A Lab instance

Return type:

models.Lab

Raises:
  • ValueError – if there’s no lab ID in the API response

  • requests.exceptions.HTTPError – if there was a transport error

import_lab_from_path(topology, title=None)

Imports an existing topology from a file / path.

Parameters:
  • topology (str) – Topology filename / path

  • title (str) – Title of the lab

Returns:

A Lab instance

Return type:

models.Lab

import_sample_lab(title)

Imports a built-in sample lab (this will be going away in the future).

Parameters:

title (str) – Sample lab name with extension

Returns:

A Lab instance

Return type:

models.Lab

is_system_ready(wait=False, max_wait=60, sleep=5)

is_system_ready reports whether the system is ready or not.

Parameters:
  • wait (int) – if this is true, the call will block until it’s ready

  • max_wait – wait for a maximum of ‘max_wait’ seconds

  • sleep – wait for ‘sleep’ seconds between tries

Returns:

ready state

Return type:

bool

join_existing_lab(lab_id, sync_lab=True)

Creates a new ClientLibrary lab instance that is retrieved from the controller.

If sync_lab is set to true, then synchronize current lab by applying the changes that were done in UI or in another ClientLibrary session.

Join preexisting lab:

lab = client_library.join_existing_lab("2e6a18")
Parameters:
  • lab_id (str) – The lab ID to be removed.

  • sync_lab (bool) – Syncronize changes.

Returns:

A Lab instance

Return type:

models.Lab

local_labs()
remove_lab(lab_id)

Use carefully, it removes a given lab:

client_library.remove_lab("1f6cd7")
Parameters:

lab_id (str) – The lab ID to be removed.

system_info()

Get information about the system where the application runs. Can be called without authentication.

Returns:

system information json

Return type:

dict

wait_for_lld_connected()

Waits until the controller has a compute node connected. (Deprecated)

INCOMPATIBLE_CONTROLLER_VERSIONS = []
VERSION = 2.1.0
property session

Returns the used Requests session object

Returns:

The Requests session object

Return type:

Requests.Session

class virl2_client.virl2_client.Version(version_str)

Bases: object

__init__(version_str)
major_differs(other)
minor_differs(other)
minor_or_patch_differs(other)
patch_differs(other)
major
minor
patch
version_str