is package to interact with GNS3.
This notebook shows examples of implemented functionality so far. Not exhaustive, work in progress etc etc.
In [1]:
# Minimal setup
from pygns3 import *
GNS3API.load_configuration()
# Main class
controller = GNS3Controller()
print(controller)
In [2]:
for compute in controller.computes:
print(f'{compute.name:{30}} ({compute.id})')
In [3]:
my_compute = GNS3Compute('local')
print(my_compute)
if my_compute.connected:
print(f"Available images for emulating on dynamips:")
for image in my_compute.images('dynamips'):
print(f" {image.filename}")
In [4]:
gns3vm = GNS3VM()
print(gns3vm)
for engine in gns3vm.engines:
for vm in engine.vms:
print(f'{engine.name:{15}} {vm}')
In [5]:
for project in controller.projects:
print(f'{project.name:{25}} {project.project_id}')
In [6]:
my_project = GNS3Project('5daa48ff-dbd6-407c-a3c6-645e743f233a')
print(my_project)
In [7]:
# Besides grabbing a project from the collection of Controller.projects it is also possible to instantiate by name
my_project = GNS3Project.from_name('Basic 4 Routers')
print(my_project)
In [8]:
# You can start, suspend and stop all nodes with a simple method.
# If the project is visible in the GUI you can confirm (Whoo blinky lights!)
my_project.start_all_nodes()
my_project.suspend_all_nodes()
my_project.stop_all_nodes()
In [9]:
# Drawings, links, nodes, and snapshots are listed by their number but internally consist of a list of objects
# Let's look at a node's settings
my_node = my_project.nodes[0]
print(my_node)
In [10]:
# There are also properties defined on a node
print(my_node.properties)
In [11]:
# Similarly the ports of a node are internally represented as a list of GNS3NodePort objects
print(my_node.ports[0])
In [12]:
# Links between nodes can currently only be displayed (later also created / deleted / captured)
print(my_project.links[0])
In [13]:
# Some pretty printing can be done like this
for link in my_project.links:
print(f'{link.from_node.name} on port {link.from_port_name} is connected over {link.link_type} '
f'to {link.to_node.name} on port {link.to_port_name}')
In [14]:
# Available snapshots can be viewed (and soon also created and deleted)
print(my_project.snapshots[0])
In [15]:
# Drawing objects can be inspected
my_drawing = my_project.drawings[0]
print(my_drawing)
In [16]:
# In theory this should work, not sure what's going wrong here. SVG from URL renders fine. #CheckLater
from IPython.display import SVG, display
display(SVG(data=my_drawing.svg))
# Would have been nice but isn't a priority