34
34
using ServiceClientModel = Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
35
35
using CrrModel = Microsoft . Azure . Management . RecoveryServices . Backup . CrossRegionRestore . Models ;
36
36
using SystemNet = System . Net ;
37
+ using Microsoft . Azure . Commands . Common . Exceptions ;
37
38
38
39
namespace Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . ProviderModel
39
40
{
@@ -87,6 +88,8 @@ public RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableProtectio
87
88
string auxiliaryAccessToken = ProviderData . ContainsKey ( ResourceGuardParams . Token ) ? ( string ) ProviderData [ ResourceGuardParams . Token ] : null ;
88
89
bool isMUAOperation = ProviderData . ContainsKey ( ResourceGuardParams . IsMUAOperation ) ? ( bool ) ProviderData [ ResourceGuardParams . IsMUAOperation ] : false ;
89
90
91
+ Logger . Instance . WriteWarning ( "Ignite (November) 2023 onwards Virtual Machine deployments using PS and CLI will default to Trusted Launch configuration. You need to ensure Policy Name used with this command is of type Enhanced Policy for Trusted Launch VMs. Non-Trusted Launch Virtual Machines will not be impacted by this change. To know more about default change and Trusted Launch, please visit https://aka.ms/TLaD." ) ;
92
+
90
93
ProtectionPolicyResource oldPolicy = null ;
91
94
ProtectionPolicyResource newPolicy = null ;
92
95
if ( parameterSetName . Contains ( "Modify" ) && item . PolicyId != null && item . PolicyId != "" )
@@ -843,10 +846,12 @@ public ProtectionPolicyResource CreatePolicy()
843
846
ProviderData . ContainsKey ( PolicyParams . SchedulePolicy ) ?
844
847
( SchedulePolicyBase ) ProviderData [ PolicyParams . SchedulePolicy ] :
845
848
null ;
846
-
847
849
CmdletModel . TieringPolicy tieringDetails = ProviderData . ContainsKey ( PolicyParams . TieringPolicy ) ? ( CmdletModel . TieringPolicy ) ProviderData [ PolicyParams . TieringPolicy ] : null ;
848
850
bool isSmartTieringEnabled = ProviderData . ContainsKey ( PolicyParams . IsSmartTieringEnabled ) ? ( bool ) ProviderData [ PolicyParams . IsSmartTieringEnabled ] : false ;
849
851
852
+ string snapshotRGName = ( string ) ProviderData [ PolicyParams . BackupSnapshotResourceGroup ] ;
853
+ string snapshotRGNameSuffix = ( string ) ProviderData [ PolicyParams . BackupSnapshotResourceGroupSuffix ] ;
854
+
850
855
// do validations
851
856
ValidateAzureVMWorkloadType ( workloadType ) ;
852
857
@@ -913,7 +918,21 @@ public ProtectionPolicyResource CreatePolicy()
913
918
timeZone = timeZoneInput ;
914
919
}
915
920
}
916
-
921
+
922
+ InstantRPAdditionalDetails instantRPAdditionalDetails = null ;
923
+ if ( snapshotRGName != null )
924
+ {
925
+ instantRPAdditionalDetails = new InstantRPAdditionalDetails ( ) ;
926
+
927
+ instantRPAdditionalDetails . AzureBackupRGNamePrefix = snapshotRGName ;
928
+ if ( snapshotRGNameSuffix != null ) instantRPAdditionalDetails . AzureBackupRGNameSuffix = snapshotRGNameSuffix ;
929
+ }
930
+ else if ( snapshotRGNameSuffix != null )
931
+ {
932
+ // resx
933
+ throw new ArgumentException ( "The parameter BackupSnapshotResourceGroupSuffix cannot be used without the BackupSnapshotResourceGroup parameter. Please provide the BackupSnapshotResourceGroup parameter or remove the BackupSnapshotResourceGroupSuffix parameter." ) ;
934
+ }
935
+
917
936
// construct Service Client policy request
918
937
ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource ( )
919
938
{
@@ -925,7 +944,8 @@ public ProtectionPolicyResource CreatePolicy()
925
944
TieringPolicy = PolicyHelpers . GetServiceClientTieringPolicy ( tieringDetails , isSmartTieringEnabled ) ,
926
945
PolicyType = ( schedulePolicy . GetType ( ) == typeof ( CmdletModel . SimpleSchedulePolicyV2 ) ) ? "V2" : null ,
927
946
TimeZone = timeZone ,
928
- InstantRpRetentionRangeInDays = snapshotRetentionInDays
947
+ InstantRpRetentionRangeInDays = snapshotRetentionInDays ,
948
+ InstantRPDetails = instantRPAdditionalDetails
929
949
}
930
950
} ;
931
951
@@ -956,6 +976,9 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
956
976
CmdletModel . TieringPolicy tieringDetails = ProviderData . ContainsKey ( PolicyParams . TieringPolicy ) ? ( CmdletModel . TieringPolicy ) ProviderData [ PolicyParams . TieringPolicy ] : null ;
957
977
bool isSmartTieringEnabled = ProviderData . ContainsKey ( PolicyParams . IsSmartTieringEnabled ) ? ( bool ) ProviderData [ PolicyParams . IsSmartTieringEnabled ] : false ;
958
978
979
+ string snapshotRGName = ( string ) ProviderData [ PolicyParams . BackupSnapshotResourceGroup ] ;
980
+ string snapshotRGNameSuffix = ( string ) ProviderData [ PolicyParams . BackupSnapshotResourceGroupSuffix ] ;
981
+
959
982
// do validations
960
983
ValidateAzureVMProtectionPolicy ( policy ) ;
961
984
Logger . Instance . WriteDebug ( "Validation of Protection Policy is successful" ) ;
@@ -1032,7 +1055,21 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
1032
1055
timeZone = timeZoneInput ;
1033
1056
}
1034
1057
}
1035
-
1058
+
1059
+ InstantRPAdditionalDetails instantRPAdditionalDetails = null ;
1060
+ if ( snapshotRGName != null )
1061
+ {
1062
+ instantRPAdditionalDetails = new InstantRPAdditionalDetails ( ) ;
1063
+
1064
+ instantRPAdditionalDetails . AzureBackupRGNamePrefix = snapshotRGName ;
1065
+ if ( snapshotRGNameSuffix != null ) instantRPAdditionalDetails . AzureBackupRGNameSuffix = snapshotRGNameSuffix ;
1066
+ }
1067
+ else if ( snapshotRGNameSuffix != null )
1068
+ {
1069
+ // resx
1070
+ throw new ArgumentException ( "The parameter BackupSnapshotResourceGroupSuffix cannot be used without the BackupSnapshotResourceGroup parameter. Please provide the BackupSnapshotResourceGroup parameter or remove the BackupSnapshotResourceGroupSuffix parameter." ) ;
1071
+ }
1072
+
1036
1073
// construct Service Client policy request
1037
1074
ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource ( )
1038
1075
{
@@ -1045,7 +1082,7 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
1045
1082
TimeZone = timeZone ,
1046
1083
PolicyType = ( ( ( AzureVmPolicy ) policy ) . SchedulePolicy . GetType ( ) == typeof ( CmdletModel . SimpleSchedulePolicyV2 ) ) ? "V2" : null ,
1047
1084
InstantRpRetentionRangeInDays = ( ( AzureVmPolicy ) policy ) . SnapshotRetentionInDays ,
1048
- InstantRPDetails = new InstantRPAdditionalDetails (
1085
+ InstantRPDetails = ( instantRPAdditionalDetails != null ) ? instantRPAdditionalDetails : new InstantRPAdditionalDetails (
1049
1086
( ( AzureVmPolicy ) policy ) . AzureBackupRGName ,
1050
1087
( ( AzureVmPolicy ) policy ) . AzureBackupRGNameSuffix )
1051
1088
}
0 commit comments