-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from AsrOneSdk/devsri-dev
Vault Credentials Client changes, enumerate vaults, create cloudservice and create vault changes
- Loading branch information
Showing
16 changed files
with
1,668 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...ommands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesCloudServiceClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery; | ||
using Microsoft.WindowsAzure; | ||
using Microsoft.WindowsAzure.Management.RecoveryServices.Models; | ||
|
||
namespace Microsoft.Azure.Commands.RecoveryServices | ||
{ | ||
/// <summary> | ||
/// Recovery services convenience client. | ||
/// </summary> | ||
public partial class PSRecoveryServicesClient | ||
{ | ||
/// <summary> | ||
/// Method to retrieve cloud services list for the current subscription | ||
/// </summary> | ||
/// <returns>list of cloud services.</returns> | ||
public IEnumerable<CloudService> GetCloudServices() | ||
{ | ||
CloudServiceListResponse response = this.GetRecoveryServicesClient.CloudServices.List(); | ||
|
||
return response.CloudServices; | ||
} | ||
|
||
/// <summary> | ||
/// Method to get Cloud Service object for a given vault | ||
/// </summary> | ||
/// <param name="vault">vault object</param> | ||
/// <returns>cloud service object.</returns> | ||
public CloudService GetCloudServiceForVault(ASRVault vault) | ||
{ | ||
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices(); | ||
CloudService cloudServiceToReturn = null; | ||
|
||
foreach (var cloudService in cloudServiceList) | ||
{ | ||
Vault selectedVault = null; | ||
if (cloudService.GeoRegion.Equals(vault.Location, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
foreach (var resource in cloudService.Resources) | ||
{ | ||
if (resource.Name.Equals(vault.Name, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
selectedVault = resource; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (selectedVault != null) | ||
{ | ||
cloudServiceToReturn = cloudService; | ||
break; | ||
} | ||
} | ||
|
||
return cloudServiceToReturn; | ||
} | ||
|
||
/// <summary> | ||
/// Method to Either find or create the cloud service. | ||
/// </summary> | ||
/// <param name="cloudServiceName">name of the cloud service to be created</param> | ||
/// <param name="cloudServiceInput">cloud service input to create the service.</param> | ||
public void FindOrCreateCloudService(string cloudServiceName, CloudServiceCreateArgs cloudServiceInput) | ||
{ | ||
bool cloudServicePresent = this.DoesCloudServiceExits(cloudServiceName); | ||
|
||
if (!cloudServicePresent) | ||
{ | ||
this.GetRecoveryServicesClient.CloudServices.Create(cloudServiceName, cloudServiceInput); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Checks whether a cloud service is present or not. | ||
/// </summary> | ||
/// <param name="cloudServiceName">name of the cloud service to be created</param> | ||
/// <returns>returns true in case the cloud service exits and false otherwise.</returns> | ||
private bool DoesCloudServiceExits(string cloudServiceName) | ||
{ | ||
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices(); | ||
bool cloudServicePresent = false; | ||
|
||
foreach (var cloudService in cloudServiceList) | ||
{ | ||
if (cloudServiceName.Equals(cloudService.Name, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
cloudServicePresent = true; | ||
break; | ||
} | ||
} | ||
|
||
return cloudServicePresent; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...vices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesVaultClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.WindowsAzure; | ||
using Microsoft.WindowsAzure.Management.RecoveryServices.Models; | ||
|
||
namespace Microsoft.Azure.Commands.RecoveryServices | ||
{ | ||
/// <summary> | ||
/// Recovery services convenience client. | ||
/// </summary> | ||
public partial class PSRecoveryServicesClient | ||
{ | ||
/// <summary> | ||
/// Method to create Azure Site Recovery Vault | ||
/// </summary> | ||
/// <param name="cloudServiceName">name of the cloud service</param> | ||
/// <param name="vaultName">name of the vault</param> | ||
/// <param name="vaultCreateInput">vault creation input object</param> | ||
/// <returns>creation response object.</returns> | ||
public VaultCreateResponse CreateVault(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreateInput) | ||
{ | ||
return this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput); | ||
} | ||
} | ||
} |
Oops, something went wrong.