Exemple #1
0
    def __init__(self, play_context, new_stdin, *args, **kwargs):
        super(Connection, self).__init__(
            play_context, new_stdin, *args, **kwargs
        )
        self._ssh_shell = None

        self._matched_prompt = None
        self._matched_cmd_prompt = None
        self._matched_pattern = None
        self._last_response = None
        self._history = list()
        self._command_response = None
        self._last_recv_window = None

        self._terminal = None
        self.cliconf = None
        self._paramiko_conn = None

        # Managing prompt context
        self._check_prompt = False
        self._task_uuid = to_text(kwargs.get("task_uuid", ""))

        if self._play_context.verbosity > 3:
            logging.getLogger("paramiko").setLevel(logging.DEBUG)

        if self._network_os:
            self._terminal = terminal_loader.get(self._network_os, self)
            if not self._terminal:
                raise AnsibleConnectionFailure(
                    "network os %s is not supported" % self._network_os
                )

            self.cliconf = cliconf_loader.get(self._network_os, self)
            if self.cliconf:
                self._sub_plugin = {
                    "type": "cliconf",
                    "name": self.cliconf._load_name,
                    "obj": self.cliconf,
                }
                self.queue_message(
                    "vvvv",
                    "loaded cliconf plugin %s from path %s for network_os %s"
                    % (
                        self.cliconf._load_name,
                        self.cliconf._original_path,
                        self._network_os,
                    ),
                )
            else:
                self.queue_message(
                    "vvvv",
                    "unable to load cliconf for network_os %s"
                    % self._network_os,
                )
        else:
            raise AnsibleConnectionFailure(
                "Unable to automatically determine host network os. Please "
                "manually configure ansible_network_os value for this host"
            )
        self.queue_message("log", "network_os is set to %s" % self._network_os)
Exemple #2
0
    def _connect(self):
        if not self.connected:
            protocol = 'https' if self.get_option('use_ssl') else 'http'
            host = self.get_option('host')
            port = self.get_option('port') or (443
                                               if protocol == 'https' else 80)
            self._url = '%s://%s:%s' % (protocol, host, port)

            httpapi = httpapi_loader.get(self._network_os, self)
            if httpapi:
                httpapi.set_become(self._play_context)
                httpapi.login(self.get_option('remote_user'),
                              self.get_option('password'))
                display.vvvv('loaded API plugin for network_os %s' %
                             self._network_os,
                             host=self._play_context.remote_addr)
            else:
                raise AnsibleConnectionFailure(
                    'unable to load API plugin for network_os %s' %
                    self._network_os)
            self._implementation_plugins.append(httpapi)

            cliconf = cliconf_loader.get(self._network_os, self)
            if cliconf:
                display.vvvv('loaded cliconf plugin for network_os %s' %
                             self._network_os,
                             host=host)
                self._implementation_plugins.append(cliconf)
            else:
                display.vvvv('unable to load cliconf for network_os %s' %
                             self._network_os)

            self._connected = True
Exemple #3
0
    def __init__(self, play_context, new_stdin, *args, **kwargs):
        super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

        self._url = None
        self._auth = None

        if self._network_os:

            self.httpapi = httpapi_loader.get(self._network_os, self)
            if self.httpapi:
                self._sub_plugins.append({'type': 'httpapi', 'name': self._network_os, 'obj': self.httpapi})
                display.vvvv('loaded API plugin for network_os %s' % self._network_os)
            else:
                raise AnsibleConnectionFailure('unable to load API plugin for network_os %s' % self._network_os)

            self.cliconf = cliconf_loader.get(self._network_os, self)
            if self.cliconf:
                self._sub_plugins.append({'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf})
                display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os)
            else:
                display.vvvv('unable to load cliconf for network_os %s' % self._network_os)
        else:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host'
            )
        display.display('network_os is set to %s' % self._network_os, log_only=True)
