Skip to content
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

zos_data_set - add force parameter to enable member delete via disp shr #718

Merged
merged 7 commits into from
Apr 10, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- zos_data_set - add force parameter to enable member delete while pdse is in use (https://github.com/ansible-collections/ibm_zos_core/pull/718).
19 changes: 14 additions & 5 deletions plugins/module_utils/data_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) IBM Corporation 2020
# Copyright (c) IBM Corporation 2020, 2023
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -116,6 +116,7 @@ def ensure_present(
sms_management_class=None,
volumes=None,
tmp_hlq=None,
force=None,
):
"""Creates data set if it does not already exist.

Expand Down Expand Up @@ -171,6 +172,8 @@ def ensure_present(
has GUARANTEED_SPACE=YES specified. Otherwise, the allocation will fail.
Defaults to None.
tmp_hlq (str, optional): High level qualifier for temporary datasets.
force (bool, optional): Used to determine behavior when performing member operations on a pdse.
Defaults to None.

Returns:
bool -- Indicates if changes were made.
Expand Down Expand Up @@ -247,11 +250,11 @@ def ensure_member_present(name, replace=False):
return True

@staticmethod
def ensure_member_absent(name):
def ensure_member_absent(name, force=False):
"""Deletes provided data set member if it exists.
Returns a boolean indicating if changes were made."""
if DataSet.data_set_member_exists(name):
DataSet.delete_member(name)
DataSet.delete_member(name, force)
return True
return False

Expand Down Expand Up @@ -772,6 +775,7 @@ def replace(
sms_management_class=None,
volumes=None,
tmp_hlq=None,
force=None,
):
"""Attempts to replace an existing data set.

