当前位置: 首页>>代码示例>>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;未经允许,请勿转载。