{ "info": { "author": "David Flores", "author_email": "davidflores7_8@hotmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# NetAPI\n\nNetwork API library that perform the core of the work -> requests execution and data parsing.\n\nIt relies on the main vendor libraries to perform its work and its main objective to grant network objects that can be used with your applications.\n\n## Installation\n\nYou can directly install it using pip\n\n```\npip install netapi\n```\n\n### Development Version\n\nYou will need [poetry](https://github.com/sdispater/poetry) for clonning and installing the repo\n\n## How it works\n\nIs a library that abstracts the connection and parsing method of the data collected on the target device. It then presents a developer-friendly object that you can use to interact with.\n\nAll the objects are created with some cool features for manipulating their attributes and creating your applications on top of it. An example is the `IPNetwork` object returned of the ipv4 address of an interface. You will see that later.\n\nThe library is divided in 3 main types of objects:\n\n- **Device**: These are connector objects used fot the `net` and `probes` objects. Needed for the execution and data collection.\n- **Net**: These are network _entities_, which basically means technologies or parts of the network protocols like interface, vlan, vrrp, bgp, etc...\n- **Probes**: These are tester objects to run in your `device` objects. For example `ping` or `trace`.\n\nThere is also a `Metadata` object that collects information about the implementation, how many times the object has been executed and timestamp. Useful for reports and other tests.\n\n### Network Entities example\n\nHere is an example of how to use the library when using a network entity. In this case `Interface`:\n\n```python\n# Use Arista pyeapi client for connection\nfrom netapi.connector.pyeapier import Device\nfrom netapi.net.pyeapier import Interface\n\nfrom pprint import pprint\n\n# Create a device connection object using its api https interface\nrouter01 = Device(\n host=\"192.168.0.77\",\n username=\"someuser\",\n password=\"somepassword\",\n transport=\"https\"\n)\n```\n\nShow device connection attributes, notice that secrets are hidden\n```python\nprint(router01)\n\nDevice(host='192.168.0.77', username='someuser', port=None, net_os='eos', transport='https')\n```\n\nYou can see the metadata for this instance and get information like timestamp, type of implementation, id of the instance, among other things:\n```python\nprint(router01.metadata)\n\nMetadata(name='device', type='entity', implementation='EOS-PYEAPI', created_at=DateTime(2019, 5, 14, 16, 47, 35, 319134), id=UUID('51d317ab-584d-4f32-a789-402770c361f2'), updated_at=None, collection_count=0, parent=None)\n```\n\nYou can run a command/action and retrieve its output. The format would depend mostly of the device, net_os, implementation (like EOS-PYEAPI or raw SSH for example) and the type of command.\n```python\n>>> pprint(router01.run('show version'))\n\n{'show version': {'architecture': 'i386',\n 'bootupTimestamp': 1557851831.0,\n 'hardwareRevision': '',\n 'internalBuildId': '1a44ce37-92c4-48b6-b922-38b7eed939b6',\n 'internalVersion': '4.21.5F-11604264.4215F',\n 'isIntlVersion': False,\n 'memFree': 1372616,\n 'memTotal': 2015608,\n 'mfgName': '',\n 'modelName': 'vEOS',\n 'serialNumber': '',\n 'systemMacAddress': '0c:59:30:85:d7:1d',\n 'uptime': 1158.4,\n 'version': '4.21.5F'}}\n```\nThis library provides common handlers, for well known network technologies. Here is an example for the Management 1 interface. Notice that I pass the device connector object:\n```python\n>>> mgmt1 = Interface(name=\"Management1\", connector=router01)\n\n# You can collect its attributes by running the get() method\n>>> mgmt1.get()\n```\n\nYou can see its attributes. Since it is an interface I will only show some key ones\n```python\nprint(mgmt1)\n\nInterface(name='Management1',\n description='Some description',\n enabled=True,\n instance='MANAGEMENT',\n members=None,\n status_up=True,\n status='connected',\n last_status_change=DateTime(2019, 5, 9, 11, 40, 38, 144796, tzinfo=Timezone('Europe/Dublin')),\n number_status_changes=4,\n last_clear=DateTime(2019, 5, 9, 11, 34, 32, 150340, tzinfo=Timezone('Europe/Dublin')),\n update_interval=5.0,\n forwarding_model='routed',\n physical=InterfacePhysical(mtu=Byte(1500.0),\n bandwidth=Bit(1000000000.0),\n duplex='duplexFull',\n mac=EUI('28-99-3A-F8-5D-E7')),\n optical=InterfaceOptical(tx=-2.5,\n rx=-5.4,\n status=\"green\",\n serial_number=\"XXXYYYZZZ\",\n media_type=\"10GBASE-SR\"),\n addresses=InterfaceIP(ipv4=IPNetwork('10.193.0.177/24'),\n ipv6=None,\n secondary_ipv4=[],\n dhcp=None))\n```\n\nNOTE: The `counters` attribute is not refelcted by default. You can access it directly with `.counters`\n\nThere are multiple parameters here but and I ommitted othere but you can see that IP addresses are netaddr IPNetwork object and similarly the MAC addresses are EUI objects. Also the counter_refresh interval are datetime objects.\n\nThese instances also have metadata\n```python\n>>> print(mgmt1.metadata)\n\nMetadata(name='interface', type='entity', implementation='EOS-PYEAPI', created_at=DateTime(2019, 5, 14, 16, 43, 44, 819105), id=UUID('73297adf-a0d6-4f8d-b247-0d793e577efb'), updated_at=DateTime(2019, 5, 14, 16, 43, 54, 483277), collection_count=1, parent=None)\n```\n\nYou can see that in the metadata the updated_at field is populated? This happened because we invoked the get() method to collect the data. Now let's change the interface description and refresh the interface data (this is done outside of the script)\n\nAssuming a change to the description was done, now retrieve again the data\n```python\n>>> print(mgmt01.description)\n\nDUMMY DESCRIPTION\n```\n\nYou can see that the description changes but also the metadata has been updated!\n```python\n>>> print(mgmt01.metadata)\n\nMetadata(name='interface', type='entity', implementation='EOS-PYEAPI', created_at=DateTime(2019, 5, 14, 16, 43, 44, 819105), id=UUID('73297adf-a0d6-4f8d-b247-0d793e577efb'), updated_at=DateTime(2019, 5, 14, 17, 20, 27, 557810), collection_count=2, parent=None)\n```\nYou can see updated_at has been updated :) and the collection_count has increased to 2\n\n### Network Probes example\n\nThis is a simple example running a Ping against an specific IP address and applying a custom analysis to the result.\n\nFirst initiate the device object and specify a target\n```python\n>>> from netapi.connector.linux.subprocesser import Device\n>>> from netapi.probe.linux.subprocesser import Ping\n\n>>> host = Device()\n>>> ping = Ping(target=\"1.1.1.1\", connector=host)\n```\n\nYou can see the `Ping` object with the following attributes:\n```python\n>>> print(ping)\n\nPing(target='1.1.1.1',target_ip=None, target_name=None, resolve_target=False, source=None, source_ip=None, instance=None, count=5, timeout=2, size=692, df_bit=False, interval=1.0, ttl=None, result=None)\n```\nYou can see that `result` attribute is empty, we need to tell to execute the `Ping` and we can apply our own logic to it.\n\nThe ping object is to be executed on my machine, you can see the command used on `ping_cmd`:\n```python\n>>> ping.generate_ping_cmd()\n>>> print(ping.ping_cmd)\n\n'ping 1.1.1.1 -s 692 -c 5 -W 2 -i 1.0'\n```\n\nIf we execute it as es we can get a result like\n```python\n>>> ping.execute()\nTrue\n\n>>> print(ping)\nPing(target='1.1.1.1',\n target_ip=None,\n target_name=None,\n resolve_target=False,\n source=None,\n source_ip=None,\n instance=None,\n count=5,\n timeout=2,\n size=692,\n df_bit=False,\n interval=1.0,\n ttl=None,\n result=PingResult(\n probes_sent=5,\n probes_received=5,\n packet_loss=0.0,\n rtt_min=25.303,\n rtt_avg=30.289,\n rtt_max=43.923,\n warning_thld=None,\n critical_thld=None,\n status='ok',\n status_up=True,\n status_code=0,\n apply_analysis=True\n )\n)\n```\n\nWe can use our own threshold in execution to manipulate the `flag` and `status_up` parameters.\n\n```python\n>>> ping.execute(critical_thld=-1)\nTrue\n\n>>> ping.result\n\nPingResult(probes_sent=5,\n probes_received=5,\n packet_loss=0.0,\n rtt_min=19.241,\n rtt_avg=23.471,\n rtt_max=26.184,\n warning_thld=None,\n critical_thld=-1,\n status='critical',\n status_up=False,\n status_code=2,\n apply_analysis=True)\n\n# If you want to have a dict\n>>> ping.to_dict()\n\n{'count': 5,\n 'df_bit': False,\n 'instance': None,\n 'interval': 1.0,\n 'metadata': {'collection_count': 4,\n 'created_at': '2019-07-05T18:19:30.075757+01:00',\n 'id': '03d55fdf-2e0d-4a66-9f18-ef33a811bc2e',\n 'implementation': 'LINUX-SUBPROCESS',\n 'name': 'ping',\n 'parent': None,\n 'type': 'entity',\n 'updated_at': '2019-07-05T18:32:32.840095+01:00'},\n 'resolve_target': False,\n 'result': {'apply_analysis': True,\n 'critical_thld': -1,\n 'packet_loss': 0.0,\n 'probes_received': 5,\n 'probes_sent': 5,\n 'rtt_avg': 23.732,\n 'rtt_max': 27.673,\n 'rtt_min': 19.733,\n 'status': 'critical',\n 'status_code': 2,\n 'status_up': False,\n 'warning_thld': None},\n 'size': 692,\n 'source': None,\n 'source_ip': None,\n 'target': '1.1.1.1',\n 'target_ip': None,\n 'target_name': None,\n 'timeout': 2,\n 'ttl': None}\n```\nYou can see that is `status_up = False` even though all the probes were received successfully. Usefull for custom testing.\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/the-networkers/netaudithor/netapi", "keywords": "network,library", "license": "MIT", "maintainer": "David Flores", "maintainer_email": "davidflores7_8@hotmail.com", "name": "netapi", "package_url": "https://pypi.org/project/netapi/", "platform": "", "project_url": "https://pypi.org/project/netapi/", "project_urls": { "Homepage": "https://gitlab.com/the-networkers/netaudithor/netapi", "Repository": "https://gitlab.com/the-networkers/netaudithor/netapi" }, "release_url": "https://pypi.org/project/netapi/0.2.1/", "requires_dist": [ "pyeapi (>=0.8.2,<0.9.0)", "netaddr (>=0.7.19,<0.8.0)", "pyyaml (>=5.1,<6.0)", "pydantic (>=0.26.0,<0.27.0)", "pendulum (>=2.0,<3.0)", "bitmath (>=1.3,<2.0)" ], "requires_python": ">=3.7,<4.0", "summary": "Network API library. A programmatic interface to network devices", "version": "0.2.1" }, "last_serial": 5492481, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "91861b23450cfbf0192573f2a88ee5d3", "sha256": "6faa82e0c794476bf5c8ad1de746f6a47daabb5601412d1fff331767e1d8afaf" }, "downloads": -1, "filename": "netapi-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "91861b23450cfbf0192573f2a88ee5d3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 36349, "upload_time": "2019-05-16T09:03:36", "url": "https://files.pythonhosted.org/packages/6b/12/0d2fceaa0d25d4bfb1f0917a9b65389078283dacfd471cc74d6bb0dd81c6/netapi-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "164997d9fd7b2a493f187bab18d1a0e4", "sha256": "5292e9b7359e1c4046253b72b34e743452d96ad077c7f6c78152caac0cde77a3" }, "downloads": -1, "filename": "netapi-0.1.0.tar.gz", "has_sig": false, "md5_digest": "164997d9fd7b2a493f187bab18d1a0e4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 25515, "upload_time": "2019-05-16T09:03:39", "url": "https://files.pythonhosted.org/packages/39/08/01089d6ef83700fee5d209078c2f6f396a6f1311041981210a222da2c145/netapi-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "130a3e588640ee2d36fe7945a1fe8d0a", "sha256": "24d89a856c6ac82e4649103df760a5576777182b31062c501803275d44c8763a" }, "downloads": -1, "filename": "netapi-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "130a3e588640ee2d36fe7945a1fe8d0a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 38058, "upload_time": "2019-05-22T12:22:47", "url": "https://files.pythonhosted.org/packages/32/0c/83b30a3d305055a068aca6df05c4659ce903fc1ab396b97f2eb934459987/netapi-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e2416ba7d02ffb412b1e9dfe381a861", "sha256": "3fd6d39181317548e1406afa95e3a5df9e17c0d3986e2d650bed061fab25a83d" }, "downloads": -1, "filename": "netapi-0.1.1.tar.gz", "has_sig": false, "md5_digest": "7e2416ba7d02ffb412b1e9dfe381a861", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 28324, "upload_time": "2019-05-22T12:22:49", "url": "https://files.pythonhosted.org/packages/9f/67/5c2e1eccf2a164d53878ee289bd8d721931a4e4d45cbbe4436585ee37795/netapi-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "0306f90a30eb304217f326f41a385ff9", "sha256": "62080e318693008a7871c49ca00787ba29145348ffbdb4a17171c55862e503a8" }, "downloads": -1, "filename": "netapi-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "0306f90a30eb304217f326f41a385ff9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 38017, "upload_time": "2019-05-29T18:11:54", "url": "https://files.pythonhosted.org/packages/ab/a2/927f59d86253ea7c02e045584005d6a647a98c65b8d14bb063fd3719be97/netapi-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5a3d19e3088f08e9373ac83694bf5346", "sha256": "6261e66b328f481d8b0028ab79a35ede87d2b6d0bc684894be13301a1fd37993" }, "downloads": -1, "filename": "netapi-0.1.2.tar.gz", "has_sig": false, "md5_digest": "5a3d19e3088f08e9373ac83694bf5346", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 28269, "upload_time": "2019-05-29T18:11:55", "url": "https://files.pythonhosted.org/packages/cd/16/845c0fba84e553001656ec7be0086f302c8890e3e9c02dde9052a1e73787/netapi-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "30e977a3c3f77d3dccf91a92e863443a", "sha256": "7370ba6ebf4c935cda98f06ced1b5a01a88a81469a9d852e2b9dc595054fd590" }, "downloads": -1, "filename": "netapi-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "30e977a3c3f77d3dccf91a92e863443a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 53131, "upload_time": "2019-07-05T17:17:31", "url": "https://files.pythonhosted.org/packages/21/80/35c3f005a24efb9a6eabf03444386f692493a0d215c4ed2a3d8d91b719ff/netapi-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6b70dc7142c425e776da9cbede08a54f", "sha256": "890025e84564f027ba5109a2746f274591d0d04e81cc927a558165ec6075d467" }, "downloads": -1, "filename": "netapi-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6b70dc7142c425e776da9cbede08a54f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 35886, "upload_time": "2019-07-05T17:17:33", "url": "https://files.pythonhosted.org/packages/81/4f/167c4225e9c6b7e054ac526dae49f8fef75938f38624c120bb9b550d15c2/netapi-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "95fee004693b883f4e63ad10e56a9b54", "sha256": "685df636ed476d3e0b7d0dfd09bcbccec06e2ae341a249cef5a4d1fbee7d8183" }, "downloads": -1, "filename": "netapi-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "95fee004693b883f4e63ad10e56a9b54", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 53578, "upload_time": "2019-07-05T17:36:48", "url": "https://files.pythonhosted.org/packages/a1/8c/a57164d980473ffffec61cc9ce660f16c6f96cce1f8fe4ab808739736cfd/netapi-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7c614f74a855dc065a5aae320f190dd9", "sha256": "18e5f6ed54c19e5f671c7a3caced428fe3c9e7c68fd32094fb2d374e11823a72" }, "downloads": -1, "filename": "netapi-0.2.1.tar.gz", "has_sig": false, "md5_digest": "7c614f74a855dc065a5aae320f190dd9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 37074, "upload_time": "2019-07-05T17:36:51", "url": "https://files.pythonhosted.org/packages/1c/62/dd714c96c7179923165002d29f1a515b093a7cc8547b5963af95f7f21b51/netapi-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "95fee004693b883f4e63ad10e56a9b54", "sha256": "685df636ed476d3e0b7d0dfd09bcbccec06e2ae341a249cef5a4d1fbee7d8183" }, "downloads": -1, "filename": "netapi-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "95fee004693b883f4e63ad10e56a9b54", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 53578, "upload_time": "2019-07-05T17:36:48", "url": "https://files.pythonhosted.org/packages/a1/8c/a57164d980473ffffec61cc9ce660f16c6f96cce1f8fe4ab808739736cfd/netapi-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7c614f74a855dc065a5aae320f190dd9", "sha256": "18e5f6ed54c19e5f671c7a3caced428fe3c9e7c68fd32094fb2d374e11823a72" }, "downloads": -1, "filename": "netapi-0.2.1.tar.gz", "has_sig": false, "md5_digest": "7c614f74a855dc065a5aae320f190dd9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 37074, "upload_time": "2019-07-05T17:36:51", "url": "https://files.pythonhosted.org/packages/1c/62/dd714c96c7179923165002d29f1a515b093a7cc8547b5963af95f7f21b51/netapi-0.2.1.tar.gz" } ] }