Skip to content

Commit 47a6858

Browse files
committed
Merge branch 'dev' into neha-dev
2 parents 583015e + 77f5b03 commit 47a6858

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

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

Lines changed: 18 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,10 @@ ClientRequestId: {3}</value>
194194
<data name="SubscriptionIsNotAssociatedWithTheAccount" xml:space="preserve">
195195
<value>Subscription {0} is not associated with the account</value>
196196
</data>
197+
<data name="ProtectionEntityAlreadyDisabled" xml:space="preserve">
198+
<value>Protection entity {0} is already disabled</value>
199+
</data>
200+
<data name="ProtectionEntityAlreadyEnabled" xml:space="preserve">
201+
<value>Protection entity {0} is already enabled</value>
202+
</data>
197203
</root>

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
3535
/// </summary>
3636
private JobResponse jobResponse = null;
3737

38+
/// <summary>
39+
/// Protection Status of the entity.
40+
/// </summary>
41+
private bool alreadyEnabled = false;
42+
3843
/// <summary>
3944
/// Holds either Name (if object is passed) or ID (if IDs are passed) of the PE.
4045
/// </summary>
@@ -52,7 +57,7 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
5257
/// </summary>
5358
[Parameter(ParameterSetName = ASRParameterSets.ByIDs, Mandatory = true)]
5459
[ValidateNotNullOrEmpty]
55-
public string ProtectionContianerId { get; set; }
60+
public string ProtectionContainerId { get; set; }
5661

5762
/// <summary>
5863
/// Gets or sets Protection Entity Object.
@@ -93,14 +98,38 @@ public override void ExecuteCmdlet()
9398
{
9499
case ASRParameterSets.ByPEObject:
95100
this.Id = this.ProtectionEntity.ID;
96-
this.ProtectionContianerId = this.ProtectionEntity.ProtectionContainerId;
101+
this.ProtectionContainerId = this.ProtectionEntity.ProtectionContainerId;
97102
this.targetNameOrId = this.ProtectionEntity.Name;
103+
this.alreadyEnabled = this.ProtectionEntity.Protected;
104+
98105
break;
99106
case ASRParameterSets.ByIDs:
100107
this.targetNameOrId = this.Id;
108+
ProtectionEntityResponse protectionEntityResponse =
109+
RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
110+
this.ProtectionContainerId,
111+
this.Id);
112+
this.alreadyEnabled = protectionEntityResponse.ProtectionEntity.Protected;
113+
this.targetNameOrId = protectionEntityResponse.ProtectionEntity.Name;
114+
101115
break;
102116
}
103117

118+
if (this.alreadyEnabled &&
119+
this.Protection.Equals(PSRecoveryServicesClient.EnableProtection, StringComparison.OrdinalIgnoreCase))
120+
{
121+
throw new ArgumentException(
122+
Properties.Resources.ProtectionEntityAlreadyEnabled,
123+
this.targetNameOrId);
124+
}
125+
else if (!this.alreadyEnabled &&
126+
this.Protection.Equals(PSRecoveryServicesClient.DisableProtection, StringComparison.OrdinalIgnoreCase))
127+
{
128+
throw new ArgumentException(
129+
Properties.Resources.ProtectionEntityAlreadyDisabled,
130+
this.targetNameOrId);
131+
}
132+
104133
this.ConfirmAction(
105134
this.Force.IsPresent || 0 != string.CompareOrdinal(this.Protection, PSRecoveryServicesClient.DisableProtection),
106135
string.Format(Properties.Resources.DisableProtectionWarning, this.targetNameOrId),
@@ -112,7 +141,7 @@ public override void ExecuteCmdlet()
112141
{
113142
this.jobResponse =
114143
RecoveryServicesClient.SetProtectionOnProtectionEntity(
115-
this.ProtectionContianerId,
144+
this.ProtectionContainerId,
116145
this.Id,
117146
this.Protection);
118147

0 commit comments

Comments
 (0)