@@ -477,35 +477,76 @@ def create_pgsnapshot(module, array):
477
477
protection_group_snapshot = suffix ,
478
478
)
479
479
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 :
486
498
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 ):
487
536
res = array .post_protection_group_snapshots (
488
537
source_names = [module .params ["name" ]],
489
538
apply_retention = module .params ["apply_retention" ],
490
- replicate_now = True ,
491
539
allow_throttle = module .params ["throttle" ],
492
540
protection_group_snapshot = suffix ,
541
+ context_names = [module .params ["context" ]],
493
542
)
494
543
else :
495
544
res = array .post_protection_group_snapshots (
496
545
source_names = [module .params ["name" ]],
497
546
apply_retention = module .params ["apply_retention" ],
498
547
allow_throttle = module .params ["throttle" ],
499
548
protection_group_snapshot = suffix ,
500
- replicate = module .params ["remote" ],
501
549
)
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
- )
509
550
510
551
if res .status_code != 200 :
511
552
module .fail_json (
@@ -526,9 +567,19 @@ def restore_pgsnapvolume(module, array):
526
567
api_version = array .get_rest_version ()
527
568
changed = True
528
569
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
532
583
module .params ["suffix" ] = latest_snapshot
533
584
if ":" in module .params ["name" ] and "::" not in module .params ["name" ]:
534
585
if get_rpgsnapshot (module , array ) is None :
@@ -558,8 +609,23 @@ def restore_pgsnapvolume(module, array):
558
609
else :
559
610
source_pod_name = ""
560
611
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" )
563
629
if not module .check_mode :
564
630
if LooseVersion (DEFAULT_API ) <= LooseVersion (array .get_rest_version ()):
565
631
if module .params ["add_to_pgs" ]:
@@ -568,19 +634,40 @@ def restore_pgsnapvolume(module, array):
568
634
add_to_pgs .append (
569
635
FixedReference (name = module .params ["add_to_pgs" ][add_pg ])
570
636
)
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 ):
579
638
res = array .post_volumes (
580
639
names = [module .params ["target" ]],
581
640
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" ]],
583
646
)
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
+ )
584
671
else :
585
672
res = array .post_volumes (
586
673
names = [module .params ["target" ]],
@@ -613,9 +700,16 @@ def delete_offload_snapshot(module, array):
613
700
snapname = module .params ["name" ] + "." + module .params ["suffix" ]
614
701
if ":" in module .params ["name" ] and module .params ["offload" ]:
615
702
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
+ )
619
713
if res .status_code != 200 :
620
714
module .fail_json (
621
715
msg = "Offload snapshot {0} does not exist on {1}" .format (
@@ -627,13 +721,23 @@ def delete_offload_snapshot(module, array):
627
721
if not module .check_mode :
628
722
if not rpg_destroyed :
629
723
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
+ )
637
741
if res .status_code != 200 :
638
742
module .fail_json (
639
743
msg = "Failed to delete offloaded snapshot {0} on target {1}. Error: {2}" .format (
@@ -643,9 +747,18 @@ def delete_offload_snapshot(module, array):
643
747
)
644
748
)
645
749
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
+ )
649
762
if res .status_code != 200 :
650
763
module .fail_json (
651
764
msg = "Failed to eradicate offloaded snapshot {0} on target {1}. Error: {2}" .format (
@@ -657,9 +770,18 @@ def delete_offload_snapshot(module, array):
657
770
else :
658
771
if module .params ["eradicate" ]:
659
772
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
+ )
663
785
if res .status_code != 200 :
664
786
module .fail_json (
665
787
msg = "Failed to eradicate offloaded snapshot {0} on target {1}. Error: {2}" .format (
@@ -686,18 +808,30 @@ def delete_pgsnapshot(module, array):
686
808
api_version = array .get_rest_version ()
687
809
if not module .check_mode :
688
810
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
+ )
693
822
if res .status_code != 200 :
694
823
module .fail_json (
695
824
msg = "Failed to delete pgroup {0}. Error {1}" .format (
696
825
snapname , res .errors [0 ].message
697
826
)
698
827
)
699
828
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 ])
701
835
if res .status_code != 200 :
702
836
module .fail_json (
703
837
msg = "Failed to delete pgroup {0}. Error {1}" .format (
@@ -713,7 +847,12 @@ def eradicate_pgsnapshot(module, array):
713
847
api_version = array .get_rest_version ()
714
848
if not module .check_mode :
715
849
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 ])
717
856
if res .status_code != 200 :
718
857
module .fail_json (
719
858
msg = "Failed to delete pgroup {0}. Error {1}" .format (
@@ -730,10 +869,17 @@ def update_pgsnapshot(module, array):
730
869
if not module .check_mode :
731
870
current_name = module .params ["name" ] + "." + module .params ["suffix" ]
732
871
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
+ )
737
883
if res .status_code != 200 :
738
884
module .fail_json (
739
885
msg = "Failed to rename {0} to {1}. Error: {2}" .format (
@@ -811,7 +957,6 @@ def main():
811
957
)
812
958
)
813
959
array = get_array (module )
814
- api_version = array .get_rest_version ()
815
960
pgroup = get_pgroup (module , array )
816
961
if not pgroup :
817
962
module .fail_json (
0 commit comments