18
18
using System . Text ;
19
19
using System . Threading . Tasks ;
20
20
using Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models ;
21
+ using CmdletModels = Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models ;
21
22
using Microsoft . Azure . Commands . RecoveryServices . Backup . Properties ;
22
- using Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
23
+ using ServiceClientModel = Microsoft . Azure . Management . RecoveryServices . Backup . Models ;
23
24
24
25
namespace Microsoft . Azure . Commands . RecoveryServices . Backup . Helpers
25
26
{
@@ -33,18 +34,18 @@ public class ConversionHelpers
33
34
/// <summary>
34
35
/// Helper function to convert ps backup container model from service response.
35
36
/// </summary>
36
- public static AzureRmRecoveryServicesBackupContainerBase GetContainerModel ( ProtectionContainerResource protectionContainer )
37
+ public static ContainerBase GetContainerModel ( ServiceClientModel . ProtectionContainerResource protectionContainer )
37
38
{
38
- AzureRmRecoveryServicesBackupContainerBase containerModel = null ;
39
+ ContainerBase containerModel = null ;
39
40
40
41
if ( protectionContainer != null &&
41
42
protectionContainer . Properties != null )
42
43
{
43
- if ( protectionContainer . Properties . GetType ( ) . IsSubclassOf ( typeof ( AzureIaaSVMProtectionContainer ) ) )
44
+ if ( protectionContainer . Properties . GetType ( ) . IsSubclassOf ( typeof ( ServiceClientModel . AzureIaaSVMProtectionContainer ) ) )
44
45
{
45
- containerModel = new AzureRmRecoveryServicesBackupIaasVmContainer ( protectionContainer ) ;
46
+ containerModel = new AzureVmContainer ( protectionContainer ) ;
46
47
}
47
- if ( protectionContainer . Properties . GetType ( ) == typeof ( MabProtectionContainer ) )
48
+ if ( protectionContainer . Properties . GetType ( ) == typeof ( ServiceClientModel . MabProtectionContainer ) )
48
49
{
49
50
containerModel = new AzureRmRecoveryServicesBackupMabContainer ( protectionContainer ) ;
50
51
}
@@ -56,18 +57,18 @@ public static AzureRmRecoveryServicesBackupContainerBase GetContainerModel(Prote
56
57
/// <summary>
57
58
/// Helper function to convert ps backup engine model from service response.
58
59
/// </summary>
59
- public static AzureRmRecoveryServicesBackupEngineBase GetBackupEngineModel ( BackupEngineResource backupEngine )
60
+ public static BackupEngineBase GetBackupEngineModel ( ServiceClientModel . BackupEngineResource backupEngine )
60
61
{
61
- AzureRmRecoveryServicesBackupEngineBase backupEngineModel = null ;
62
+ BackupEngineBase backupEngineModel = null ;
62
63
63
64
if ( backupEngine != null &&
64
65
backupEngine . Properties != null )
65
66
{
66
- if ( backupEngine . Properties . GetType ( ) == ( typeof ( DpmBackupEngine ) ) )
67
+ if ( backupEngine . Properties . GetType ( ) == ( typeof ( ServiceClientModel . DpmBackupEngine ) ) )
67
68
{
68
- backupEngineModel = new AzureRmRecoveryServicesBackupDpmBackupEngine ( backupEngine ) ;
69
+ backupEngineModel = new DpmBackupEngine ( backupEngine ) ;
69
70
}
70
- else if ( backupEngine . Properties . GetType ( ) == ( typeof ( AzureBackupServerEngine ) ) )
71
+ else if ( backupEngine . Properties . GetType ( ) == ( typeof ( ServiceClientModel . AzureBackupServerEngine ) ) )
71
72
{
72
73
backupEngineModel = new AzureRmRecoveryServicesBackupAzureBackupServerEngine ( backupEngine ) ;
73
74
}
@@ -79,9 +80,9 @@ public static AzureRmRecoveryServicesBackupEngineBase GetBackupEngineModel(Backu
79
80
/// <summary>
80
81
/// Helper function to convert ps backup container model list from service response.
81
82
/// </summary>
82
- public static List < AzureRmRecoveryServicesBackupContainerBase > GetContainerModelList ( IEnumerable < ProtectionContainerResource > protectionContainers )
83
+ public static List < ContainerBase > GetContainerModelList ( IEnumerable < ServiceClientModel . ProtectionContainerResource > protectionContainers )
83
84
{
84
- List < AzureRmRecoveryServicesBackupContainerBase > containerModels = new List < AzureRmRecoveryServicesBackupContainerBase > ( ) ;
85
+ List < ContainerBase > containerModels = new List < ContainerBase > ( ) ;
85
86
86
87
foreach ( var protectionContainer in protectionContainers )
87
88
{
@@ -94,9 +95,9 @@ public static List<AzureRmRecoveryServicesBackupContainerBase> GetContainerModel
94
95
/// <summary>
95
96
/// Helper function to convert ps backup engine model list from service response.
96
97
/// </summary>
97
- public static List < AzureRmRecoveryServicesBackupEngineBase > GetBackupEngineModelList ( IEnumerable < BackupEngineResource > backupEngines )
98
+ public static List < BackupEngineBase > GetBackupEngineModelList ( IEnumerable < ServiceClientModel . BackupEngineResource > backupEngines )
98
99
{
99
- List < AzureRmRecoveryServicesBackupEngineBase > backupEngineModel = new List < AzureRmRecoveryServicesBackupEngineBase > ( ) ;
100
+ List < BackupEngineBase > backupEngineModel = new List < BackupEngineBase > ( ) ;
100
101
101
102
foreach ( var backupEngine in backupEngines )
102
103
{
@@ -113,78 +114,78 @@ public static List<AzureRmRecoveryServicesBackupEngineBase> GetBackupEngineModel
113
114
/// <summary>
114
115
/// Helper function to convert ps backup policy model from service response.
115
116
/// </summary>
116
- public static AzureRmRecoveryServicesBackupPolicyBase GetPolicyModel ( ProtectionPolicyResource hydraResponse )
117
+ public static PolicyBase GetPolicyModel ( ServiceClientModel . ProtectionPolicyResource serviceClientResponse )
117
118
{
118
- AzureRmRecoveryServicesBackupPolicyBase policyModel = null ;
119
+ PolicyBase policyModel = null ;
119
120
120
- if ( hydraResponse == null || hydraResponse . Properties == null )
121
+ if ( serviceClientResponse == null || serviceClientResponse . Properties == null )
121
122
{
122
- Logger . Instance . WriteDebug ( "Policy Hydra response is Null/Empty" ) ;
123
- throw new ArgumentException ( Resources . EmptyHydraResponseException ) ;
123
+ Logger . Instance . WriteDebug ( "Policy Service Client response is Null/Empty" ) ;
124
+ throw new ArgumentException ( Resources . EmptyServiceClientResponseException ) ;
124
125
}
125
126
126
- if ( hydraResponse . Properties . GetType ( ) == typeof ( AzureIaaSVMProtectionPolicy ) )
127
+ if ( serviceClientResponse . Properties . GetType ( ) == typeof ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) )
127
128
{
128
- if ( ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy . GetType ( ) !=
129
- typeof ( LongTermRetentionPolicy ) )
129
+ if ( ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy . GetType ( ) !=
130
+ typeof ( ServiceClientModel . LongTermRetentionPolicy ) )
130
131
{
131
132
Logger . Instance . WriteDebug ( "Unknown RetentionPolicy object received: " +
132
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy . GetType ( ) ) ;
133
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy . GetType ( ) ) ;
133
134
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
134
135
return null ;
135
136
}
136
137
137
- if ( ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy . GetType ( ) !=
138
- typeof ( SimpleSchedulePolicy ) )
138
+ if ( ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy . GetType ( ) !=
139
+ typeof ( ServiceClientModel . SimpleSchedulePolicy ) )
139
140
{
140
141
Logger . Instance . WriteDebug ( "Unknown SchedulePolicy object received: " +
141
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy . GetType ( ) ) ;
142
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy . GetType ( ) ) ;
142
143
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
143
144
return null ;
144
145
}
145
146
146
- policyModel = new AzureRmRecoveryServicesBackupIaasVmPolicy ( ) ;
147
- AzureRmRecoveryServicesBackupIaasVmPolicy iaasPolicyModel = policyModel as AzureRmRecoveryServicesBackupIaasVmPolicy ;
147
+ policyModel = new AzureVmPolicy ( ) ;
148
+ AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy ;
148
149
iaasPolicyModel . WorkloadType = Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models . WorkloadType . AzureVM ;
149
150
iaasPolicyModel . BackupManagementType = Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models . BackupManagementType . AzureVM ;
150
- iaasPolicyModel . RetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy ( ( LongTermRetentionPolicy )
151
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . RetentionPolicy ) ;
152
- iaasPolicyModel . SchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy ( ( SimpleSchedulePolicy )
153
- ( ( AzureIaaSVMProtectionPolicy ) hydraResponse . Properties ) . SchedulePolicy ) ;
151
+ iaasPolicyModel . RetentionPolicy = PolicyHelpers . GetPSLongTermRetentionPolicy ( ( ServiceClientModel . LongTermRetentionPolicy )
152
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . RetentionPolicy ) ;
153
+ iaasPolicyModel . SchedulePolicy = PolicyHelpers . GetPSSimpleSchedulePolicy ( ( ServiceClientModel . SimpleSchedulePolicy )
154
+ ( ( ServiceClientModel . AzureIaaSVMProtectionPolicy ) serviceClientResponse . Properties ) . SchedulePolicy ) ;
154
155
}
155
156
else
156
157
{
157
158
// we will enter this case when service supports new workload and customer
158
159
// still using old version of azure powershell. Trace warning message, ignore and return
159
160
Logger . Instance . WriteDebug ( "Unknown Policy object received: " +
160
- hydraResponse . Properties . GetType ( ) ) ;
161
+ serviceClientResponse . Properties . GetType ( ) ) ;
161
162
Logger . Instance . WriteWarning ( Resources . UpdateToNewAzurePowershellWarning ) ;
162
163
return null ;
163
164
}
164
165
165
- policyModel . Name = hydraResponse . Name ;
166
- policyModel . Id = hydraResponse . Id ;
166
+ policyModel . Name = serviceClientResponse . Name ;
167
+ policyModel . Id = serviceClientResponse . Id ;
167
168
168
169
return policyModel ;
169
170
}
170
171
171
172
/// <summary>
172
173
/// Helper function to convert ps backup policy list model from service response.
173
174
/// </summary>
174
- public static List < AzureRmRecoveryServicesBackupPolicyBase > GetPolicyModelList (
175
- ProtectionPolicyListResponse hydraListResponse )
175
+ public static List < PolicyBase > GetPolicyModelList (
176
+ ServiceClientModel . ProtectionPolicyListResponse serviceClientListResponse )
176
177
{
177
- if ( hydraListResponse == null || hydraListResponse . ItemList == null ||
178
- hydraListResponse . ItemList . Value == null || hydraListResponse . ItemList . Value . Count == 0 )
178
+ if ( serviceClientListResponse == null || serviceClientListResponse . ItemList == null ||
179
+ serviceClientListResponse . ItemList . Value == null || serviceClientListResponse . ItemList . Value . Count == 0 )
179
180
{
180
181
Logger . Instance . WriteDebug ( "Received empty list of policies from service" ) ;
181
182
return null ;
182
183
}
183
184
184
- List < AzureRmRecoveryServicesBackupPolicyBase > policyModels = new List < AzureRmRecoveryServicesBackupPolicyBase > ( ) ;
185
- AzureRmRecoveryServicesBackupPolicyBase policyModel = null ;
185
+ List < PolicyBase > policyModels = new List < PolicyBase > ( ) ;
186
+ PolicyBase policyModel = null ;
186
187
187
- foreach ( ProtectionPolicyResource resource in hydraListResponse . ItemList . Value )
188
+ foreach ( ServiceClientModel . ProtectionPolicyResource resource in serviceClientListResponse . ItemList . Value )
188
189
{
189
190
policyModel = GetPolicyModel ( resource ) ;
190
191
if ( policyModel != null )
@@ -204,17 +205,17 @@ public static List<AzureRmRecoveryServicesBackupPolicyBase> GetPolicyModelList(
204
205
/// <summary>
205
206
/// Helper function to convert ps backup policy item from service response.
206
207
/// </summary>
207
- public static AzureRmRecoveryServicesBackupItemBase GetItemModel ( ProtectedItemResource protectedItem )
208
+ public static ItemBase GetItemModel ( ServiceClientModel . ProtectedItemResource protectedItem )
208
209
{
209
- AzureRmRecoveryServicesBackupItemBase itemModel = null ;
210
+ ItemBase itemModel = null ;
210
211
211
212
if ( protectedItem != null &&
212
213
protectedItem . Properties != null )
213
214
{
214
- if ( protectedItem . Properties . GetType ( ) . IsSubclassOf ( typeof ( AzureIaaSVMProtectedItem ) ) )
215
+ if ( protectedItem . Properties . GetType ( ) . IsSubclassOf ( typeof ( ServiceClientModel . AzureIaaSVMProtectedItem ) ) )
215
216
{
216
217
string policyName = null ;
217
- string policyId = ( ( AzureIaaSVMProtectedItem ) protectedItem . Properties ) . PolicyId ;
218
+ string policyId = ( ( ServiceClientModel . AzureIaaSVMProtectedItem ) protectedItem . Properties ) . PolicyId ;
218
219
if ( ! string . IsNullOrEmpty ( policyId ) )
219
220
{
220
221
Dictionary < UriEnums , string > keyValueDict =
@@ -226,7 +227,7 @@ public static AzureRmRecoveryServicesBackupItemBase GetItemModel(ProtectedItemRe
226
227
HelperUtils . ParseUri ( protectedItem . Id ) ,
227
228
protectedItem . Id ) ;
228
229
229
- itemModel = new AzureRmRecoveryServicesBackupIaasVmItem (
230
+ itemModel = new AzureVmItem (
230
231
protectedItem ,
231
232
IdUtils . GetNameFromUri ( containerUri ) ,
232
233
Cmdlets . Models . ContainerType . AzureVM ,
@@ -240,9 +241,9 @@ public static AzureRmRecoveryServicesBackupItemBase GetItemModel(ProtectedItemRe
240
241
/// <summary>
241
242
/// Helper function to convert ps backup policy item list from service response.
242
243
/// </summary>
243
- public static List < AzureRmRecoveryServicesBackupItemBase > GetItemModelList ( IEnumerable < ProtectedItemResource > protectedItems )
244
+ public static List < ItemBase > GetItemModelList ( IEnumerable < ServiceClientModel . ProtectedItemResource > protectedItems )
244
245
{
245
- List < AzureRmRecoveryServicesBackupItemBase > itemModels = new List < AzureRmRecoveryServicesBackupItemBase > ( ) ;
246
+ List < ItemBase > itemModels = new List < ItemBase > ( ) ;
246
247
247
248
foreach ( var protectedItem in protectedItems )
248
249
{
0 commit comments