Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# Keep the Galaxy builds
!cloudera-cluster-*.tar.gz

# Ignore the cm-client build
cm-client

# Ignore the test output
tests/output

Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/cm_controller_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initialize_client(self):
else:
config.host = self._discover_endpoint(config)

self.api_client = ApiClient()
self.api_client = ApiClient(configuration=config)

def _setup_logger(self, log_level, log_format):
"""Configures the logging of the HTTP activity"""
Expand Down
18 changes: 9 additions & 9 deletions plugins/module_utils/cm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ansible.module_utils.common.dict_transformations import recursive_diff
from ansible.module_utils.common.text.converters import to_native, to_text
from time import sleep

from cm_client import (
ApiBulkCommandList,
ApiClient,
Expand All @@ -42,11 +43,10 @@
ApiConfigList,
ApiEntityTag,
Configuration,
ClouderaManagerResourceApi,
CommandsResourceApi,
)
from cm_client.rest import ApiException, RESTClientObject
from cm_client.apis.cloudera_manager_resource_api import ClouderaManagerResourceApi
from cm_client.apis.commands_resource_api import CommandsResourceApi


__credits__ = ["[email protected]"]
__maintainer__ = ["[email protected]"]
Expand Down Expand Up @@ -485,6 +485,8 @@ def __init__(self, module: AnsibleModule):

self.logger.debug("CM API agent: %s", self.agent_header)

self.client_config = config

if self.verify_tls is False:
disable_warnings(InsecureRequestWarning)

Expand All @@ -499,17 +501,15 @@ def get_param(self, param, default=None):

def initialize_client(self):
"""Creates the CM API client"""
config = Configuration()

# If provided a CM endpoint URL, use it directly
if self.url:
config.host = str(self.url).rstrip(" /")
self.client_config.host = str(self.url).rstrip(" /")
# Otherwise, run discovery on missing parts
else:
config.host = self.discover_endpoint(config)
self.client_config.host = self.discover_endpoint(self.client_config)

# Create and set the API Client
self.api_client = ApiClient()
self.api_client = ApiClient(configuration=self.client_config)

# Update the User Agent
self.api_client.user_agent = self.agent_header
Expand All @@ -528,7 +528,7 @@ def discover_endpoint(self, config):
"""Discovers the scheme and version of a potential Cloudara Manager host."""
# Get the authentication headers and REST client
headers = self.get_auth_headers(config)
rest = RESTClientObject()
rest = RESTClientObject(config)

# Resolve redirects to establish HTTP scheme and port
pre_rendered = Url(
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"molecule-plugins[ec2]",
"ansible-core<2.17", # For RHEL 8 support
"jmespath",
"cm-client",
# "cm-client", # Use hatch run install-cm-client
"python-gnupg",
"ansible-lint",
"antsibull-docs >= 2.0.0, < 3.0.0",
Expand All @@ -43,6 +43,13 @@ lint = [
"pre-commit run -a",
"antsibull-docs lint-collection-docs --plugin-docs --validate-collection-refs=all --skip-rstcheck .",
]
install-cm-client = [
"mkdir -p cm-client",
"curl -L https://archive.cloudera.com/cm7/7.13.1/generic/jar/cm_api/cloudera-manager-api-swagger-7.13.1.tar -o cm-client/cloudera-manager-api.tar",
"tar xf cm-client/cloudera-manager-api.tar -C cm-client",
"pip install cm-client/swagger/python",
"rm -r cm-client",
]

[tool.hatch.envs.docs]
python = "3.12"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def cm_api_client(conn) -> ApiClient:
# Set host
config.host = f"{url}/api/{version}"

client = ApiClient()
client = ApiClient(configuration=config)
client.user_agent = "pytest"
return client

Expand Down
Loading