gns3fy

Gns3Connector Objects

def __init__(self, url=None, user=None, cred=None, verify=False, api_version=2)

Connector to be use for interaction against GNS3 server controller API.

Attributes:

Returns:

Gns3Connector instance

Example:

>>> server = Gns3Connector(url="http://<address>:3080")
>>> print(server.get_version())
{'local': False, 'version': '2.2.0b4'}

Gns3Connector.__init__()

def __init__(self, url=None, user=None, cred=None, verify=False, api_version=2)

Gns3Connector.http_call()

def http_call(self, method, url, data=None, json_data=None, headers=None, verify=False, params=None)

Performs the HTTP operation actioned

Required Attributes:

Gns3Connector.get_version()

def get_version(self)

Returns the version information of GNS3 server

Gns3Connector.projects_summary()

def projects_summary(self, is_print=True)

Returns a summary of the projects in the server. If is_print is False, it will return a list of tuples like:

[(name, project_id, total_nodes, total_links, status) ...]

Gns3Connector.get_projects()

def get_projects(self)

Returns the list of the projects on the server

Gns3Connector.get_project()

def get_project(self, name=None, project_id=None)

Retrieves a project from either a name or ID

Required Attributes:

Gns3Connector.templates_summary()

def templates_summary(self, is_print=True)

Returns a summary of the templates in the server. If is_print is False, it will return a list of tuples like:

[(name, template_id, template_type, builtin, console_type, category) ...]

Gns3Connector.get_templates()

def get_templates(self)

Returns the templates defined on the server.

Gns3Connector.get_template()

def get_template(self, name=None, template_id=None)

Retrieves a template from either a name or ID

Required Attributes:

Gns3Connector.update_template()

def update_template(self, name=None, template_id=None, kwargs)

