Skip to content

Commit a21f8fb

Browse files
committed
Add Fusion support to pgsnap module
1 parent cf86341 commit a21f8fb

File tree

2 files changed

+203
-56
lines changed

2 files changed

+203
-56
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- purefa_pgsnap - Added support for Fusion.

plugins/modules/purefa_pgsnap.py

Lines changed: 201 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -477,35 +477,76 @@ def create_pgsnapshot(module, array):
477477
protection_group_snapshot=suffix,
478478
)
479479
else:
480-
if (
481-
list(array.get_protection_groups(names=[module.params["name"]]).items)[
482-
0
483-
].target_count
484-
> 0
485-
):
480+
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version):
481+
remote_target = (
482+
list(
483+
array.get_protection_groups(
484+
names=[module.params["name"]],
485+
context_names=[module.params["context"]],
486+
).items
487+
)[0].target_count
488+
> 0
489+
)
490+
else:
491+
remote_target = (
492+
list(
493+
array.get_protection_groups(names=[module.params["name"]]).items
494+
)[0].target_count
495+
> 0
496+
)
497+
if remote_target:
486498
if module.params["now"]:
499+
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version):
500+
res = array.post_protection_group_snapshots(
501+
source_names=[module.params["name"]],
502+
apply_retention=module.params["apply_retention"],
503+
replicate_now=True,
504+
allow_throttle=module.params["throttle"],
505+
protection_group_snapshot=suffix,
506+
context_names=[module.params["context"]],
507+
)
508+
else:
509+
res = array.post_protection_group_snapshots(
510+
source_names=[module.params["name"]],
511+
apply_retention=module.params["apply_retention"],
512+
replicate_now=True,
513+
allow_throttle=module.params["throttle"],
514+
protection_group_snapshot=suffix,
515+
)
516+
else:
517+
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version):
518+
res = array.post_protection_group_snapshots(
519+
source_names=[module.params["name"]],
520+
apply_retention=module.params["apply_retention"],
521+
allow_throttle=module.params["throttle"],
522+
protection_group_snapshot=suffix,
523+
replicate=module.params["remote"],
524+
context_names=[module.params["context"]],
525+
)
526+
else:
527+
res = array.post_protection_group_snapshots(
528+
source_names=[module.params["name"]],
529+
apply_retention=module.params["apply_retention"],
530+
allow_throttle=module.params["throttle"],
531+
protection_group_snapshot=suffix,
532+
replicate=module.params["remote"],
533+
)
534+
else:
535+
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version):
487536
res = array.post_protection_group_snapshots(
488537
source_names=[module.params["name"]],
489538
apply_retention=module.params["apply_retention"],
490-
replicate_now=True,
491539
allow_throttle=module.params["throttle"],
492540
protection_group_snapshot=suffix,
541+
context_names=[module.params["context"]],
493542
)
494543
else:
495544
res = array.post_protection_group_snapshots(
496545
source_names=[module.params["name"]],
497546
apply_retention=module.params["apply_retention"],
498547
allow_throttle=module.params["throttle"],
499548
protection_group_snapshot=suffix,
500-
replicate=module.params["remote"],
501549
)
502-
else:
503-
res = array.post_protection_group_snapshots(
504-
source_names=[module.params["name"]],
505-
apply_retention=module.params["apply_retention"],
506-
allow_throttle=module.params["throttle"],
507-
protection_group_snapshot=suffix,
508-
)
509550

