Wrapper that tests the type of _session.

        Purpose: This decorator function is used by all functions within
              | the Jaide class that interact with a device to ensure the
              | proper session type is in use. If it is not, it will
              | attempt to migrate _session to that type before moving
              | to the originally requested function.
              | > **NOTE:** This function is a decorator, and should not be
              | >  used directly. All other methods in this class that touch
              | >  the Junos device are wrapped by this function to ensure the
              | >  proper connection type is used.

        @param function: the function that is being wrapped around
        @type function: function

        @returns: the originally requested function
        @rtype: function

def check_instance(function):
        """ Wrapper that tests the type of _session.

        Purpose: This decorator function is used by all functions within
              | the Jaide class that interact with a device to ensure the
              | proper session type is in use. If it is not, it will
              | attempt to migrate _session to that type before moving
              | to the originally requested function.
              | > **NOTE:** This function is a decorator, and should not be
              | >  used directly. All other methods in this class that touch
              | >  the Junos device are wrapped by this function to ensure the
              | >  proper connection type is used.

        @param function: the function that is being wrapped around
        @type function: function

        @returns: the originally requested function
        @rtype: function
        """
        def wrapper(self, *args, **kwargs):
            func_trans = {
                "commit": manager.Manager,
                "compare_config": manager.Manager,
                "commit_check": manager.Manager,
                "device_info": manager.Manager,
                "diff_config": manager.Manager,
                "health_check": manager.Manager,
                "interface_errors": manager.Manager,
                "op_cmd": paramiko.client.SSHClient,
                "shell_cmd": paramiko.client.SSHClient,
                "scp_pull": paramiko.client.SSHClient,
                "scp_push": paramiko.client.SSHClient
            }
            # when doing an operational command, logging in as root
            # brings you to shell, so we need to enter the device as a shell
            # connection, and move to cli to perform the command
            # this is a one-off because the isinstance() check will be bypassed
            if self.username == "root" and function.__name__ == "op_cmd":
                if not self._session:
                    self.conn_type = "paramiko"
                    self.connect()
                if not self._shell:
                    self.conn_type = "root"
                    self.connect()
                self.shell_to_cli()  # check if we're in the cli
            # Have to call shell command separately, since we are using _shell
            # for comparison, not _session.
            elif function.__name__ == 'shell_cmd':
                if not self._shell:
                    self.conn_type = "shell"
                    self.connect()
                self.cli_to_shell()  # check if we're in shell.
            if isinstance(self._session, func_trans[function.__name__]):
                # If they're doing SCP, we have to check for both _session and
                # _scp
                if function.__name__ in ['scp_pull', 'scp_push']:
                    if not isinstance(self._scp, SCPClient):
                        self.conn_type = "scp"
                        self.connect()
            else:
                self.disconnect()
                if function.__name__ == "op_cmd":
                    self.conn_type = "paramiko"
                elif function.__name__ in ["scp_pull", "scp_push"]:
                    self.conn_type = "scp"
                else:
                    self.conn_type = "ncclient"
                self.connect()
            return function(self, *args, **kwargs)
        return wrapper