Skip to content

Commit 277c794

Browse files
committed
Merge pull request #19 from AsrOneSdk/sriramvu-dev
Update VM properties
2 parents f6edab8 + c6085dc commit 277c794

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesVMClient.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,24 @@ public VirtualMachineResponse GetAzureSiteRecoveryVirtualMachine(
4747
{
4848
return this.GetSiteRecoveryClient().Vm.Get(protectionContainerId, virtualMachineId, this.GetRequestHeaders());
4949
}
50+
51+
/// <summary>
52+
/// Updates Virtual Machine properties.
53+
/// </summary>
54+
/// <param name="protectionContainerId">Protection Container ID</param>
55+
/// <param name="virtualMachineId">Virtual Machine ID</param>
56+
/// <param name="updateVmPropertiesInput">Update VM properties input</param>
57+
/// <returns>Job response</returns>
58+
public JobResponse UpdateVmProperties(
59+
string protectionContainerId,
60+
string virtualMachineId,
61+
UpdateVmPropertiesInput updateVmPropertiesInput)
62+
{
63+
return this.GetSiteRecoveryClient().Vm.UpdateVmProperties(
64+
protectionContainerId,
65+
virtualMachineId,
66+
updateVmPropertiesInput,
67+
this.GetRequestHeaders());
68+
}
5069
}
5170
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

Comments
 (0)