Skip to content

Commit

Permalink
New cmdlets
Browse files Browse the repository at this point in the history
  • Loading branch information
grizzlytheodore committed Aug 13, 2020
1 parent ee8b1d3 commit b58aed2
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ function Test-DiskAccessObject
try
{
# Common
$loc = Get-ComputeVMLocation;
$loc = "northcentralus";
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$diskAccess = New-AzDiskAccess -ResourceGroupName $rgname -Name $diskname -location $loc
Expand Down
110 changes: 110 additions & 0 deletions src/Compute/Compute/Disk/GetAzDiskAccessCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Automation.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
namespace Microsoft.Azure.Commands.Compute.Automation
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "DiskAccess", DefaultParameterSetName = DefaultParameterSet)]
[OutputType(typeof(PSDiskAccess))]
public partial class GetAzureDiskAccess : ComputeAutomationBaseCmdlet
{
private const string DefaultParameterSet = "DefaultParameterSet";
private const string InputObjectParameterSet = "InputObjectParameterSet";
private const string ResourceIDParameterSet = "ResourceIDParameterSet";
[Parameter(
ParameterSetName = DefaultParameterSet,
Position = 0,
ValueFromPipelineByPropertyName = true)]
[ResourceGroupCompleter]
[SupportsWildcards]
public string ResourceGroupName { get; set; }
[Parameter(
ParameterSetName = DefaultParameterSet,
Position = 1,
ValueFromPipelineByPropertyName = true)]
[ResourceNameCompleter("Microsoft.Compute/diskAccesses", "ResourceGroupName")]
[SupportsWildcards]
[Alias("diskAccessName")]
public string Name { get; set; }
[Parameter(
Mandatory = true,
Position = 0,
ParameterSetName = ResourceIDParameterSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Resource ID for your disk access.")]
[ResourceIdCompleter("Microsoft.Compute/diskAccesses")]
public string ResourceId { get; set; }
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
ExecuteClientAction(() =>
{
string resourceGroupName = this.ResourceGroupName;
string diskName = this.DiskName;
if (ShouldGetByName(resourceGroupName, diskName))
{
var result = DisksClient.Get(resourceGroupName, diskName);
var psObject = new PSDisk();
ComputeAutomationAutoMapperProfile.Mapper.Map<Disk, PSDisk>(result, psObject);
WriteObject(psObject);
}
else if (ShouldListByResourceGroup(resourceGroupName, diskName))
{
var result = DisksClient.ListByResourceGroup(resourceGroupName);
var resultList = result.ToList();
var nextPageLink = result.NextPageLink;
while (!string.IsNullOrEmpty(nextPageLink))
{
var pageResult = DisksClient.ListByResourceGroupNext(nextPageLink);
foreach (var pageItem in pageResult)
{
resultList.Add(pageItem);
}
nextPageLink = pageResult.NextPageLink;
}
var psObject = new List<PSDiskList>();
foreach (var r in resultList)
{
psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map<Disk, PSDiskList>(r));
}
WriteObject(TopLevelWildcardFilter(resourceGroupName, diskName, psObject), true);
}
else
{
var result = DisksClient.List();
var resultList = result.ToList();
var nextPageLink = result.NextPageLink;
while (!string.IsNullOrEmpty(nextPageLink))
{
var pageResult = DisksClient.ListNext(nextPageLink);
foreach (var pageItem in pageResult)
{
resultList.Add(pageItem);
}
nextPageLink = pageResult.NextPageLink;
}
var psObject = new List<PSDiskList>();
foreach (var r in resultList)
{
psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map<Disk, PSDiskList>(r));
}
WriteObject(TopLevelWildcardFilter(resourceGroupName, diskName, psObject), true);
}
});
}
}
}
*/
2 changes: 1 addition & 1 deletion src/Compute/Compute/Disk/NewAzDiskAccessCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NewAzureDiskAccess : ComputeAutomationBaseCmdlet
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Alias("DiskAssessName")]
[Alias("DiskAccessName")]
public string Name { get; set; }

[Parameter(
Expand Down
12 changes: 6 additions & 6 deletions src/Compute/Compute/Disk/RemoveDiskAccessCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public partial class RemoveAzureDiskAccess : ComputeAutomationBaseCmdlet
private const string ResourceIDParameterSet = "ResourceIDParameterSet";

[Parameter(
ParameterSetName = DefaultParameterSet,
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
ParameterSetName = DefaultParameterSet,
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceGroupCompleter]
public string ResourceGroupName { get; set; }

Expand All @@ -34,7 +34,7 @@ public partial class RemoveAzureDiskAccess : ComputeAutomationBaseCmdlet
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceNameCompleter("Microsoft.Compute/diskAccesses", "ResourceGroupName")]
[Alias("DiskName")]
[Alias("DiskAccessName")]
public string Name { get; set; }

[Parameter(
Expand Down Expand Up @@ -64,7 +64,7 @@ public override void ExecuteCmdlet()
base.ExecuteCmdlet();
ExecuteClientAction(() =>
{
if (ShouldProcess(this.Name, VerbsCommon.Remove)
if (ShouldProcess(this.Name, VerbsCommon.Remove))
{
string resourceGroupName;
string diskAccessName;
Expand Down

0 comments on commit b58aed2

Please sign in to comment.