Skip to content

Commit

Permalink
Add cdp_region to common SDK options
Browse files Browse the repository at this point in the history
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
  • Loading branch information
wmudge committed Dec 21, 2023
1 parent b5c8fac commit ac14ea4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
9 changes: 9 additions & 0 deletions plugins/doc_fragments/cdp_sdk_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class ModuleDocFragment(object):
default: False
aliases:
- debug_endpoints
cdp_region:
description:
- Specify the Cloudera Data Platform endpoint region.
type: str
required: False
default: "default"
aliases:
- cdp_endpoint_region
- endpoint_region
'''

RETURN = r'''
Expand Down
47 changes: 29 additions & 18 deletions plugins/module_utils/cdp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@


__credits__ = ["cleroy@cloudera.com"]
__maintainer__ = [
"dchaffelson@cloudera.com",
"wmudge@cloudera.com"
]
__maintainer__ = ["dchaffelson@cloudera.com", "wmudge@cloudera.com"]


class CdpModule(object):
"""A base CDP module class for common parameters, fields, and methods."""

class _Decorators(object):
@classmethod
def process_debug(cls, f):
Expand All @@ -50,11 +48,11 @@ def _impl(self, *args, **kwargs):
def __init__(self, module):
# Set common parameters
self.module = module
self.tls = self._get_param('verify_tls', False)
self.debug = self._get_param('debug', False)
self.strict = self._get_param('strict', False)
self.agent_header = self._get_param('agent_header', 'ClouderaFoundry')
self.cp_region = self._get_param('cp_region', 'default')
self.tls = self._get_param("verify_tls", False)
self.debug = self._get_param("debug", False)
self.strict = self._get_param("strict", False)
self.agent_header = self._get_param("agent_header", "ClouderaFoundry")
self.cdp_region = self._get_param("cdp_region", "default")

# Initialize common return values
self.log_out = None
Expand All @@ -69,7 +67,7 @@ def __init__(self, module):
error_handler=self._cdp_module_throw_error,
warning_handler=self._cdp_module_throw_warning,
agent_header=self.agent_header,
cp_region=self.cp_region
cp_region=self.cdp_region, # Note, parameter name switch
)

# Private functions
Expand All @@ -80,11 +78,15 @@ def _get_param(self, param, default=None):
return self.module.params[param] if param in self.module.params else default
return default

def _cdp_module_throw_error(self, error: 'CdpError'):
def _cdp_module_throw_error(self, error: "CdpError"):
"""Error handler for CDPy SDK"""
self.module.fail_json(msg=str(error.message), error=str(error.__dict__), violations=error.violations)
self.module.fail_json(
msg=str(error.message),
error=str(error.__dict__),
violations=error.violations,
)

def _cdp_module_throw_warning(self, warning: 'CdpWarning'):
def _cdp_module_throw_warning(self, warning: "CdpWarning"):
"""Warning handler for CDPy SDK"""
if self.module._debug or self.module._verbosity >= 2:
self.module.warn(warning.message)
Expand All @@ -94,9 +96,18 @@ def argument_spec(**spec):
"""Default Ansible Module spec values for convenience"""
return dict(
**spec,
verify_tls=dict(required=False, type='bool', default=True, aliases=['tls']),
debug=dict(required=False, type='bool', default=False, aliases=['debug_endpoints']),
strict=dict(required=False, type='bool', default=False, aliases=['strict_errors']),
agent_header=dict(required=False, type='str', default='ClouderaFoundry'),
cp_region=dict(required=False, type='str', default='default')
verify_tls=dict(required=False, type="bool", default=True, aliases=["tls"]),
debug=dict(
required=False, type="bool", default=False, aliases=["debug_endpoints"]
),
strict=dict(
required=False, type="bool", default=False, aliases=["strict_errors"]
),
agent_header=dict(required=False, type="str", default="ClouderaFoundry"),
cdp_region=dict(
required=False,
type="str",
default="default",
aliases=["cdp_endpoint_region", "endpoint_region"],
)
)

0 comments on commit ac14ea4

Please sign in to comment.