Skip to content

Commit 5ab2876

Browse files
committed
update VM properties
1 parent 7e055ab commit 5ab2876

File tree

3 files changed

+228
-29
lines changed

3 files changed

+228
-29
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/SetAzureSiteRecoveryVM.cs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections.Generic;
1617
using System.Management.Automation;
1718
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
1819
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
@@ -45,28 +46,43 @@ public class SetAzureSiteRecoveryVirtualMachine : RecoveryServicesCmdletBase
4546
/// </summary>
4647
[Parameter]
4748
[ValidateNotNullOrEmpty]
48-
public string Name { get; set; }
49+
public string RecoveryAzureVMName { get; set; }
4950

5051
/// <summary>
5152
/// Gets or sets Recovery Azure VM size
5253
/// </summary>
5354
[Parameter]
5455
[ValidateNotNullOrEmpty]
55-
public string Size { get; set; }
56+
public string RecoveryAzureVMSize { get; set; }
57+
58+
/// <summary>
59+
/// Gets or sets Recovery Azure Network Id
60+
/// </summary>
61+
[Parameter]
62+
[ValidateNotNullOrEmpty]
63+
public string RecoveryAzureNetworkId { get; set; }
5664

5765
/// <summary>
5866
/// Gets or sets Selected Primary Network interface card Id
5967
/// </summary>
6068
[Parameter]
6169
[ValidateNotNullOrEmpty]
62-
public string PrimaryNic { get; set; }
70+
public string PrimaryNicId { get; set; }
6371

6472
/// <summary>
65-
/// Gets or sets Recovery Azure Network Id
73+
/// Gets or sets recovery VM subnet name
74+
/// </summary>
75+
[Parameter]
76+
[ValidateNotNullOrEmpty]
77+
public string RecoveryVMSubnetName { get; set; }
78+
79+
/// <summary>
80+
/// Gets or sets recovery NIC static IP address
6681
/// </summary>
6782
[Parameter]
6883
[ValidateNotNullOrEmpty]
69-
public string RecoveryNetworkId { get; set; }
84+
public string RecoveryNicIPAddress { get; set; }
85+
7086
#endregion Parameters
7187

7288
/// <summary>
@@ -75,28 +91,28 @@ public class SetAzureSiteRecoveryVirtualMachine : RecoveryServicesCmdletBase
7591
public override void ExecuteCmdlet()
7692
{
7793
// Check for at least one option
78-
if (string.IsNullOrEmpty(this.Name) &&
79-
string.IsNullOrEmpty(this.Size) &&
80-
string.IsNullOrEmpty(this.PrimaryNic) &&
81-
string.IsNullOrEmpty(this.RecoveryNetworkId))
94+
if (string.IsNullOrEmpty(this.RecoveryAzureVMName) &&
95+
string.IsNullOrEmpty(this.RecoveryAzureVMSize) &&
96+
string.IsNullOrEmpty(this.PrimaryNicId) &&
97+
(string.IsNullOrEmpty(this.RecoveryAzureNetworkId) ||
98+
string.IsNullOrEmpty(this.RecoveryVMSubnetName) ||
99+
string.IsNullOrEmpty(this.RecoveryNicIPAddress)))
82100
{
83101
this.WriteWarning(Properties.Resources.ArgumentsMissingForUpdateVmProperties.ToString());
84102
return;
85103
}
86104

87-
// Both primary & recovery inputs should be present
88-
if (string.IsNullOrEmpty(this.PrimaryNic) ^
89-
string.IsNullOrEmpty(this.RecoveryNetworkId))
90-
{
91-
this.WriteWarning(Properties.Resources.NetworkArgumentsMissingForUpdateVmProperties.ToString());
92-
return;
93-
}
94-
95105
VMProperties updateVmPropertiesInput = new VMProperties();
96-
updateVmPropertiesInput.RecoveryAzureVMName = this.Name;
97-
updateVmPropertiesInput.RecoveryAzureVMSize = this.Size;
98-
//// updateVmPropertiesInput.SelectedPrimaryNicId = this.PrimaryNic;
99-
updateVmPropertiesInput.SelectedRecoveryAzureNetworkId = this.RecoveryNetworkId;
106+
updateVmPropertiesInput.RecoveryAzureVMName = this.RecoveryAzureVMName;
107+
updateVmPropertiesInput.RecoveryAzureVMSize = this.RecoveryAzureVMSize;
108+
updateVmPropertiesInput.SelectedRecoveryAzureNetworkId = this.RecoveryAzureNetworkId;
109+
110+
updateVmPropertiesInput.VMNics = new List<VMNicDetails>();
111+
VMNicDetails vmnicDetails = new VMNicDetails();
112+
vmnicDetails.NicId = this.PrimaryNicId;
113+
vmnicDetails.RecoveryVMSubnetName = this.RecoveryVMSubnetName;
114+
vmnicDetails.ReplicaNicStaticIPAddress = this.RecoveryNicIPAddress;
115+
updateVmPropertiesInput.VMNics.Add(vmnicDetails);
100116

101117
this.jobResponse = RecoveryServicesClient.UpdateVmProperties(
102118
this.VirtualMachine.ProtectionContainerId,

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSContracts.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,64 @@ public class AzureVmDiskDetails
13221322
[DataMember]
13231323
public ulong MaxSizeMB { get; set; }
13241324
}
1325+
1326+
/// <summary>
1327+
/// VM properties.
1328+
/// </summary>
1329+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
1330+
[SuppressMessage(
1331+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
1332+
"SA1402:FileMayOnlyContainASingleClass",
1333+
Justification = "Keeping all related classes together.")]
1334+
public class VMProps
1335+
{
1336+
/// <summary>
1337+
/// Gets or sets Recovery Azure given name.
1338+
/// </summary>
1339+
[DataMember]
1340+
public string RecoveryAzureVMName { get; set; }
1341+
1342+
/// <summary>
1343+
/// Gets or sets the Recovery Azure VM size.
1344+
/// </summary>
1345+
[DataMember]
1346+
public string RecoveryAzureVMSize { get; set; }
1347+
1348+
/// <summary>
1349+
/// Gets or sets the selected recovery azure network Id.
1350+
/// </summary>
1351+
[DataMember]
1352+
public string SelectedRecoveryAzureNetworkId { get; set; }
1353+
1354+
/// <summary>
1355+
/// Gets or sets the list of VM NIC details.
1356+
/// </summary>
1357+
[DataMember]
1358+
public List<VMNic> VMNics { get; set; }
1359+
}
1360+
1361+
/// <summary>
1362+
/// Replication provider specific settings.
1363+
/// </summary>
1364+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
1365+
[SuppressMessage(
1366+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
1367+
"SA1402:FileMayOnlyContainASingleClass",
1368+
Justification = "Keeping all related classes together.")]
1369+
public class ReplicationProviderSpecificSettings
1370+
{
1371+
/// <summary>
1372+
/// Gets or sets Azure VM Disk details.
1373+
/// </summary>
1374+
[DataMember]
1375+
public AzureVmDiskDetails AzureVMDiskDetails { get; set; }
1376+
1377+
/// <summary>
1378+
/// Gets or sets VM properties.
1379+
/// </summary>
1380+
[DataMember]
1381+
public VMProps VMProperties { get; set; }
1382+
}
13251383
}
13261384

