Пример #1
0
    def __init__(self,
                 hostname,
                 vdom=None,
                 username=None,
                 password=None,
                 keyfile=None,
                 timeout=60):
        """
        Represents a device running FortiOS.

        A :py:class:`FortiOS` object has three different :class:`~pyFG.forticonfig.FortiConfig` objects:

        * **running_config** -- You can populate this from the device or from a file with the\
            :func:`~pyFG.fortios.FortiOS.load_config` method. This will represent the live config\
            of the device and shall not be modified by any means as that might break other methods as the \
            :func:`~pyFG.fortios.FortiOS.commit`
        * **candidate_config** -- You can populate this using the same mechanisms as you would populate the\
            running_config. This represents the config you want to reach so, if you want to apply\
            changes, here is where you would apply them.
        * **original_config** -- This is automatically populated when you do a commit with the original config\
            prior to the commit. This is useful for the :func:`~pyFG.fortios.FortiOS.rollback` operation or for\
            checking stuff later on.

        Args:
            * **hostname** (str) -- FQDN or IP of the device you want to connect.
            * **vdom** (str) -- VDOM you want to connect to. If it is None we will run the commands without moving\
                to a VDOM.
            * **username** (str) -- Username to connect to the device. If none is specified the current user will be\
                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.

        """
        self.hostname = hostname
        self.vdom = vdom
        self.original_config = None
        self.running_config = FortiConfig('running', vdom=vdom)
        self.candidate_config = FortiConfig('candidate', vdom=vdom)
        self.ssh = None
        self.username = username
        self.password = password
        self.keyfile = keyfile
        self.timeout = timeout
Пример #2
0
    def _reload_config(self, reload_original_config):
        """
        This command will update the running config from the live device.

        Args:
            * reload_original_config:
                * If ``True`` the original config will be loaded with the running config before reloading the\
                original config.
                * If ``False`` the original config will remain untouched.
        """
        # We don't want to reload the config under some circumstances
        if reload_original_config:
            self.original_config = self.running_config
            self.original_config.set_name('original')

        paths = self.running_config.get_paths()

        self.running_config = FortiConfig('running', vdom=self.vdom)

        for path in paths:
            self.load_config(path, empty_candidate=True)