Skip to content

Commit

Permalink
Enable sdk log gathering (#125)
Browse files Browse the repository at this point in the history
Enable sdk log gathering

Reviewed-by: OpenTelekomCloud Bot
  • Loading branch information
gtema authored Nov 28, 2022
1 parent 6b1d83c commit 4c3d199
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/doc_fragments/otc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class ModuleDocFragment(object):
choices: [ admin, internal, public ]
default: public
aliases: [ endpoint_type ]
sdk_log_path:
description:
- Path to the logfile of the OpenStackSDK. If empty no log is written
type: str
sdk_log_level:
description: Log level of the OpenStackSDK
type: str
default: WARN
choices: [ERROR, WARN, INFO, DEBUG]
requirements:
- python >= 3.6
- openstacksdk >= 0.36.0
Expand Down
14 changes: 14 additions & 0 deletions plugins/module_utils/otc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def openstack_full_argument_spec(**kwargs):
interface=dict(
default='public', choices=['public', 'internal', 'admin'],
aliases=['endpoint_type']),
sdk_log_path=dict(default=None, type='str'),
sdk_log_level=dict(
default='WARN', type='str', choices=['ERROR', 'WARN', 'INFO', 'DEBUG'])
)
spec.update(kwargs)
return spec
Expand Down Expand Up @@ -95,6 +98,7 @@ def __init__(self):
self.exit = self.exit_json = self.ansible.exit_json
self.fail = self.fail_json = self.ansible.fail_json
self.sdk, self.conn = self.openstack_cloud_from_module()
self.setup_sdk_logging()

def log(self, msg):
"""Prints log message to system log.
Expand All @@ -114,6 +118,16 @@ def debug(self, msg):
self.ansible.log(
" ".join(['[DEBUG]', msg]))

def setup_sdk_logging(self):
log_path = self.params.get('sdk_log_path')
if log_path is not None:
log_level = self.params.get('sdk_log_level')
sdk.enable_logging(
debug=True if log_level == 'DEBUG' else False,
http_debug=True if log_level == 'DEBUG' else False,
path=log_path
)

def openstack_cloud_from_module(self, min_version='0.6.9'):
if self.otce_min_version:
min_version = self.otce_min_version
Expand Down

0 comments on commit 4c3d199

Please sign in to comment.