Skip to content

Commit f98ac03

Browse files
committed
PS for Enable/Disable/PFO/Commit
1 parent d8cf399 commit f98ac03

17 files changed

+1428
-610
lines changed

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,40 @@ public IEnumerable<CloudService> GetCloudServices()
3636
return response.CloudServices;
3737
}
3838

39-
/// <summary>
40-
/// Method to get Cloud Service object for a given vault
41-
/// </summary>
42-
/// <param name="vault">vault object</param>
43-
/// <returns>cloud service object.</returns>
44-
public CloudService GetCloudServiceForVault(ASRVault vault)
45-
{
46-
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
47-
CloudService cloudServiceToReturn = null;
39+
/////// <summary>
40+
/////// Method to get Cloud Service object for a given vault
41+
/////// </summary>
42+
/////// <param name="vault">vault object</param>
43+
/////// <returns>cloud service object.</returns>
44+
////public CloudService GetCloudServiceForVault(ASRVault vault)
45+
////{
46+
//// IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
47+
//// CloudService cloudServiceToReturn = null;
4848

49-
foreach (var cloudService in cloudServiceList)
50-
{
51-
Vault selectedVault = null;
52-
if (cloudService.GeoRegion.Equals(vault.Location, StringComparison.InvariantCultureIgnoreCase))
53-
{
54-
foreach (var resource in cloudService.Resources)
55-
{
56-
if (resource.Name.Equals(vault.Name, StringComparison.InvariantCultureIgnoreCase))
57-
{
58-
selectedVault = resource;
59-
break;
60-
}
61-
}
62-
}
49+
//// foreach (var cloudService in cloudServiceList)
50+
//// {
51+
//// Vault selectedVault = null;
52+
//// if (cloudService.GeoRegion.Equals(vault.Location, StringComparison.InvariantCultureIgnoreCase))
53+
//// {
54+
//// foreach (var resource in cloudService.Resources)
55+
//// {
56+
//// if (resource.Name.Equals(vault.Name, StringComparison.InvariantCultureIgnoreCase))
57+
//// {
58+
//// selectedVault = resource;
59+
//// break;
60+
//// }
61+
//// }
62+
//// }
6363

64-
if (selectedVault != null)
65-
{
66-
cloudServiceToReturn = cloudService;
67-
break;
68-
}
69-
}
64+
//// if (selectedVault != null)
65+
//// {
66+
//// cloudServiceToReturn = cloudService;
67+
//// break;
68+
//// }
69+
//// }
7070

71-
return cloudServiceToReturn;
72-
}
71+
//// return cloudServiceToReturn;
72+
////}
7373