13271385
namespace Microsoft.Azure.Portal.HybridServicesCore

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSObjects.cs

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Diagnostics.CodeAnalysis;
18+
using System.IO;
1819
using System.Runtime.Serialization;
20+
using System.Xml;
21+
using System.Xml.Serialization;
1922
using Microsoft.Azure.Common.Authentication;
2023
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
2124
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;
@@ -910,14 +913,69 @@ public ASRProtectionEntity(ProtectionEntity pe)
910913

911914
if (!string.IsNullOrWhiteSpace(pe.ReplicationProviderSettings))
912915
{
913-
AzureVmDiskDetails diskDetails;
914-
DataContractUtils.Deserialize<AzureVmDiskDetails>(
915-
pe.ReplicationProviderSettings, out diskDetails);
916-
917-
this.Disks = diskDetails.Disks;
918-
this.OSDiskId = diskDetails.VHDId;
919-
this.OSDiskName = diskDetails.OsDisk;
920-
this.OS = diskDetails.OsType;
916+
if (pe.ReplicationProvider == Constants.HyperVReplicaAzure)
917+
{
918+
ReplicationProviderSpecificSettings providerDetails;
919+
DataContractUtils.Deserialize<ReplicationProviderSpecificSettings>(
920+
pe.ReplicationProviderSettings, out providerDetails);
921+
922+
this.RecoveryAzureVMName = providerDetails.VMProperties.RecoveryAzureVMName;
923+
this.RecoveryAzureVMSize = providerDetails.VMProperties.RecoveryAzureVMSize;
924+
this.SelectedRecoveryAzureNetworkId =
925+
providerDetails.VMProperties.SelectedRecoveryAzureNetworkId;
926+
this.VMNics = new List<VMNic>();
927+
928+
// Missing Nic details on serializing, going with the below workaround.
929+
XmlDocument xmlDoc = new XmlDocument();
930+
xmlDoc.LoadXml(pe.ReplicationProviderSettings);
931+
XmlNodeList parentNode = xmlDoc.GetElementsByTagName("VMNicDetails");
932+
foreach (XmlNode childrenNode in parentNode)
933+
{
934+
VMNic vmnicDetails = new VMNic();
935+
foreach (XmlNode childNode in childrenNode.ChildNodes)
936+
{
937+
switch (childNode.Name)
938+
{
939+
case "NicId":
940+
vmnicDetails.NicId = childNode.InnerText;
941+
break;
942+
case "VMSubnetName":
943+
vmnicDetails.VMSubnetName = childNode.InnerText;
944+
break;
945+
case "VMNetworkName":
946+
vmnicDetails.VMNetworkName = childNode.InnerText;
947+
break;
948+
case "RecoveryVMNetworkId":
949+
vmnicDetails.RecoveryVMNetworkId = childNode.InnerText;
950+
break;
951+
case "RecoveryVMSubnetName":
952+
vmnicDetails.RecoveryVMSubnetName = childNode.InnerText;
953+
break;
954+
case "ReplicaNicStaticIPAddress":
955+
vmnicDetails.RecoveryNicStaticIPAddress = childNode.InnerText;
956+
break;
957+
}
958+
}
959+
960+
this.VMNics.Add(vmnicDetails);
961+
}
962+
963+
this.Disks = providerDetails.AzureVMDiskDetails.Disks;
964+
this.OSDiskId = providerDetails.AzureVMDiskDetails.VHDId;
965+
this.OSDiskName = providerDetails.AzureVMDiskDetails.OsDisk;
966+
this.OS = providerDetails.AzureVMDiskDetails.OsType;
967+
}
968+
else
969+
{
970+
AzureVmDiskDetails diskDetails;
971+
DataContractUtils.Deserialize<AzureVmDiskDetails>(
972+
pe.ReplicationProviderSettings, out diskDetails);
973+
974+
this.Disks = diskDetails.Disks;
975+
this.OSDiskId = diskDetails.VHDId;
976+
this.OSDiskName = diskDetails.OsDisk;
977+
this.OS = diskDetails.OsType;
978+
}
921979
}
922980

