19
19
using System . Threading . Tasks ;
20
20
using Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models ;
21
21
using Microsoft . Azure . Commands . RecoveryServices . Backup . Properties ;
22
- using Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
22
+ using ServiceClientModel = Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
23
23
24
24
namespace Microsoft . Azure . Commands . RecoveryServices . Backup . Helpers
25
25
{
26
26
public class ConversionHelpers
27
27
{
28
28
#region containers
29
- public static AzureRmRecoveryServicesBackupContainerBase GetContainerModel ( ProtectionContainerResource protectionContainer )
29
+ public static ContainerBase GetContainerModel ( ServiceClientModel . ProtectionContainerResource protectionContainer )
30
30
{
31
- AzureRmRecoveryServicesBackupContainerBase containerModel = null ;
31
+ ContainerBase containerModel = null ;
32
32
33
33
if ( protectionContainer != null &&
34
34
protectionContainer . Properties != null )
35
35
{
36
- if ( protectionContainer . Properties . GetType ( ) . IsSubclassOf ( typeof ( AzureIaaSVMProtectionContainer ) ) )
36
+ if ( protectionContainer . Properties . GetType ( ) . IsSubclassOf ( typeof ( ServiceClientModel . AzureIaaSVMProtectionContainer ) ) )
37
37
{
38
- containerModel = new AzureRmRecoveryServicesBackupIaasVmContainer ( protectionContainer ) ;
38
+ containerModel = new AzureVmContainer ( protectionContainer ) ;
39
39
}
40
- if ( protectionContainer . Properties . GetType ( ) == typeof ( MabProtectionContainer ) )
40
+ if ( protectionContainer . Properties . GetType ( ) == typeof ( ServiceClientModel . MabProtectionContainer ) )
41
41
{
42
42
containerModel = new AzureRmRecoveryServicesBackupMabContainer ( protectionContainer ) ;
43
43
}
@@ -46,18 +46,18 @@ public static AzureRmRecoveryServicesBackupContainerBase GetContainerModel(Prote
46
46
return containerModel ;
47
47
}
48
48
49
- public static AzureRmRecoveryServicesBackupEngineBase GetBackupEngineModel ( BackupEngineResource backupEngine )
49
+ public static BackupEngineBase GetBackupEngineModel ( ServiceClientModel . BackupEngineResource backupEngine )
50
50
{
51
- AzureRmRecoveryServicesBackupEngineBase backupEngineModel = null ;
51
+ BackupEngineBase backupEngineModel = null ;
52
52
53
53
if ( backupEngine != null &&
54
54
backupEngine . Properties != null )
55
55
{
56
- if ( backupEngine . Properties . GetType ( ) == ( typeof ( DpmBackupEngine ) ) )
56
+ if ( backupEngine . Properties . GetType ( ) == ( typeof ( ServiceClientModel . DpmBackupEngine ) ) )
57
57
{
58
- backupEngineModel = new AzureRmRecoveryServicesBackupDpmBackupEngine ( backupEngine ) ;
58
+ backupEngineModel = new DpmBackupEngine ( backupEngine ) ;
59
59
}
60
- else if ( backupEngine . Properties . GetType ( ) == ( typeof ( AzureBackupServerEngine ) ) )
60
+ else if ( backupEngine . Properties . GetType ( ) == ( typeof ( ServiceClientModel . AzureBackupServerEngine ) ) )
61
61
{
62
62
backupEngineModel = new AzureRmRecoveryServicesBackupAzureBackupServerEngine ( backupEngine ) ;
63
63
}
@@ -66,9 +66,9 @@ public static AzureRmRecoveryServicesBackupEngineBase GetBackupEngineModel(Backu
66
66
return backupEngineModel ;
67
67
}
68
68
69
- public static List < AzureRmRecoveryServicesBackupContainerBase > GetContainerModelList ( IEnumerable < ProtectionContainerResource > protectionContainers )
69
+ public static List < ContainerBase > GetContainerModelList ( IEnumerable < ServiceClientModel . ProtectionContainerResource > protectionContainers )
70
70
{
71
- List < AzureRmRecoveryServicesBackupContainerBase > containerModels = new List < AzureRmRecoveryServicesBackupContainerBase > ( ) ;
71
+ List < ContainerBase > containerModels = new List < ContainerBase > ( ) ;
72
72
73
73
foreach ( var protectionContainer in protectionContainers )
74
74
{
@@ -78,9 +78,9 @@ public static List<AzureRmRecoveryServicesBackupContainerBase> GetContainerModel
78
78
return containerModels ;
79
79
}
80
80
81
- public static List < AzureRmRecoveryServicesBackupEngineBase > GetBackupEngineModelList ( IEnumerable < BackupEngineResource > backupEngines )
81
+ public static List < BackupEngineBase > GetBackupEngineModelList ( IEnumerable < ServiceClientModel . BackupEngineResource > backupEngines )
82
82
{
83
- List < AzureRmRecoveryServicesBackupEngineBase > backupEngineModel = new List < AzureRmRecoveryServicesBackupEngineBase > ( ) ;
83
+ List < BackupEngineBase > backupEngineModel = new List < BackupEngineBase > ( ) ;
84
84
85
85
foreach ( var backupEngine in backupEngines )
86
86
{
@@ -93,75 +93,75 @@ public static List<AzureRmRecoveryServicesBackupEngineBase> GetBackupEngineModel
93
93
#endregion
94
94
95
95
#region policy
96
- public static AzureRmRecoveryServicesBackupPolicyBase GetPolicyModel ( ProtectionPolicyResource hydraResponse )
96
+ public static PolicyBase GetPolicyModel ( ServiceClientModel . ProtectionPolicyResource serviceClientResponse )
97
97
{
98
- AzureRmRecoveryServicesBackupPolicyBase policyModel = null ;
98
+ PolicyBase policyModel = null ;
99
99
100
- if ( hydraResponse == null || hydraResponse . Properties == null )
100
+ if ( serviceClientResponse == null || serviceClientResponse . Properties == null )
101
101
{
102
- Logger . Instance . WriteDebug ( "Policy Hydra response is Null/Empty" ) ;
103
- throw new ArgumentException ( Resources . EmptyHydraResponseException ) ;
102
+ Logger . Instance . WriteDebug ( "Policy Service Client response is Null/Empty" ) ;
103
+ throw new ArgumentException ( Resources . EmptyServiceClientResponseException ) ;
104
104
}
105
105
106
- if ( hydraResponse . Properties . GetType ( ) == typeof ( AzureIaaSVMProtectionPolicy ) )
106
+ if ( serviceClientResponse . Properties . GetType ( ) == typeof ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) )
107
107
{
108
- if ( ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy . GetType ( ) !=
109
- typeof ( LongTermRetentionPolicy ) )
108
+ if ( ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy . GetType ( ) !=
109
+ typeof ( ServiceClientModel . LongTermRetentionPolicy ) )
110
110
{
111
111
Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
112
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy . GetType ( ) ) ;
112
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy . GetType ( ) ) ;
113
113
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
114
114
return null ;
115
115
}
116
116
117
- if ( ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy . GetType ( ) !=
118
- typeof ( SimpleSchedulePolicy ) )
117
+ if ( ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy . GetType ( ) !=
118
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
119
119
{
120
120
Logger . Instance . WriteDebug ( "Unknown SchedulePolicy object received: " +
121
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy . GetType ( ) ) ;
121
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy . GetType ( ) ) ;
122
122
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
123
123
return null ;
124
124
}
125
125
126
- policyModel = new AzureRmRecoveryServicesBackupIaasVmPolicy ( ) ;
127
- AzureRmRecoveryServicesBackupIaasVmPolicy iaasPolicyModel = policyModel as AzureRmRecoveryServicesBackupIaasVmPolicy ;
126
+ policyModel = new AzureVmPolicy ( ) ;
127
+ AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy ;
128
128
iaasPolicyModel . WorkloadType = Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models . WorkloadType . AzureVM ;
129
129
iaasPolicyModel . BackupManagementType = Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models . BackupManagementType . AzureVM ;
130
- iaasPolicyModel . RetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy ( ( LongTermRetentionPolicy )
131
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy ) ;
132
- iaasPolicyModel . SchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy ( ( SimpleSchedulePolicy )
133
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy ) ;
130
+ iaasPolicyModel . RetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy ( ( ServiceClientModel . LongTermRetentionPolicy )
131
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy ) ;
132
+ iaasPolicyModel . SchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy ( ( ServiceClientModel . SimpleSchedulePolicy )
133
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy ) ;
134
134
}
135
135
else
136
136
{
137
137
// we will enter this case when service supports new workload and customer
138
138
// still using old version of azure powershell. Trace warning message, ignore and return
139
139
Logger . Instance . WriteDebug ( "Unknown Policy object received: " +
140
- hydraResponse . Properties . GetType ( ) ) ;
140
+ serviceClientResponse . Properties . GetType ( ) ) ;
141
141
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
142
142
return null ;
143
143
}
144
144
145
- policyModel . Name = hydraResponse . Name ;
146
- policyModel . Id = hydraResponse . Id ;
145
+ policyModel . Name = serviceClientResponse . Name ;
146
+ policyModel . Id = serviceClientResponse . Id ;
147
147
148
148
return policyModel ;
149
149
}
150
150
151
- public static List < AzureRmRecoveryServicesBackupPolicyBase > GetPolicyModelList (
152
- ProtectionPolicyListResponse hydraListResponse )
151
+ public static List < PolicyBase > GetPolicyModelList (
152
+ ServiceClientModel . ProtectionPolicyListResponse serviceClientListResponse )
153
153
{
154
- if ( hydraListResponse == null || hydraListResponse . ItemList == null ||
155
- hydraListResponse . ItemList . Value == null || hydraListResponse . ItemList . Value . Count == 0 )
154
+ if ( serviceClientListResponse == null || serviceClientListResponse . ItemList == null ||
155
+ serviceClientListResponse . ItemList . Value == null || serviceClientListResponse . ItemList . Value . Count == 0 )
156
156
{
157
157
Logger . Instance . WriteDebug ( "Received empty list of policies from service" ) ;
158
158
return null ;
159
159
}
160
160
161
- List < AzureRmRecoveryServicesBackupPolicyBase > policyModels = new List < AzureRmRecoveryServicesBackupPolicyBase > ( ) ;
162
- AzureRmRecoveryServicesBackupPolicyBase policyModel = null ;
161
+ List < PolicyBase > policyModels = new List < PolicyBase > ( ) ;
162
+ PolicyBase policyModel = null ;
163
163
164
- foreach ( ProtectionPolicyResource resource in hydraListResponse . ItemList . Value )
164
+ foreach ( ServiceClientModel . ProtectionPolicyResource resource in serviceClientListResponse . ItemList . Value )
165
165
{
166
166
policyModel = GetPolicyModel ( resource ) ;
167
167
if ( policyModel != null )
@@ -178,17 +178,17 @@ public static List<AzureRmRecoveryServicesBackupPolicyBase> GetPolicyModelList(
178
178
179
179
#region Item
180
180
181
- public static AzureRmRecoveryServicesBackupItemBase GetItemModel ( ProtectedItemResource protectedItem )
181
+ public static ItemBase GetItemModel ( ServiceClientModel . ProtectedItemResource protectedItem )
182
182
{
183
- AzureRmRecoveryServicesBackupItemBase itemModel = null ;
183
+ ItemBase itemModel = null ;
184
184
185
185
if ( protectedItem != null &&
186
186
protectedItem . Properties != null )
187
187
{
188
- if ( protectedItem . Properties . GetType ( ) . IsSubclassOf ( typeof ( AzureIaaSVMProtectedItem ) ) )
188
+ if ( protectedItem . Properties . GetType ( ) . IsSubclassOf ( typeof ( ServiceClientModel . AzureIaaSVMProtectedItem ) ) )
189
189
{
190
190
string policyName = null ;
191
- string policyId = ( ( AzureIaaSVMProtectedItem ) protectedItem . Properties ) . PolicyId ;
191
+ string policyId = ( ( ServiceClientModel . AzureIaaSVMProtectedItem ) protectedItem . Properties ) . PolicyId ;
192
192
if ( ! string . IsNullOrEmpty ( policyId ) )
193
193
{
194
194
Dictionary < UriEnums , string > keyValueDict =
@@ -200,7 +200,7 @@ public static AzureRmRecoveryServicesBackupItemBase GetItemModel(ProtectedItemRe
200
200
HelperUtils . ParseUri ( protectedItem . Id ) ,
201
201
protectedItem . Id ) ;
202
202
203
- itemModel = new AzureRmRecoveryServicesBackupIaasVmItem (
203
+ itemModel = new AzureVmItem (
204
204
protectedItem ,
205
205
IdUtils . GetNameFromUri ( containerUri ) ,
206
206
Cmdlets . Models . ContainerType . AzureVM ,
@@ -211,9 +211,9 @@ public static AzureRmRecoveryServicesBackupItemBase GetItemModel(ProtectedItemRe
211
211
return itemModel ;
212
212
}
213
213
214
- public static List < AzureRmRecoveryServicesBackupItemBase > GetItemModelList ( IEnumerable < ProtectedItemResource > protectedItems )
214
+ public static List < ItemBase > GetItemModelList ( IEnumerable < ServiceClientModel . ProtectedItemResource > protectedItems )
215
215
{
216
- List < AzureRmRecoveryServicesBackupItemBase > itemModels = new List < AzureRmRecoveryServicesBackupItemBase > ( ) ;
216
+ List < ItemBase > itemModels = new List < ItemBase > ( ) ;
217
217
218
218
foreach ( var protectedItem in protectedItems )
219
219
{
0 commit comments