本文整理汇总了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
示例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)
示例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
示例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)
示例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)
示例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')
示例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')
示例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)