Exemple #4
0
    def __init__(self, play_context, new_stdin, *args, **kwargs):
        super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

        self._ssh_shell = None

        self._matched_prompt = None
        self._matched_cmd_prompt = None
        self._matched_pattern = None
        self._last_response = None
        self._history = list()
        self._command_response = None

        self._terminal = None
        self.cliconf = None
        self.paramiko_conn = None

        if self._play_context.verbosity > 3:
            logging.getLogger('paramiko').setLevel(logging.DEBUG)

        if self._network_os:

            self.cliconf = cliconf_loader.get(self._network_os, self)
            if self.cliconf:
                self.queue_message('vvvv', 'loaded cliconf plugin for network_os %s' % self._network_os)
                self._sub_plugin = {'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf}
            else:
                self.queue_message('vvvv', 'unable to load cliconf for network_os %s' % self._network_os)
        else:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host'
            )
        self.queue_message('log', 'network_os is set to %s' % self._network_os)
Exemple #5
0
    def _connect(self):
        '''
        Connects to the remote device and starts the terminal
        '''
        if self.connected:
            return

        if self._play_context.password and not self._play_context.private_key_file:
            C.PARAMIKO_LOOK_FOR_KEYS = False

        ssh = ParamikoSshConnection(self._play_context, '/dev/null')._connect()
        self.ssh = ssh.ssh

        display.vvvv('ssh connection done, setting terminal',
                     host=self._play_context.remote_addr)

        self._ssh_shell = self.ssh.invoke_shell()
        self._ssh_shell.settimeout(self._play_context.timeout)

        network_os = self._play_context.network_os
        if not network_os:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host')

        self._terminal = terminal_loader.get(network_os, self)
        if not self._terminal:
            raise AnsibleConnectionFailure('network os %s is not supported' %
                                           network_os)

        display.vvvv('loaded terminal plugin for network_os %s' % network_os,
                     host=self._play_context.remote_addr)

        self._cliconf = cliconf_loader.get(network_os, self)
        if self._cliconf:
            display.vvvv('loaded cliconf plugin for network_os %s' %
                         network_os,
                         host=self._play_context.remote_addr)
        else:
            display.vvvv('unable to load cliconf for network_os %s' %
                         network_os)

        self.receive()

        display.vvvv('firing event: on_open_shell()',
                     host=self._play_context.remote_addr)
        self._terminal.on_open_shell()

        if self._play_context.become and self._play_context.become_method == 'enable':
            display.vvvv('firing event: on_authorize',
                         host=self._play_context.remote_addr)
            auth_pass = self._play_context.become_pass
            self._terminal.on_authorize(passwd=auth_pass)

        display.vvvv('ssh connection has completed successfully',
                     host=self._play_context.remote_addr)
        self._connected = True

        return self
Exemple #6
0
    def _connect(self):
        '''
        Connects to the remote device and starts the terminal
        '''
        if not self.connected:
            if not self._network_os:
                raise AnsibleConnectionFailure(
                    'Unable to automatically determine host network os. Please '
                    'manually configure ansible_network_os value for this host'
                )
            display.display('network_os is set to %s' % self._network_os, log_only=True)

            self.paramiko_conn = connection_loader.get('paramiko', self._play_context, '/dev/null')
            self.paramiko_conn._set_log_channel(self._get_log_channel())
            self.paramiko_conn.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)})
            self.paramiko_conn.force_persistence = self.force_persistence
            ssh = self.paramiko_conn._connect()

            host = self.get_option('host')
            display.vvvv('ssh connection done, setting terminal', host=host)

            self._ssh_shell = ssh.ssh.invoke_shell()
            self._ssh_shell.settimeout(self.get_option('persistent_command_timeout'))

            self._terminal = terminal_loader.get(self._network_os, self)
            if not self._terminal:
                raise AnsibleConnectionFailure('network os %s is not supported' % self._network_os)

            display.vvvv('loaded terminal plugin for network_os %s' % self._network_os, host=host)

            self.cliconf = cliconf_loader.get(self._network_os, self)
            if self.cliconf:
                display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os, host=host)
                self._implementation_plugins.append(self.cliconf)
            else:
                display.vvvv('unable to load cliconf for network_os %s' % self._network_os)

            super(Connection, self)._connect()

            self.receive(prompts=self._terminal.terminal_initial_prompt, answer=self._terminal.terminal_initial_answer,
                         newline=self._terminal.terminal_inital_prompt_newline)

            display.vvvv('firing event: on_open_shell()', host=host)
            self._terminal.on_open_shell()

            if self._play_context.become and self._play_context.become_method == 'enable':
                display.vvvv('firing event: on_become', host=host)
                auth_pass = self._play_context.become_pass
                self._terminal.on_become(passwd=auth_pass)

            display.vvvv('ssh connection has completed successfully', host=host)
            self._connected = True

        return self
