diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 68a47cf6..b0b90143 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,12 @@ CHANGELOG ========= +1.1.1 (2023-03-16) +------------------ +* [new] ./examples/ssh_vdom.py +* [change] README.rst ssh + + 1.1.0 (2023-03-05) ------------------ * [new] ciscoconfparse diff --git a/README.rst b/README.rst index 7a8a7a9c..070829fe 100644 --- a/README.rst +++ b/README.rst @@ -48,7 +48,7 @@ or install the package from github.com release .. code:: bash - pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.1.0.tar.gz + pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.1.1.tar.gz or install the package from github.com repository @@ -934,6 +934,8 @@ SSH --- **SSH(host, username, password, ssh)** SSH connector to the Fortigate. Contains methods to get and put configuration commands using ssh. +Note, FortigateAPI parameter "vdom" used in REST API only and not used in SSH. +In order to send cli commands to a specific vdom, you need "config vdom" before. =============== ======= ============================================================================ Parameter Type Description @@ -996,6 +998,12 @@ SSH examples: `./examples/ssh.py`_ +SSH examples for working with vdom: + +- get system arp from interfaces associated with vdom="VDOM" +- get system arp from interfaces associated with vdom="root" + +`./examples/ssh_vdom.py`_ ---------------------------------------------------------------------------------------------------- @@ -1049,3 +1057,4 @@ CiscoConfParse examples: .. _`./examples/policy_extended_filter.py`: ./examples/policy_extended_filter.py .. _`./examples/snmp_community.py`: ./examples/snmp_community.py .. _`./examples/ssh.py`: ./examples/ssh.py +.. _`./examples/ssh_vdom.py`: ./examples/ssh_vdom.py diff --git a/examples/ssh_vdom.py b/examples/ssh_vdom.py new file mode 100644 index 00000000..8f3491aa --- /dev/null +++ b/examples/ssh_vdom.py @@ -0,0 +1,48 @@ +"""SSH examples for working with vdom: +- get system arp from interfaces associated with vdom="VDOM" +- get system arp from interfaces associated with vdom="root" +""" + +from fortigate_api import FortigateAPI + +HOST = "hostname" +USERNAME = "username" +PASSWORD = "password" +VDOM = "VDOM" + +# Fortigate with configured VDOMs. diagnostic commands for custom vdom +fgt_vdom = FortigateAPI(host=HOST, username=USERNAME, password=PASSWORD) +vdom_commands = ["config vdom", f"edit {VDOM}"] +output = fgt_vdom.ssh.send_config_set(vdom_commands) +print(output) +# config vdom +# +# hostname (vdom) # edit VDOM +# current vf=VDOM:1 +# +# hostname (VDOM) # + +output = fgt_vdom.ssh.send_command("get system arp") +print(output) +# hostname (VDOM) # +# Address Age(min) Hardware Addr Interface +# 10.0.1.1 0 00:00:00:00:00:71 v1000 +# 10.0.4.1 0 00:00:00:00:00:71 v4000 + +# Fortigate with configured VDOMs. diagnostic commands for vdom=root +fgt_root = FortigateAPI(host=HOST, username=USERNAME, password=PASSWORD) +vdom_commands = ["config vdom", "edit root"] +output = fgt_root.ssh.send_config_set(vdom_commands) +print(output) +# config vdom +# +# hostname (vdom) # edit root +# current vf=root:0 +# +# hostname (root) # + +output = fgt_root.ssh.send_command("get system arp") +print(output) +# hostname (root) # +# Address Age(min) Hardware Addr Interface +# 10.0.5.1 7 00:00:00:00:00:71 v5000 diff --git a/fortigate_api/fortigate_api.py b/fortigate_api/fortigate_api.py index 14af2052..e1573a70 100644 --- a/fortigate_api/fortigate_api.py +++ b/fortigate_api/fortigate_api.py @@ -50,7 +50,8 @@ def __init__(self, **kwargs): False - disable (default) :type verify: bool - :param vdom: Name of virtual domain (default "root") + :param vdom: Name of virtual domain (default "root"). + Used in REST API (Not used in SSH) :type vdom: str :param ssh: Netmiko ConnectHandler parameters diff --git a/pyproject.toml b/pyproject.toml index 83a6fcc0..3ce1d95c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "fortigate_api" -version = "1.1.0" +version = "1.1.1" authors = [ { name="Vladimir Prusakov", email="vladimir.prusakovs@gmail.com" }, ] @@ -31,7 +31,7 @@ classifiers = [ "Homepage" = "https://github.com/vladimirs-git/fortigate-api" "Repository" = "https://github.com/vladimirs-git/fortigate-api" "Bug Tracker" = "https://github.com/vladimirs-git/fortigate-api/issues" -"Download URL" = "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.1.0.tar.gz" +"Download URL" = "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.1.1.tar.gz" [tool.setuptools.packages.find] include = ["fortigate_api"] [tool.setuptools.package-data] diff --git a/tests/ccp_/__init__.py b/tests/ccp_/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/ccp_/helpers__ccp.py b/tests/helpers__ccp.py similarity index 100% rename from tests/ccp_/helpers__ccp.py rename to tests/helpers__ccp.py diff --git a/tests/ccp_/test__ccp.py b/tests/test__ccp.py similarity index 99% rename from tests/ccp_/test__ccp.py rename to tests/test__ccp.py index 9db01ddb..9e0b6bc5 100644 --- a/tests/ccp_/test__ccp.py +++ b/tests/test__ccp.py @@ -3,7 +3,7 @@ import unittest from fortigate_api import ccp -from tests.ccp_.helpers__ccp import ( +from tests.helpers__ccp import ( BLOCK_A1, BLOCK_A2, BLOCK_E2,