Skip to content

Commit 702c98d

Browse files
committed
Merge pull request #41 from AsrOneSdk/neha-dev
Bug fixes, GetVault by Name
2 parents 2d5728c + 1a12910 commit 702c98d

File tree

7 files changed

+154
-28
lines changed

7 files changed

+154
-28
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Microsoft.Azure.Commands.RecoveryServices.dll-help.xml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7711,16 +7711,36 @@ Vault has been created
77117711
<dev:version></dev:version>
77127712
</command:details>
77137713
<maml:description>
7714-
<maml:para>Retrieves Azure Site Recovery Vault</maml:para>
7714+
<maml:para>Retrieves the information of the active Azure Site Recovery Vault</maml:para>
77157715
</maml:description>
77167716
<!-- Cmdlet syntax section-->
77177717
<command:syntax>
77187718
<command:syntaxItem>
77197719
<maml:name>Get-AzureSiteRecoveryVault</maml:name>
7720+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
7721+
<maml:name>Name</maml:name>
7722+
<maml:description>
7723+
<maml:para></maml:para>
7724+
</maml:description>
7725+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
7726+
</command:parameter>
77207727
</command:syntaxItem>
77217728
</command:syntax>
77227729
<!-- Cmdlet parameter section -->
77237730
<command:parameters>
7731+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
7732+
<maml:name>Name</maml:name>
7733+
<maml:description>
7734+
<maml:para></maml:para>
7735+
7736+
</maml:description>
7737+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
7738+
<dev:type>
7739+
<maml:name>string</maml:name>
7740+
<maml:uri/>
7741+
</dev:type>
7742+
<dev:defaultValue></dev:defaultValue>
7743+
</command:parameter>
77247744
</command:parameters>
77257745
<!-- Input - Output section-->
77267746
<command:inputTypes>
@@ -7779,15 +7799,15 @@ Vault has been created
77797799
<maml:para>C:\PS&gt;</maml:para>
77807800
</maml:introduction>
77817801
<dev:code>
7782-
Get-AzureSiteRecoveryVault
7783-
7784-
Name : testVault
7785-
ID : 6467459117934545458
7786-
CloudServiceName : CS-West-US-RecoveryServices
7787-
SubscriptionId : a5aa5997-33e5-46cc-8ab8-8bd89b76b7ba
7788-
StatusReason :
7789-
Status : Active
7790-
Location : West US
7802+
Get-AzureSiteRecoveryVault
7803+
7804+
Name : testVault
7805+
ID : 6467459117934545458
7806+
CloudServiceName : CS-West-US-RecoveryServices
7807+
SubscriptionId : a5aa5997-33e5-46cc-8ab8-8bd89b76b7ba
7808+
StatusReason :
7809+
Status : Active
7810+
Location : West US
77917811
</dev:code>
77927812
<dev:remarks>
77937813
<maml:para>Description</maml:para>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,7 @@ ClientRequestId: {3}</value>
239239
<data name="InvalidReplicationFrequency" xml:space="preserve">
240240
<value>Replication Frequency {0} is invalid</value>
241241
</data>
242+
<data name="VaultNotFound" xml:space="preserve">
243+
<value>Vault {0} is not associated with the given subscription.</value>
244+
</data>
242245
</root>

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

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,117 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2323
/// <summary>
2424
/// Retrieves Azure Site Recovery Vault.
2525
/// </summary>
26-
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVault")]
26+
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVault", DefaultParameterSetName = ASRParameterSets.Default)]
2727
[OutputType(typeof(List<ASRVault>))]
2828
public class GetAzureSiteRecoveryVaults : RecoveryServicesCmdletBase
2929
{
30+
#region Parameters
31+
/// <summary>
32+
/// Gets or sets name of the Vault.
33+
/// </summary>
34+
[Parameter(ParameterSetName = ASRParameterSets.ByName, Mandatory = true)]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
#endregion Parameters
38+
3039
/// <summary>
3140
/// ProcessRecord of the command.
3241
/// </summary>
3342
public override void ExecuteCmdlet()
3443
{
3544
try
3645
{
37-
IEnumerable<CloudService> cloudServiceList = RecoveryServicesClient.GetCloudServices();
46+
switch (this.ParameterSetName)
47+
{
48+
case ASRParameterSets.ByName:
49+
this.GetByName();
50+
break;
51+
case ASRParameterSets.Default:
52+
this.GetByDefault();
53+
break;
54+
}
55+
}
56+
catch (Exception exception)
57+
{
58+
this.HandleException(exception);
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Queries all, by default.
64+
/// </summary>
65+
private void GetByDefault()
66+
{
67+
List<ASRVault> vaultList = this.GetVaults();
68+
69+
this.WriteVaults(vaultList);
70+
}
71+
72+
/// <summary>
73+
/// Queries by name.
74+
/// </summary>
75+
private void GetByName()
76+
{
77+
bool vaultFound = false;
78+
79+
List<ASRVault> vaultList = this.GetVaults(out vaultFound);
80+
81+
if (!vaultFound)
82+
{
83+
throw new InvalidOperationException(
84+
string.Format(
85+
Properties.Resources.VaultNotFound,
86+
this.Name));
87+
}
88+
89+
this.WriteVaults(vaultList);
90+
}
3891

39-
List<ASRVault> vaultList = new List<ASRVault>();
40-
foreach (var cloudService in cloudServiceList)
92+
/// <summary>
93+
/// Overloaded GetVaults method so as to pass the out variable
94+
/// </summary>
95+
/// <returns>List of ASR Vaults</returns>
96+
private List<ASRVault> GetVaults()
97+
{
98+
bool temp = false;
99+
return this.GetVaults(out temp);
100+
}
101+
102+
/// <summary>
103+
/// Gets the vaults in the cloud service.
104+
/// </summary>
105+
/// <param name="vaultFound">Out variable to indicate if the vault was found</param>
106+
/// <returns>List of ASR Vaults</returns>
107+
private List<ASRVault> GetVaults(out bool vaultFound)
108+
{
109+
vaultFound = false;
110+
111+
IEnumerable<CloudService> cloudServiceList = RecoveryServicesClient.GetCloudServices();
112+
113+
List<ASRVault> vaultList = new List<ASRVault>();
114+
foreach (var cloudService in cloudServiceList)
115+
{
116+
foreach (var vault in cloudService.Resources)
41117
{
42-
foreach (var vault in cloudService.Resources)
118+
if (vault.Type.Equals(Constants.ASRVaultType, StringComparison.InvariantCultureIgnoreCase))
43119
{
44-
if (vault.Type.Equals(Constants.ASRVaultType, StringComparison.InvariantCultureIgnoreCase))
120+
if (string.Compare(this.ParameterSetName, ASRParameterSets.ByName, StringComparison.OrdinalIgnoreCase) == 0)
121+
{
122+
if (string.Compare(this.Name, vault.Name, StringComparison.OrdinalIgnoreCase) == 0)
123+
{
124+
vaultFound = true;
125+
vaultList.Add(new ASRVault(cloudService, vault));
126+
}
127+
}
128+
else
45129
{
46130
vaultList.Add(new ASRVault(cloudService, vault));
47131
}
48132
}
49133
}
50-
51-
this.WriteVaults(vaultList);
52-
}
53-
catch (Exception exception)
54-
{
55-
this.HandleException(exception);
56134
}
135+
136+
return vaultList;
57137
}
58138

59139
/// <summary>
@@ -64,5 +144,14 @@ private void WriteVaults(IList<ASRVault> vaultList)
64144
{
65145
this.WriteObject(vaultList, true);
66146
}
147+
148+
/// <summary>
149+
/// Writes Vault
150+
/// </summary>
151+
/// <param name="vault">Vault object</param>
152+
private void WriteVault(ASRVault vault)
153+
{
154+
this.WriteObject(vault);
155+
}
67156
}
68157
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public override void ExecuteCmdlet()
7171
case ASRParameterSets.EnterpriseToAzure:
7272
if (this.ProtectionProfile.ReplicationProvider != Constants.HyperVReplicaAzure)
7373
{
74-
throw new InvalidOperationException(
75-
string.Format(
76-
Properties.Resources.IncorrectReplicationProvider,
77-
this.ProtectionProfile.ReplicationProvider));
74+
throw new Exception("Please provide recovery container object.");
7875
}
7976
else
8077
{

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public class HyperVReplicaAzureProtectionProfileDetails
784784
/// Hyper-V Replica specific protection profile details.
785785
/// </summary>
786786
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
787-
public class HyperVReplicaProtectionProfileDetails
787+
public class HyperVReplicaSP1ProtectionProfileDetails
788788
{
789789
/// <summary>
790790
/// Gets or sets a value indicating the number of recovery points.
@@ -846,7 +846,14 @@ public class HyperVReplicaProtectionProfileDetails
846846
/// </summary>
847847
[DataMember]
848848
public string ReplicaDeletionOption { get; set; }
849+
}
849850

851+
/// <summary>
852+
/// Hyper-V Replica Blue specific protection profile details.
853+
/// </summary>
854+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
855+
public class HyperVReplicaProtectionProfileDetails : HyperVReplicaSP1ProtectionProfileDetails
856+
{
850857
/// <summary>
851858
/// Gets or sets a value indicating the replication interval.
852859
/// </summary>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ public ASRProtectionProfile(ProtectionProfile profile)
578578

579579
this.HyperVReplicaProviderSettingsObject.CompressionEnabled =
580580
details.CompressionEnabled;
581-
this.HyperVReplicaProviderSettingsObject.ReplicationFrequencyInSeconds = 0;
581+
this.HyperVReplicaProviderSettingsObject.ReplicationFrequencyInSeconds =
582+
details.ReplicationFrequencyInSeconds;
582583

583584
this.HyperVReplicaProviderSettingsObject.RecoveryPoints = details.RecoveryPoints;
584585
this.HyperVReplicaProviderSettingsObject.ReplicationMethod = details.OnlineReplicationMethod ?

0 commit comments

Comments
 (0)