内聚网络SDK
cohesivenet的Python项目详细描述
Python内聚网络SDK
内聚网络SDK是Python工具,提供从用Python编写的应用程序访问VNS3和VNS3:msapi。它还包括用于构建网络拓扑的通用管道和宏函数。在
支持的API版本
SDK将尽最大努力始终保持向后兼容。所有SDK版本都将支持从VNS3 v4.8.4开始的VNS3版本,以及从v2.1.1开始的VNS3:ms版本。在
cohesivenet==X | VNS3 API | MS API |
---|---|---|
0.3.X | 4.8.4-4.11.1 | 2.1.1-2.3.5 |
0.1.35-0.2.X | 4.8.4-4.10.1 | 2.1.1-2.3.5 |
0.1.34 | 4.8.4-4.10.1 | N/A |
0.1.33 | 4.8.4-4.9.2 | N/A |
0.1.32 | 4.8.4-4.9.1 | N/A |
0.1.0-31 | 4.8.4 | N/A |
- 使用SDK示例查看VNS3 API specifications。在
- 使用SDK示例查看VNS3:ms API specifications。在
安装
你可以用PIP安装
pip install cohesivenet
(您可能需要使用根权限运行pip
:sudo pip install cohesivenet
)
或通过Setuptools安装。在
^{pr2}$(或sudo python setup.py install
为所有用户安装软件包)
使用
配置客户端
importcohesivenetfrompprintimportpprintconfiguration=cohesivenet.Configuration(host='https://[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="https://[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)
方法
每个子api可从VNS3Client实例获得,如下所示:
# 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 credentials
常见API模式:cohesivenet.macros
许多API调用被一起调用以配置拓扑或更新网络配置。更多宏将添加到 越来越简化VNS3拓扑的创建和配置。更多的文档即将发布。在
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)
日志
可以将SDK配置为发出日志,以便更好地了解它在做什么。SDK支持信息、调试和错误日志记录。在
有两种方法可以启用它:
- 在
将环境变量
COHESIVE_LOG_LEVEL
设置为值debug
、info
或{} $ exportCOHESIVE_LOG_LEVEL=debug
在 - 在
通过Python的日志模块启用它:
importlogginglogging.basicConfig()logging.getLogger('cohesivenet').setLevel(logging.DEBUG)
在
作者
- 项目
标签: