12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using System ;
16
- using System . Collections . Generic ;
17
15
using Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models ;
18
16
using Microsoft . Azure . Commands . RecoveryServices . Backup . Properties ;
17
+ using System ;
18
+ using System . Collections . Generic ;
19
19
using ServiceClientModel = Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
20
20
21
21
namespace Microsoft . Azure . Commands . RecoveryServices . Backup . Helpers
@@ -55,6 +55,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
55
55
{
56
56
containerModel = new AzureFileShareContainer ( protectionContainer ) ;
57
57
}
58
+ else if ( protectionContainer . Properties . GetType ( ) ==
59
+ typeof ( ServiceClientModel . AzureVMAppContainerProtectionContainer ) )
60
+ {
61
+ containerModel = new AzureVmWorkloadContainer ( protectionContainer ) ;
62
+ }
58
63
}
59
64
60
65
return containerModel ;
@@ -190,7 +195,7 @@ public static PolicyBase GetPolicyModelForAzureSql(ServiceClientModel.Protection
190
195
ServiceClientModel . SimpleRetentionPolicy azureSqlRetentionPolicy =
191
196
( ServiceClientModel . SimpleRetentionPolicy ) azureSqlPolicy . RetentionPolicy ;
192
197
sqlPolicyModel . RetentionPolicy =
193
- PolicyHelpers . GetPSSimpleRetentionPolicy ( azureSqlRetentionPolicy , null ) ;
198
+ PolicyHelpers . GetPSSimpleRetentionPolicy ( azureSqlRetentionPolicy , null , "AzureSql" ) ;
194
199
return policyModel ;
195
200
}
196
201
@@ -236,6 +241,86 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
236
241
return policyModel ;
237
242
}
238
243
244
+ public static PolicyBase GetPolicyModelForAzureVmWorkload ( ServiceClientModel . ProtectionPolicyResource serviceClientResponse ,
245
+ PolicyBase policyModel )
246
+ {
247
+ ServiceClientModel . AzureVmWorkloadProtectionPolicy azureVmWorkloadPolicy =
248
+ ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ;
249
+
250
+ foreach ( var policy in azureVmWorkloadPolicy . SubProtectionPolicy )
251
+ {
252
+ if ( string . Compare ( policy . PolicyType , "Full" ) == 0 )
253
+ {
254
+ if ( policy . SchedulePolicy . GetType ( ) !=
255
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
256
+ {
257
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
258
+ policy . SchedulePolicy . GetType ( ) ) ;
259
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
260
+ return null ;
261
+ }
262
+ if ( policy . RetentionPolicy . GetType ( ) !=
263
+ typeof ( ServiceClientModel . LongTermRetentionPolicy ) )
264
+ {
265
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
266
+ policy . RetentionPolicy . GetType ( ) ) ;
267
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
268
+ return null ;
269
+ }
270
+ }
271
+ else if ( string . Compare ( policy . PolicyType , "Differential" ) == 0 )
272
+ {
273
+ if ( policy . SchedulePolicy . GetType ( ) !=
274
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
275
+ {
276
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
277
+ policy . SchedulePolicy . GetType ( ) ) ;
278
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
279
+ return null ;
280
+ }
281
+ if ( policy . RetentionPolicy . GetType ( ) !=
282
+ typeof ( ServiceClientModel . SimpleRetentionPolicy ) )
283
+ {
284
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
285
+ policy . RetentionPolicy . GetType ( ) ) ;
286
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
287
+ return null ;
288
+ }
289
+ }
290
+ else if ( string . Compare ( policy . PolicyType , "Log" ) == 0 )
291
+ {
292
+ if ( policy . SchedulePolicy . GetType ( ) !=
293
+ typeof ( ServiceClientModel . LogSchedulePolicy ) )
294
+ {
295
+ Logger . Instance . WriteDebug ( "Unknown Schedule object received: " +
296
+ policy . SchedulePolicy . GetType ( ) ) ;
297
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
298
+ return null ;
299
+ }
300
+ if ( policy . RetentionPolicy . GetType ( ) !=
301
+ typeof ( ServiceClientModel . SimpleRetentionPolicy ) )
302
+ {
303
+ Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
304
+ policy . RetentionPolicy . GetType ( ) ) ;
305
+ Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
306
+ return null ;
307
+ }
308
+ }
309
+ }
310
+
311
+ policyModel = new AzureVmWorkloadPolicy ( ) ;
312
+ AzureVmWorkloadPolicy azureVmWorkloadPolicyModel = policyModel as AzureVmWorkloadPolicy ;
313
+ azureVmWorkloadPolicyModel . WorkloadType = WorkloadType . MSSQL ;
314
+ azureVmWorkloadPolicyModel . BackupManagementType = BackupManagementType . AzureWorkload ;
315
+ azureVmWorkloadPolicyModel . IsCompression =
316
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . IsCompression ;
317
+ azureVmWorkloadPolicyModel . IsDifferentialBackupEnabled = false ;
318
+ azureVmWorkloadPolicyModel . IsLogBackupEnabled = false ;
319
+ GetPSSubProtectionPolicy ( azureVmWorkloadPolicyModel , serviceClientResponse ,
320
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
321
+ return policyModel ;
322
+ }
323
+
239
324
/// <summary>
240
325
/// Helper function to convert ps backup policy model from service response.
241
326
/// </summary>
@@ -263,6 +348,11 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
263
348
{
264
349
policyModel = GetPolicyModelForAzureFileShare ( serviceClientResponse , policyModel ) ;
265
350
}
351
+ else if ( serviceClientResponse . Properties . GetType ( ) ==
352
+ typeof ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) )
353
+ {
354
+ policyModel = GetPolicyModelForAzureVmWorkload ( serviceClientResponse , policyModel ) ;
355
+ }
266
356
else
267
357
{
268
358
// we will enter this case when service supports new workload and customer
@@ -338,8 +428,38 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
338
428
{
339
429
itemModel = GetAzureFileShareItemModel ( protectedItem ) ;
340
430
}
431
+
432
+ if ( protectedItem . Properties . GetType ( ) ==
433
+ typeof ( ServiceClientModel . AzureVmWorkloadSQLDatabaseProtectedItem ) )
434
+ {
435
+ itemModel = GetAzureVmWorkloadItemModel ( protectedItem ) ;
436
+ }
437
+ }
438
+
439
+ return itemModel ;
440
+ }
441
+
442
+ private static ItemBase GetAzureVmWorkloadItemModel ( ServiceClientModel . ProtectedItemResource protectedItem )
443
+ {
444
+ ItemBase itemModel ;
445
+ string policyName = null ;
446
+ string policyId = ( ( ServiceClientModel . AzureVmWorkloadSQLDatabaseProtectedItem ) protectedItem . Properties ) . PolicyId ;
447
+ if ( ! string . IsNullOrEmpty ( policyId ) )
448
+ {
449
+ Dictionary < UriEnums , string > keyValueDict =
450
+ HelperUtils . ParseUri ( policyId ) ;
451
+ policyName = HelperUtils . GetPolicyNameFromPolicyId ( keyValueDict , policyId ) ;
341
452
}
342
453
454
+ string containerUri = HelperUtils . GetContainerUri (
455
+ HelperUtils . ParseUri ( protectedItem . Id ) ,
456
+ protectedItem . Id ) ;
457
+
458
+ itemModel = new AzureWorkloadSQLDatabaseProtectedItem (
459
+ protectedItem ,
460
+ containerUri ,
461
+ ContainerType . AzureVMAppContainer ,
462
+ policyName ) ;
343
463
return itemModel ;
344
464
}
345
465
@@ -418,7 +538,42 @@ private static ItemBase GetAzureVmItemModel(ServiceClientModel.ProtectedItemReso
418
538
}
419
539
420
540
/// <summary>
421
- /// Helper function to convert ps backup policy item list from service response.
541
+ /// Helper function to convert ps protectable item from service response.
542
+ /// </summary>
543
+ public static ProtectableItemBase GetProtectableItemModel ( ServiceClientModel . WorkloadProtectableItemResource protectableItem )
544
+ {
545
+ ProtectableItemBase itemModel = null ;
546
+
547
+ if ( protectableItem != null &&
548
+ protectableItem . Properties != null )
549
+ {
550
+ if ( protectableItem . Properties . GetType ( ) . IsSubclassOf ( typeof ( ServiceClientModel . AzureVmWorkloadProtectableItem ) ) )
551
+ {
552
+ itemModel = GetAzureWorkloadProtectableItemModel ( protectableItem ) ;
553
+ }
554
+ }
555
+
556
+ return itemModel ;
557
+ }
558
+
559
+ private static ProtectableItemBase GetAzureWorkloadProtectableItemModel ( ServiceClientModel . WorkloadProtectableItemResource protectableItem )
560
+ {
561
+ ProtectableItemBase itemModel ;
562
+
563
+ string containerUri = HelperUtils . GetContainerUri (
564
+ HelperUtils . ParseUri ( protectableItem . Id ) ,
565
+ protectableItem . Id ) ;
566
+
567
+ itemModel = new AzureWorkloadProtectableItem (
568
+ protectableItem ,
569
+ containerUri ,
570
+ ContainerType . AzureVMAppContainer ) ;
571
+
572
+ return itemModel ;
573
+ }
574
+
575
+ /// <summary>
576
+ /// Helper function to convert ps item list from service response.
422
577
/// </summary>
423
578
public static List < ItemBase > GetItemModelList ( IEnumerable < ServiceClientModel . ProtectedItemResource > protectedItems )
424
579
{
@@ -431,6 +586,60 @@ public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.Pro
431
586
432
587
return itemModels ;
433
588
}
589
+
590
+ public static void GetPSSubProtectionPolicy ( AzureVmWorkloadPolicy azureVmWorkloadPolicyModel ,
591
+ ServiceClientModel . ProtectionPolicyResource serviceClientResponse , string timeZone )
592
+ {
593
+ foreach ( var subProtectionPolicy in
594
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . SubProtectionPolicy )
595
+ {
596
+ if ( string . Compare ( subProtectionPolicy . PolicyType , "Full" ) == 0 )
597
+ {
598
+ azureVmWorkloadPolicyModel . FullBackupSchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy (
599
+ ( ServiceClientModel . SimpleSchedulePolicy ) subProtectionPolicy . SchedulePolicy ,
600
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
601
+
602
+ azureVmWorkloadPolicyModel . FullBackupRetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy (
603
+ ( ServiceClientModel . LongTermRetentionPolicy ) subProtectionPolicy . RetentionPolicy ,
604
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
605
+ }
606
+ else if ( string . Compare ( subProtectionPolicy . PolicyType , "Differential" ) == 0 )
607
+ {
608
+ azureVmWorkloadPolicyModel . DifferentialBackupSchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy (
609
+ ( ServiceClientModel . SimpleSchedulePolicy ) subProtectionPolicy . SchedulePolicy ,
610
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
611
+ azureVmWorkloadPolicyModel . DifferentialBackupRetentionPolicy = PolicyHelpers . GetPSSimpleRetentionPolicy (
612
+ ( ServiceClientModel . SimpleRetentionPolicy ) subProtectionPolicy . RetentionPolicy ,
613
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone , "AzureWorkload" ) ;
614
+ azureVmWorkloadPolicyModel . IsDifferentialBackupEnabled = true ;
615
+ }
616
+ else if ( string . Compare ( subProtectionPolicy . PolicyType , "Log" ) == 0 )
617
+ {
618
+ azureVmWorkloadPolicyModel . LogBackupSchedulePolicy = PolicyHelpers . GetPSLogSchedulePolicy ( ( ServiceClientModel . LogSchedulePolicy )
619
+ subProtectionPolicy . SchedulePolicy ,
620
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone ) ;
621
+ azureVmWorkloadPolicyModel . LogBackupRetentionPolicy = PolicyHelpers . GetPSSimpleRetentionPolicy ( ( ServiceClientModel . SimpleRetentionPolicy )
622
+ subProtectionPolicy . RetentionPolicy ,
623
+ ( ( ServiceClientModel . AzureVmWorkloadProtectionPolicy ) serviceClientResponse . Properties ) . Settings . TimeZone , "AzureWorkload" ) ;
624
+ azureVmWorkloadPolicyModel . IsLogBackupEnabled = true ;
625
+ }
626
+ }
627
+ }
628
+
629
+ /// <summary>
630
+ /// Helper function to convert ps protectable item list from service response.
631
+ /// </summary>
632
+ public static List < ProtectableItemBase > GetProtectableItemModelList ( IEnumerable < ServiceClientModel . WorkloadProtectableItemResource > protectableItems )
633
+ {
634
+ List < ProtectableItemBase > itemModels = new List < ProtectableItemBase > ( ) ;
635
+
636
+ foreach ( var protectableItem in protectableItems )
637
+ {
638
+ itemModels . Add ( GetProtectableItemModel ( protectableItem ) ) ;
639
+ }
640
+
641
+ return itemModels ;
642
+ }
434
643
#endregion
435
644
}
436
645
}
0 commit comments