23
23
using Microsoft . Azure . Management . BackupServices . Models ;
24
24
using MBS = Microsoft . Azure . Management . BackupServices ;
25
25
using Microsoft . WindowsAzure . Commands . ServiceManagement . Model ;
26
- using Microsoft . Azure . Commands . AzureBackup . Properties ;
27
26
using Microsoft . Azure . Commands . AzureBackup . Models ;
28
27
using Microsoft . Azure . Commands . AzureBackup . Helpers ;
29
28
using Microsoft . Azure . Management . BackupServices ;
@@ -39,15 +38,15 @@ public class RegisterAzureBackupContainer : AzureBackupVaultCmdletBase
39
38
internal const string V1VMParameterSet = "V1VM" ;
40
39
internal const string V2VMParameterSet = "V2VM" ;
41
40
42
- [ Parameter ( Mandatory = true , ValueFromPipelineByPropertyName = true , ParameterSetName = V1VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VMName ) ]
43
- [ Parameter ( Mandatory = true , ValueFromPipelineByPropertyName = true , ParameterSetName = V2VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VMName ) ]
41
+ [ Parameter ( Mandatory = false , ValueFromPipelineByPropertyName = true , ParameterSetName = V1VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VirtualMachine ) ]
42
+ [ Parameter ( Mandatory = false , ValueFromPipelineByPropertyName = true , ParameterSetName = V2VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VirtualMachine ) ]
44
43
public string Name { get ; set ; }
45
44
46
- [ Parameter ( Mandatory = true , ValueFromPipelineByPropertyName = true , ParameterSetName = V1VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . ServiceName ) ]
45
+ [ Parameter ( Mandatory = false , ValueFromPipelineByPropertyName = true , ParameterSetName = V1VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VirtualMachine ) ]
47
46
public string ServiceName { get ; set ; }
48
47
49
- [ Parameter ( Mandatory = true , ValueFromPipelineByPropertyName = true , ParameterSetName = V2VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . RGName ) ]
50
- public string ResourceGroupName { get ; set ; }
48
+ [ Parameter ( Mandatory = false , ValueFromPipelineByPropertyName = true , ParameterSetName = V2VMParameterSet , HelpMessage = AzureBackupCmdletHelpMessage . VirtualMachine ) ]
49
+ public string VMResourceGroupName { get ; set ; }
51
50
52
51
53
52
public override void ExecuteCmdlet ( )
@@ -70,7 +69,7 @@ public override void ExecuteCmdlet()
70
69
else if ( this . ParameterSetName == V2VMParameterSet )
71
70
{
72
71
vmName = Name ;
73
- rgName = ResourceGroupName ;
72
+ rgName = VMResourceGroupName ;
74
73
WriteDebug ( String . Format ( "Registering ARM-V2 VM, VMName: {0}, ResourceGroupName: {1}" , vmName , rgName ) ) ;
75
74
ServiceOrRG = "ResourceGroupName" ;
76
75
}
@@ -95,7 +94,7 @@ public override void ExecuteCmdlet()
95
94
//Container is not discovered. Throw exception
96
95
string errMsg = String . Format ( "Failed to discover VM {0} under {1} {2}. Please make sure names are correct and VM is not deleted" , vmName , ServiceOrRG , rgName ) ;
97
96
WriteDebug ( errMsg ) ;
98
- ThrowTerminatingError ( new ErrorRecord ( new Exception ( Resources . AzureVMNotFound ) , string . Empty , ErrorCategory . InvalidArgument , null ) ) ;
97
+ throw new Exception ( errMsg ) ; //TODO: Sync with piyush and srub error msg
99
98
}
100
99
}
101
100
@@ -107,43 +106,41 @@ public override void ExecuteCmdlet()
107
106
var operationId = AzureBackupClient . RegisterContainer ( registrationRequest ) ;
108
107
109
108
var operationStatus = GetOperationStatus ( operationId ) ;
110
- WriteObject ( operationStatus . Jobs . FirstOrDefault ( ) ) ;
109
+ WriteObject ( operationStatus . JobList . FirstOrDefault ( ) ) ;
111
110
} ) ;
112
111
}
113
112
114
113
private void RefreshContainer ( )
115
114
{
116
- bool isRetryNeeded = true ;
115
+ bool isRetyNeeded = true ;
117
116
int retryCount = 1 ;
118
117
bool isDiscoverySuccessful = false ;
119
- string errorMessage = string . Empty ;
120
- while ( isRetryNeeded && retryCount <= 3 )
118
+ while ( isRetyNeeded && retryCount <= 3 )
121
119
{
122
120
var operationId = AzureBackupClient . RefreshContainers ( ) ;
123
121
124
122
//Now wait for the operation to Complete
125
- isRetryNeeded = WaitForDiscoveryToComplete ( operationId , out isDiscoverySuccessful , out errorMessage ) ;
123
+ isRetyNeeded = WaitForDiscoveryToCOmplete ( operationId , out isDiscoverySuccessful ) ;
126
124
retryCount ++ ;
127
125
}
128
126
129
127
if ( ! isDiscoverySuccessful )
130
128
{
131
- ThrowTerminatingError ( new ErrorRecord ( new Exception ( errorMessage ) , string . Empty , ErrorCategory . InvalidArgument , null ) ) ;
129
+ //Discovery failed
130
+ throw new Exception ( ) ; //TODO:
132
131
}
133
132
}
134
133
135
- private bool WaitForDiscoveryToComplete ( Guid operationId , out bool isDiscoverySuccessful , out string errorMessage )
134
+ private bool WaitForDiscoveryToCOmplete ( Guid operationId , out bool isDiscoverySuccessful )
136
135
{
137
136
bool isRetryNeeded = false ;
138
- var status = TrackOperation ( operationId ) ;
139
- errorMessage = String . Empty ;
137
+ var status = TrackOperation ( operationId ) ;
140
138
141
139
isDiscoverySuccessful = true ;
142
140
//If operation fails check if retry is needed or not
143
141
if ( status . OperationResult != AzureBackupOperationResult . Succeeded . ToString ( ) )
144
142
{
145
143
isDiscoverySuccessful = false ;
146
- errorMessage = status . Message ;
147
144
WriteDebug ( String . Format ( "Discovery operation failed with ErrorCode: {0}" , status . ErrorCode ) ) ;
148
145
if ( ( status . ErrorCode == AzureBackupOperationErrorCode . DiscoveryInProgress . ToString ( ) ||
149
146
( status . ErrorCode == AzureBackupOperationErrorCode . BMSUserErrorObjectLocked . ToString ( ) ) ) )
0 commit comments