|
49 | 49 | type: bool
|
50 | 50 | default: false
|
51 | 51 | required: false
|
| 52 | + identical_gdg_copy: |
| 53 | + description: |
| 54 | + - If set to C(true), and the destination GDG does not exist, the module |
| 55 | + will copy the source GDG to the destination GDG with identical GDS absolute names. |
| 56 | + - If set to C(false), the copy will be done as a normal copy, without |
| 57 | + preserving the source GDG absolute names. |
| 58 | + type: bool |
| 59 | + default: false |
| 60 | + required: false |
52 | 61 | backup:
|
53 | 62 | description:
|
54 | 63 | - Specifies whether a backup of the destination should be created before
|
@@ -983,6 +992,7 @@ def __init__(
|
983 | 992 | asa_text=False,
|
984 | 993 | backup_name=None,
|
985 | 994 | force_lock=False,
|
| 995 | + identical_gdg_copy=False, |
986 | 996 | tmphlq=None
|
987 | 997 | ):
|
988 | 998 | """Utility class to handle copying data between two targets.
|
@@ -1047,6 +1057,7 @@ def __init__(
|
1047 | 1057 | self.aliases = aliases
|
1048 | 1058 | self.backup_name = backup_name
|
1049 | 1059 | self.force_lock = force_lock
|
| 1060 | + self.identical_gdg_copy = identical_gdg_copy |
1050 | 1061 | self.tmphlq = tmphlq
|
1051 | 1062 |
|
1052 | 1063 | def run_command(self, cmd, **kwargs):
|
@@ -1175,22 +1186,29 @@ def copy_to_gdg(self, src, dest):
|
1175 | 1186 | """
|
1176 | 1187 | src_view = gdgs.GenerationDataGroupView(src)
|
1177 | 1188 | generations = src_view.generations()
|
1178 |
| - dest_generation = f"{dest}(+1)" |
1179 |
| - |
1180 | 1189 | copy_args = {
|
1181 | 1190 | "options": ""
|
1182 | 1191 | }
|
1183 |
| - |
1184 | 1192 | if self.is_binary or self.asa_text:
|
1185 | 1193 | copy_args["options"] = "-B"
|
1186 | 1194 |
|
| 1195 | + success = True |
1187 | 1196 | for gds in generations:
|
1188 |
| - rc = datasets.copy(gds.name, dest_generation, **copy_args) |
1189 |
| - |
| 1197 | + # If identical_gdg_copy is True, use exact source generation name in destination |
| 1198 | + if self.identical_gdg_copy: |
| 1199 | + src_gen_absolute = gds.name |
| 1200 | + parts = src_gen_absolute.split('.') |
| 1201 | + # Extract generation number |
| 1202 | + generation_part = parts[-1] |
| 1203 | + dest_gen_name = f"{dest}.{generation_part}" |
| 1204 | + else: |
| 1205 | + # If identical_gdg_copy is False, use the default next generation |
| 1206 | + dest_gen_name = f"{dest}(+1)" |
| 1207 | + # Perform the copy operation |
| 1208 | + rc = datasets.copy(gds.name, dest_gen_name, **copy_args) |
1190 | 1209 | if rc != 0:
|
1191 |
| - return False |
1192 |
| - |
1193 |
| - return True |
| 1210 | + success = False |
| 1211 | + return success |
1194 | 1212 |
|
1195 | 1213 | def _copy_tree(self, entries, src, dest, dirs_exist_ok=False):
|
1196 | 1214 | """Recursively copy USS directory to another USS directory.
|
@@ -3358,6 +3376,7 @@ def run_module(module, arg_def):
|
3358 | 3376 | force = module.params.get('force')
|
3359 | 3377 | force_lock = module.params.get('force_lock')
|
3360 | 3378 | content = module.params.get('content')
|
| 3379 | + identical_gdg_copy = module.params.get('identical_gdg_copy', False) |
3361 | 3380 |
|
3362 | 3381 | # Set temporary directory at os environment level
|
3363 | 3382 | os.environ['TMPDIR'] = f"{os.path.realpath(module.tmpdir)}/"
|
@@ -3585,10 +3604,19 @@ def run_module(module, arg_def):
|
3585 | 3604 | dest_member_exists = dest_exists and data_set.DataSet.files_in_data_set_members(root_dir, dest)
|
3586 | 3605 | elif src_ds_type in data_set.DataSet.MVS_PARTITIONED:
|
3587 | 3606 | dest_member_exists = dest_exists and data_set.DataSet.data_set_shared_members(src, dest)
|
3588 |
| - |
3589 | 3607 | except Exception as err:
|
3590 | 3608 | module.fail_json(msg=str(err))
|
3591 |
| - |
| 3609 | + identical_gdg_copy = module.params.get('identical_gdg_copy', False) |
| 3610 | + if identical_gdg_copy: |
| 3611 | + # Validate destination GDG doesn't exist |
| 3612 | + if dest_exists: |
| 3613 | + module.fail_json( |
| 3614 | + msg=( |
| 3615 | + f"Identical GDG copy failed: {raw_dest} already exists." |
| 3616 | + "When using option identical_gdg_copy the destination GDG should not exist." |
| 3617 | + ), |
| 3618 | + changed=False |
| 3619 | + ) |
3592 | 3620 | # Checking that we're dealing with a positive generation when dest does not
|
3593 | 3621 | # exist.
|
3594 | 3622 | if is_dest_gds and not is_dest_gds_active:
|
@@ -3793,6 +3821,7 @@ def run_module(module, arg_def):
|
3793 | 3821 | asa_text=asa_text,
|
3794 | 3822 | backup_name=backup_name,
|
3795 | 3823 | force_lock=force_lock,
|
| 3824 | + identical_gdg_copy=module.params.get('identical_gdg_copy', False), |
3796 | 3825 | tmphlq=tmphlq
|
3797 | 3826 | )
|
3798 | 3827 |
|
@@ -3950,6 +3979,7 @@ def main():
|
3950 | 3979 | executable=dict(type='bool', default=False),
|
3951 | 3980 | asa_text=dict(type='bool', default=False),
|
3952 | 3981 | aliases=dict(type='bool', default=False, required=False),
|
| 3982 | + identical_gdg_copy=dict(type='bool', default=False), |
3953 | 3983 | encoding=dict(
|
3954 | 3984 | type='dict',
|
3955 | 3985 | required=False,
|
|
0 commit comments