Package: cohesivenet
Python Cohesive Networks SDKCohesive Networks SDK is Python tool providing access to the VNS3 and VNS3:ms APIs from applications written in Python. It also includes common pipelines and macro functions for building network topologies.API Versions supportedThe SDK will make best efforts to always be backwards compatible. All SDK releases will support VNS3 versions starting with VNS3 v4.8.4 and VNS3:ms starting with v2.1.1.cohesivenet==XVNS3 APIMS API0.4.1-1.x.x4.8.4-6.0.02.1.1-2.5.X0.4.04.8.4-5.0.02.1.1-2.3.50.3.X4.8.4-4.11.32.1.1-2.3.50.1.35-0.2.X4.8.4-4.10.12.1.1-2.3.50.1.344.8.4-4.10.1N/A0.1.334.8.4-4.9.2N/A0.1.324.8.4-4.9.1N/A0.1.0-314.8.4N/AViewVNS3 API specificationswith SDK examples.ViewVNS3:ms API specificationswith SDK examples.InstallationYou can PIP install withpipinstallcohesivenet(you may need to runpipwith root permission:sudo pip install cohesivenet)or Install viaSetuptools.pythonsetup.pyinstall--user(orsudo python setup.py installto install the package for all users)UsageConfiguring a Clientimportcohesivenetfrompprintimportpprintconfiguration=cohesivenet.Configuration(host='[vns3-host]:8000',username='api',password='YOUR_PASSWORD',verify_ssl=False)# Local cert is used by default. Can add your own cert.# Configure HTTP basic authorization: basicAuthconfiguration.username='api'configuration.password='YOUR_PASSWORD'configuration.host="[vns3-host]:8000"# Create an instance of the API classvns3_controller=cohesivenet.VNS3Client(configuration)try:api_response=vns3_controller.config.get_config()pprint(api_response)exceptcohesivenet.ApiExceptionase:print("Exception fetching VNS3 Configuration get_config():%s\n"%e)# ORfromcohesivenet.macrosimportconnectasvns3_connectvns3_host="55.55.55.55:8000"api_user="api"api_ps="test1234"vns3=vns3_connect.get_client(vns3_host,api_user,api_ps)config=vns3.config.get_config()print(config.response)Storing state VNS3 ClientSometimes its useful to be able to cache particular state on VNS3 client as it is passed through scripts. This can be used with theadd_to_statefunction on a VNS3Client:fromcohesivenet.macrosimportvns3_connectvns3=vns3_connect.get_vns3_client(host="10.10.10.10:8000",username="api",password="heresmypassword")peering_status_data=vns3.peering.get_peering_status()my_peer_id=peering_status_data.response.idvns3.add_to_state('peer_id',my_peer_id)# Later to retrievevns3.query_state('peer_id')# => my_peer_id# Viewing entire state:vns3.state# => dict# Update state with dict:my_state_updates={'peer_id':my_peer_id,'secondary_ip':my_secondary_ip}vns3.update_state(my_state_updates)MethodsEach sub-api is available from the VNS3Client instance as follows:# VNS3vns3_client.access# Manage access urls and api tokensvns3_client.bgp# BGPApi for Border Gateway Protocol methodsvns3_client.config# ConfigurationApi provides VNS3 config methodsvns3_client.firewall# FirewallApi for configuring VNS3 policiesvns3_client.ipsec# IPsecApi for IPsec tunnel methodsvns3_client.interfaces# InterfacesApi for viewing VNS3 interfacesvns3_client.monitoring# MonitoringAlertingApivns3_client.network_edge_plugins# NetworkEdgePluginsApivns3_client.overlay_network# OverlayNetworkApi for managing the overlay networkvns3_client.peering# PeeringApi for peering VNS3 controllersvns3_client.routing# RoutingApi for configuring routingvns3_client.snapshots# SnapshotsApi for managing backupsvns3_client.sys_admin# SystemAdministrationApi for access and sys admin tasksvns3_client.licensing# LicensingApi for controller licensing# VNS3:msms_client.access# Provision short-lived access URLs or API keys for any VNS3 controller in your topologyms_client.admin# Configure VNS3:ms administration settings such as LDAP integrationms_client.vns3_management# Manage VNS3 controllers in your network topology, automating snapshots, HA and morems_client.cloud_monitoring# Configure and monitor your cloud by tracking cloud VPCs, virtual networks and VNS3 topologiesms_client.system# System configuration such as SSL, NTP hosts and remote supportms_client.backups# Configure backups for VNS3:ms and your controller snapshotsms_client.user# User management endpoints for configuring credentialsCommon API patterns:cohesivenet.macrosMany API calls are called together to configure a topology or update a network configuration. More macros will be added to
increasingly simplify VNS3 topology creation and configuration. More documentation to come.macros.admin# Admin operations typically applied to multiple controllers at oncemacros.config# configuring multiple clientsmacros.connect# connecting to clientsmacros.firewall# firewall operations like idempotently creating full firewallmacros.ipsec# ipsec operations like creating a tunnel and then a routemacros.network_edge_plugins# Manage container system network, images and running containersmacros.overlay_network# overlay network functions like calculating network segments of the overlaymacros.peering# topology peering operations like creating a peering mesh between controllersmacros.routing# Operations for updating routing in your topologymacros.state# Methods for fetching the state of your controller(s)LoggingThe SDK can be configured to emit logs for better visibility into what it's doing. The SDK supports INFO, DEBUG, and ERROR logging.There are two ways to enable it:Set the environment variableCOHESIVE_LOG_LEVELto the valuedebug,infoorerror$exportCOHESIVE_LOG_LEVEL=debugEnable it through Python's logging module:importlogginglogging.basicConfig()logging.getLogger('cohesivenet').setLevel(logging.DEBUG)Authorsolutions@cohesive.net