Skip to content

Commit a87e14a

Browse files
committed
Merge branch 'dev' of https://github.com/AsrOneSdk/azure-powershell into sriramvu-dev
Conflicts: src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/StartAzureSiteRecoveryPlannedFailoverJob.cs
2 parents 7060901 + 8bb31e3 commit a87e14a

15 files changed

+311
-57
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: 27 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ ClientRequestId: {3}</value>
230230
<data name="NetworkArgumentsMissingForUpdateVmProperties" xml:space="preserve">
231231
<value>Please provide both Source Nic and Recovery Target to update</value>
232232
</data>
233+
<data name="MandatoryParamFromNextRelease" xml:space="preserve">
234+
<value>"'{0}' will be a mandatory paramter from next release."</value>
235+
</data>
236+
<data name="IDBasedParamUsageNotSupportedFromNextRelease" xml:space="preserve">
237+
<value>"Calls using ID based parameter '{0}' will not be supported from next release. Please use its corresponding full object parameter instead."</value>
238+
</data>
233239
<data name="InvalidReplicationFrequency" xml:space="preserve">
234240
<value>Replication Frequency {0} is invalid</value>
235241
</data>
242+
<data name="VaultNotFound" xml:space="preserve">
243+
<value>Vault {0} is not associated with the given subscription.</value>
244+
</data>
236245
</root>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/RecoveryServicesCmdletBase.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,22 @@ protected override void StopProcessing()
168168
/// Validates if the usage by ID is allowed or not.
169169
/// </summary>
170170
/// <param name="replicationProvider">Replication provider.</param>
171-
protected void ValidateUsageById(string replicationProvider)
171+
/// <param name="paramName">Parameter name.</param>
172+
protected void ValidateUsageById(string replicationProvider, string paramName)
172173
{
173174
if (replicationProvider != Constants.HyperVReplica)
174175
{
175-
throw new Exception("Call using ID parameter is not supported.");
176+
throw new Exception(
177+
string.Format(
178+
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
179+
paramName));
176180
}
177181
else
178182
{
179-
this.WriteWarning("Call using 'ID' parameter will not be supported from next release. Please use full object parameter instead.");
183+
this.WriteWarningWithTimestamp(
184+
string.Format(
185+
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
186+
paramName));
180187
}
181188
}
182189

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public class GetAzureSiteRecoveryJob : RecoveryServicesCmdletBase
5252
[ValidateNotNullOrEmpty]
5353
public DateTime? StartTime { get; set; }
5454

55+
/// <summary>
56+
/// Gets or sets end time. Allows to filter the list of jobs ended before it.
57+
/// </summary>
58+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "Represents end time of jobs to query.")]
59+
[ValidateNotNullOrEmpty]
60+
public DateTime? EndTime { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets target object id.
64+
/// </summary>
65+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "ID of the object on which Job was targeted to.")]
66+
[ValidateNotNullOrEmpty]
67+
public string TargetObjectId { get; set; }
68+
5569
/// <summary>
5670
/// Gets or sets state. Take string input for possible States of ASR Job. Use this parameter
5771
/// to get filtered view of Jobs
@@ -121,7 +135,15 @@ private void GetByParam()
121135
this.StartTime.Value.ToUniversalTime().ToBinary().ToString();
122136
}
123137

138+
if (this.EndTime.HasValue)
139+
{
140+
jqp.EndTime =
141+
this.EndTime.Value.ToUniversalTime().ToBinary().ToString();
142+
}
143+
124144
jqp.State = this.State;
145+
jqp.ObjectId = this.TargetObjectId;
146+
125147
this.WriteJobs(RecoveryServicesClient.GetAzureSiteRecoveryJob(jqp).Jobs);
126148
}
127149

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/SetAzureSiteRecoveryProtectionEntity.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,48 @@ public override void ExecuteCmdlet()
168168
string profileId = string.Empty;
169169
var input = new EnableProtectionInput();
170170

171+
if (this.ProtectionEntity == null)
172+
{
173+
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
174+
this.ProtectionContainerId,
175+
this.Id);
176+
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
177+
}
178+
171179
// Get the replciation provider from profile object otherwise assume its E2E.
172180
// Let the call go without profileId set.
173-
string replicationProvider = Constants.HyperVReplica;
181+
string replicationProvider = null;
182+
174183
if (this.ProtectionProfile != null)
175184
{
176185
profileId = this.ProtectionProfile.ID;
177186
replicationProvider = this.ProtectionProfile.ReplicationProvider;
178187
}
179-
180-
if (this.ProtectionEntity == null)
188+
else
181189
{
182-
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
183-
this.ProtectionContainerId,
184-
this.Id);
185-
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
190+
this.WriteWarningWithTimestamp(
191+
string.Format(
192+
Properties.Resources.MandatoryParamFromNextRelease,
193+
"ProtectionProfile"));
194+
string pcId = this.ProtectionContainerId ?? this.ProtectionEntity.ProtectionContainerId;
195+
var pc = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer(
196+
pcId);
197+
198+
// PC will have all profiles associated with same replciation providers only.
199+
replicationProvider =
200+
pc.ProtectionContainer.AvailableProtectionProfiles.Count < 1 ?
201+
null :
202+
pc.ProtectionContainer.AvailableProtectionProfiles[0].ReplicationProvider;
186203

187-
this.ValidateUsageById(replicationProvider);
204+
if (replicationProvider != Constants.HyperVReplica)
205+
{
206+
throw new Exception("Please provide the protection profile object. It can be chosen from available protection profiles of the protection container.");
207+
}
208+
}
209+
210+
if (this.ParameterSetName == ASRParameterSets.ByIDs)
211+
{
212+
this.ValidateUsageById(replicationProvider, "Id");
188213
}
189214

190215
if (replicationProvider == Constants.HyperVReplicaAzure)

0 commit comments

Comments
 (0)