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
15 changes: 13 additions & 2 deletions plugins/module_utils/cm_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Cloudera, Inc. All Rights Reserved.
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,13 +25,14 @@
from urllib3.exceptions import InsecureRequestWarning, MaxRetryError, HTTPError
from urllib3.util import Url
from urllib.parse import urljoin

from time import sleep
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_text

from cm_client import ApiClient, Configuration
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]"]
Expand Down Expand Up @@ -207,6 +208,16 @@ def set_session_cookie(self):
api_instance.get_version()
self.api_client.cookie = self.api_client.last_response.getheader("Set-Cookie")

def wait_for_command_state(self,command_id, polling_interval):
command_api_instance = CommandsResourceApi(self.api_client)
while True:
get_command_state = command_api_instance.read_command_with_http_info(command_id=command_id)
state = get_command_state[0].active
if not state:
break
sleep(polling_interval)
return True

def call_api(self, path, method, query=None, field="items", body=None):
"""Wrapper to call a CM API endpoint path directly."""
path_params = []
Expand Down
Loading