-
Notifications
You must be signed in to change notification settings - Fork 43
[Enabler][zos_operator] Update module interface #2230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fernandofloresg
merged 19 commits into
dev
from
enabler/2158/update_zos_operator_interface
Aug 12, 2025
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
37c1191
Test
AndreMarcel99 f14e24b
Fix test xos operator
fecf0ff
Fix tab
93487cf
Fix tab
8860671
Fix tab
da1943c
Fix tab
5c773a3
Fix tab
627fe1b
Fix tab
340cd04
Fix tab
6d1b262
Fix tab
fa45568
Add fragment
593adc1
Fix sanity
c808e84
Update changelogs/fragments/2230_zos_operator_interface_update.yml
AndreMarcel99 c7e816d
Update changelogs/fragments/2230_zos_operator_interface_update.yml
AndreMarcel99 359fd0d
Update plugins/modules/zos_operator.py
AndreMarcel99 29ab62d
Update plugins/modules/zos_operator.py
AndreMarcel99 5c390a1
Update plugins/modules/zos_operator.py
AndreMarcel99 aabc7a4
Fix validation
e1963c8
Modify operation test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
breaking_changes: | ||
- zos_operator - Option ``wait_time_s`` is deprecated in favor of ``wait_time``. New option ``time_unit`` is added to select | ||
seconds or centiseconds. New return value ``time_unit`` is added. Return value ``wait_time_s`` is deprecated in favor of ``wait_time``. | ||
AndreMarcel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(https://github.com/ansible-collections/ibm_zos_core/pull/2230). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,17 +50,26 @@ | |
type: bool | ||
required: false | ||
default: false | ||
wait_time_s: | ||
wait_time: | ||
description: | ||
- Set maximum time in seconds to wait for the commands to execute. | ||
- When set to 0, the system default is used. | ||
- This option is helpful on a busy system requiring more time to execute | ||
commands. | ||
- Setting I(wait) can instruct if execution should wait the | ||
full I(wait_time_s). | ||
full I(wait_time). | ||
type: int | ||
required: false | ||
default: 1 | ||
time_unit: | ||
description: | ||
- Set the C(wait_time) unit of time, could be s(seconds) or cs(centiseconds). | ||
AndreMarcel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: str | ||
required: false | ||
default: s | ||
choices : | ||
AndreMarcel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- s | ||
- cs | ||
case_sensitive: | ||
description: | ||
- If C(true), the command will not be converted to uppercase before | ||
|
@@ -103,11 +112,17 @@ | |
- name: Execute operator command to show jobs, always waiting 5 seconds for response | ||
zos_operator: | ||
cmd: 'd a,all' | ||
wait_time_s: 5 | ||
wait_time: 5 | ||
|
||
- name: Display the system symbols and associated substitution texts. | ||
zos_operator: | ||
cmd: 'D SYMBOLS' | ||
|
||
- name: Execute an operator command to show device status and allocation wait 10 centiseconds. | ||
zos_operator: | ||
cmd: 'd u' | ||
wait_time : 10 | ||
time_unit : 'cs' | ||
""" | ||
|
||
RETURN = r""" | ||
|
@@ -125,16 +140,22 @@ | |
sample: d u,all | ||
elapsed: | ||
description: | ||
The number of seconds that elapsed waiting for the command to complete. | ||
The number of seconds or centiseconds that elapsed waiting for the command to complete. | ||
returned: always | ||
type: float | ||
sample: 51.53 | ||
wait_time_s: | ||
wait_time: | ||
description: | ||
The maximum time in seconds to wait for the commands to execute. | ||
The maximum time in the time_unit set to wait for the commands to execute. | ||
returned: always | ||
type: int | ||
sample: 5 | ||
time_unit: | ||
description: | ||
The time_unit set for wait_time. | ||
AndreMarcel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
returned: always | ||
type: str | ||
sample: s | ||
content: | ||
description: | ||
The resulting text from the command submitted. | ||
|
@@ -200,14 +221,16 @@ | |
opercmd = ZOAUImportError(traceback.format_exc()) | ||
|
||
|
||
def execute_command(operator_cmd, timeout_s=1, preserve=False, *args, **kwargs): | ||
def execute_command(operator_cmd, time_unit, timeout=1, preserve=False, *args, **kwargs): | ||
""" | ||
Executes an operator command. | ||
|
||
Parameters | ||
---------- | ||
operator_cmd : str | ||
Command to execute. | ||
time_unit : str | ||
Unit of time to wait of execution of the command. | ||
timeout : int | ||
Time until it stops whether it finished or not. | ||
preserve : bool | ||
|
@@ -223,15 +246,20 @@ def execute_command(operator_cmd, timeout_s=1, preserve=False, *args, **kwargs): | |
Return code, standard output, standard error and time elapsed from start to finish. | ||
""" | ||
# as of ZOAU v1.3.0, timeout is measured in centiseconds, therefore: | ||
timeout_c = 100 * timeout_s | ||
if time_unit == "s": | ||
timeout = 100 * timeout | ||
|
||
start = timer() | ||
response = opercmd.execute(operator_cmd, timeout=timeout_c, preserve=preserve, *args, **kwargs) | ||
response = opercmd.execute(operator_cmd, timeout=timeout, preserve=preserve, *args, **kwargs) | ||
end = timer() | ||
rc = response.rc | ||
stdout = response.stdout_response | ||
stderr = response.stderr_response | ||
elapsed = round(end - start, 2) | ||
if time_unit != "s": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could just check if |
||
elapsed = round((end - start) * 100, 2) | ||
else: | ||
elapsed = round(end - start, 2) | ||
|
||
return rc, stdout, stderr, elapsed | ||
|
||
|
||
|
@@ -252,7 +280,8 @@ def run_module(): | |
module_args = dict( | ||
cmd=dict(type="str", required=True), | ||
verbose=dict(type="bool", required=False, default=False), | ||
wait_time_s=dict(type="int", required=False, default=1), | ||
wait_time=dict(type="int", required=False, default=1), | ||
time_unit=dict(type="str", required=False, choices=["s", "cs"], default="s"), | ||
case_sensitive=dict(type="bool", required=False, default=False), | ||
) | ||
|
||
|
@@ -294,7 +323,8 @@ def run_module(): | |
# call is returned from run_operator_command, specifying what was run. | ||
# result["cmd"] = new_params.get("cmd") | ||
result["cmd"] = rc_message.get("call") | ||
result["wait_time_s"] = new_params.get("wait_time_s") | ||
result["wait_time"] = new_params.get("wait_time") | ||
result["time_unit"] = new_params.get("time_unit") | ||
result["changed"] = False | ||
|
||
# rc=0, something succeeded (the calling script ran), | ||
|
@@ -309,7 +339,8 @@ def run_module(): | |
module.fail_json(msg=("A non-zero return code was received : {0}. Review the response for more details.").format(result["rc"]), | ||
cmd=result["cmd"], | ||
elapsed_time=result["elapsed"], | ||
wait_time_s=result["wait_time_s"], | ||
wait_time=result["wait_time"], | ||
time_unit=result["time_unit"], | ||
stderr=str(error) if error is not None else result["content"], | ||
stderr_lines=str(error).splitlines() if error is not None else result["content"], | ||
changed=result["changed"],) | ||
|
@@ -338,9 +369,10 @@ def parse_params(params): | |
""" | ||
arg_defs = dict( | ||
cmd=dict(arg_type="str", required=True), | ||
verbose=dict(arg_type="bool", required=False), | ||
wait_time_s=dict(arg_type="int", required=False), | ||
case_sensitive=dict(arg_type="bool", required=False), | ||
verbose=dict(arg_type="bool", required=False, default=False), | ||
wait_time=dict(arg_type="int", required=False, default=1), | ||
time_unit=dict(type="str", required=False, choices=["s", "cs"], default="s"), | ||
case_sensitive=dict(arg_type="bool", required=False, default=False), | ||
) | ||
parser = BetterArgParser(arg_defs) | ||
new_params = parser.parse_args(params) | ||
|
@@ -369,7 +401,8 @@ def run_operator_command(params): | |
kwargs.update({"verbose": True}) | ||
kwargs.update({"debug": True}) | ||
|
||
wait_s = params.get("wait_time_s") | ||
wait_time = params.get("wait_time") | ||
time_unit = params.get("time_unit") | ||
cmdtxt = params.get("cmd") | ||
preserve = params.get("case_sensitive") | ||
|
||
|
@@ -381,7 +414,7 @@ def run_operator_command(params): | |
kwargs.update({"wait": True}) | ||
|
||
args = [] | ||
rc, stdout, stderr, elapsed = execute_command(cmdtxt, timeout_s=wait_s, preserve=preserve, *args, **kwargs) | ||
rc, stdout, stderr, elapsed = execute_command(cmdtxt, time_unit=time_unit, timeout=wait_time, preserve=preserve, *args, **kwargs) | ||
|
||
if rc > 0: | ||
message = "\nOut: {0}\nErr: {1}\nRan: {2}".format(stdout, stderr, cmdtxt) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.