Skip to content

Commit 75fb3aa

Browse files
committed
Fix NextLink
1 parent 192b8fe commit 75fb3aa

File tree

5 files changed

+298
-9
lines changed

5 files changed

+298
-9
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@
317317
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VMDynamicTests\RunVMDynamicTests.json">
318318
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
319319
</None>
320+
<None Include="Templates\azuredeploy.json">
321+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
322+
</None>
320323
</ItemGroup>
321324
<ItemGroup>
322325
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,12 @@ public void TestGetVMSizeFromAllLocations()
116116
{
117117
ComputeTestController.NewInstance.RunPsTest("Test-GetVMSizeFromAllLocations");
118118
}
119+
120+
[Fact(Skip = "Fix NextLink")]
121+
[Trait(Category.AcceptanceType, Category.CheckIn)]
122+
public void TestVirtualMachineListWithPaging()
123+
{
124+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineListWithPaging");
125+
}
119126
}
120127
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,3 +1352,64 @@ function Test-GetVMSizeFromAllLocations
13521352
Write-Output ('Found VM Size Standard_A3 in Location: ' + $loc);
13531353
}
13541354
}
1355+
1356+
<#
1357+
.SYNOPSIS
1358+
Test Virtual Machine List with Paging
1359+
#>
1360+
function Test-VirtualMachineListWithPaging
1361+
{
1362+
# Setup
1363+
$rgname = Get-ComputeTestResourceName
1364+
1365+
try
1366+
{
1367+
# Common
1368+
$loc = 'West US';
1369+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
1370+
1371+
$numberOfInstances = 51;
1372+
$vmSize = 'Standard_A0';
1373+
1374+
$templateFile = ".\Templates\azuredeploy.json";
1375+
$paramFile = ".\Templates\azuredeploy-parameters-51vms.json";
1376+
$paramContent =
1377+
@"
1378+
{
1379+
"newStorageAccountName": {
1380+
"value": "${rgname}sto"
1381+
},
1382+
"adminUsername": {
1383+
"value": "Foo12"
1384+
},
1385+
"adminPassword": {
1386+
"value": "BaR@123${rgname}"
1387+
},
1388+
"numberOfInstances": {
1389+
"value": $numberOfInstances
1390+
},
1391+
"location": {
1392+
"value": "$loc"
1393+
},
1394+
"vmSize": {
1395+
"value": "$vmSize"
1396+
}
1397+
}
1398+
"@;
1399+
1400+
Set-Content -Path $paramFile -Value $paramContent -Force -Verbose;
1401+
1402+
New-AzureResourceGroupDeployment -Name "${rgname}dp" -ResourceGroupName $rgname -TemplateFile $templateFile -TemplateParameterFile $paramFile -Verbose;
1403+
1404+
$vms = Get-AzureVM -ResourceGroupName $rgname;
1405+
Assert-True { $vms.Count -eq $numberOfInstances };
1406+
1407+
$vms = Get-AzureVM;
1408+
Assert-True { $vms.Count -ge $numberOfInstances };
1409+
}
1410+
finally
1411+
{
1412+
# Cleanup
1413+
Clean-ResourceGroup $rgname
1414+
}
1415+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"adminUsername": {
6+
"type": "string",
7+
"metadata": {
8+
"description": "Admin username for VM"
9+
}
10+
},
11+
"adminPassword": {
12+
"type": "securestring",
13+
"metadata": {
14+
"description": "Admin password for VM"
15+
}
16+
},
17+
"newStorageAccountName": {
18+
"type": "string",
19+
"metadata": {
20+
"description": "Unique storage account name"
21+
}
22+
},
23+
"numberOfInstances": {
24+
"type": "int",
25+
"defaultValue": 2,
26+
"metadata": {
27+
"description": "Number of VMs to deploy"
28+
}
29+
},
30+
"location": {
31+
"type": "string",
32+
"allowedValues": [
33+
"West US",
34+
"East US",
35+
"West Europe",
36+
"East Asia",
37+
"Southeast Asia"
38+
],
39+
"metadata": {
40+
"description": "Location to deploy the VM in"
41+
}
42+
},
43+
"vmSize": {
44+
"type": "string",
45+
"metadata": {
46+
"description": "Size of the Virtual Machine."
47+
}
48+
},
49+
"imagePublisher": {
50+
"type": "string",
51+
"defaultValue": "Canonical",
52+
"metadata": {
53+
"description": "Image Publisher"
54+
}
55+
},
56+
"imageOffer": {
57+
"type": "string",
58+
"defaultValue": "UbuntuServer",
59+
"metadata": {
60+
"description": "Image Offer"
61+
}
62+
},
63+
"imageSKU": {
64+
"type": "string",
65+
"defaultValue": "14.04.2-LTS",
66+
"metadata": {
67+
"description": "Image SKU"
68+
}
69+
}
70+
},
71+
"variables": {
72+
"virtualNetworkName": "myVNET",
73+
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
74+
"addressPrefix": "10.0.0.0/16",
75+
"subnet1Name": "Subnet-1",
76+
"subnet1Prefix": "10.0.0.0/24",
77+
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/', variables('subnet1Name'))]",
78+
"vmStorageAccountContainerName": "vhds"
79+
},
80+
"resources": [
81+
{
82+
"type": "Microsoft.Storage/storageAccounts",
83+
"name": "[parameters('newStorageAccountName')]",
84+
"apiVersion": "2015-05-01-preview",
85+
"location": "[parameters('location')]",
86+
"properties": {
87+
"accountType": "Standard_LRS"
88+
}
89+
},
90+
{
91+
"apiVersion": "2015-05-01-preview",
92+
"type": "Microsoft.Network/virtualNetworks",
93+
"name": "[variables('virtualNetworkName')]",
94+
"location": "[parameters('location')]",
95+
"properties": {
96+
"addressSpace": {
97+
"addressPrefixes": [
98+
"[variables('addressPrefix')]"
99+
]
100+
},
101+
"subnets": [
102+
{
103+
"name": "[variables('subnet1Name')]",
104+
"properties": {
105+
"addressPrefix": "[variables('subnet1Prefix')]"
106+
}
107+
}
108+
]
109+
}
110+
},
111+
{
112+
"apiVersion": "2015-05-01-preview",
113+
"type": "Microsoft.Network/publicIPAddresses",
114+
"name": "[concat('publicIP', copyIndex())]",
115+
"location": "[parameters('location')]",
116+
"copy": {
117+
"name": "publicIPLoop",
118+
"count": "[parameters('numberOfInstances')]"
119+
},
120+
"properties": {
121+
"publicIPAllocationMethod": "Dynamic"
122+
}
123+
},
124+
{
125+
"apiVersion": "2015-05-01-preview",
126+
"type": "Microsoft.Network/networkInterfaces",
127+
"name": "[concat('nic', copyindex())]",
128+
"location": "[parameters('location')]",
129+
"copy": {
130+
"name": "nicLoop",
131+
"count": "[parameters('numberOfInstances')]"
132+
},
133+
"dependsOn": [
134+
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
135+
"[concat('Microsoft.Network/publicIPAddresses/', 'publicIP', copyindex())]"
136+
],
137+
"properties": {
138+
"ipConfigurations": [
139+
{
140+
"name": "ipconfig1",
141+
"properties": {
142+
"privateIPAllocationMethod": "Dynamic",
143+
"publicIPAddress": {
144+
"id": "[resourceId('Microsoft.Network/publicIPAddresses',concat('publicIP', copyindex()))]"
145+
},
146+
"subnet": {
147+
"id": "[variables('subnet1Ref')]"
148+
}
149+
}
150+
}
151+
]
152+
}
153+
},
154+
{
155+
"apiVersion": "2015-05-01-preview",
156+
"type": "Microsoft.Compute/virtualMachines",
157+
"name": "[concat('myvm', copyIndex())]",
158+
"location": "[parameters('location')]",
159+
"copy": {
160+
"name": "virtualMachineLoop",
161+
"count": "[parameters('numberOfInstances')]"
162+
},
163+
"dependsOn": [
164+
"[concat('Microsoft.Network/networkInterfaces/', 'nic', copyindex())]",
165+
"[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]"
166+
],
167+
"properties": {
168+
"hardwareProfile": {
169+
"vmSize": "[parameters('vmSize')]"
170+
},
171+
"osProfile": {
172+
"computername": "[concat('vm', copyIndex())]",
173+
"adminUsername": "[parameters('adminUsername')]",
174+
"adminPassword": "[parameters('adminPassword')]"
175+
},
176+
"storageProfile": {
177+
"imageReference": {
178+
"publisher": "[parameters('imagePublisher')]",
179+
"offer": "[parameters('imageOffer')]",
180+
"sku": "[parameters('imageSKU')]",
181+
"version": "latest"
182+
},
183+
"osDisk": {
184+
"name": "osdisk",
185+
"vhd": {
186+
"uri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/vhds/','osdisk', copyIndex(), '.vhd')]"
187+
},
188+
"caching": "ReadWrite",
189+
"createOption": "FromImage"
190+
}
191+
},
192+
"networkProfile": {
193+
"networkInterfaces": [
194+
{
195+
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat('nic', copyindex()))]"
196+
}
197+
]
198+
}
199+
}
200+
}
201+
]
202+
}
203+

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,43 @@ public override void ExecuteCmdlet()
9191
}
9292
else
9393
{
94-
VirtualMachineListResponse result = null;
95-
94+
VirtualMachineListResponse vmListResult = null;
9695
if (!string.IsNullOrEmpty(this.ResourceGroupName))
9796
{
98-
result = this.VirtualMachineClient.List(this.ResourceGroupName);
97+
vmListResult = this.VirtualMachineClient.List(this.ResourceGroupName);
9998
}
10099
else if (this.NextLink != null)
101100
{
102-
result = this.VirtualMachineClient.ListNext(this.NextLink.ToString());
101+
vmListResult = this.VirtualMachineClient.ListNext(this.NextLink.ToString());
103102
}
104103
else
105104
{
106105
var listParams = new ListParameters();
107-
result = this.VirtualMachineClient.ListAll(listParams);
106+
vmListResult = this.VirtualMachineClient.ListAll(listParams);
108107
}
109108

110109
var psResultList = new List<PSVirtualMachine>();
111-
foreach (var item in result.VirtualMachines)
110+
111+
while (vmListResult != null)
112112
{
113-
var psItem = Mapper.Map<PSVirtualMachine>(item);
114-
psItem = Mapper.Map<AzureOperationResponse, PSVirtualMachine>(result, psItem);
115-
psResultList.Add(psItem);
113+
if (vmListResult.VirtualMachines != null)
114+
{
115+
foreach (var item in vmListResult.VirtualMachines)
116+
{
117+
var psItem = Mapper.Map<PSVirtualMachine>(item);
118+
psItem = Mapper.Map<AzureOperationResponse, PSVirtualMachine>(vmListResult, psItem);
119+
psResultList.Add(psItem);
120+
}
121+
}
122+
123+
if (!string.IsNullOrEmpty(vmListResult.NextLink))
124+
{
125+
vmListResult = this.VirtualMachineClient.ListNext(vmListResult.NextLink);
126+
}
127+
else
128+
{
129+
vmListResult = null;
130+
}
116131
}
117132

118133
WriteObject(psResultList, true);

0 commit comments

Comments
 (0)