Python ansible.errors.AnsibleConnectionFailure() Examples

The following are 9 code examples of ansible.errors.AnsibleConnectionFailure(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ansible.errors , or try the search function .
Example #1
Source File: ce.py    From CloudEngine-Ansible with GNU General Public License v3.0 6 votes vote down vote up
def on_open_shell(self):
        try:
            self._exec_cli_command('screen-length 0 temporary')
        except AnsibleConnectionFailure:
            raise AnsibleConnectionFailure('unable to set terminal parameters') 
Example #2
Source File: aruba.py    From aruba-ansible-modules with Apache License 2.0 6 votes vote down vote up
def on_open_shell(self):
        try:
            self._exec_cli_command(b'no pag')
        except AnsibleConnectionFailure:
            self._connection.queue_message('warning', 'Unable to configure paging, command responses may be truncated') 
Example #3
Source File: arubaoss.py    From aruba-ansible-modules with Apache License 2.0 6 votes vote down vote up
def run_commands(self, commands=None, check_rc=False):
        '''
        Run commands on the switch
        '''
        if commands is None:
            raise ValueError("'commands' value is required")
        responses = list()
        for cmd in to_list(commands):

            if not isinstance(cmd, Mapping):
                cmd = {'command': cmd}

            try:
                out = self.send_command(**cmd)
            except AnsibleConnectionFailure as exception:

                if check_rc:
                    raise
                out = getattr(exception, 'err', exception)

            out = to_text(out, errors='surrogate_or_strict')

            responses.append(out)

        return responses 
Example #4
Source File: vmanage.py    From python-viptela with GNU General Public License v3.0 5 votes vote down vote up
def login(self, username, password):
        if username and password:
            payload = {'user': username, 'password': password}
            url = '/web_api/login'
            response, response_data = self.send_request(url, payload)
        else:
            raise AnsibleConnectionFailure('Username and password are required for login')

        try:
            self.connection._auth = {'X-chkp-sid': response_data['sid']}
            self.connection._session_uid = response_data['uid']
        except KeyError:
            raise ConnectionError(
                'Server returned response without token info during connection authentication: %s' % response) 
Example #5
Source File: vmanage.py    From python-viptela with GNU General Public License v3.0 5 votes vote down vote up
def send_request(self, path, body_params):
        data = json.dumps(body_params) if body_params else '{}'

        try:
            self._display_request()
            response, response_data = self.connection.send(path, data, method='POST', headers=BASE_HEADERS)
            value = self._get_response_value(response_data)

            return response.getcode(), self._response_to_json(value)
        except AnsibleConnectionFailure as e:
            return 404, 'Object not found'
        except HTTPError as e:
            error = json.loads(e.read())
            return e.code, error 
Example #6
Source File: ftd.py    From FTDAnsible with GNU General Public License v3.0 5 votes vote down vote up
def login(self, username, password):
        def request_token_payload(username, password):
            return {
                'grant_type': 'password',
                'username': username,
                'password': password
            }

        def refresh_token_payload(refresh_token):
            return {
                'grant_type': 'refresh_token',
                'refresh_token': refresh_token
            }

        if self.refresh_token:
            payload = refresh_token_payload(self.refresh_token)
        elif username and password:
            payload = request_token_payload(username, password)
        else:
            raise AnsibleConnectionFailure('Username and password are required for login in absence of refresh token')

        response = self._lookup_login_url(payload)

        try:
            self.refresh_token = response['refresh_token']
            self.access_token = response['access_token']
            self.connection._auth = {'Authorization': 'Bearer %s' % self.access_token}
        except KeyError:
            raise ConnectionError(
                'Server returned response without token info during connection authentication: %s' % response) 
Example #7
Source File: test_ftd.py    From FTDAnsible with GNU General Public License v3.0 5 votes vote down vote up
def test_login_raises_exception_when_no_refresh_token_and_no_credentials(self):
        with self.assertRaises(AnsibleConnectionFailure) as res:
            self.ftd_plugin.login(None, None)
        assert 'Username and password are required' in str(res.exception) 
Example #8
Source File: arubaoss.py    From aruba-ansible-modules with Apache License 2.0 5 votes vote down vote up
def on_open_shell(self):
        try:
            self._exec_cli_command(b'no pag')
        except AnsibleConnectionFailure:
            self._connection.queue_message('warning', 'Unable to configure paging, command responses may be truncated') 
Example #9
Source File: mitogen_kubectl.py    From mitogen with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        if kubectl is None:
            raise AnsibleConnectionFailure(self.not_supported_msg)
        super(Connection, self).__init__(*args, **kwargs)