923981
if (pe.ProtectionProfile != null &&
@@ -1082,6 +1140,26 @@ public ASRProtectionEntity(
10821140
/// Gets or sets Replication provider.
10831141
/// </summary>
10841142
public string ReplicationProvider { get; set; }
1143+
1144+
/// <summary>
1145+
/// Gets or sets Recovery Azure VM Name
1146+
/// </summary>
1147+
public string RecoveryAzureVMName { get; set; }
1148+
1149+
/// <summary>
1150+
/// Gets or sets the Recovery Azure VM size.
1151+
/// </summary>
1152+
public string RecoveryAzureVMSize { get; set; }
1153+
1154+
/// <summary>
1155+
/// Gets or sets the selected recovery azure network Id.
1156+
/// </summary>
1157+
public string SelectedRecoveryAzureNetworkId { get; set; }
1158+
1159+
/// <summary>
1160+
/// Gets or sets the list of VM NIC details.
1161+
/// </summary>
1162+
public List<VMNic> VMNics { get; set; }
10851163
}
10861164

10871165
/// <summary>
@@ -1665,4 +1743,51 @@ public class VirtualHardDisk
16651743
[DataMember]
16661744
public string Name { get; set; }
16671745
}
1746+
1747+
/// <summary>
1748+
/// Partial details of a NIC of a VM.
1749+
/// </summary>
1750+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
1751+
[SuppressMessage(
1752+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
1753+
"SA1402:FileMayOnlyContainASingleClass",
1754+
Justification = "Keeping all related classes together.")]
1755+
public class VMNic
1756+
{
1757+
/// <summary>
1758+
/// Gets or sets ID of the NIC.
1759+
/// </summary>
1760+
[DataMember]
1761+
public string NicId { get; set; }
1762+
1763+
/// <summary>
1764+
/// Gets or sets Name of the VM subnet.
1765+
/// </summary>
1766+
[DataMember]
1767+
public string VMSubnetName { get; set; }
1768+
1769+
/// <summary>
1770+
/// Gets or sets Name of the VM network.
1771+
/// </summary>
1772+
[DataMember]
1773+
public string VMNetworkName { get; set; }
1774+
1775+
/// <summary>
1776+
/// Gets or sets Id of the recovery VM Network.
1777+
/// </summary>
1778+
[DataMember]
1779+
public string RecoveryVMNetworkId { get; set; }
1780+
1781+
/// <summary>
1782+
/// Gets or sets the name of the recovery VM subnet.
1783+
/// </summary>
1784+
[DataMember]
1785+
public string RecoveryVMSubnetName { get; set; }
1786+
1787+
/// <summary>
1788+
/// Gets or sets the static IP address of the replica NIC.
1789+
/// </summary>
1790+
[DataMember]
1791+
public string RecoveryNicStaticIPAddress { get; set; }
1792+
}
16681793
}

0 commit comments

Comments
 (0)