本文整理汇总了Python中tower_cli.api.client.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: status
def status(self, pk=None, detail=False, **kwargs):
"""Print the current job status."""
# Get the job from Ansible Tower.
debug.log('Asking for project update status.', header='details')
project = client.get('/projects/%d/' % pk).json()
# Determine the appropriate project update.
if 'current_update' in project['related']:
debug.log('A current update exists; retrieving it.',
header='details')
job = client.get(project['related']['current_update'][7:]).json()
elif project['related'].get('last_update', None):
debug.log('No current update exists; retrieving the most '
'recent update.', header='details')
job = client.get(project['related']['last_update'][7:]).json()
else:
raise exc.NotFound('No project updates exist.')
# In most cases, we probably only want to know the status of the job
# and the amount of time elapsed. However, if we were asked for
# verbose information, provide it.
if detail:
return job
# Print just the information we need.
return {
'elapsed': job['elapsed'],
'failed': job['failed'],
'status': job['status'],
}
示例2: update
def update(self, inventory_source, monitor=False, timeout=None, **kwargs):
"""Update the given inventory source."""
# Establish that we are able to update this inventory source
# at all.
debug.log('Asking whether the inventory source can be updated.',
header='details')
r = client.get('%s%d/update/' % (self.endpoint, inventory_source))
if not r.json()['can_update']:
raise exc.BadRequest('Tower says it cannot run an update against '
'this inventory source.')
# Run the update.
debug.log('Updating the inventory source.', header='details')
r = client.post('%s%d/update/' % (self.endpoint, inventory_source))
# If we were told to monitor the project update's status, do so.
if monitor:
result = self.monitor(inventory_source, timeout=timeout)
inventory = client.get('/inventory_sources/%d/' %
result['inventory_source'])\
.json()['inventory']
result['inventory'] = int(inventory)
return result
# Done.
return {'status': 'ok'}
示例3: test_auth_error
def test_auth_error(self):
"""Establish that authentication errors raise the AuthError
exception.
"""
with client.test_mode as t:
t.register('/ping/', 'ERRORED!!', status_code=401)
with self.assertRaises(exc.AuthError):
client.get('/ping/')
示例4: test_forbidden_error
def test_forbidden_error(self):
"""Establish that forbidden errors raise the ForbiddenError
exception.
"""
with client.test_mode as t:
t.register('/ping/', 'ERRORED!!', status_code=403)
with self.assertRaises(exc.Forbidden):
client.get('/ping/')
示例5: test_not_found_error
def test_not_found_error(self):
"""Establish that authentication errors raise the NotFound
exception.
"""
with client.test_mode as t:
t.register('/ping/', 'ERRORED!!', status_code=404)
with self.assertRaises(exc.NotFound):
client.get('/ping/')
示例6: test_method_not_allowed_error
def test_method_not_allowed_error(self):
"""Establish that authentication errors raise the MethodNotAllowed
exception.
"""
with client.test_mode as t:
t.register('/ping/', 'ERRORED!!', status_code=405)
with self.assertRaises(exc.MethodNotAllowed):
client.get('/ping/')
示例7: test_bad_request_error
def test_bad_request_error(self):
"""Establish that other errors not covered above raise the
BadRequest exception.
"""
with client.test_mode as t:
t.register('/ping/', "I'm a teapot!", status_code=418)
with self.assertRaises(exc.BadRequest):
client.get('/ping/')
示例8: test_server_error
def test_server_error(self):
"""Establish that server errors raise the ServerError
exception as expected.
"""
with client.test_mode as t:
t.register('/ping/', 'ERRORED!!', status_code=500)
with self.assertRaises(exc.ServerError):
client.get('/ping/')
示例9: test_disable_connection_warning
def test_disable_connection_warning(self):
"""Establish that the --insecure flag will cause the program to
call disable_warnings in the urllib3 package.
"""
with mock.patch('requests.packages.urllib3.disable_warnings') as g:
with client.test_mode as t:
t.register('/ping/', "I'm a teapot!", status_code=200)
with settings.runtime_values(insecure=False):
client.get('/ping/')
assert g.called
示例10: test_failed_suggestion_protocol
def test_failed_suggestion_protocol(self):
"""Establish that if connection fails and protocol not given,
tower-cli suggests that to the user."""
with settings.runtime_values(verbose=False, host='foo.co'):
with mock.patch.object(Session, 'request') as req:
req.side_effect = requests.exceptions.SSLError
with mock.patch.object(click, 'secho') as secho:
with self.assertRaises(exc.ConnectionError):
client.get('/ping/')
self.assertTrue(secho.called)
示例11: test_connection_ssl_error
def test_connection_ssl_error(self):
"""Establish that if we get a ConnectionError or an SSLError
back from requests, that we deal with it nicely.
"""
for ErrorType in REQUESTS_ERRORS:
with settings.runtime_values(verbose=False, host='https://foo.co'):
with mock.patch.object(Session, 'request') as req:
req.side_effect = ErrorType
with self.assertRaises(exc.ConnectionError):
client.get('/ping/')
示例12: update
def update(self, inventory_source, monitor=False, wait=False,
timeout=None, **kwargs):
"""Update the given inventory source.
=====API DOCS=====
Update the given inventory source.
:param inventory_source: Primary key or name of the inventory source to be updated.
:type inventory_source: str
:param monitor: Flag that if set, immediately calls ``monitor`` on the newly launched inventory update
rather than exiting with a success.
:type monitor: bool
:param wait: Flag that if set, monitor the status of the inventory update, but do not print while it is
in progress.
:type wait: bool
:param timeout: If provided with ``monitor`` flag set, this attempt will time out after the given number
of seconds.
:type timeout: int
:param `**kwargs`: Fields used to override underlyingl inventory source fields when creating and launching
an inventory update.
:returns: Result of subsequent ``monitor`` call if ``monitor`` flag is on; Result of subsequent ``wait``
call if ``wait`` flag is on; dictionary of "status" if none of the two flags are on.
:rtype: dict
:raises tower_cli.exceptions.BadRequest: When the inventory source cannot be updated.
=====API DOCS=====
"""
# Establish that we are able to update this inventory source
# at all.
debug.log('Asking whether the inventory source can be updated.', header='details')
r = client.get('%s%d/update/' % (self.endpoint, inventory_source))
if not r.json()['can_update']:
raise exc.BadRequest('Tower says it cannot run an update against this inventory source.')
# Run the update.
debug.log('Updating the inventory source.', header='details')
r = client.post('%s%d/update/' % (self.endpoint, inventory_source), data={})
inventory_update_id = r.json()['inventory_update']
# If we were told to monitor the project update's status, do so.
if monitor or wait:
if monitor:
result = self.monitor(inventory_update_id, parent_pk=inventory_source, timeout=timeout)
elif wait:
result = self.wait(inventory_update_id, parent_pk=inventory_source, timeout=timeout)
inventory = client.get('/inventory_sources/%d/' % result['inventory_source']).json()['inventory']
result['inventory'] = int(inventory)
return result
# Done.
return {
'id': inventory_update_id,
'status': 'ok'
}
示例13: test_connection_ssl
def test_connection_ssl(self):
with client.test_mode as t:
t.register_json('/ping/', {'status': 'ok'})
https_adapter = client.adapters['https://']
with mock.patch.object(FauxAdapter, 'send', wraps=https_adapter.send) as mock_send:
client.get('/ping/')
mock_send.assert_called_once_with(
mock.ANY, cert=None, proxies=mock.ANY, stream=mock.ANY,
timeout=mock.ANY, verify=True
)
self.assertTrue(mock_send.call_args[1]['verify'])
示例14: test_connection_ssl_error_verbose
def test_connection_ssl_error_verbose(self):
"""Establish that if we get a ConnectionError or an SSLError
back from requests, that we deal with it nicely, and
additionally print the internal error if verbose is True.
"""
for ErrorType in REQUESTS_ERRORS:
with settings.runtime_values(verbose=True, host='https://foo.co'):
with mock.patch.object(Session, 'request') as req:
req.side_effect = ErrorType
with mock.patch.object(debug, 'log') as dlog:
with self.assertRaises(exc.ConnectionError):
client.get('/ping/')
self.assertEqual(dlog.call_count, 5)
示例15: list
def list(self, root=False, **kwargs):
"""Return a list of groups."""
# Option to list children of a parent group
if kwargs.get('parent', None):
self.set_child_endpoint(
parent=kwargs['parent'],
inventory=kwargs.get('inventory', None)
)
kwargs.pop('parent')
# Sanity check: If we got `--root` and no inventory, that's an
# error.
if root and not kwargs.get('inventory', None):
raise exc.UsageError('The --root option requires specifying an '
'inventory also.')
# If we are tasked with getting root groups, do that.
if root:
inventory_id = kwargs['inventory']
r = client.get('/inventories/%d/root_groups/' % inventory_id)
return r.json()
# Return the superclass implementation.
return super(Resource, self).list(**kwargs)