本文整理匯總了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)