@@ -190,7 +190,7 @@ public static PolicyBase GetPolicyModelForAzureSql(ServiceClientModel.Protection
190
190
ServiceClientModel . SimpleRetentionPolicy azureSqlRetentionPolicy =
191
191
( ServiceClientModel . SimpleRetentionPolicy ) azureSqlPolicy . RetentionPolicy ;
192
192
sqlPolicyModel . RetentionPolicy =
193
- PolicyHelpers . GetPSSimpleRetentionPolicy ( azureSqlRetentionPolicy , null ) ;
193
+ PolicyHelpers . GetPSSimpleRetentionPolicy ( azureSqlRetentionPolicy , null , "AzureSql" ) ;
194
194
return policyModel ;
195
195
}
196
196
@@ -236,6 +236,85 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
236
236
return policyModel ;
237
237
}
238
238
239
+ public static PolicyBase GetPolicyModelForAzureVmWorkload ( ServiceClientModel . ProtectionPolicyResource serviceClientResponse ,
240
+ PolicyBase policyModel )
241
+ {
242
+ ServiceClientModel . AzureVmWorkloadProtectionPolicy azureVmWorkloadPolicy =
243
+ ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ;
244
+
245
+ foreach ( var policy in azureVmWorkloadPolicy . SubProtectionPolicy )
246
+ {
247
+ if ( string . Compare ( policy . PolicyType , "Full" ) == 0 )
248
+ {
249
+ if ( policy . SchedulePolicy . GetType ( ) !=
250
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
251
+ {
252
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
253
+ policy . SchedulePolicy . GetType ( ) ) ;
254
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
255
+ return null ;
256
+ }
257
+ if ( policy . RetentionPolicy . GetType ( ) !=
258
+ typeof ( ServiceClientModel . LongTermRetentionPolicy ) )
259
+ {
260
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
261
+ policy . RetentionPolicy . GetType ( ) ) ;
262
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
263
+ return null ;
264
+ }
265
+ }
266
+ else if ( string . Compare ( policy . PolicyType , "Differential" ) == 0 )
267
+ {
268
+ if ( policy . SchedulePolicy . GetType ( ) !=
269
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
270
+ {
271
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
272
+ policy . SchedulePolicy . GetType ( ) ) ;
273
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
274
+ return null ;
275
+ }
276
+ if ( policy . RetentionPolicy . GetType ( ) !=
277
+ typeof ( ServiceClientModel . SimpleRetentionPolicy ) )
278
+ {
279
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
280
+ policy . RetentionPolicy . GetType ( ) ) ;
281
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
282
+ return null ;
283
+ }
284
+ }
285
+ else if ( string . Compare ( policy . PolicyType , "Log" ) == 0 )
286
+ {
287
+ if ( policy . SchedulePolicy . GetType ( ) !=
288
+ typeof ( ServiceClientModel . LogSchedulePolicy ) )
289
+ {
290
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
291
+ policy . SchedulePolicy . GetType ( ) ) ;
292
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
293
+ return null ;
294
+ }
295
+ if ( policy . RetentionPolicy . GetType ( ) !=
296
+ typeof ( ServiceClientModel . SimpleRetentionPolicy ) )
297
+ {
298
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
299
+ policy . RetentionPolicy . GetType ( ) ) ;
300
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
301
+ return null ;
302
+ }
303
+ }
304
+ }
305
+
306
+ policyModel = new AzureVmWorkloadPolicy ( ) ;
307
+ AzureVmWorkloadPolicy azureVmWorkloadPolicyModel = policyModel as AzureVmWorkloadPolicy ;
308
+ azureVmWorkloadPolicyModel . WorkloadType = WorkloadType . MSSQL ;
309
+ azureVmWorkloadPolicyModel . BackupManagementType = BackupManagementType . AzureWorkload ;
310
+ azureVmWorkloadPolicyModel . IsCompression =
311
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . IsCompression ;
312
+ GetPSSubProtectionPolicy ( azureVmWorkloadPolicyModel , serviceClientResponse ,
313
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
314
+
315
+ return policyModel ;
316
+ }
317
+
239
318
/// <summary>
240
319
/// Helper function to convert ps backup policy model from service response.
241
320
/// </summary>
@@ -263,6 +342,11 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
263
342
{
264
343
policyModel = GetPolicyModelForAzureFileShare ( serviceClientResponse , policyModel ) ;
265
344
}
345
+ else if ( serviceClientResponse . Properties . GetType ( ) ==
346
+ typeof ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) )
347
+ {
348
+ policyModel = GetPolicyModelForAzureVmWorkload ( serviceClientResponse , policyModel ) ;
349
+ }
266
350
else
267
351
{
268
352
// we will enter this case when service supports new workload and customer
@@ -431,6 +515,53 @@ public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.Pro
431
515
432
516
return itemModels ;
433
517
}
518
+
519
+ public static SettingsBase GetPSPolicySetting ( ServiceClientModel . Settings policySettings )
520
+ {
521
+ SettingsBase settings = new SettingsBase ( ) ;
522
+ settings . IsCompression = policySettings . IsCompression ;
523
+ settings . Issqlcompression = policySettings . Issqlcompression ;
524
+ settings . TimeZone = policySettings . TimeZone ;
525
+
526
+ return settings ;
527
+ }
528
+
529
+ public static void GetPSSubProtectionPolicy ( AzureVmWorkloadPolicy azureVmWorkloadPolicyModel ,
530
+ ServiceClientModel . ProtectionPolicyResource serviceClientResponse , string timeZone )
531
+ {
532
+ foreach ( var subProtectionPolicy in
533
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . SubProtectionPolicy )
534
+ {
535
+ if ( string . Compare ( subProtectionPolicy . PolicyType , "Full" ) == 0 )
536
+ {
537
+ azureVmWorkloadPolicyModel . FullBackupSchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy (
538
+ ( ServiceClientModel . SimpleSchedulePolicy ) subProtectionPolicy . SchedulePolicy ,
539
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
540
+
541
+ azureVmWorkloadPolicyModel . FullBackupRetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy (
542
+ ( ServiceClientModel . LongTermRetentionPolicy ) subProtectionPolicy . RetentionPolicy ,
543
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
544
+ }
545
+ else if ( string . Compare ( subProtectionPolicy . PolicyType , "Differential" ) == 0 )
546
+ {
547
+ azureVmWorkloadPolicyModel . DifferentialBackupSchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy (
548
+ ( ServiceClientModel . SimpleSchedulePolicy ) subProtectionPolicy . SchedulePolicy ,
549
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
550
+ azureVmWorkloadPolicyModel . DifferentialBackupRetentionPolicy = PolicyHelpers . GetPSSimpleRetentionPolicy (
551
+ ( ServiceClientModel . SimpleRetentionPolicy ) subProtectionPolicy . RetentionPolicy ,
552
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone , "AzureWorkload" ) ;
553
+ }
554
+ else if ( string . Compare ( subProtectionPolicy . PolicyType , "Log" ) == 0 )
555
+ {
556
+ azureVmWorkloadPolicyModel . LogBackupSchedulePolicy = PolicyHelpers . GetPSLogSchedulePolicy ( ( ServiceClientModel . LogSchedulePolicy )
557
+ subProtectionPolicy . SchedulePolicy ,
558
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
559
+ azureVmWorkloadPolicyModel . LogBackupRetentionPolicy = PolicyHelpers . GetPSSimpleRetentionPolicy ( ( ServiceClientModel . SimpleRetentionPolicy )
560
+ subProtectionPolicy . RetentionPolicy ,
561
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone , "AzureWorkload" ) ;
562
+ }
563
+ }
564
+ }
434
565
#endregion
435
566
}
436
567
}
0 commit comments