コード例 #1
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_plugin = {
                    "type": "httpapi",
                    "name": self.httpapi._load_name,
                    "obj": self.httpapi,
                }
                self.queue_message(
                    "vvvv",
                    "loaded API plugin %s from path %s for network_os %s" % (
                        self.httpapi._load_name,
                        self.httpapi._original_path,
                        self._network_os,
                    ),
                )
            else:
                raise AnsibleConnectionFailure(
                    "unable to load API plugin 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)
コード例 #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
コード例 #3
0
ファイル: httpapi.py プロジェクト: zhongshan0525/ansible
    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_plugin = {
                    'type': 'httpapi',
                    'name': self._network_os,
                    'obj': self.httpapi
                }
                self.queue_message(
                    '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)

        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)
コード例 #4
0
    def __init__(self, play_context, new_stdin, *args, **kwargs):
        super(Connection, self).__init__(play_context, new_stdin, *args,
                                         **kwargs)

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

        self._local = connection_loader.get('local', play_context, '/dev/null')
        self._local.set_options()

        self._cliconf = None

        self._ansible_playbook_pid = kwargs.get('ansible_playbook_pid')

        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._httpapi = httpapi_loader.get(network_os, self)
        if self._httpapi:
            display.vvvv('loaded API plugin for network_os %s' % network_os,
                         host=self._play_context.remote_addr)
        else:
            raise AnsibleConnectionFailure(
                'unable to load API plugin for network_os %s' % network_os)

        self._url = None
        self._auth = None

        # reconstruct the socket_path and set instance values accordingly
        self._update_connection_state()
コード例 #5
0
    def load_platform_plugins(self, platform_type=None):
        platform_type = platform_type or self.get_option("platform_type")

        if platform_type:
            self.httpapi = httpapi_loader.get(platform_type, self)
            if self.httpapi:
                self._sub_plugin = {
                    "type": "httpapi",
                    "name": self.httpapi._load_name,
                    "obj": self.httpapi,
                }
                self.queue_message(
                    "vvvv",
                    "loaded API plugin %s from path %s for platform type %s" %
                    (
                        self.httpapi._load_name,
                        self.httpapi._original_path,
                        platform_type,
                    ),
                )
            else:
                raise AnsibleConnectionFailure(
                    "unable to load API plugin for platform type %s" %
                    platform_type)

        else:
            raise AnsibleConnectionFailure(
                "Unable to automatically determine host platform type. Please "
                "manually configure platform_type value for this host")
        self.queue_message("log", "platform_type is set to %s" % platform_type)
コード例 #6
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)