Skip to content

Commit 3092e45

Browse files
committed
Create and Enumerate Site
1 parent 6e99f8a commit 3092e45

File tree

8 files changed

+258
-3
lines changed

8 files changed

+258
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
126126
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesProtectionProfileClient.cs" />
127127
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClientHelper.cs" />
128+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesSiteClient.cs" />
128129
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
129130
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
130131
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
@@ -143,6 +144,8 @@
143144
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
144145
<Compile Include="RecoveryServicesCmdletBase.cs" />
145146
<Compile Include="Properties\AssemblyInfo.cs" />
147+
<Compile Include="Service\NewAzureSiteRecoverySite.cs" />
148+
<Compile Include="Service\GetAzureSiteRecoverySite.cs" />
146149
<Compile Include="Service\SetAzureSiteRecoveryVirtualMachine.cs" />
147150
<Compile Include="Service\StartAzureSiteRecoveryProtectionProfileAssociationJob.cs" />
148151
<Compile Include="Service\CreateAzureSiteRecoveryProtectionProfileObject.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
16+
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
17+
using Microsoft.WindowsAzure;
18+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices
21+
{
22+
/// <summary>
23+
/// Recovery services convenience client.
24+
/// </summary>
25+
public partial class PSRecoveryServicesClient
26+
{
27+
/// <summary>
28+
/// Method to get the Azure site recovery sites
29+
/// </summary>
30+
/// <param name="vault">vault object</param>
31+
/// <returns>Site list response</returns>
32+
public SiteListResponse GetAzureSiteRecoverySites(ASRVault vault = null)
33+
{
34+
if (vault != null)
35+
{
36+
Utilities.UpdateVaultSettings(new ASRVaultCreds()
37+
{
38+
CloudServiceName = vault.CloudServiceName,
39+
ResourceName = vault.Name
40+
});
41+
}
42+
43+
return this.GetSiteRecoveryClient().Sites.List(this.GetRequestHeaders(false));
44+
}
45+
46+
/// <summary>
47+
/// Method to create a Site
48+
/// </summary>
49+
/// <param name="siteName">name of the site</param>
50+
/// <param name="siteType">type of the site</param>
51+
/// <param name="vault">vault object</param>
52+
/// <returns>job object for the creation.</returns>
53+
public JobResponse CreateAzureSiteRecoverySite(string siteName, string siteType = null, ASRVault vault = null)
54+
{
55+
if (vault != null)
56+
{
57+
Utilities.UpdateVaultSettings(new ASRVaultCreds()
58+
{
59+
CloudServiceName = vault.CloudServiceName,
60+
ResourceName = vault.Name
61+
});
62+
}
63+
64+
if (string.IsNullOrEmpty(siteType))
65+
{
66+
siteType = FabricProviders.HyperVSite;
67+
}
68+
69+
SiteCreationInput input = new SiteCreationInput()
70+
{
71+
Name = siteName,
72+
FabricType = siteType
73+
};
74+
75+
return this.GetSiteRecoveryClient().Sites.Create(input, this.GetRequestHeaders(false));
76+
}
77+
}
78+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
/// Retrieves Azure Site Recovery Site.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoverySite")]
27+
[OutputType(typeof(List<Site>))]
28+
public class GetAzureSiteRecoverySite : RecoveryServicesCmdletBase
29+
{
30+
#region Parameters
31+
32+
/// <summary>
33+
/// Gets or sets the vault name
34+
/// </summary>
35+
[Parameter(ParameterSetName = ASRParameterSets.ByObject, Mandatory = false, HelpMessage = "Vault Object for which the site list is to be fetched")]
36+
[ValidateNotNullOrEmpty]
37+
public ASRVault Vault { get; set; }
38+
39+
#endregion
40+
41+
/// <summary>
42+
/// ProcessRecord of the command.
43+
/// </summary>
44+
public override void ExecuteCmdlet()
45+
{
46+
try
47+
{
48+
SiteListResponse response = RecoveryServicesClient.GetAzureSiteRecoverySites(this.Vault);
49+
50+
this.WriteSites(response.Sites);
51+
}
52+
catch (Exception exception)
53+
{
54+
this.HandleException(exception);
55+
}
56+
}
57+
58+
/// <summary>
59+
/// Writes Sites
60+
/// </summary>
61+
/// <param name="siteList">List of Sites</param>
62+
private void WriteSites(IList<Site> siteList)
63+
{
64+
this.WriteObject(siteList, true);
65+
}
66+
}
67+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
namespace Microsoft.Azure.Commands.RecoveryServices
2727
{
2828
/// <summary>
29-
/// Retrieves Azure Site Recovery Server.
29+
/// Retrieves Azure Site Recovery Vault Settings File.
3030
/// </summary>
31-
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVaultSettingsFile", DefaultParameterSetName = ASRParameterSets.ByObject)]
31+
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVaultSettingsFile", DefaultParameterSetName = ASRParameterSets.ByParam)]
3232
[OutputType(typeof(VaultSettingsFilePath))]
3333
public class GetAzureSiteRecoveryVaultSettingsFile : RecoveryServicesCmdletBase
3434
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void ExecuteCmdlet()
5757
}
5858

5959
/// <summary>
60-
/// Writes Virtual Machines.
60+
/// Writes Vaults
6161
/// </summary>
6262
/// <param name="vaultList">List of Vaults</param>
6363
private void WriteVaults(IList<ASRVault> vaultList)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
/// Retrieves Azure Site Recovery Site.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.New, "AzureSiteRecoverySite")]
27+
[OutputType(typeof(ASRJob))]
28+
public class NewAzureSiteRecoverySite : RecoveryServicesCmdletBase
29+
{
30+
#region Parameters
31+
32+
/// <summary>
33+
/// Gets or sets the name of the site to be created
34+
/// </summary>
35+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = true, HelpMessage = "Name of the site to be created")]
36+
[ValidateNotNullOrEmpty]
37+
public string Name { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the name of the site to be created
41+
/// </summary>
42+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false, HelpMessage = "Type of the site to be created")]
43+
[ValidateNotNullOrEmpty]
44+
public string Type { get; set; }
45+
46+
/// <summary>
47+
/// Gets or sets the vault name
48+
/// </summary>
49+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false, HelpMessage = "Vault Object for which the site has to be created")]
50+
[ValidateNotNullOrEmpty]
51+
public ASRVault Vault { get; set; }
52+
53+
#endregion
54+
55+
/// <summary>
56+
/// ProcessRecord of the command.
57+
/// </summary>
58+
public override void ExecuteCmdlet()
59+
{
60+
try
61+
{
62+
JobResponse response = RecoveryServicesClient.CreateAzureSiteRecoverySite(this.Name, this.Type, this.Vault);
63+
64+
this.WriteObject(response.Job, true);
65+
}
66+
catch (Exception exception)
67+
{
68+
this.HandleException(exception);
69+
}
70+
}
71+
}
72+
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,41 @@ public enum RpErrorCode
122122
ResourceExtendedInfoNotFound
123123
}
124124

125+
/// <summary>
126+
/// Fabric type class.
127+
/// </summary>
128+
[SuppressMessage(
129+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
130+
"SA1402:FileMayOnlyContainASingleClass",
131+
Justification = "Keeping all contracts together.")]
132+
public class FabricProviders
133+
{
134+
/// <summary>
135+
/// Unknown type.
136+
/// </summary>
137+
public const string Other = "Other";
138+
139+
/// <summary>
140+
/// VMM server type.
141+
/// </summary>
142+
public const string VMM = "VMM";
143+
144+
/// <summary>
145+
/// Azure fabric type.
146+
/// </summary>
147+
public const string Azure = "Azure";
148+
149+
/// <summary>
150+
/// HyperVSite server type.
151+
/// </summary>
152+
public const string HyperVSite = "HyperVSite";
153+
154+
/// <summary>
155+
/// InMage server type.
156+
/// </summary>
157+
public const string VCenter = "VCenter";
158+
}
159+
125160
/// <summary>
126161
/// Error contract returned when some exception occurs in ASR REST API.
127162
/// </summary>

0 commit comments

Comments
 (0)