Skip to content

Commit a5e087e

Browse files
author
Florent Flament
committed
Displaying curl commands for nova and cinder calls
When using the -v option, displays curl equivalent commands and http messages exchanged with the nova and cinder API servers. Displays the same messages as those displayed with the --debug option of python-novaclient and python-cinderclient. Implements: blueprint curl-commands-in-debugging-messages for nova and cinder related calls Change-Id: Ibc8ef79d874334585b81d652b9c7df9e874fffa9
1 parent de27c1b commit a5e087e

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎openstackclient/common/utils.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Common client utilities"""
1717

18+
import logging
1819
import os
1920
import six
2021
import sys
@@ -215,3 +216,16 @@ def wait_for_status(status_f,
215216
callback(progress)
216217
time.sleep(sleep_time)
217218
return retval
219+
220+
221+
def get_effective_log_level():
222+
"""Returns the lowest logging level considered by logging handlers
223+
224+
Retrieve an return the smallest log level set among the root
225+
logger's handlers (in case of multiple handlers).
226+
"""
227+
root_log = logging.getLogger()
228+
min_log_lvl = logging.CRITICAL
229+
for handler in root_log.handlers:
230+
min_log_lvl = min(min_log_lvl, handler.level)
231+
return min_log_lvl

‎openstackclient/compute/client.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def make_client(instance):
3535
instance._api_version[API_NAME],
3636
API_VERSIONS)
3737
LOG.debug('instantiating compute client: %s' % compute_client)
38+
39+
# Set client http_log_debug to True if verbosity level is high enough
40+
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
41+
3842
client = compute_client(
3943
username=instance._username,
4044
api_key=instance._password,
@@ -49,7 +53,8 @@ def make_client(instance):
4953
extensions=[],
5054
service_type=API_NAME,
5155
# FIXME(dhellmann): what is service_name?
52-
service_name='')
56+
service_name='',
57+
http_log_debug=http_log_debug)
5358

5459
# Populate the Nova client to skip another auth query to Identity
5560
if instance._url:

‎openstackclient/volume/client.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ def make_client(instance):
3737
)
3838

3939
LOG.debug('instantiating volume client')
40+
41+
# Set client http_log_debug to True if verbosity level is high enough
42+
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
43+
4044
client = volume_client(
4145
username=instance._username,
4246
api_key=instance._password,
4347
project_id=instance._project_name,
4448
auth_url=instance._auth_url,
4549
cacert=instance._cacert,
4650
insecure=instance._insecure,
51+
http_log_debug=http_log_debug
4752
)
4853

4954
return client

0 commit comments

Comments
 (0)