Bring back the output from client.http_log()
Ported from novaclient https://review.openstack.org/9241 Support CINDERCLIENT_DEBUG as synonym for --debug Change-Id: Ic03b9e7d84c8db14f6e193ca2b478fd0d70d1299
This commit is contained in:
@@ -31,13 +31,6 @@ from cinderclient import service_catalog
|
|||||||
from cinderclient import utils
|
from cinderclient import utils
|
||||||
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
if 'CINDERCLIENT_DEBUG' in os.environ and os.environ['CINDERCLIENT_DEBUG']:
|
|
||||||
ch = logging.StreamHandler()
|
|
||||||
_logger.setLevel(logging.DEBUG)
|
|
||||||
_logger.addHandler(ch)
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPClient(httplib2.Http):
|
class HTTPClient(httplib2.Http):
|
||||||
|
|
||||||
USER_AGENT = 'python-cinderclient'
|
USER_AGENT = 'python-cinderclient'
|
||||||
@@ -46,7 +39,8 @@ class HTTPClient(httplib2.Http):
|
|||||||
timeout=None, tenant_id=None, proxy_tenant_id=None,
|
timeout=None, tenant_id=None, proxy_tenant_id=None,
|
||||||
proxy_token=None, region_name=None,
|
proxy_token=None, region_name=None,
|
||||||
endpoint_type='publicURL', service_type=None,
|
endpoint_type='publicURL', service_type=None,
|
||||||
service_name=None, volume_service_name=None, retries=None):
|
service_name=None, volume_service_name=None, retries=None,
|
||||||
|
http_log_debug=False):
|
||||||
super(HTTPClient, self).__init__(timeout=timeout)
|
super(HTTPClient, self).__init__(timeout=timeout)
|
||||||
self.user = user
|
self.user = user
|
||||||
self.password = password
|
self.password = password
|
||||||
@@ -60,6 +54,7 @@ class HTTPClient(httplib2.Http):
|
|||||||
self.service_name = service_name
|
self.service_name = service_name
|
||||||
self.volume_service_name = volume_service_name
|
self.volume_service_name = volume_service_name
|
||||||
self.retries = int(retries or 0)
|
self.retries = int(retries or 0)
|
||||||
|
self.http_log_debug = http_log_debug
|
||||||
|
|
||||||
self.management_url = None
|
self.management_url = None
|
||||||
self.auth_token = None
|
self.auth_token = None
|
||||||
@@ -70,8 +65,14 @@ class HTTPClient(httplib2.Http):
|
|||||||
self.force_exception_to_status_code = True
|
self.force_exception_to_status_code = True
|
||||||
self.disable_ssl_certificate_validation = insecure
|
self.disable_ssl_certificate_validation = insecure
|
||||||
|
|
||||||
|
self._logger = logging.getLogger(__name__)
|
||||||
|
if self.http_log_debug:
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
self._logger.setLevel(logging.DEBUG)
|
||||||
|
self._logger.addHandler(ch)
|
||||||
|
|
||||||
def http_log(self, args, kwargs, resp, body):
|
def http_log(self, args, kwargs, resp, body):
|
||||||
if not _logger.isEnabledFor(logging.DEBUG):
|
if not self.http_log_debug:
|
||||||
return
|
return
|
||||||
|
|
||||||
string_parts = ['curl -i']
|
string_parts = ['curl -i']
|
||||||
@@ -85,10 +86,10 @@ class HTTPClient(httplib2.Http):
|
|||||||
header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
|
header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
|
||||||
string_parts.append(header)
|
string_parts.append(header)
|
||||||
|
|
||||||
_logger.debug("REQ: %s\n" % "".join(string_parts))
|
self._logger.debug("REQ: %s\n" % "".join(string_parts))
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
_logger.debug("REQ BODY: %s\n" % (kwargs['body']))
|
self._logger.debug("REQ BODY: %s\n" % (kwargs['body']))
|
||||||
_logger.debug("RESP:%s %s\n", resp, body)
|
self._logger.debug("RESP:%s %s\n", resp, body)
|
||||||
|
|
||||||
def request(self, *args, **kwargs):
|
def request(self, *args, **kwargs):
|
||||||
kwargs.setdefault('headers', kwargs.get('headers', {}))
|
kwargs.setdefault('headers', kwargs.get('headers', {}))
|
||||||
@@ -140,7 +141,7 @@ class HTTPClient(httplib2.Http):
|
|||||||
except exceptions.Unauthorized:
|
except exceptions.Unauthorized:
|
||||||
if auth_attempts > 0:
|
if auth_attempts > 0:
|
||||||
raise
|
raise
|
||||||
_logger.debug("Unauthorized, reauthenticating.")
|
self._logger.debug("Unauthorized, reauthenticating.")
|
||||||
self.management_url = self.auth_token = None
|
self.management_url = self.auth_token = None
|
||||||
# First reauth. Discount this attempt.
|
# First reauth. Discount this attempt.
|
||||||
attempts -= 1
|
attempts -= 1
|
||||||
@@ -153,7 +154,8 @@ class HTTPClient(httplib2.Http):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
_logger.debug("Failed attempt(%s of %s), retrying in %s seconds" %
|
self._logger.debug(
|
||||||
|
"Failed attempt(%s of %s), retrying in %s seconds" %
|
||||||
(attempts, self.retries, backoff))
|
(attempts, self.retries, backoff))
|
||||||
sleep(backoff)
|
sleep(backoff)
|
||||||
backoff *= 2
|
backoff *= 2
|
||||||
@@ -223,7 +225,7 @@ class HTTPClient(httplib2.Http):
|
|||||||
# GET ...:5001/v2.0/tokens/#####/endpoints
|
# GET ...:5001/v2.0/tokens/#####/endpoints
|
||||||
url = '/'.join([url, 'tokens', '%s?belongsTo=%s'
|
url = '/'.join([url, 'tokens', '%s?belongsTo=%s'
|
||||||
% (self.proxy_token, self.proxy_tenant_id)])
|
% (self.proxy_token, self.proxy_tenant_id)])
|
||||||
_logger.debug("Using Endpoint URL: %s" % url)
|
self._logger.debug("Using Endpoint URL: %s" % url)
|
||||||
resp, body = self.request(url, "GET",
|
resp, body = self.request(url, "GET",
|
||||||
headers={'X-Auth_Token': self.auth_token})
|
headers={'X-Auth_Token': self.auth_token})
|
||||||
return self._extract_service_catalog(url, resp, body,
|
return self._extract_service_catalog(url, resp, body,
|
||||||
|
@@ -81,8 +81,9 @@ class OpenStackCinderShell(object):
|
|||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
parser.add_argument('--debug',
|
parser.add_argument('--debug',
|
||||||
default=False,
|
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
default=utils.env('CINDERCLIENT_DEBUG',
|
||||||
|
default=False),
|
||||||
help="Print debugging output")
|
help="Print debugging output")
|
||||||
|
|
||||||
parser.add_argument('--os-username',
|
parser.add_argument('--os-username',
|
||||||
@@ -415,7 +416,8 @@ class OpenStackCinderShell(object):
|
|||||||
service_type=service_type,
|
service_type=service_type,
|
||||||
service_name=service_name,
|
service_name=service_name,
|
||||||
volume_service_name=volume_service_name,
|
volume_service_name=volume_service_name,
|
||||||
retries=options.retries)
|
retries=options.retries,
|
||||||
|
http_log_debug=args.debug)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not utils.isunauthenticated(args.func):
|
if not utils.isunauthenticated(args.func):
|
||||||
|
@@ -27,7 +27,8 @@ class Client(object):
|
|||||||
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
||||||
endpoint_type='publicURL', extensions=None,
|
endpoint_type='publicURL', extensions=None,
|
||||||
service_type='volume', service_name=None,
|
service_type='volume', service_name=None,
|
||||||
volume_service_name=None, retries=None):
|
volume_service_name=None, retries=None,
|
||||||
|
http_log_debug=False):
|
||||||
# FIXME(comstud): Rename the api_key argument above when we
|
# FIXME(comstud): Rename the api_key argument above when we
|
||||||
# know it's not being used as keyword argument
|
# know it's not being used as keyword argument
|
||||||
password = api_key
|
password = api_key
|
||||||
@@ -62,7 +63,8 @@ class Client(object):
|
|||||||
service_type=service_type,
|
service_type=service_type,
|
||||||
service_name=service_name,
|
service_name=service_name,
|
||||||
volume_service_name=volume_service_name,
|
volume_service_name=volume_service_name,
|
||||||
retries=retries)
|
retries=retries,
|
||||||
|
http_log_debug=http_log_debug)
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user