Skip to content

Commit

Permalink
Add CM Service module (#194)
Browse files Browse the repository at this point in the history
* Add wait_for_command_state function to cm_utils
* Add pytest for CM Service module

Signed-off-by: rsuplina <[email protected]>
  • Loading branch information
rsuplina authored Jan 24, 2024
1 parent 6a2326c commit 049fb36
Show file tree
Hide file tree
Showing 3 changed files with 460 additions and 2 deletions.
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

0 comments on commit 049fb36

Please sign in to comment.