510551
if res.status_code != 200:
511552
module.fail_json(
@@ -526,9 +567,19 @@ def restore_pgsnapvolume(module, array):
526567
api_version = array.get_rest_version()
527568
changed = True
528569
if module.params["suffix"] == "latest":
529-
latest_snapshot = list(
530-
array.get_protection_group_snapshots(names=[module.params["name"]]).items
531-
)[-1].suffix
570+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
571+
latest_snapshot = list(
572+
array.get_protection_group_snapshots(
573+
names=[module.params["name"]],
574+
context_names=[module.params["context"]],
575+
).items
576+
)[-1].suffix
577+
else:
578+
latest_snapshot = list(
579+
array.get_protection_group_snapshots(
580+
names=[module.params["name"]]
581+
).items
582+
)[-1].suffix
532583
module.params["suffix"] = latest_snapshot
533584
if ":" in module.params["name"] and "::" not in module.params["name"]:
534585
if get_rpgsnapshot(module, array) is None:
@@ -558,8 +609,23 @@ def restore_pgsnapvolume(module, array):
558609
else:
559610
source_pod_name = ""
560611
if source_pod_name != target_pod_name:
561-
if list(array.get_pods(names=[target_pod_name]).items)[0].array_count > 1:
562-
module.fail_json(msg="Volume cannot be restored to a stretched pod")
612+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
613+
if (
614+
list(
615+
array.get_pods(
616+
names=[target_pod_name],
617+
context_names=[module.params["context"]],
618+
).items
619+
)[0].array_count
620+
> 1
621+
):
622+
module.fail_json(msg="Volume cannot be restored to a stretched pod")
623+
else:
624+
if (
625+
list(array.get_pods(names=[target_pod_name]).items)[0].array_count
626+
> 1
627+
):
628+
module.fail_json(msg="Volume cannot be restored to a stretched pod")
563629
if not module.check_mode:
564630
if LooseVersion(DEFAULT_API) <= LooseVersion(array.get_rest_version()):
565631
if module.params["add_to_pgs"]:
@@ -568,19 +634,40 @@ def restore_pgsnapvolume(module, array):
568634
add_to_pgs.append(
569635
FixedReference(name=module.params["add_to_pgs"][add_pg])
570636
)
571-
res = array.post_volumes(
572-
names=[module.params["target"]],
573-
volume=VolumePost(source=Reference(name=source_volume)),
574-
with_default_protection=module.params["with_default_protection"],
575-
add_to_protection_group_names=add_to_pgs,
576-
)
577-
else:
578-
if module.params["overwrite"]:
637+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
579638
res = array.post_volumes(
580639
names=[module.params["target"]],
581640
volume=VolumePost(source=Reference(name=source_volume)),
582-
overwrite=module.params["overwrite"],
641+
with_default_protection=module.params[
642+
"with_default_protection"
643+
],
644+
add_to_protection_group_names=add_to_pgs,
645+
context_names=[module.params["context"]],
583646
)
647+
else:
648+
res = array.post_volumes(
649+
names=[module.params["target"]],
650+
volume=VolumePost(source=Reference(name=source_volume)),
651+
with_default_protection=module.params[
652+
"with_default_protection"
653+
],
654+
add_to_protection_group_names=add_to_pgs,
655+
)
656+
else:
657+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
658+
if module.params["overwrite"]:
659+
res = array.post_volumes(
660+
names=[module.params["target"]],
661+
volume=VolumePost(source=Reference(name=source_volume)),
662+
overwrite=module.params["overwrite"],
663+
context_names=[module.params["context"]],
664+
)
665+
else:
666+
res = array.post_volumes(
667+
names=[module.params["target"]],
668+
volume=VolumePost(source=Reference(name=source_volume)),
669+
overwrite=module.params["overwrite"],
670+
)
584671
else:
585672
res = array.post_volumes(
586673
names=[module.params["target"]],
@@ -613,9 +700,16 @@ def delete_offload_snapshot(module, array):
613700
snapname = module.params["name"] + "." + module.params["suffix"]
614701
if ":" in module.params["name"] and module.params["offload"]:
615702
if _check_offload(module, array):
616-
res = array.get_remote_protection_group_snapshots(
617-
names=[snapname], on=module.params["offload"]
618-
)
703+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
704+
res = array.get_remote_protection_group_snapshots(
705+
names=[snapname],
706+
on=module.params["offload"],
707+
context_names=[module.params["context"]],
708+
)
709+
else:
710+
res = array.get_remote_protection_group_snapshots(
711+
names=[snapname], on=module.params["offload"]
712+
)
619713
if res.status_code != 200:
620714
module.fail_json(
621715
msg="Offload snapshot {0} does not exist on {1}".format(
@@ -627,13 +721,23 @@ def delete_offload_snapshot(module, array):
627721
if not module.check_mode:
628722
if not rpg_destroyed:
629723
changed = True
630-
res = array.patch_remote_protection_group_snapshots(
631-
names=[snapname],
632-
on=module.params["offload"],
633-
remote_protection_group_snapshot=DestroyedPatchPost(
634-
destroyed=True
635-
),
636-
)
724+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
725+
res = array.patch_remote_protection_group_snapshots(
726+
names=[snapname],
727+
on=module.params["offload"],
728+
remote_protection_group_snapshot=DestroyedPatchPost(
729+
destroyed=True
730+
),
731+
context_names=[module.params["context"]],
732+
)
733+
else:
734+
res = array.patch_remote_protection_group_snapshots(
735+
names=[snapname],
736+
on=module.params["offload"],
737+
remote_protection_group_snapshot=DestroyedPatchPost(
738+
destroyed=True
739+
),
740+
)
637741
if res.status_code != 200:
638742
module.fail_json(
639743
msg="Failed to delete offloaded snapshot {0} on target {1}. Error: {2}".format(
@@ -643,9 +747,18 @@ def delete_offload_snapshot(module, array):
643747
)
644748
)
645749
if module.params["eradicate"]:
646-
res = array.delete_remote_protection_group_snapshots(
647-
names=[snapname], on=module.params["offload"]
648-
)
750+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(
751+
api_version
752+
):
753+
res = array.delete_remote_protection_group_snapshots(
754+
names=[snapname],
755+
on=module.params["offload"],
756+
context_names=[module.params["context"]],
757+
)
758+
else:
759+
res = array.delete_remote_protection_group_snapshots(
760+
names=[snapname], on=module.params["offload"]
761+
)
649762
if res.status_code != 200:
650763
module.fail_json(
651764
msg="Failed to eradicate offloaded snapshot {0} on target {1}. Error: {2}".format(
@@ -657,9 +770,18 @@ def delete_offload_snapshot(module, array):
657770
else:
658771
if module.params["eradicate"]:
659772
changed = True
660-
res = array.delete_remote_protection_group_snapshots(
661-
names=[snapname], on=module.params["offload"]
662-
)
773+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(
774+
api_version
775+
):
776+
res = array.delete_remote_protection_group_snapshots(
777+
names=[snapname],
778+
on=module.params["offload"],
779+
context_names=[module.params["context"]],
780+
)
781+
else:
782+
res = array.delete_remote_protection_group_snapshots(
783+
names=[snapname], on=module.params["offload"]
784+
)
663785
if res.status_code != 200:
664786
module.fail_json(
665787
msg="Failed to eradicate offloaded snapshot {0} on target {1}. Error: {2}".format(
@@ -686,18 +808,30 @@ def delete_pgsnapshot(module, array):
686808
api_version = array.get_rest_version()
687809
if not module.check_mode:
688810
snapname = module.params["name"] + "." + module.params["suffix"]
689-
res = array.patch_protection_group_snapshots(
690-
names=[snapname],
691-
protection_group_snapshot=ProtectionGroupSnapshotPatch(destroyed=True),
692-
)
811+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
812+
res = array.patch_protection_group_snapshots(
813+
names=[snapname],
814+
protection_group_snapshot=ProtectionGroupSnapshotPatch(destroyed=True),
815+
context_names=[module.params["context"]],
816+
)
817+
else:
818+
res = array.patch_protection_group_snapshots(
819+
names=[snapname],
820+
protection_group_snapshot=ProtectionGroupSnapshotPatch(destroyed=True),
821+
)
693822
if res.status_code != 200:
694823
module.fail_json(
695824
msg="Failed to delete pgroup {0}. Error {1}".format(
696825
snapname, res.errors[0].message
697826
)
698827
)
699828
if module.params["eradicate"]:
700-
res = array.delete_protection_group_snapshots(names=[snapname])
829+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
830+
res = array.delete_protection_group_snapshots(
831+
names=[snapname], context_names=[module.params["context"]]
832+
)
833+
else:
834+
res = array.delete_protection_group_snapshots(names=[snapname])
701835
if res.status_code != 200:
702836
module.fail_json(
703837
msg="Failed to delete pgroup {0}. Error {1}".format(
@@ -713,7 +847,12 @@ def eradicate_pgsnapshot(module, array):
713847
api_version = array.get_rest_version()
714848
if not module.check_mode:
715849
snapname = module.params["name"] + "." + module.params["suffix"]
716-
res = array.delete_protection_group_snapshots(names=[snapname])
850+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
851+
res = array.delete_protection_group_snapshots(
852+
names=[snapname], context_names=[module.params["context"]]
853+
)
854+
else:
855+
res = array.delete_protection_group_snapshots(names=[snapname])
717856
if res.status_code != 200:
718857
module.fail_json(
719858
msg="Failed to delete pgroup {0}. Error {1}".format(
@@ -730,10 +869,17 @@ def update_pgsnapshot(module, array):
730869
if not module.check_mode:
731870
current_name = module.params["name"] + "." + module.params["suffix"]
732871
new_name = module.params["name"] + "." + module.params["target"]
733-
res = array.patch_protection_group_snapshots(
734-
names=[current_name],
735-
protection_group_snapshot=ProtectionGroupSnapshotPatch(name=new_name),
736-
)
872+
if LooseVersion(CONTEXT_API_VERSION) >= LooseVersion(api_version):
873+
res = array.patch_protection_group_snapshots(
874+
names=[current_name],
875+
protection_group_snapshot=ProtectionGroupSnapshotPatch(name=new_name),
876+
context_names=[module.params["context"]],
877+
)
878+
else:
879+
res = array.patch_protection_group_snapshots(
880+
names=[current_name],
881+
protection_group_snapshot=ProtectionGroupSnapshotPatch(name=new_name),
882+
)
737883
if res.status_code != 200:
738884
module.fail_json(
739885
msg="Failed to rename {0} to {1}. Error: {2}".format(
@@ -811,7 +957,6 @@ def main():
811957
)
812958
)
813959
array = get_array(module)
814-
api_version = array.get_rest_version()
815960
pgroup = get_pgroup(module, array)
816961
if not pgroup:
817962
module.fail_json(

0 commit comments

Comments
 (0)