virl2_client package

Python bindings for the Cisco VIRL 2 Network Simulation Platform

This file is part of VIRL 2

Copyright 2020 Cisco Systems Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Submodules

virl2_client.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

virl2_client.utils

exception virl2_client.utils.TextFsmNotInstalled

Bases: Exception

class virl2_client.utils.TextFsmTemplateHelper

Bases: object

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)

virl2_client.virl2_client

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

all_labs()

Retrieves a list of all defined labs.

Returns

A list of lab objects

Return type

list[models.Lab]

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()

Returns list of all lab IDs.

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.

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

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.

property session

Returns the used Requests session object

Returns

The Requests session object

Return type

Requests.Session

wait_for_lld_connected()

Waits until the controller has a compute node connected.

exception virl2_client.virl2_client.InitializationError

Bases: Exception