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 . Commands . RecoveryServices . SiteRecovery ;
18+ using Microsoft . Azure . Portal . RecoveryServices . Models . Common ;
19+ using Microsoft . WindowsAzure . Management . SiteRecovery . Models ;
20+
21+ namespace Microsoft . Azure . Commands . RecoveryServices
22+ {
23+ /// <summary>
24+ /// Set Protection Entity protection state.
25+ /// </summary>
26+ [ Cmdlet ( VerbsCommon . Set , "AzureSiteRecoveryVirtualMachine" ) ]
27+ [ OutputType ( typeof ( ASRJob ) ) ]
28+ public class SetAzureSiteRecoveryVirtualMachine : RecoveryServicesCmdletBase
29+ {
30+ #region Parameters
31+ /// <summary>
32+ /// Job response.
33+ /// </summary>
34+ private JobResponse jobResponse = null ;
35+
36+ /// <summary>
37+ /// Gets or sets ID of the Virtual Machine.
38+ /// </summary>
39+ [ Parameter ( Mandatory = true ) ]
40+ [ ValidateNotNullOrEmpty ]
41+ public ASRVirtualMachine VirtualMachine { get ; set ; }
42+
43+ /// <summary>
44+ /// Gets or sets Recovery Azure VM given name
45+ /// </summary>
46+ [ Parameter ]
47+ [ ValidateNotNullOrEmpty ]
48+ public string Name { get ; set ; }
49+
50+ /// <summary>
51+ /// Gets or sets Recovery Azure VM size
52+ /// </summary>
53+ [ Parameter ]
54+ [ ValidateNotNullOrEmpty ]
55+ public string Size { get ; set ; }
56+
57+ /// <summary>
58+ /// Gets or sets Selected Primary Network interface card Id
59+ /// </summary>
60+ [ Parameter ]
61+ [ ValidateNotNullOrEmpty ]
62+ public string PrimaryNic { get ; set ; }
63+
64+ /// <summary>
65+ /// Gets or sets Recovery Azure Network Id
66+ /// </summary>
67+ [ Parameter ]
68+ [ ValidateNotNullOrEmpty ]
69+ public string RecoveryNetworkId { get ; set ; }
70+ #endregion Parameters
71+
72+ /// <summary>
73+ /// ProcessRecord of the command.
74+ /// </summary>
75+ public override void ExecuteCmdlet ( )
76+ {
77+ // validate the srouce nic & target network together
78+ UpdateVmPropertiesInput updateVmPropertiesInput = new UpdateVmPropertiesInput ( ) ;
79+ updateVmPropertiesInput . RecoveryAzureVmGivenName = this . Name ;
80+ updateVmPropertiesInput . RecoveryAzureVmSize = this . Size ;
81+ updateVmPropertiesInput . SelectedPrimaryNicId = this . PrimaryNic ;
82+ updateVmPropertiesInput . RecoveryAzureNetworkId = this . RecoveryNetworkId ;
83+
84+ this . jobResponse = RecoveryServicesClient . UpdateVmProperties (
85+ this . VirtualMachine . ProtectionContainerId ,
86+ this . VirtualMachine . ID ,
87+ updateVmPropertiesInput ) ;
88+
89+ this . WriteJob ( this . jobResponse . Job ) ;
90+ }
91+
92+ /// <summary>
93+ /// Writes Job.
94+ /// </summary>
95+ /// <param name="job">JOB object</param>
96+ private void WriteJob ( Microsoft . WindowsAzure . Management . SiteRecovery . Models . Job job )
97+ {
98+ this . WriteObject ( new ASRJob ( job ) ) ;
99+ }
100+ }
101+ }
0 commit comments