|
| 1 | + |
| 2 | +Palo Alto Networks PAN-OS SDK for Python |
| 3 | +======================================== |
| 4 | + |
| 5 | +The PAN-OS SDK for Python (pan-os-python) is a package to help interact with |
| 6 | +Palo Alto Networks devices (including physical and virtualized Next-generation |
| 7 | +Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics |
| 8 | +the traditional interaction with the device via the GUI or CLI/API. |
| 9 | + |
| 10 | + |
| 11 | +* Documentation: http://pan-os-python.readthedocs.io |
| 12 | + |
| 13 | +---- |
| 14 | + |
| 15 | + |
| 16 | +.. image:: https://img.shields.io/pypi/v/pan-os-python.svg |
| 17 | + :target: https://pypi.python.org/pypi/pan-os-python |
| 18 | + :alt: Latest version released on PyPi |
| 19 | + |
| 20 | + |
| 21 | +.. image:: https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7%20%7C%203.8-blueviolet |
| 22 | + :target: https://pypi.python.org/pypi/pan-os-python |
| 23 | + :alt: Python versions |
| 24 | + |
| 25 | + |
| 26 | +.. image:: https://img.shields.io/pypi/l/pan-os-python |
| 27 | + :target: https://github.com/PaloAltoNetworks/pan-os-python/blob/develop/LICENSE |
| 28 | + :alt: License |
| 29 | + |
| 30 | + |
| 31 | +.. image:: https://img.shields.io/badge/docs-latest-brightgreen.svg |
| 32 | + :target: http://pan-os-python.readthedocs.io/en/latest/?badge=latest |
| 33 | + :alt: Documentation Status |
| 34 | + |
| 35 | + |
| 36 | +.. image:: https://img.shields.io/badge/chat%20on-GitHub%20Discussions-brightgreen |
| 37 | + :target: https://github.com/PaloAltoNetworks/pan-os-python/discussions |
| 38 | + :alt: Chat on GitHub Discussions |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +.. image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg |
| 43 | + :target: https://github.com/semantic-release/semantic-release |
| 44 | + :alt: semantic-release |
| 45 | + |
| 46 | + |
| 47 | +.. image:: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg |
| 48 | + :target: https://conventionalcommits.org/ |
| 49 | + :alt: Conventional Commits |
| 50 | + |
| 51 | + |
| 52 | +.. image:: https://img.shields.io/badge/Powered%20by-DepHell-red |
| 53 | + :target: https://github.com/dephell/dephell |
| 54 | + :alt: Powered by DepHell |
| 55 | + |
| 56 | + |
| 57 | +.. image:: https://img.shields.io/github/contributors/PaloAltoNetworks/pan-os-python |
| 58 | + :target: https://github.com/PaloAltoNetworks/pan-os-python/graphs/contributors/ |
| 59 | + :alt: GitHub contributors |
| 60 | + |
| 61 | + |
| 62 | +---- |
| 63 | + |
| 64 | +Features |
| 65 | +-------- |
| 66 | + |
| 67 | + |
| 68 | +* Object model of Firewall and Panorama configuration |
| 69 | +* Multiple connection methods including Panorama as a proxy |
| 70 | +* All operations natively vsys-aware |
| 71 | +* Support for high availability pairs and retry/recovery during node failure |
| 72 | +* Batch User-ID operations |
| 73 | +* Device API exception classification |
| 74 | + |
| 75 | +Status |
| 76 | +------ |
| 77 | + |
| 78 | +Palo Alto Networks PAN-OS SDK for Python is considered stable. It is fully tested |
| 79 | +and used in many production environments. Semantic versioning is applied to indicate |
| 80 | +bug fixes, new features, and breaking changes in each version. |
| 81 | + |
| 82 | +Install |
| 83 | +------- |
| 84 | + |
| 85 | +Install using pip: |
| 86 | + |
| 87 | +.. code-block:: shell |
| 88 | +
|
| 89 | + pip install pan-os-python |
| 90 | +
|
| 91 | +Upgrade to the latest version: |
| 92 | + |
| 93 | +.. code-block:: shell |
| 94 | +
|
| 95 | + pip install --upgrade pan-os-python |
| 96 | +
|
| 97 | +If you have poetry installed, you can also add pan-os-python to your project: |
| 98 | + |
| 99 | +.. code-block:: shell |
| 100 | +
|
| 101 | + poetry add pan-os-python |
| 102 | +
|
| 103 | +How to import |
| 104 | +------------- |
| 105 | + |
| 106 | +To use pan-os-python in a project: |
| 107 | + |
| 108 | +.. code-block:: python |
| 109 | +
|
| 110 | + import panos |
| 111 | +
|
| 112 | +You can also be more specific about which modules you want to import: |
| 113 | + |
| 114 | +.. code-block:: python |
| 115 | +
|
| 116 | + from panos import firewall |
| 117 | + from panos import network |
| 118 | +
|
| 119 | +A few examples |
| 120 | +-------------- |
| 121 | + |
| 122 | +For configuration tasks, create a tree structure using the classes in |
| 123 | +each module. Nodes hierarchy must follow the model in the |
| 124 | +`Configuration Tree <http://pan-os-python.readthedocs.io/en/latest/configtree.html>`_. |
| 125 | + |
| 126 | +The following examples assume the modules were imported as such: |
| 127 | + |
| 128 | +.. code-block:: python |
| 129 | +
|
| 130 | + from panos import firewall |
| 131 | + from panos import network |
| 132 | +
|
| 133 | +Create an interface and commit: |
| 134 | + |
| 135 | +.. code-block:: python |
| 136 | +
|
| 137 | + fw = firewall.Firewall("10.0.0.1", api_username="admin", api_password="admin") |
| 138 | + eth1 = network.EthernetInterface("ethernet1/1", mode="layer3") |
| 139 | + fw.add(eth1) |
| 140 | + eth1.create() |
| 141 | + fw.commit() |
| 142 | +
|
| 143 | +Operational commands leverage the 'op' method of the device: |
| 144 | + |
| 145 | +.. code-block:: python |
| 146 | +
|
| 147 | + fw = firewall.Firewall("10.0.0.1", api_username="admin", api_password="admin") |
| 148 | + print fw.op("show system info") |
| 149 | +
|
| 150 | +Some operational commands have methods to refresh the variables in an object: |
| 151 | + |
| 152 | +.. code-block:: python |
| 153 | +
|
| 154 | + # populates the version, serial, and model variables from the live device |
| 155 | + fw.refresh_system_info() |
| 156 | +
|
| 157 | +See more examples in the `Usage Guide <http://pan-os-python.readthedocs.io/en/latest/usage.html>`_. |
| 158 | + |
| 159 | +Upgrade from pandevice |
| 160 | +---------------------- |
| 161 | + |
| 162 | +This ``pan-os-python`` package is the evolution of the older ``pandevice`` package. To |
| 163 | +upgrade from ``pandevice`` to ``pan-os-python``\ , follow these steps. |
| 164 | + |
| 165 | +Step 1. Ensure you are using python3 |
| 166 | + |
| 167 | + `Python2 is end-of-life <https://www.python.org/doc/sunset-python-2/>`_ and not |
| 168 | + supported by ``pan-os-python``. |
| 169 | + |
| 170 | +Step 2. Uninstall pandevice: |
| 171 | + |
| 172 | +.. code-block:: shell |
| 173 | +
|
| 174 | + pip uninstall pandevice |
| 175 | + # or |
| 176 | + poetry remove pandevice |
| 177 | +
|
| 178 | +Step 3. Install pan-os-python: |
| 179 | + |
| 180 | +.. code-block:: shell |
| 181 | +
|
| 182 | + pip3 install pan-os-python |
| 183 | + # or |
| 184 | + poetry add pan-os-python |
| 185 | +
|
| 186 | +Step 4. Change the import statements in your code from ``pandevice`` to ``panos``. For example: |
| 187 | + |
| 188 | +.. code-block:: python |
| 189 | +
|
| 190 | + import pandevice |
| 191 | + from pandevice.firewall import Firewall |
| 192 | +
|
| 193 | + # would change to |
| 194 | +
|
| 195 | + import panos |
| 196 | + from panos.firewall import Firewall |
| 197 | +
|
| 198 | +Step 5. Test your script or application |
| 199 | + |
| 200 | + There are no known breaking changes |
| 201 | + between ``pandevice v0.14.0`` and ``pan-os-python v1.0.0``\ , but it is a major |
| 202 | + upgrade so please verify everything works as expected. |
| 203 | + |
| 204 | +Contributors |
| 205 | +------------ |
| 206 | + |
| 207 | + |
| 208 | +* Brian Torres-Gil - `btorresgil <https://github.com/btorresgil>`_ |
| 209 | +* Garfield Freeman - `shinmog <https://github.com/shinmog>`_ |
| 210 | +* John Anderson - `lampwins <https://github.com/lampwins>`_ |
| 211 | +* Aditya Sripal - `AdityaSripal <https://github.com/AdityaSripal>`_ |
| 212 | + |
| 213 | +Thank you to `Kevin Steves <https://github.com/kevinsteves>`_\ , creator of the `pan-python library <https://github.com/kevinsteves/pan-python>`_ |
0 commit comments