fortigate-api


Namefortigate-api JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/vladimirs-git/fortigate-api
SummaryPython package to configure Fortigate (Fortios) devices using REST API and SSH
upload_time2024-01-24 17:53:26
maintainer
docs_urlNone
authorVladimirs Prusakovs
requires_python>=3.8,<4.0
licenseApache-2.0
keywords fortigate fortios rest api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
.. image:: https://img.shields.io/pypi/v/fortigate-api.svg
   :target: https://pypi.python.org/pypi/fortigate-api
.. image:: https://img.shields.io/pypi/pyversions/fortigate-api.svg
   :target: https://pypi.python.org/pypi/fortigate-api
.. image:: https://img.shields.io/github/last-commit/vladimirs-git/fortigate-api
   :target: https://pypi.python.org/pypi/fortigate-api


fortigate-api
=============

Python package to configure Fortigate (Fortios) devices using REST API.

    - FortiGateAPI - Python connector to Fortigate API endpoints.
    - FortiGate - Python wrapper for the FortiOS REST API.

Checked with FortiOS = v6.4.14.
Fully documented on `Read the Docs`_.


----------------------------------------------------------------------------------------

Quickstart
==========

Install the package from pypi.org

.. code:: bash

    pip install fortigate-api

or from github.com repository

.. code:: bash

    pip install git+https://github.com/vladimirs-git/fortigate-api

----------------------------------------------------------------------------------------

.. code:: python

    """Quickstart FortiGateAPI.

    - Create address in the Fortigate
    - Get all addresses from the Fortigate vdom root
    - Get address by name (unique identifier)
    - Filter address by operator contains `=@`
    - Update address data in the Fortigate
    - Delete address from the Fortigate
    """

    from pprint import pprint

    from fortigate_api import FortiGateAPI

    HOST = "host"
    USERNAME = "username"
    PASSWORD = "password"

    api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)

    # Create address in the Fortigate
    data = {
        "name": "ADDRESS",
        "obj-type": "ip",
        "subnet": "127.0.0.100 255.255.255.252",
        "type": "ipmask",
    }
    response = api.cmdb.firewall.address.create(data)
    print(f"address.create {response}")  # address.create <Response [200]>

    # Get all addresses from the Fortigate vdom root
    items = api.cmdb.firewall.address.get()
    print(f"All addresses count={len(items)}")  # All addresses count=14

    # Get address by name (unique identifier)
    items = api.cmdb.firewall.address.get(name="ADDRESS")
    print(f"addresses count={len(items)}")  # addresses count=1
    pprint(items)
    #  [{"comment": "",
    #    "name": "ADDRESS",
    #    "subnet": "127.0.0.100 255.255.255.252",
    #    "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
    #    ...
    #    }]

    # Filter address by operator contains `=@`
    items = api.cmdb.firewall.address.get(filter="subnet=@127.0")
    print(f"Filtered by `=@`, count={len(items)}")  # Filtered by `=@`, count=2

    # Update address data in the Fortigate
    data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
    response = api.cmdb.firewall.address.update(data)
    print(f"address.update {response}")  # address.update <Response [200]>

    # Delete address from the Fortigate
    response = api.cmdb.firewall.address.delete("ADDRESS")
    print(f"address.delete {response}")  # address.delete <Response [200]>

    api.logout()


.. code:: python

    """Quickstart FortiGate.

    - Creates address in the Fortigate
    - Get address by name (unique identifier)
    - Updates address data in the Fortigate
    - Delete address from the Fortigate
    """

    from pprint import pprint

    from fortigate_api import FortiGate

    HOST = "host"
    USERNAME = "username"
    PASSWORD = "password"

    fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD)

    # Creates address in the Fortigate
    data = {
        "name": "ADDRESS",
        "obj-type": "ip",
        "subnet": "127.0.0.100 255.255.255.252",
        "type": "ipmask",
    }
    response = fgt.post(url="api/v2/cmdb/firewall/address/", data=data)
    print(f"POST {response}", )  # POST <Response [200]>

    # Get address by name (unique identifier)
    response = fgt.get(url="api/v2/cmdb/firewall/address/ADDRESS")
    print(f"GET {response}", )  # POST <Response [200]>
    result = response.json()["results"]
    pprint(result)
    #  [{"name": "ADDRESS",
    #    "subnet": "127.0.0.100 255.255.255.252",
    #    "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
    #    ...
    #    }]

    # Updates address data in the Fortigate
    data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
    response = fgt.put(url="api/v2/cmdb/firewall/address/ADDRESS", data=data)
    print(f"PUT {response}")  # PUT <Response [200]>

    # Delete address from the Fortigate
    response = fgt.delete(url="api/v2/cmdb/firewall/address/ADDRESS")
    print(f"DELETE {response}", )  # DELETE <Response [200]>

    fgt.logout()