Updates a template by giving its name or UUID. For more information [API INFO] (http://api.gns3.net/en/2.2/api/v2/controller/template/ templatestemplateid.html#put-v2-templates-template-id)

Required Attributes:

Gns3Connector.create_template()

def create_template(self, kwargs)

Creates a template by giving its attributes. For more information [API INFO] (http://api.gns3.net/en/2.2/api/v2/controller/template/ templates.html#post-v2-templates)

Required Attributes:

Gns3Connector.delete_template()

def delete_template(self, name=None, template_id=None)

Deletes a template by giving its attributes. For more information [API INFO] (http://api.gns3.net/en/2.2/api/v2/controller/template/ templatestemplateid.html#id16)

Required Attributes:

Gns3Connector.get_nodes()

def get_nodes(self, project_id)

Retieves the nodes defined on the project

Required Attributes:

Gns3Connector.get_node()

def get_node(self, project_id, node_id)

Returns the node by locating its ID.

Required Attributes:

def get_links(self, project_id)

Retrieves the links defined in the project.

Required Attributes:

def get_link(self, project_id, link_id)

Returns the link by locating its ID.

Required Attributes:

Gns3Connector.create_project()

def create_project(self, kwargs)

Pass a dictionary type object with the project parameters to be created.

Required Attributes:

Returns

JSON project information

Gns3Connector.delete_project()

def delete_project(self, project_id)

Deletes a project from server.

Required Attributes:

Gns3Connector.get_computes()

def get_computes(self)

Returns a list of computes.

Returns:

List of dictionaries of the computes attributes like cpu/memory usage

Gns3Connector.get_compute()

def get_compute(self, compute_id="local")

Returns a compute.

Returns:

Dictionary of the compute attributes like cpu/memory usage

Gns3Connector.get_compute_images()

def get_compute_images(self, emulator, compute_id="local")

Returns a list of images available for a compute.

Required Attributes:

Returns:

List of dictionaries with images available for the compute for the specified emulator

Gns3Connector.get_compute_ports()

def get_compute_ports(self, compute_id="local")

Returns ports used and configured by a compute.

Required Attributes:

Returns:

Dictionary of console_ports used and range, as well as the udp_ports

GNS3 Link API object. For more information visit: Links Endpoint API information

Attributes:

Returns:

Link instance

Example:

>>> link = Link(project_id=<pr_id>, link_id=<link_id> connector=<Gns3Connector
instance>)
>>> link.get()
>>> print(link.link_type)
'ethernet'

Link.get()

def get(self)

Retrieves the information from the link endpoint.

Required Attributes:

Link.delete()

def delete(self)

Deletes a link endpoint from the project. It sets to None the attributes link_id when executed sucessfully

Required Attributes:

Link.create()

def create(self)

Creates a link endpoint

Required Attributes:

Node Objects

GNS3 Node API object. For more information visit: Node Endpoint API information

Attributes:

Returns:

Node instance

Example:

>>> alpine = Node(name="alpine1", node_type="docker", template="alpine",
project_id=<pr_id>, connector=<Gns3Connector instance>)
>>> alpine.create()
>>> print(alpine.node_id)
'SOME-UUID-GENERATED'

Node.get()

def get(self, get_links=True)

Retrieves the node information. When get_links is True it also retrieves the links respective to the node.

Required Attributes:

def get_links(self)

Retrieves the links of the respective node. They will be saved at the links attribute

Required Attributes:

Node.start()

def start(self)

Starts the node.

Required Attributes:

Node.stop()

def stop(self)

Stops the node.

Required Attributes:

Node.reload()

def reload(self)

Reloads the node.

Required Attributes:

Node.suspend()

def suspend(self)

Suspends the node.

Required Attributes:

Node.update()

def update(self, kwargs)

Updates the node instance by passing the keyword arguments of the attributes you want updated

Example:

router01.update(name="router01-CSX")

This will update the project auto_close attribute to True

Required Attributes:

Node.create()

def create(self)

Creates a node.

By default it will fetch the nodes properties for creation based on the template or template_id attribute supplied. This can be overriden/updated by sending a dictionary of the properties under extra_properties.

Required Node instance attributes:

Node.delete()

def delete(self)

Deletes the node from the project. It sets to None the attributes node_id and name when executed successfully

Required Attributes:

Node.get_file()

def get_file(self, path)

Retrieve a file in the node directory.

Required Attributes:

Node.write_file()

def write_file(self, path, data)

Places a file content on a specified node file path. Used mainly for docker images.

Example to update an alpine docker network interfaces:

>>> data = '''
    auto eth0
    iface eth0 inet dhcp
    '''

>>> alpine_node.write_file(path='/etc/network/interfaces', data=data)

Required Attributes:

Project Objects

GNS3 Project API object. For more information visit: Project Endpoint API information

Attributes:

Returns:

Project instance

Example:

>>> lab = Project(name="lab", connector=<Gns3Connector instance>)
>>> lab.create()
>>> print(lab.status)
'opened'

Project.get()

def get(self, get_links=True, get_nodes=True, get_stats=True)

Retrieves the projects information.

Required Attributes:

Project.create()

def create(self)

Creates the project.

Required Attributes:

Project.update()

def update(self, kwargs)

Updates the project instance by passing the keyword arguments of the attributes you want updated

Example:

lab.update(auto_close=True)

This will update the project auto_close attribute to True

Required Attributes:

Project.delete()

def delete(self)

Deletes the project from the server. It sets to None the attributes project_id and name when executed successfully

Required Attributes:

Project.close()

def close(self)

Closes the project on the server.

Required Attributes:

Project.open()

def open(self)

Opens the project on the server.

Required Attributes:

Project.get_stats()

def get_stats(self)

Retrieve the stats of the project.

Required Attributes:

Project.get_file()

def get_file(self, path)

Retrieve a file in the project directory. Beware you have warranty to be able to access only to file global to the project.

Required Attributes:

Project.write_file()

def write_file(self, path, data)

Places a file content on a specified project file path. Beware you have warranty to be able to access only to file global to the project.

Example to create a README.txt for the project:

>>> data = '''
    This is a README description!
    '''

>>> project.write_file(path='README.txt', data=data)

Required Attributes:

Project.get_nodes()

def get_nodes(self)

Retrieve the nodes of the project.

Required Attributes:

def get_links(self)

Retrieve the links of the project.

Required Attributes:

Project.start_nodes()

def start_nodes(self, poll_wait_time=5)

Starts all the nodes inside the project.

Required Attributes:

Project.stop_nodes()

def stop_nodes(self, poll_wait_time=5)

Stops all the nodes inside the project.

Required Attributes:

Project.reload_nodes()

def reload_nodes(self, poll_wait_time=5)

Reloads all the nodes inside the project.

Required Attributes:

Project.suspend_nodes()

def suspend_nodes(self, poll_wait_time=5)

Suspends all the nodes inside the project.

Required Attributes:

Project.nodes_summary()

def nodes_summary(self, is_print=True)

Returns a summary of the nodes insode the project. If is_print is False, it will return a list of tuples like:

[(node_name, node_status, node_console, node_id) ...]

Required Attributes:

Project.nodes_inventory()

def nodes_inventory(self)

Returns an inventory-style dictionary of the nodes

Example:

{ "router01": { "server": "127.0.0.1", "name": "router01", "console_port": 5077, "type": "vEOS" } }

Required Attributes:

def links_summary(self, is_print=True)

Returns a summary of the links insode the project. If is_print is False, it will return a list of tuples like:

[(node_a, port_a, node_b, port_b) ...]

Required Attributes:

Project.get_node()

def get_node(self, name=None, node_id=None)

Returns the Node object by searching for the name or the node_id.

Required Attributes:

Required keyword arguments: - name or node_id

NOTE: Run method get_nodes() manually to refresh list of nodes if necessary

def get_link(self, link_id)

Returns the Link object by locating its ID

Required Attributes:

NOTE: Run method get_links() manually to refresh list of links if necessary

Project.create_node()

def create_node(self, kwargs)

Creates a node. To know available parameters see Node object, specifically the create method. The most basic example would be:

project.create_node(name='test-switch01', template='Ethernet switch')

Required Project instance attributes:

Required keyword aguments:

def create_link(self, node_a, port_a, node_b, port_b)

Creates a link.

Required Attributes:

Project.get_snapshots()

def get_snapshots(self)

Retrieves list of snapshots of the project

Required Project instance attributes:

Project.get_snapshot()

def get_snapshot(self, name=None, snapshot_id=None)

Returns the Snapshot by searching for the name or the snapshot_id.

Required Attributes:

Required keyword arguments: - name or snapshot_id

Project.create_snapshot()

def create_snapshot(self, name)

Creates a snapshot of the project

Required Project instance attributes:

Required keyword aguments:

Project.delete_snapshot()

def delete_snapshot(self, name=None, snapshot_id=None)

Deletes a snapshot of the project

Required Project instance attributes:

Required keyword aguments:

Project.restore_snapshot()

def restore_snapshot(self, name=None, snapshot_id=None)

Restore a snapshot from disk

Required Project instance attributes:

Required keyword aguments:

Project.arrange_nodes_circular()

def arrange_nodes_circular(self, radius=120)

Re-arrgange the existing nodes in a circular fashion

Attributes:

Example

>>> proj = Project(name='project_name', connector=Gns3connector)
>>> proj.arrange_nodes()

Project.get_drawings()

def get_drawings(self)

Retrieves list of drawings of the project

Required Project instance attributes: