Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

enhancement: add support to configure channel timeout in pyFG.FortiOS #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pyFG/fortios.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

class FortiOS(object):

def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=None, timeout=60):
def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=None, timeout=60,
chan_timeout=20):
"""
Represents a device running FortiOS.

Expand All @@ -44,7 +45,8 @@ def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=No
used
* **password** (str) -- Username password
* **keyfile** (str) -- Path to the private key in case you want to use this authentication method.
* **timeout** (int) -- Time in seconds to wait for the device to respond.
* **timeout** (int) -- Time in seconds to wait for connecting the device.
* **chan_timeout** (int) -- Time in seconds to wait for the device to respond via channel.

"""
self.hostname = hostname
Expand All @@ -57,6 +59,7 @@ def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=No
self.password = password
self.keyfile = keyfile
self.timeout = timeout
self.chan_timeout = chan_timeout

# Set key exchange explcitly to address known fortinet issue
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',
Expand Down Expand Up @@ -139,7 +142,7 @@ def execute_command(self, command):
err_msg = 'Something happened when executing some commands on device'

chan = self.ssh.get_transport().open_session()
chan.settimeout(5)
chan.settimeout(self.chan_timeout)

chan.exec_command(command)

Expand Down