Skip to content

Commit 0e1387b

Browse files
committed
Merge pull request Azure#1057 from chidmdxx/DeleteAzureRmLocaion
Delete Get-AzureRmLocation
2 parents 0570089 + 21e8851 commit 0e1387b

File tree

23 files changed

+8272
-8492
lines changed

23 files changed

+8272
-8492
lines changed

src/ResourceManager/ApiManagement/Commands.ApiManagement.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ Gets all locations for a provider
5050
#>
5151
function Get-ProviderLocations($provider)
5252
{
53-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
54-
$location.Locations
53+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
54+
{
55+
$namespace = $provider.Split("/")[0]
56+
if($provider.Contains("/"))
57+
{
58+
$type = $provider.Substring($namespace.Length + 1)
59+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
60+
61+
if ($location -eq $null)
62+
{
63+
return @("Central US", "East US")
64+
} else
65+
{
66+
return $location.Locations[0]
67+
}
68+
}
69+
70+
return @("Central US", "East US")
71+
}
72+
73+
return @("Central US", "East US")
5574
}

src/ResourceManager/ApiManagement/Commands.SMAPI.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ Gets all locations for a provider
5050
#>
5151
function Get-ProviderLocations($provider)
5252
{
53-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
54-
$location.Locations
53+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
54+
{
55+
$namespace = $provider.Split("/")[0]
56+
if($provider.Contains("/"))
57+
{
58+
$type = $provider.Substring($namespace.Length + 1)
59+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
60+
61+
if ($location -eq $null)
62+
{
63+
return @("West US", "East US")
64+
} else
65+
{
66+
return $location.Locations[0]
67+
}
68+
}
69+
70+
return @("West US", "East US")
71+
}
72+
73+
return @("West US", "East US")
5574
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/Common.ps1

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ Gets the location for the Batch account provider. Default to West US if none fou
3636
#>
3737
function Get-BatchAccountProviderLocation($index)
3838
{
39-
$location = Get-AzureRmLocation | where {$_.Name -eq "Microsoft.Batch/batchAccounts"}
40-
if ($location -eq $null)
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
4140
{
42-
"West US"
43-
}
44-
else
45-
{
46-
if ($index -eq $null)
47-
{
48-
$location.Locations[0]
49-
}
50-
else
51-
{
52-
$location.Locations[$index]
41+
$namespace = $provider.Split("/")[0]
42+
if($provider.Contains("/"))
43+
{
44+
$type = $provider.Substring($namespace.Length + 1)
45+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
46+
47+
if ($location -eq $null)
48+
{
49+
return "West US"
50+
} else
51+
{
52+
return $location.Locations[0]
53+
}
5354
}
54-
}
55+
56+
return "West US"
57+
}
58+
59+
return "WestUS"
5560
}
5661

5762
<#

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,28 +398,27 @@ function Get-SasUri
398398
# Get a Location according to resource provider.
399399
function Get-ResourceProviderLocation
400400
{
401-
param ([string] $name, [string] $default = "westus", [bool] $canonical = $true)
402-
403-
$loc = Get-AzureRmLocation | where { $_.Name.Equals($name) };
404-
405-
if ($loc -eq $null)
406-
{
407-
throw 'There is no available locations with given parameters';
408-
}
409-
410-
if ($loc.LocationsString.ToLowerInvariant().Replace(" ", "").Contains($default.ToLowerInvariant().Replace(" ","")))
401+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
411402
{
412-
return $default;
403+
$namespace = $provider.Split("/")[0]
404+
if($provider.Contains("/"))
405+
{
406+
$type = $provider.Substring($namespace.Length + 1)
407+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
408+
409+
if ($location -eq $null)
410+
{
411+
return "West US"
412+
} else
413+
{
414+
return $location.Locations[0]
415+
}
416+
}
417+
418+
return "West US"
413419
}
414420

415-
if ($canonical)
416-
{
417-
return $loc.Locations[0].ToLowerInvariant().Replace(" ", "");
418-
}
419-
else
420-
{
421-
return $loc.Locations[0];
422-
}
421+
return "WestUS"
423422
}
424423

425424
function Get-ComputeVMLocation

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ function Test-GetAzureRmVMDscExtension
113113
#helper methods for ARM
114114
function Get-DefaultResourceGroupLocation
115115
{
116-
$location = Get-AzureRmLocation | where {$_.Name -eq "Microsoft.Resources/resourceGroups"}
117-
return $location.Locations[0]
116+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
117+
{
118+
$namespace = "Microsoft.Resources"
119+
$type = "resourceGroups"
120+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
121+
122+
if ($location -eq $null)
123+
{
124+
return "West US"
125+
} else
126+
{
127+
return $location.Locations[0]
128+
}
129+
}
130+
131+
return "West US"
118132
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@
1414

1515
function get_all_vm_locations
1616
{
17-
$st = Write-Verbose 'Getting all Azure location - Start';
18-
19-
$locations = Get-AzureRmLocation | where { $_.Name -eq 'Microsoft.Compute/virtualMachines' } | select -ExpandProperty Locations;
17+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
18+
{
19+
$namespace = "Microsoft.Compute"
20+
$type = "virtualMachines"
21+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
22+
23+
if ($location -eq $null)
24+
{
25+
$st = Write-Verbose 'Getting all Azure location - End';
26+
return @("West US", "East US")
27+
} else
28+
{
29+
$st = Write-Verbose 'Getting all Azure location - End';
30+
return $location.Locations
31+
}
32+
}
2033

2134
$st = Write-Verbose 'Getting all Azure location - End';
22-
23-
return $locations;
35+
return @("West US", "East US")
2436
}
2537

2638
function get_all_standard_vm_sizes

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ function Test-VMImageCmdletOutputFormat
17111711
# Test Get VM Size from All Locations
17121712
function Test-GetVMSizeFromAllLocations
17131713
{
1714-
$locations = Get-AzureRmLocation | where { $_.Name -like 'Microsoft.Compute/virtualMachines' } | select -ExpandProperty Locations;
1714+
$locations = get_all_vm_locations;
17151715
foreach ($loc in $locations)
17161716
{
17171717
$vmsizes = Get-AzureRmVMSize -Location $loc;
@@ -1722,6 +1722,26 @@ function Test-GetVMSizeFromAllLocations
17221722
}
17231723
}
17241724

1725+
function get_all_vm_locations
1726+
{
1727+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
1728+
{
1729+
$namespace = "Microsoft.Compute"
1730+
$type = "virtualMachines"
1731+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
1732+
1733+
if ($location -eq $null)
1734+
{
1735+
return @("West US", "East US")
1736+
} else
1737+
{
1738+
return $location.Locations
1739+
}
1740+
}
1741+
1742+
return @("West US", "East US")
1743+
}
1744+
17251745
<#
17261746
.SYNOPSIS
17271747
Test Virtual Machine List with Paging

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,27 @@ Gets the default location for a provider
3636
#>
3737
function Get-ProviderLocation($provider)
3838
{
39-
$location = Get-AzureRmLocation | where {[string]::Compare($_.Name, $provider, $True) -eq $True}
40-
if ($location -eq $null) {
41-
"West US"
42-
} else {
43-
$location.Locations[0]
44-
}
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
40+
{
41+
$namespace = $provider.Split("/")[0]
42+
if($provider.Contains("/"))
43+
{
44+
$type = $provider.Substring($namespace.Length + 1)
45+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
46+
47+
if ($location -eq $null)
48+
{
49+
return "West US"
50+
} else
51+
{
52+
return $location.Locations[0]
53+
}
54+
}
55+
56+
return "West US"
57+
}
58+
59+
return "WestUS"
4560
}
4661

4762
<#

src/ResourceManager/Insights/Commands.Insights.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,27 @@ Gets the default location for a provider
3636
#>
3737
function Get-ProviderLocation($provider)
3838
{
39-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
40-
if ($location -eq $null) {
41-
"West US"
42-
} else {
43-
$location.Locations[0]
44-
}
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
40+
{
41+
$namespace = $provider.Split("/")[0]
42+
if($provider.Contains("/"))
43+
{
44+
$type = $provider.Substring($namespace.Length + 1)
45+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
46+
47+
if ($location -eq $null)
48+
{
49+
return "West US"
50+
} else
51+
{
52+
return $location.Locations[0]
53+
}
54+
}
55+
56+
return "West US"
57+
}
58+
59+
return "WestUS"
4560
}
4661

4762
<#

src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/Common.ps1

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,22 @@ Gets the location for the Website. Default to West US if none found.
3636
#>
3737
function Get-Location
3838
{
39-
$location = Get-AzureRmLocation | where {$_.Name -eq "Microsoft.KeyVault/vaults"}
40-
if ($location -eq $null)
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
4140
{
42-
return "East US"
43-
}
44-
else
45-
{
46-
$location.Locations[0]
41+
$namespace = "Microsoft.KeyVault"
42+
$type = "vaults"
43+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
44+
45+
if ($location -eq $null)
46+
{
47+
return "East US"
48+
} else
49+
{
50+
return $location.Locations[0]
51+
}
4752
}
53+
54+
return "East US"
4855
}
4956

5057
<#
@@ -53,12 +60,27 @@ Gets the default location for a provider
5360
#>
5461
function Get-ProviderLocation($provider)
5562
{
56-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
57-
if ($location -eq $null) {
58-
"East US"
59-
} else {
60-
$location.Locations[0]
61-
}
63+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
64+
{
65+
$namespace = $provider.Split("/")[0]
66+
if($provider.Contains("/"))
67+
{
68+
$type = $provider.Substring($namespace.Length + 1)
69+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
70+
71+
if ($location -eq $null)
72+
{
73+
return "East US"
74+
} else
75+
{
76+
return $location.Locations[0]
77+
}
78+
}
79+
80+
return "East US"
81+
}
82+
83+
return "East US"
6284
}
6385

6486
<#

0 commit comments

Comments
 (0)