Skip to content

Commit 95a6a5a

Browse files
committed
resolved conflicts
2 parents 448b4aa + 5f9689b commit 95a6a5a

15 files changed

+665
-43
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Commands.RecoveryServices.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,13 @@
167167
<Compile Include="Properties\AssemblyInfo.cs" />
168168
<Compile Include="Service\GetAzureSiteRecoveryStoragePoolMapping.cs" />
169169
<Compile Include="Service\GetAzureSiteRecoveryVault.cs" />
170+
<Compile Include="Service\RemoveAzureSiteRecoverySite.cs" />
170171
<Compile Include="Service\NewAzureSiteRecoverySite.cs" />
171172
<Compile Include="Service\GetAzureSiteRecoverySite.cs" />
172173
<Compile Include="Service\NewAzureSiteRecoveryStoragePoolMapping.cs" />
173174
<Compile Include="Service\RemoveAzureSiteRecoveryStoragePoolMapping.cs" />
175+
<Compile Include="Service\RemoveAzureSiteRecoveryVault.cs" />
176+
<Compile Include="Service\SetAzureSiteRecoveryProtectionProfile.cs" />
174177
<Compile Include="Service\SetAzureSiteRecoveryVM.cs" />
175178
<Compile Include="Service\StartAzureSiteRecoveryProtectionProfileAssociationJob.cs" />
176179
<Compile Include="Service\CreateAzureSiteRecoveryProtectionProfileObject.cs" />

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesServerClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public partial class PSRecoveryServicesClient
2626
/// <summary>
2727
/// Gets Azure Site Recovery Servers.
2828
/// </summary>
29+
/// <param name="shouldSignRequest">Boolean indicating if the request should be signed ACIK</param>
2930
/// <returns>Server list response</returns>
30-
public ServerListResponse GetAzureSiteRecoveryServer()
31+
public ServerListResponse GetAzureSiteRecoveryServer(bool shouldSignRequest = true)
3132
{
32-
return this.GetSiteRecoveryClient().Servers.List(this.GetRequestHeaders());
33+
return this.GetSiteRecoveryClient().Servers.List(this.GetRequestHeaders(shouldSignRequest));
3334
}
3435

3536
/// <summary>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesSiteClient.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
1617
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
1718
using Microsoft.WindowsAzure.Management.SiteRecovery;
@@ -74,5 +75,45 @@ public JobResponse CreateAzureSiteRecoverySite(string siteName, string siteType
7475

7576
return this.GetSiteRecoveryClient().Sites.Create(input, this.GetRequestHeaders(false));
7677
}
78+
79+
/// <summary>
80+
/// Method to delete a Site
81+
/// </summary>
82+
/// <param name="siteName">name of the site</param>
83+
/// <param name="vault">vault object</param>
84+
/// <returns>job object for the creation.</returns>
85+
public JobResponse DeleteAzureSiteRecoverySite(string siteName, ASRVault vault = null)
86+
{
87+
if (vault != null)
88+
{
89+
Utilities.UpdateVaultSettings(new ASRVaultCreds()
90+
{
91+
CloudServiceName = vault.CloudServiceName,
92+
ResourceName = vault.Name
93+
});
94+
}
95+
96+
string siteID = null;
97+
SiteListResponse response = this.GetAzureSiteRecoverySites(vault);
98+
foreach (var site in response.Sites)
99+
{
100+
if (siteName.Equals(site.Name, StringComparison.OrdinalIgnoreCase))
101+
{
102+
siteID = site.ID;
103+
break;
104+
}
105+
}
106+
107+
if (string.IsNullOrEmpty(siteID))
108+
{
109+
// Site does not exist
110+
throw new InvalidOperationException(
111+
string.Format(
112+
Properties.Resources.SiteDetailsNotValid,
113+
siteName));
114+
}
115+
116+
return this.GetSiteRecoveryClient().Sites.Delete(siteID, this.GetRequestHeaders(false));
117+
}
77118
}
78119
}

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesVaultClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,16 @@ public RecoveryServicesOperationStatusResponse CreateVault(string cloudServiceNa
3333
{
3434
return this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput);
3535
}
36+
37+
/// <summary>
38+
/// Method to delete Azure Site Recovery Vault
39+
/// </summary>
40+
/// <param name="cloudServiceName">name of the cloud service</param>
41+
/// <param name="vaultName">name of the vault</param>
42+
/// <returns>Operation response object.</returns>
43+
public AzureOperationResponse DeleteVault(string cloudServiceName, string vaultName)
44+
{
45+
return this.GetRecoveryServicesClient.Vaults.Delete(cloudServiceName, vaultName);
46+
}
3647
}
3748
}

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