Exemple #7
0
    def _connect(self):
        '''
        Connects to the remote device and starts the terminal
        '''
        if self.connected:
            return

        self.paramiko_conn = connection_loader.get('paramiko', self._play_context, '/dev/null')
        self.paramiko_conn._set_log_channel(self._get_log_channel())
        self.paramiko_conn.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)})
        self.paramiko_conn.force_persistence = self.force_persistence
        ssh = self.paramiko_conn._connect()

        display.vvvv('ssh connection done, setting terminal', host=self._play_context.remote_addr)

        self._ssh_shell = ssh.ssh.invoke_shell()
        self._ssh_shell.settimeout(self._play_context.timeout)

        network_os = self._play_context.network_os
        if not network_os:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host'
            )

        self._terminal = terminal_loader.get(network_os, self)
        if not self._terminal:
            raise AnsibleConnectionFailure('network os %s is not supported' % network_os)

        display.vvvv('loaded terminal plugin for network_os %s' % network_os, host=self._play_context.remote_addr)

        self._cliconf = cliconf_loader.get(network_os, self)
        if self._cliconf:
            display.vvvv('loaded cliconf plugin for network_os %s' % network_os, host=self._play_context.remote_addr)
        else:
            display.vvvv('unable to load cliconf for network_os %s' % network_os)

        self.receive(prompts=self._terminal.terminal_initial_prompt, answer=self._terminal.terminal_initial_answer,
                     newline=self._terminal.terminal_inital_prompt_newline)

        display.vvvv('firing event: on_open_shell()', host=self._play_context.remote_addr)
        self._terminal.on_open_shell()

        if self._play_context.become and self._play_context.become_method == 'enable':
            display.vvvv('firing event: on_become', host=self._play_context.remote_addr)
            auth_pass = self._play_context.become_pass
            self._terminal.on_become(passwd=auth_pass)

        display.vvvv('ssh connection has completed successfully', host=self._play_context.remote_addr)
        self._connected = True

        return self
Exemple #8
0
    def __init__(self, play_context, new_stdin, *args, **kwargs):
        super(Connection, self).__init__(play_context, new_stdin, *args,
                                         **kwargs)

        self._ssh_shell = None

        self._matched_prompt = None
        self._matched_cmd_prompt = None
        self._matched_pattern = None
        self._last_response = None
        self._history = list()
        self._command_response = None
        self._last_recv_window = None

        self._terminal = None
        self.cliconf = None
        self._paramiko_conn = None

        # Managing prompt context
        self._check_prompt = False
        self._task_uuid = to_text(kwargs.get('task_uuid', ''))

        if self._play_context.verbosity > 3:
            logging.getLogger('paramiko').setLevel(logging.DEBUG)

        if self._network_os:
            self._terminal = terminal_loader.get(self._network_os, self)
            if not self._terminal:
                raise AnsibleConnectionFailure(
                    'network os %s is not supported' % self._network_os)

            self.cliconf = cliconf_loader.get(self._network_os, self)
            if self.cliconf:
                self._sub_plugin = {
                    'type': 'cliconf',
                    'name': self.cliconf._load_name,
                    'obj': self.cliconf
                }
                self.queue_message(
                    'vvvv',
                    'loaded cliconf plugin %s from path %s for network_os %s' %
                    (self.cliconf._load_name, self.cliconf._original_path,
                     self._network_os))
            else:
                self.queue_message(
                    'vvvv', 'unable to load cliconf for network_os %s' %
                    self._network_os)
        else:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host')
        self.queue_message('log', 'network_os is set to %s' % self._network_os)
