forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for storage target create. (Azure#17)
* Add PS wrapper classes required for storage targets. * Add help for create storage target. * Add new storage target cmdlet. * Update resource designer for storage target.
- Loading branch information
Showing
11 changed files
with
578 additions
and
1 deletion.
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
193 changes: 193 additions & 0 deletions
193
src/StorageCache/HPCCache/Commands/NewAzHpcStorageTarget.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,193 @@ | ||
namespace Microsoft.Azure.Commands.HPCCache | ||
{ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Net; | ||
using Microsoft.Azure.Commands.Common.Strategies; | ||
using Microsoft.Azure.Commands.HPCCache.Properties; | ||
using Microsoft.Azure.Management.StorageCache; | ||
using Microsoft.Azure.Management.StorageCache.Models; | ||
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; | ||
using Microsoft.Rest.Azure; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
|
||
/// <summary> | ||
/// NewAzHpcStorageTarget. | ||
/// </summary> | ||
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCacheStorageTarget")] | ||
[OutputType(typeof(PSHpcStorageTarget))] | ||
public class NewAzHpcStorageTarget : HpcCacheBaseCmdlet | ||
{ | ||
private const string NfsStorageTargetParameterSet = "NfsParameterSet"; | ||
private const string ClfsStorageTargetParameterSet = "ClfsParameterSet"; | ||
private StorageTarget storageTarget; | ||
|
||
/// <summary> | ||
/// Gets or sets resource Group Name. | ||
/// </summary> | ||
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of resource group under which you want to create cache.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets resource CacheName. | ||
/// </summary> | ||
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")] | ||
[ValidateNotNullOrEmpty] | ||
public string CacheName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets resource storage target name. | ||
/// </summary> | ||
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of storage target.")] | ||
[ValidateNotNullOrEmpty] | ||
public string StorageTargetName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets CLFS storage target. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = ClfsStorageTargetParameterSet, HelpMessage = "Create CLFS storage target.")] | ||
[ValidateNotNullOrEmpty] | ||
public SwitchParameter CLFS { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets NFS storage target. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = NfsStorageTargetParameterSet, HelpMessage = "Create NFS storage target.")] | ||
[ValidateNotNullOrEmpty] | ||
public SwitchParameter NFS { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets CLFS storage target StorageContainerID. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = ClfsStorageTargetParameterSet, HelpMessage = "StorageContainerID.")] | ||
[ValidateNotNullOrEmpty] | ||
public string StorageContainerID { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets NFS storage target hostname. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = NfsStorageTargetParameterSet, HelpMessage = "NFS host name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string HostName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets NFS storage target usage model. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = NfsStorageTargetParameterSet, HelpMessage = "NFS usage model.")] | ||
[ValidateNotNullOrEmpty] | ||
public string UsageModel { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets junctions. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = ClfsStorageTargetParameterSet, HelpMessage = "Junction.")] | ||
[Parameter(Mandatory = false, ParameterSetName = NfsStorageTargetParameterSet, HelpMessage = "Junction.")] | ||
[ValidateNotNullOrEmpty] | ||
public Hashtable[] Junctions { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets AsJob. | ||
/// </summary> | ||
[Parameter(Mandatory = false, HelpMessage = "AsJob.")] | ||
public SwitchParameter AsJob { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void ExecuteCmdlet() | ||
{ | ||
this.storageTarget = this.CLFS.IsPresent ? this.CreateClfsStorageTargetParameters() : this.CreateNfsStorageTargetParameters(); | ||
if (this.IsParameterBound(c => c.Junctions)) | ||
{ | ||
this.storageTarget.Junctions = new List<NamespaceJunction>(); | ||
foreach (var junction in this.Junctions) | ||
{ | ||
var nameSpaceJunction = HashtableToDictionary<string, string>(junction); | ||
this.storageTarget.Junctions.Add( | ||
new NamespaceJunction( | ||
nameSpaceJunction.GetOrNull("namespacePath"), | ||
nameSpaceJunction.GetOrNull("targetPath"), | ||
nameSpaceJunction.GetOrNull("nfsExport"))); | ||
} | ||
} | ||
|
||
this.DoesStorageTargetExists(); | ||
var results = new List<PSHpcStorageTarget>() { this.CreateStorageTargetModel() }; | ||
this.WriteObject(results, enumerateCollection: true); | ||
} | ||
|
||
private PSHpcStorageTarget CreateStorageTargetModel() | ||
{ | ||
return new PSHpcStorageTarget( | ||
this.HpcCacheClient.StorageTargets.CreateOrUpdate( | ||
this.ResourceGroupName, | ||
this.CacheName, | ||
this.StorageTargetName, | ||
this.storageTarget)); | ||
} | ||
|
||
private bool DoesStorageTargetExists() | ||
{ | ||
try | ||
{ | ||
var resource = this.HpcCacheClient.StorageTargets.Get( | ||
this.ResourceGroupName, | ||
this.CacheName, | ||
this.StorageTargetName); | ||
|
||
throw new Exception(string.Format(Resources.UpgradeHpcCache, this.StorageTargetName, this.CacheName)); | ||
} | ||
catch (CloudErrorException e) | ||
{ | ||
if (e.Body.Error.Code == "NotFound") | ||
{ | ||
return false; | ||
} | ||
|
||
throw; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Create CLFS storage target parameters. | ||
/// </summary> | ||
/// <returns>CLFS storage target parameters.</returns> | ||
private StorageTarget CreateClfsStorageTargetParameters() | ||
{ | ||
ClfsTarget clfsTarget = new ClfsTarget() | ||
{ | ||
Target = this.StorageContainerID, | ||
}; | ||
|
||
StorageTarget storageTargetParameters = new StorageTarget | ||
{ | ||
TargetType = "clfs", | ||
Clfs = clfsTarget, | ||
}; | ||
|
||
return storageTargetParameters; | ||
} | ||
|
||
/// <summary> | ||
/// Create CLFS storage target parameters. | ||
/// </summary> | ||
/// <returns>CLFS storage target parameters.</returns> | ||
private StorageTarget CreateNfsStorageTargetParameters() | ||
{ | ||
Nfs3Target nfs3Target = new Nfs3Target() | ||
{ | ||
Target = this.HostName, | ||
UsageModel = this.UsageModel, | ||
}; | ||
|
||
StorageTarget storageTargetParameters = new StorageTarget | ||
{ | ||
TargetType = "nfs3", | ||
Nfs3 = nfs3Target, | ||
}; | ||
|
||
return storageTargetParameters; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models | ||
{ | ||
using StorageCacheModels = Microsoft.Azure.Management.StorageCache.Models; | ||
|
||
/// <summary> | ||
/// PSHpcClfsTarget. | ||
/// </summary> | ||
public class PSHpcClfsTarget | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PSHpcClfsTarget"/> class. | ||
/// </summary> | ||
/// <param name="clfsTarget">clfsTarget.</param> | ||
public PSHpcClfsTarget(StorageCacheModels.ClfsTarget clfsTarget) | ||
{ | ||
this.Target = clfsTarget.Target; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or Sets Clfs Target. | ||
/// </summary> | ||
public string Target { get; set; } | ||
} | ||
} |
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,44 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models | ||
{ | ||
using StorageCacheModels = Microsoft.Azure.Management.StorageCache.Models; | ||
|
||
/// <summary> | ||
/// PSHpcNfs3Target. | ||
/// </summary> | ||
public class PSHpcNfs3Target | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PSHpcNfs3Target"/> class. | ||
/// </summary> | ||
/// <param name="nfs3Target">nfs3Target.</param> | ||
public PSHpcNfs3Target(StorageCacheModels.Nfs3Target nfs3Target) | ||
{ | ||
this.Target = nfs3Target.Target; | ||
this.UsageModel = nfs3Target.UsageModel; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or Sets NFS3 Target. | ||
/// </summary> | ||
public string Target { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or Sets storageTarget UsageModel. | ||
/// </summary> | ||
public string UsageModel { get; set; } | ||
} | ||
} |
Oops, something went wrong.