Lines changed: 63 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,25 @@ Please provide a storage account with the same location as that of the vault.</v
256256
<data name="StorageAccountValidationUnsuccessful" xml:space="preserve">
257257
<value>The Subscription or Storage account couldn’t be validated. For failovers to be successful, the Subscription should belong to your account, the Storage account to the Subscription and Storage account location must be the same as location of your Vault.</value>
258258
</data>
259+
<data name="RemoveSiteWarning" xml:space="preserve">
260+
<value>Are you sure you want to remove Site {0}</value>
261+
</data>
262+
<data name="RemoveSiteWhatIfMessage" xml:space="preserve">
263+
<value>Removes Site</value>
264+
</data>
265+
<data name="RemoveVaultWarning" xml:space="preserve">
266+
<value>Are you sure you want to remove Vault {0}</value>
267+
</data>
268+
<data name="RemoveVaultWhatIfMessage" xml:space="preserve">
269+
<value>Removes Vault</value>
270+
</data>
271+
<data name="SiteDetailsNotValid" xml:space="preserve">
272+
<value>Site name {0} is not valid. Please try again with the correct site details.</value>
273+
</data>
274+
<data name="VaultDeletionSuccessMessage" xml:space="preserve">
275+
<value>Vault has been deleted</value>
276+
</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>
259280
</root>

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,6 @@ public override void ExecuteCmdlet()
219219
}
220220
}
221221

222-
/// <summary>
223-
/// Handles interrupts.
224-
/// </summary>
225-
protected override void StopProcessing()
226-
{
227-
// Ctrl + C and etc
228-
base.StopProcessing();
229-
this.StopProcessingFlag = true;
230-
}
231-
232222
/// <summary>
233223
/// Creates an E2A Protection Profile Object
234224
/// </summary>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
19+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices
22+
{
23+
/// <summary>
24+
/// Removes Azure Site Recovery Site.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Remove, "AzureSiteRecoverySite")]
27+
[OutputType(typeof(ASRJob))]
28+
public class RemoveAzureSiteRecoverySite : RecoveryServicesCmdletBase
29+
{
30+
#region Parameters
31+
32+
/// <summary>
33+
/// Gets or sets the name of the site to be deleted
34+
/// </summary>
35+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = true, HelpMessage = "Name of the site to be deleted")]
36+
[ValidateNotNullOrEmpty]
37+
public string Name { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the vault
41+
/// </summary>
42+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false, HelpMessage = "Vault Object for which the site has to be deleted")]
43+
[ValidateNotNullOrEmpty]
44+
public ASRVault Vault { get; set; }
45+
46+
/// <summary>
47+
/// Gets or sets switch parameter. On passing, command does not ask for confirmation.
48+
/// </summary>
49+
[Parameter(Mandatory = false)]
50+
public SwitchParameter Force { get; set; }
51+
52+
#endregion
53+
54+
/// <summary>
55+
/// ProcessRecord of the command.
56+
/// </summary>
57+
public override void ExecuteCmdlet()
58+
{
59+
try
60+
{
61+
// Check if site has registered servers and prevent the operation
62+
// But the rest api is exposed and can be called directly
63+
// - best to add this validation in service then before deleting a site
64+
this.ConfirmAction(
65+
this.Force.IsPresent,
66+
string.Format(Properties.Resources.RemoveSiteWarning, this.Name),
67+
string.Format(Properties.Resources.RemoveSiteWhatIfMessage),
68+
this.Name,
69+
() =>
70+
{
71+
JobResponse response =
72+
RecoveryServicesClient.DeleteAzureSiteRecoverySite(
73+
this.Name,
74+
this.Vault);
75+
76+
this.WriteObject(response.Job, true);
77+
});
78+
}
79+
catch (Exception exception)
80+
{
81+
this.HandleException(exception);
82+
}
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)