Skip to content

Commit 69eed75

Browse files
committed
Check if the vault has registered servers before removing it
1 parent 569d5fe commit 69eed75

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

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
@@ -274,4 +274,7 @@ Please provide a storage account with the same location as that of the vault.</v
274274
<data name="VaultDeletionSuccessMessage" xml:space="preserve">
275275
<value>Vault has been deleted</value>
276276
</data>
277+
<data name="VaultCannotBeDeleted" xml:space="preserve">
278+
<value>Vault {0} cannot be deleted as it contains registered servers. Unregister them and then retry the operation.</value>
279+
</data>
277280
</root>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Commands.RecoveryServices.Properties;
1919
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
2020
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;
21+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2122

2223
namespace Microsoft.Azure.Commands.RecoveryServices
2324
{
@@ -58,6 +59,20 @@ public override void ExecuteCmdlet()
5859
try
5960
{
6061
// Check if vault has servers registered to it - prevent the operation.
62+
// Invocation of the api directly will result in a call similar to purge
63+
// But here we can't modify at service level.
64+
// Impact of this check on user is that the vault settings file has to be imported for this to work
65+
ServerListResponse serverListResponse =
66+
RecoveryServicesClient.GetAzureSiteRecoveryServer();
67+
68+
if (serverListResponse.Servers.Count != 0)
69+
{
70+
throw new InvalidOperationException(
71+
string.Format(
72+
Properties.Resources.VaultCannotBeDeleted,
73+
this.Vault.Name));
74+
}
75+
6176
this.ConfirmAction(
6277
this.Force.IsPresent,
6378
string.Format(Properties.Resources.RemoveVaultWarning, this.Vault.Name),

0 commit comments

Comments
 (0)