7474
/// <summary>
7575
/// Method to Either find or create the cloud service.

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

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2424
/// </summary>
2525
public partial class PSRecoveryServicesClient
2626
{
27-
/// <summary>
28-
/// Represents Enable protection.
29-
/// </summary>
30-
public const string EnableProtection = "Enable";
31-
32-
/// <summary>
33-
/// Represents Disable protection.
34-
/// </summary>
35-
public const string DisableProtection = "Disable";
36-
3727
/// <summary>
3828
/// Retrieves Protection Entity.
3929
/// </summary>
@@ -71,35 +61,34 @@ public ProtectionEntityResponse GetAzureSiteRecoveryProtectionEntity(
7161
/// </summary>
7262
/// <param name="protectionContainerId">Protection Container ID</param>
7363
/// <param name="virtualMachineId">Virtual Machine ID</param>
74-
/// <param name="protection">Protection state to set</param>
64+
/// <param name="input">Enable protection input.</param>
7565
/// <returns>Job response</returns>
76-
public JobResponse SetProtectionOnProtectionEntity(
66+
public JobResponse EnableProtection(
7767
string protectionContainerId,
7868
string virtualMachineId,
79-
string protection)
69+
EnableProtectionInput input)
8070
{
81-
var requestHeaders = this.GetRequestHeaders();
82-
83-
JobResponse jobResponse = null;
84-
85-
if (0 == string.Compare(EnableProtection, protection, StringComparison.OrdinalIgnoreCase))
86-
{
87-
jobResponse = null;
88-
/* this.GetSiteRecoveryClient().ProtectionEntity.EnableProtection(
89-
protectionContainerId,
90-
virtualMachineId,
91-
requestHeaders); */
92-
}
93-
else if (0 == string.Compare(DisableProtection, protection, StringComparison.OrdinalIgnoreCase))
94-
{
95-
jobResponse =
96-
this.GetSiteRecoveryClient().ProtectionEntity.DisableProtection(
97-
protectionContainerId,
98-
virtualMachineId,
99-
requestHeaders);
100-
}
71+
return this.GetSiteRecoveryClient().ProtectionEntity.EnableProtection(
72+
protectionContainerId,
73+
virtualMachineId,
74+
input,
75+
this.GetRequestHeaders());
76+
}
10177

102-
return jobResponse;
78+
/// <summary>
79+
/// Sets protection on Protection entity.
80+
/// </summary>
81+
/// <param name="protectionContainerId">Protection Container ID</param>
82+
/// <param name="virtualMachineId">Virtual Machine ID</param>
83+
/// <returns>Job response</returns>
84+
public JobResponse DisbleProtection(
85+
string protectionContainerId,
86+
string virtualMachineId)
87+
{
88+
return this.GetSiteRecoveryClient().ProtectionEntity.DisableProtection(
89+
protectionContainerId,
90+
virtualMachineId,
91+
this.GetRequestHeaders());
10392
}
10493

10594
/// <summary>
@@ -164,15 +153,18 @@ public JobResponse StartAzureSiteRecoveryTestFailover(
164153
/// </summary>
165154
/// <param name="protectionContainerId">Protection Container ID</param>
166155
/// <param name="protectionEntityId">Recovery Plan ID</param>
156+
/// <param name="request">Commit failover request.</param>
167157
/// <returns>Job response</returns>
168158
public JobResponse StartAzureSiteRecoveryCommitFailover(
169159
string protectionContainerId,
170-
string protectionEntityId)
160+
string protectionEntityId,
161+
CommitFailoverRequest request)
171162
{
172-
return null; /* this.GetSiteRecoveryClient().ProtectionEntity.CommitFailover(
163+
return this.GetSiteRecoveryClient().ProtectionEntity.CommitFailover(
173164
protectionContainerId,
174165
protectionEntityId,
175-
this.GetRequestHeaders()); */
166+
request,
167+
this.GetRequestHeaders());
176168
}
177169

178170
/// <summary>

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2424
/// </summary>
2525
public partial class PSRecoveryServicesClient
2626
{
27-
/// <summary>
28-
/// Represents direction primary to secondary.
29-
/// </summary>
30-
public const string PrimaryToRecovery = "PrimaryToRecovery";
31-
32-
/// <summary>
33-
/// Represents direction secondary to primary.
34-
/// </summary>
35-
public const string RecoveryToPrimary = "RecoveryToPrimary";
36-
37-
/// <summary>
38-
/// Represents primary location.
39-
/// </summary>
40-
public const string PrimaryLocation = "Primary";
41-
42-
/// <summary>
43-
/// Represents Recovery location.
44-
/// </summary>
45-
public const string RecoveryLocation = "Recovery";
46-
4727
/// <summary>
4828
/// Gets Azure Site Recovery Plan.
4929
/// </summary>

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

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
using System.Threading.Tasks;
1818
using Microsoft.Azure.Commands.RecoveryServices.Properties;
1919
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
20-
using Microsoft.Azure.Portal.HybridServicesCore;
20+
////using Microsoft.Azure.Portal.HybridServicesCore;
2121
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
2222
using Microsoft.WindowsAzure;
2323
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
@@ -68,39 +68,39 @@ public async Task<UploadCertificateResponse> UpdateVaultCertificate(CertificateA
6868
/// <param name="vault">vault object</param>
6969
/// <param name="site">site object </param>
7070
/// <returns>credential object</returns>
71-
public ASRVaultCreds GenerateVaultCredential(X509Certificate2 managementCert, ASRVault vault, Site site)
72-
{
73-
Utilities.UpdateVaultSettings(new ASRVaultCreds()
74-
{
75-
CloudServiceName = vault.CloudServiceName,
76-
ResourceName = vault.Name
77-
});
78-
79-
// Get Channel Integrity key
80-
string channelIntegrityKey;
81-
Task<string> getChannelIntegrityKey = this.GetChannelIntegrityKey();
82-
83-
// Making sure we can generate the file, once the SDK and portal are inter-operable
84-
// upload certificate and fetch of ACIK can be made parallel to improvve the performace.
85-
getChannelIntegrityKey.Wait();
86-
87-
// Upload certificate
88-
UploadCertificateResponse acsDetails;
89-
Task<UploadCertificateResponse> uploadCertificate = this.UpdateVaultCertificate(managementCert);
90-
uploadCertificate.Wait();
91-
92-
acsDetails = uploadCertificate.Result;
93-
channelIntegrityKey = getChannelIntegrityKey.Result;
94-
95-
ASRVaultCreds asrVaultCreds = this.GenerateCredentialObject(
96-
managementCert,
97-
acsDetails,
98-
channelIntegrityKey,
99-
vault,
100-
site);
101-
102-
return asrVaultCreds;
103-
}
71+
////public ASRVaultCreds GenerateVaultCredential(X509Certificate2 managementCert, ASRVault vault, Site site)
72+
////{
73+
//// Utilities.UpdateVaultSettings(new ASRVaultCreds()
74+
//// {
75+
//// CloudServiceName = vault.CloudServiceName,
76+
//// ResourceName = vault.Name
77+
//// });
78+
79+
//// // Get Channel Integrity key
80+
//// string channelIntegrityKey;
81+
//// Task<string> getChannelIntegrityKey = this.GetChannelIntegrityKey();
82+
83+
//// // Making sure we can generate the file, once the SDK and portal are inter-operable
84+
//// // upload certificate and fetch of ACIK can be made parallel to improvve the performace.
85+
//// getChannelIntegrityKey.Wait();
86+
87+
//// // Upload certificate
88+
//// UploadCertificateResponse acsDetails;
89+
//// Task<UploadCertificateResponse> uploadCertificate = this.UpdateVaultCertificate(managementCert);
90+
//// uploadCertificate.Wait();
91+
92+
//// acsDetails = uploadCertificate.Result;
93+
//// channelIntegrityKey = getChannelIntegrityKey.Result;
94+
95+
//// ASRVaultCreds asrVaultCreds = this.GenerateCredentialObject(
96+
//// managementCert,
97+
//// acsDetails,
98+
//// channelIntegrityKey,
99+
//// vault,
100+
//// site);
101+
102+
//// return asrVaultCreds;
103+
////}
104104

105105
/// <summary>
106106
/// Method to update vault certificate
@@ -187,23 +187,23 @@ private ResourceExtendedInfo CreateVaultExtendedInformation()
187187
/// <param name="vault">vault object</param>
188188
/// <param name="site">site object</param>
189189
/// <returns>vault credential object</returns>
190-
private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault, Site site)
191-
{
192-
string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));
193-
194-
AcsNamespace acsNamespace = new AcsNamespace(acsDetails);
195-
196-
ASRVaultCreds vaultCreds = new ASRVaultCreds(
197-
vault.SubscriptionId,
198-
vault.Name,
199-
serializedCertifivate,
200-
acsNamespace,
201-
channelIntegrityKey,
202-
vault.CloudServiceName,
203-
site.ID,
204-
site.Name);
205-
206-
return vaultCreds;
207-
}
190+
////private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault, Site site)
191+
////{
192+
//// string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));
193+
194+
//// AcsNamespace acsNamespace = new AcsNamespace(acsDetails);
195+
196+
//// ASRVaultCreds vaultCreds = new ASRVaultCreds(
197+
//// vault.SubscriptionId,
198+
//// vault.Name,
199+
//// serializedCertifivate,
200+
//// acsNamespace,
201+
//// channelIntegrityKey,
202+
//// vault.CloudServiceName,
203+
//// site.ID,
204+
//// site.Name);
205+
206+
//// return vaultCreds;
207+
////}
208208
}
209209
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Runtime.Serialization;
1818
using System.Threading;
1919
using System.Xml;
20+
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
2021
using Microsoft.WindowsAzure;
2122
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2223
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
@@ -161,5 +162,27 @@ protected override void StopProcessing()
161162
base.StopProcessing();
162163
this.StopProcessingFlag = true;
163164
}
165+
166+
/// <summary>
167+
/// Validates if the usage by ID is allowed or not.
168+
/// </summary>
169+
/// <param name="replicationProvider">Replication provider.</param>
170+
protected void ValidateUsageById(string replicationProvider)
171+
{
172+
if (replicationProvider != Constants.HyperVReplica)
173+
{
174+
throw new Exception("Call using ID parameter is not supported.");
175+
}
176+
}
177+
178+
/// <summary>
179+
/// Gets the current vault location.
180+
/// </summary>
181+
/// <returns>The current vault location.</returns>
182+
protected string GetCurrentValutLocation()
183+
{
184+
string location = "Southeast Asia";
185+
return location;
186+
}
164187
}
165188
}

0 commit comments

Comments
 (0)