當前位置: 首頁>>代碼示例>>Python>>正文


Python errors.AnsibleConnectionFailure方法代碼示例

本文整理匯總了Python中ansible.errors.AnsibleConnectionFailure方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.AnsibleConnectionFailure方法的具體用法?Python errors.AnsibleConnectionFailure怎麽用?Python errors.AnsibleConnectionFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ansible.errors的用法示例。


在下文中一共展示了errors.AnsibleConnectionFailure方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_commands

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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 
開發者ID:aruba,項目名稱:aruba-ansible-modules,代碼行數:27,代碼來源:arubaoss.py

示例2: login

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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) 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:16,代碼來源:vmanage.py

示例3: send_request

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:16,代碼來源:vmanage.py

示例4: login

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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) 
開發者ID:CiscoDevNet,項目名稱:FTDAnsible,代碼行數:32,代碼來源:ftd.py

示例5: test_login_raises_exception_when_no_refresh_token_and_no_credentials

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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) 
開發者ID:CiscoDevNet,項目名稱:FTDAnsible,代碼行數:6,代碼來源:test_ftd.py

示例6: on_open_shell

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
def on_open_shell(self):
        try:
            self._exec_cli_command('screen-length 0 temporary')
        except AnsibleConnectionFailure:
            raise AnsibleConnectionFailure('unable to set terminal parameters') 
開發者ID:HuaweiSwitch,項目名稱:CloudEngine-Ansible,代碼行數:7,代碼來源:ce.py

示例7: on_open_shell

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
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') 
開發者ID:aruba,項目名稱:aruba-ansible-modules,代碼行數:7,代碼來源:aruba.py

示例8: __init__

# 需要導入模塊: from ansible import errors [as 別名]
# 或者: from ansible.errors import AnsibleConnectionFailure [as 別名]
def __init__(self, *args, **kwargs):
        if kubectl is None:
            raise AnsibleConnectionFailure(self.not_supported_msg)
        super(Connection, self).__init__(*args, **kwargs) 
開發者ID:dw,項目名稱:mitogen,代碼行數:6,代碼來源:mitogen_kubectl.py


注:本文中的ansible.errors.AnsibleConnectionFailure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。