1
+ // ----------------------------------------------------------------------------------
2
+ //
3
+ // Copyright Microsoft Corporation
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ // ----------------------------------------------------------------------------------
14
+
15
+ using System ;
16
+ using System . Management . Automation ;
17
+ using Microsoft . Azure . Management . SiteRecovery . Models ;
18
+
19
+ namespace Microsoft . Azure . Commands . SiteRecovery
20
+ {
21
+ /// <summary>
22
+ /// Retrieves Azure Site Recovery Server.
23
+ /// </summary>
24
+ [ Cmdlet ( VerbsData . Update , "AzureRmSiteRecoveryServer" , DefaultParameterSetName = ASRParameterSets . Default ) ]
25
+ public class UpdateAzureRmSiteRecoveryServer : SiteRecoveryCmdletBase
26
+ {
27
+ #region Parameters
28
+
29
+ /// <summary>
30
+ /// Gets or sets the Server.
31
+ /// </summary>
32
+ [ Parameter ( Mandatory = true , ValueFromPipeline = true ) ]
33
+ [ ValidateNotNullOrEmpty ]
34
+ public ASRServer Server { get ; set ; }
35
+
36
+ #endregion Parameters
37
+
38
+ /// <summary>
39
+ /// ProcessRecord of the command.
40
+ /// </summary>
41
+ public override void ExecuteCmdlet ( )
42
+ {
43
+ try
44
+ {
45
+ RefreshServer ( ) ;
46
+ }
47
+ catch ( Exception exception )
48
+ {
49
+ this . HandleException ( exception ) ;
50
+ }
51
+ }
52
+
53
+ /// <summary>
54
+ /// Refresh Server
55
+ /// </summary>
56
+ private void RefreshServer ( )
57
+ {
58
+ if ( ( String . Compare ( this . Server . FabricType , Constants . VMM ) != 0 && String . Compare ( this . Server . FabricType , Constants . HyperVSite ) != 0 ) )
59
+ {
60
+ throw new PSInvalidOperationException ( Properties . Resources . InvalidServerType ) ;
61
+ }
62
+
63
+ LongRunningOperationResponse response =
64
+ RecoveryServicesClient . RefreshAzureSiteRecoveryProvider ( Utilities . GetValueFromArmId ( this . Server . ID , ARMResourceTypeConstants . ReplicationFabrics ) , this . Server . Name ) ;
65
+
66
+ JobResponse jobResponse =
67
+ RecoveryServicesClient
68
+ . GetAzureSiteRecoveryJobDetails ( PSRecoveryServicesClient . GetJobIdFromReponseLocation ( response . Location ) ) ;
69
+
70
+ WriteObject ( new ASRJob ( jobResponse . Job ) ) ;
71
+ }
72
+ }
73
+ }
0 commit comments