Skip to content

Commit 5719934

Browse files
authored
Add location to datalake backup module (#211)
Signed-off-by: Jim Enright <[email protected]>
1 parent 307ad8e commit 5719934

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugins/modules/datalake_backup.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
description:
4848
- The location of the backup to use during the restore
4949
- When not specified the location used will be the backup storage of the environment
50-
- If provided the I(backup_id) parameter is required
51-
- Only applicable when I(state=restore)
50+
- The I(backup_id) parameter is required when provided with I(state=restore),
5251
required: false
5352
type: str
5453
skip_atlas_indexes:
@@ -455,9 +454,9 @@ def __init__(self, module):
455454
self.backup_name = self._get_param("backup_name")
456455
self.state = self._get_param("state").lower()
457456
self.wait = self._get_param("wait", False)
457+
self.backup_location = self._get_param("backup_location")
458458
# ...variables for restore only
459459
self.backup_id = self._get_param("backup_id")
460-
self.backup_location = self._get_param("backup_location")
461460
self.skip_atlas_indexes = self._get_param("skip_atlas_indexes")
462461
self.skip_atlas_metadata = self._get_param("skip_atlas_metadata")
463462
self.skip_ranger_audits = self._get_param("skip_ranger_audits")
@@ -476,15 +475,20 @@ def process(self):
476475
# Check parameters that should only specified with state=restore
477476
if self.state == "backup" and (
478477
self.backup_id
479-
or self.backup_location
480478
or self.skip_atlas_indexes
481479
or self.skip_atlas_metadata
482480
or self.skip_ranger_audits
483481
or self.skip_ranger_hms_metadata
484482
or self.skip_validation
485483
):
486484
self.module.fail_json(
487-
msg="Unable to use 'state=backup' with args 'backup_id', 'backup_location', 'skip_atlas_indexes', 'skip_atlas_metadata', 'skip_ranger_audits', 'skip_ranger_hms_metadata' or 'skip_validation'",
485+
msg="Unable to use 'state=backup' with args 'backup_id', 'skip_atlas_indexes', 'skip_atlas_metadata', 'skip_ranger_audits', 'skip_ranger_hms_metadata' or 'skip_validation'",
486+
)
487+
488+
# Validate that backup_location requires backup_id only when state=restore
489+
if self.state == "restore" and self.backup_location and not self.backup_id:
490+
self.module.fail_json(
491+
msg="backup_location requires backup_id when state=restore",
488492
)
489493

490494
# Confirm datalake exists
@@ -500,6 +504,7 @@ def process(self):
500504
backup = self.cdpy.datalake.create_datalake_backup(
501505
datalake_name=self.datalake_name,
502506
backup_name=self.backup_name,
507+
backup_location=self.backup_location,
503508
)
504509

505510
if self.wait:
@@ -604,9 +609,6 @@ def main():
604609
skip_ranger_hms_metadata=dict(required=False, type="bool"),
605610
skip_validation=dict(required=False, type="bool"),
606611
),
607-
required_by={
608-
"backup_location": ("backup_id"),
609-
},
610612
mutually_exclusive=[
611613
["backup_name", "backup_id"],
612614
],

0 commit comments

Comments
 (0)