Exemple #9
0
    def _connect(self):
        """Connections to the device and sets the terminal type"""

        if self._play_context.password and not self._play_context.private_key_file:
            C.PARAMIKO_LOOK_FOR_KEYS = False

        super(Connection, self)._connect()

        display.display('ssh connection done, setting terminal', log_only=True)

        self._shell = self.ssh.invoke_shell()
        self._shell.settimeout(self._play_context.timeout)

        network_os = self._play_context.network_os
        if not network_os:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host')

        self._terminal = terminal_loader.get(network_os, self)
        if not self._terminal:
            raise AnsibleConnectionFailure('network os %s is not supported' %
                                           network_os)

        display.display('loaded terminal plugin for network_os %s' %
                        network_os,
                        log_only=True)

        self._cliconf = cliconf_loader.get(network_os, self)
        if self._cliconf:
            self._rpc.add(self._cliconf)
            display.display('loaded cliconf plugin for network_os %s' %
                            network_os,
                            log_only=True)
        else:
            display.display('unable to load cliconf for network_os %s' %
                            network_os)

        self.receive()

        display.display('firing event: on_open_shell()', log_only=True)
        self._terminal.on_open_shell()

        if getattr(self._play_context, 'become', None):
            display.display('firing event: on_authorize', log_only=True)
            auth_pass = self._play_context.become_pass
            self._terminal.on_authorize(passwd=auth_pass)

        self._connected = True
        display.display('ssh connection has completed successfully',
                        log_only=True)
Exemple #10
0
    def _connect(self):
        if self.connected:
            return
        network_os = self._play_context.network_os

        protocol = 'https' if self.get_option('use_ssl') else 'http'
        host = self.get_option('host')
        port = self.get_option('port') or (443 if protocol == 'https' else 80)
        self._url = '%s://%s:%s' % (protocol, host, port)

        self._cliconf = cliconf_loader.get(network_os, self)
        if self._cliconf:
            display.vvvv('loaded cliconf plugin for network_os %s' % network_os, host=host)
        else:
            display.vvvv('unable to load cliconf for network_os %s' % network_os)

        self._connected = True
Exemple #11
0
    def _connect(self):
        """Connections to the device and sets the terminal type"""

        if self._play_context.password and not self._play_context.private_key_file:
            C.PARAMIKO_LOOK_FOR_KEYS = False

        super(Connection, self)._connect()

        display.display('ssh connection done, setting terminal', log_only=True)

        self._shell = self.ssh.invoke_shell()
        self._shell.settimeout(self._play_context.timeout)

        network_os = self._play_context.network_os
        if not network_os:
            raise AnsibleConnectionFailure(
                'Unable to automatically determine host network os. Please '
                'manually configure ansible_network_os value for this host'
            )

        self._terminal = terminal_loader.get(network_os, self)
        if not self._terminal:
            raise AnsibleConnectionFailure('network os %s is not supported' % network_os)

        display.display('loaded terminal plugin for network_os %s' % network_os, log_only=True)

        self._cliconf = cliconf_loader.get(network_os, self)
        if self._cliconf:
            self._rpc.add(self._cliconf)
            display.display('loaded cliconf plugin for network_os %s' % network_os, log_only=True)
        else:
            display.display('unable to load cliconf for network_os %s' % network_os)

        self.receive()

        display.display('firing event: on_open_shell()', log_only=True)
        self._terminal.on_open_shell()

        if getattr(self._play_context, 'become', None):
            display.display('firing event: on_authorize', log_only=True)
            auth_pass = self._play_context.become_pass
            self._terminal.on_authorize(passwd=auth_pass)

        self._connected = True
        display.display('ssh connection has completed successfully', log_only=True)