----------------------------------------------------------------------------------------

.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vladimirs-git/fortigate-api",
    "name": "fortigate-api",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "fortigate,fortios,rest,api",
    "author": "Vladimirs Prusakovs",
    "author_email": "vladimir.prusakovs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fd/ba/b1a7ad01b9891b2cd76a3b97a5800e3b0f4d7cd8732527882c1208703883/fortigate_api-2.0.1.tar.gz",
    "platform": null,
    "description": "\n.. image:: https://img.shields.io/pypi/v/fortigate-api.svg\n   :target: https://pypi.python.org/pypi/fortigate-api\n.. image:: https://img.shields.io/pypi/pyversions/fortigate-api.svg\n   :target: https://pypi.python.org/pypi/fortigate-api\n.. image:: https://img.shields.io/github/last-commit/vladimirs-git/fortigate-api\n   :target: https://pypi.python.org/pypi/fortigate-api\n\n\nfortigate-api\n=============\n\nPython package to configure Fortigate (Fortios) devices using REST API.\n\n    - FortiGateAPI - Python connector to Fortigate API endpoints.\n    - FortiGate - Python wrapper for the FortiOS REST API.\n\nChecked with FortiOS = v6.4.14.\nFully documented on `Read the Docs`_.\n\n\n----------------------------------------------------------------------------------------\n\nQuickstart\n==========\n\nInstall the package from pypi.org\n\n.. code:: bash\n\n    pip install fortigate-api\n\nor from github.com repository\n\n.. code:: bash\n\n    pip install git+https://github.com/vladimirs-git/fortigate-api\n\n----------------------------------------------------------------------------------------\n\n.. code:: python\n\n    \"\"\"Quickstart FortiGateAPI.\n\n    - Create address in the Fortigate\n    - Get all addresses from the Fortigate vdom root\n    - Get address by name (unique identifier)\n    - Filter address by operator contains `=@`\n    - Update address data in the Fortigate\n    - Delete address from the Fortigate\n    \"\"\"\n\n    from pprint import pprint\n\n    from fortigate_api import FortiGateAPI\n\n    HOST = \"host\"\n    USERNAME = \"username\"\n    PASSWORD = \"password\"\n\n    api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)\n\n    # Create address in the Fortigate\n    data = {\n        \"name\": \"ADDRESS\",\n        \"obj-type\": \"ip\",\n        \"subnet\": \"127.0.0.100 255.255.255.252\",\n        \"type\": \"ipmask\",\n    }\n    response = api.cmdb.firewall.address.create(data)\n    print(f\"address.create {response}\")  # address.create <Response [200]>\n\n    # Get all addresses from the Fortigate vdom root\n    items = api.cmdb.firewall.address.get()\n    print(f\"All addresses count={len(items)}\")  # All addresses count=14\n\n    # Get address by name (unique identifier)\n    items = api.cmdb.firewall.address.get(name=\"ADDRESS\")\n    print(f\"addresses count={len(items)}\")  # addresses count=1\n    pprint(items)\n    #  [{\"comment\": \"\",\n    #    \"name\": \"ADDRESS\",\n    #    \"subnet\": \"127.0.0.100 255.255.255.252\",\n    #    \"uuid\": \"a386e4b0-d6cb-51ec-1e28-01e0bc0de43c\",\n    #    ...\n    #    }]\n\n    # Filter address by operator contains `=@`\n    items = api.cmdb.firewall.address.get(filter=\"subnet=@127.0\")\n    print(f\"Filtered by `=@`, count={len(items)}\")  # Filtered by `=@`, count=2\n\n    # Update address data in the Fortigate\n    data = {\"name\": \"ADDRESS\", \"subnet\": \"127.0.0.255 255.255.255.255\"}\n    response = api.cmdb.firewall.address.update(data)\n    print(f\"address.update {response}\")  # address.update <Response [200]>\n\n    # Delete address from the Fortigate\n    response = api.cmdb.firewall.address.delete(\"ADDRESS\")\n    print(f\"address.delete {response}\")  # address.delete <Response [200]>\n\n    api.logout()\n\n\n.. code:: python\n\n    \"\"\"Quickstart FortiGate.\n\n    - Creates address in the Fortigate\n    - Get address by name (unique identifier)\n    - Updates address data in the Fortigate\n    - Delete address from the Fortigate\n    \"\"\"\n\n    from pprint import pprint\n\n    from fortigate_api import FortiGate\n\n    HOST = \"host\"\n    USERNAME = \"username\"\n    PASSWORD = \"password\"\n\n    fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD)\n\n    # Creates address in the Fortigate\n    data = {\n        \"name\": \"ADDRESS\",\n        \"obj-type\": \"ip\",\n        \"subnet\": \"127.0.0.100 255.255.255.252\",\n        \"type\": \"ipmask\",\n    }\n    response = fgt.post(url=\"api/v2/cmdb/firewall/address/\", data=data)\n    print(f\"POST {response}\", )  # POST <Response [200]>\n\n    # Get address by name (unique identifier)\n    response = fgt.get(url=\"api/v2/cmdb/firewall/address/ADDRESS\")\n    print(f\"GET {response}\", )  # POST <Response [200]>\n    result = response.json()[\"results\"]\n    pprint(result)\n    #  [{\"name\": \"ADDRESS\",\n    #    \"subnet\": \"127.0.0.100 255.255.255.252\",\n    #    \"uuid\": \"a386e4b0-d6cb-51ec-1e28-01e0bc0de43c\",\n    #    ...\n    #    }]\n\n    # Updates address data in the Fortigate\n    data = {\"name\": \"ADDRESS\", \"subnet\": \"127.0.0.255 255.255.255.255\"}\n    response = fgt.put(url=\"api/v2/cmdb/firewall/address/ADDRESS\", data=data)\n    print(f\"PUT {response}\")  # PUT <Response [200]>\n\n    # Delete address from the Fortigate\n    response = fgt.delete(url=\"api/v2/cmdb/firewall/address/ADDRESS\")\n    print(f\"DELETE {response}\", )  # DELETE <Response [200]>\n\n    fgt.logout()\n\n\n\n----------------------------------------------------------------------------------------\n\n.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python package to configure Fortigate (Fortios) devices using REST API and SSH",
    "version": "2.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/vladimirs-git/fortigate-api/issues",
        "Download URL": "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/2.0.1.tar.gz",
        "Homepage": "https://github.com/vladimirs-git/fortigate-api",
        "Repository": "https://github.com/vladimirs-git/fortigate-api"
    },
    "split_keywords": [
        "fortigate",
        "fortios",
        "rest",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a276e018ab9f2772d5d1cfb8489b446d001a69044a8ea1963dfca920569e9ac",
                "md5": "dcf7a8878538af7f4c067c09c2253cba",
                "sha256": "6e231c123d0f760176e92c7e4209621eae7801d40446ff6dea2d91d32977e674"
            },
            "downloads": -1,
            "filename": "fortigate_api-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dcf7a8878538af7f4c067c09c2253cba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 3522164,
            "upload_time": "2024-01-24T17:53:24",
            "upload_time_iso_8601": "2024-01-24T17:53:24.085695Z",
            "url": "https://files.pythonhosted.org/packages/7a/27/6e018ab9f2772d5d1cfb8489b446d001a69044a8ea1963dfca920569e9ac/fortigate_api-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fdbab1a7ad01b9891b2cd76a3b97a5800e3b0f4d7cd8732527882c1208703883",
                "md5": "60936830b2525ca9614bccad56c62649",
                "sha256": "07354e148c96836d5e5dfd7431222d8021a15ccd0e7f5c5a95ac4825f2c5cb3a"
            },
            "downloads": -1,
            "filename": "fortigate_api-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "60936830b2525ca9614bccad56c62649",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 3237838,
            "upload_time": "2024-01-24T17:53:26",
            "upload_time_iso_8601": "2024-01-24T17:53:26.603479Z",
            "url": "https://files.pythonhosted.org/packages/fd/ba/b1a7ad01b9891b2cd76a3b97a5800e3b0f4d7cd8732527882c1208703883/fortigate_api-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 17:53:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vladimirs-git",
    "github_project": "fortigate-api",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "fortigate-api"
}
        
Elapsed time: 0.17306s