Expand Down Expand Up @@ -826,6 +830,8 @@ def replace(
has GUARANTEED_SPACE=YES specified. Otherwise, the allocation will fail.
Defaults to None.
tmp_hlq (str, optional): High level qualifier for temporary datasets.
force (bool, optional): Used to determine behavior when performing member operations on a pdse.
Defaults to None.
"""
arguments = locals()
DataSet.delete(name)
Expand Down Expand Up @@ -884,6 +890,7 @@ def create(
sms_management_class=None,
volumes=None,
tmp_hlq=None,
force=None,
):
"""A wrapper around zoautil_py
Dataset.create() to raise exceptions on failure.
Expand Down Expand Up @@ -940,6 +947,8 @@ def create(
has GUARANTEED_SPACE=YES specified. Otherwise, the allocation will fail.
Defaults to None.
tmp_hlq (str, optional): High level qualifier for temporary datasets.
force (bool, optional): Used to determine behavior when performing member operations on a pdse.
Defaults to None.
Raises:
DatasetCreateError: When data set creation fails.
"""
Expand Down Expand Up @@ -992,7 +1001,7 @@ def create_member(name):
raise DatasetMemberCreateError(name, rc)

@staticmethod
def delete_member(name):
def delete_member(name, force=False):
"""A wrapper around zoautil_py
Dataset.delete_members() to raise exceptions on failure.

Expand All @@ -1002,7 +1011,7 @@ def delete_member(name):
Raises:
DatasetMemberDeleteError: When data set member deletion fails.
"""
rc = datasets.delete_members(name)
rc = datasets.delete_members(name, force=force)
if rc > 0:
raise DatasetMemberDeleteError(name, rc)

Expand Down
71 changes: 70 additions & 1 deletion plugins/modules/zos_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
- >
If I(state=absent) and the data set does exist on the managed node,
remove the data set, module completes successfully with I(changed=True).
- >
If I(state=absent) and I(type=MEMBER) and I(force=True), the data set
will be opened with I(DISP=SHR) such that the entire data set can be
accessed by other processes while the specified member is deleted.
- >
If I(state=absent) and I(volumes) is provided, and the data set is not
found in the catalog, the module attempts to perform catalog using supplied
Expand Down Expand Up @@ -247,6 +251,20 @@
that is not available, then the value C(TMPHLQ) is used.
required: false
type: str
force:
description:
- Specifies that the data set can be shared with others during a member
delete operation which results in the data set you are updating to be
simultaneously updated by others.
- This is helpful when a data set is being used in a long running process
such as a started task and you are wanting to delete a member.
- The I(force=True) option enables sharing of data sets through the
disposition I(DISP=SHR).
- The I(force=True) only applies to data set members when I(state=absent)
and I(type=MEMBER).
type: bool
required: false
default: false
batch:
description:
- Batch can be used to perform operations on multiple data sets in a single module call.
Expand All @@ -271,6 +289,11 @@
- >
If I(state=absent) and the data set does exist on the managed node,
remove the data set, module completes successfully with I(changed=True).
- >
If I(state=absent) and I(type=MEMBER) and I(force=True), the data
set will be opened with I(DISP=SHR) such that the entire data set
can be accessed by other processes while the specified member is
deleted.
- >
If I(state=absent) and I(volumes) is provided, and the data set is not
found in the catalog, the module attempts to perform catalog using supplied
Expand Down Expand Up @@ -467,6 +490,21 @@
type: bool
required: false
default: false
force:
description:
- Specifies that the data set can be shared with others during a member
delete operation which results in the data set you are updating to
be simultaneously updated by others.
- This is helpful when a data set is being used in a long running
process such as a started task and you are wanting to delete a
member.
- The I(force=True) option enables sharing of data sets through the
disposition I(DISP=SHR).
- The I(force=True) only applies to data set members when
I(state=absent) and I(type=MEMBER).
type: bool
required: false
default: false

"""
EXAMPLES = r"""
Expand Down Expand Up @@ -552,6 +590,13 @@
state: absent
type: MEMBER

- name: Remove a member from an existing PDS/E by opening with disposition DISP=SHR
zos_data_set:
name: someds.name.here(mydata)
state: absent
type: MEMBER
force: yes

- name: Create multiple partitioned data sets and add one or more members to each
zos_data_set:
batch:
Expand Down Expand Up @@ -894,14 +939,17 @@ def perform_data_set_operations(name, state, **extra_args):
"""Calls functions to perform desired operations on
one or more data sets. Returns boolean indicating if changes were made."""
changed = False
# passing in **extra_args forced me to modify the acceptable parameters
# for multiple functions in data_set.py including ensure_present, replace
# and create where the force parameter has no bearing.
if state == "present" and extra_args.get("type") != "MEMBER":
changed = DataSet.ensure_present(name, **extra_args)
elif state == "present" and extra_args.get("type") == "MEMBER":
changed = DataSet.ensure_member_present(name, extra_args.get("replace"))
elif state == "absent" and extra_args.get("type") != "MEMBER":
changed = DataSet.ensure_absent(name, extra_args.get("volumes"))
elif state == "absent" and extra_args.get("type") == "MEMBER":
changed = DataSet.ensure_member_absent(name)
changed = DataSet.ensure_member_absent(name, extra_args.get("force"))
elif state == "cataloged":
changed = DataSet.ensure_cataloged(name, extra_args.get("volumes"))
elif state == "uncataloged":
Expand Down Expand Up @@ -1017,6 +1065,11 @@ def parse_and_validate_args(params):
aliases=["volume"],
dependencies=["state"],
),
force=dict(
type="bool",
required=False,
default=False,
),
),
),
# For individual data set args
Expand Down Expand Up @@ -1086,6 +1139,11 @@ def parse_and_validate_args(params):
required=False,
default=None
),
force=dict(
type="bool",
required=False,
default=False,
),
mutually_exclusive=[
["batch", "name"],
# ["batch", "state"],
Expand All @@ -1102,6 +1160,7 @@ def parse_and_validate_args(params):
["batch", "key_length"],
# ["batch", "replace"],
["batch", "volumes"],
# ["batch", "force"],
],
)
parser = BetterArgParser(arg_defs)
Expand Down Expand Up @@ -1162,6 +1221,11 @@ def run_module():
default=False,
),
volumes=dict(type="raw", required=False, aliases=["volume"]),
force=dict(
type="bool",
required=False,
default=False,
),
),
),
# For individual data set args
Expand Down Expand Up @@ -1213,6 +1277,11 @@ def run_module():
required=False,
default=None
),
force=dict(
type="bool",
required=False,
default=False
),
)
result = dict(changed=False, message="", names=[])

Expand Down
Loading