Skip to content

equivalent to azure location list in new CLI #1520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joshgav opened this issue Dec 9, 2016 · 8 comments
Closed

equivalent to azure location list in new CLI #1520

joshgav opened this issue Dec 9, 2016 · 8 comments

Comments

@joshgav
Copy link

joshgav commented Dec 9, 2016

It was sometimes helpful in ye olde Azure CLI to list available locations, their short names, and their features with the azure location list command. Would it be possible to include an equivalent here?

An informational page might be sufficient too. I found this page, but it's not particularly developer-friendly and it doesn't include short names.

Thank you!

@joshgav
Copy link
Author

joshgav commented Dec 9, 2016

never mind - I found az account list-locations. Thanks!

@joshgav joshgav closed this as completed Dec 9, 2016
@CarlosJoseChaconChavarria

"az account list-locations -o table"
to get it in an easy readable format

DisplayName          Latitude    Longitude    Name
-------------------  ----------  -----------  ------------------
East Asia            22.267      114.188      eastasia
Southeast Asia       1.283       103.833      southeastasia
Central US           41.5908     -93.6208     centralus
East US              37.3719     -79.8164     eastus
East US 2            36.6681     -78.3889     eastus2
West US              37.783      -122.417     westus
North Central US     41.8819     -87.6278     northcentralus
South Central US     29.4167     -98.5        southcentralus
North Europe         53.3478     -6.2597      northeurope
West Europe          52.3667     4.9          westeurope
Japan West           34.6939     135.5022     japanwest
Japan East           35.68       139.77       japaneast
Brazil South         -23.55      -46.633      brazilsouth
Australia East       -33.86      151.2094     australiaeast
Australia Southeast  -37.8136    144.9631     australiasoutheast
South India          12.9822     80.1636      southindia
Central India        18.5822     73.9197      centralindia
West India           19.088      72.868       westindia
Canada Central       43.653      -79.383      canadacentral
Canada East          46.817      -71.217      canadaeast
UK South             50.941      -0.799       uksouth
UK West              53.427      -3.084       ukwest
West Central US      40.890      -110.234     westcentralus
West US 2            47.233      -119.852     westus2
Korea Central        37.5665     126.9780     koreacentral
Korea South          35.1796     129.0756     koreasouth
France Central       46.3772     2.3730       francecentral
France South         43.8345     2.1972       francesouth
Australia Central    -35.3075    149.1244     australiacentral
Australia Central 2  -35.3075    149.1244     australiacentral2
South Africa North   -25.731340  28.218370    southafricanorth
South Africa West    -34.075691  18.843266    southafricawest

@ArcherN9
Copy link

I prefer az account list-locations --query "[].{DisplayName:displayName, Name:name}" -o table. There's really no need to pair it up with latlong values.

DisplayName          Name
-------------------  ------------------
East Asia            eastasia
Southeast Asia       southeastasia
Central US           centralus
East US              eastus
East US 2            eastus2
West US              westus
North Central US     northcentralus
South Central US     southcentralus
North Europe         northeurope
West Europe          westeurope
Japan West           japanwest
Japan East           japaneast
Brazil South         brazilsouth
Australia East       australiaeast
Australia Southeast  australiasoutheast
South India          southindia
Central India        centralindia
West India           westindia
Canada Central       canadacentral
Canada East          canadaeast
UK South             uksouth
UK West              ukwest
West Central US      westcentralus
West US 2            westus2
Korea Central        koreacentral
Korea South          koreasouth
France Central       francecentral
France South         francesouth
Australia Central    australiacentral
Australia Central 2  australiacentral2
UAE Central          uaecentral
UAE North            uaenorth
South Africa North   southafricanorth
South Africa West    southafricawest

@rbyshko
Copy link

rbyshko commented May 18, 2020

Sort by DisplayName:

az account list-locations --query "sort_by([].{DisplayName:displayName, Name:name}, &DisplayName)" --output table

@elasticdotventures
Copy link

You can also allow a user to select the location using fzf, i.e. to make an interactive chooser for location:

Pulled from http://github.com/elasticdotventures/_b00t_

az account list-locations -o json | jq -c --raw-output '.[]|[.name,.displayName] | @tsv' | sort | fzf-tmux --delimiter='\t' --with-nth=1 --preview='echo {2}' --height 40% | awk '{print $1}'

@jiasli
Copy link
Member

jiasli commented May 5, 2021

@elasticdotventures, thanks for the suggestion. fzf is definitely a great fuzzy finder.

@jiasli
Copy link
Member

jiasli commented May 5, 2021

@ArcherN9,

I prefer az account list-locations --query "[].{DisplayName:displayName, Name:name}" -o table. There's really no need to pair it up with latlong values.

If you run az account list-locations --debug, you will see the result is from Subscriptions - List Locations REST API.

msrest.http_logger: Request URL: 'https://management.azure.com/subscriptions/xxx/locations?api-version=2019-11-01'
msrest.http_logger: Request method: 'GET'
...
msrest.http_logger: Response content:
msrest.http_logger: {"value":[{"id":"/subscriptions/xxx/locations/eastus","name":"eastus","displayName":"East US","regionalDisplayName":"(US) East US","metadata":{"regionType":"Physical","regionCategory":"Recommended","geographyGroup":"US","longitude":"-79.8164","latitude":"37.3719","physicalLocation":"Virginia"

The API version has been bumped from 2019-06-01 to 2019-11-01 in #14229.

In 2019-06-01

latitude and longitude are at the root of Location.

https://github.com/Azure/azure-sdk-for-python/blob/27e4203818e227ba2604ff52dcf55ce2293c4c37/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_06_01/models/_models_py3.py#L125-L132

class Location(msrest.serialization.Model):

    _attribute_map = {
        'id': {'key': 'id', 'type': 'str'},
        'subscription_id': {'key': 'subscriptionId', 'type': 'str'},
        'name': {'key': 'name', 'type': 'str'},
        'display_name': {'key': 'displayName', 'type': 'str'},
        'latitude': {'key': 'latitude', 'type': 'str'},
        'longitude': {'key': 'longitude', 'type': 'str'},
    }

As table output shows root-level attributes, Azure CLI just shows latitude and longitude as-is.

In 2019-11-01

latitude and longitude are moved to LocationMetadata.

https://github.com/Azure/azure-sdk-for-python/blob/27e4203818e227ba2604ff52dcf55ce2293c4c37/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/models/_models_py3.py#L124-L131

class Location(msrest.serialization.Model):

    _attribute_map = {
        'id': {'key': 'id', 'type': 'str'},
        'subscription_id': {'key': 'subscriptionId', 'type': 'str'},
        'name': {'key': 'name', 'type': 'str'},
        'display_name': {'key': 'displayName', 'type': 'str'},
        'regional_display_name': {'key': 'regionalDisplayName', 'type': 'str'},
        'metadata': {'key': 'metadata', 'type': 'LocationMetadata'},
    }

https://github.com/Azure/azure-sdk-for-python/blob/27e4203818e227ba2604ff52dcf55ce2293c4c37/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/models/_models_py3.py#L201-L209

class LocationMetadata(msrest.serialization.Model):

    _attribute_map = {
        'region_type': {'key': 'regionType', 'type': 'str'},
        'region_category': {'key': 'regionCategory', 'type': 'str'},
        'geography_group': {'key': 'geographyGroup', 'type': 'str'},
        'longitude': {'key': 'longitude', 'type': 'str'},
        'latitude': {'key': 'latitude', 'type': 'str'},
        'physical_location': {'key': 'physicalLocation', 'type': 'str'},
        'paired_region': {'key': 'pairedRegion', 'type': '[PairedRegion]'},
    }
$ az account list-locations
[
  {
    "displayName": "East US",
    "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/locations/eastus",
    "metadata": {
      "geographyGroup": "US",
      "latitude": "37.3719",    ##### Notice this attribute's location
      "longitude": "-79.8164",  ##### Notice this attribute's location
      "pairedRegion": [
        {
          "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/locations/westus",
          "name": "westus",
          "subscriptionId": null
        }
      ],
      "physicalLocation": "Virginia",
      "regionCategory": "Recommended",
      "regionType": "Physical"
    },
    "name": "eastus",
    "regionalDisplayName": "(US) East US",
    "subscriptionId": null
  },

Therefore, the latest Azure CLI doesn't show latitude and longitude in table output anymore:

$ az account list-locations --output table
DisplayName               Name                 RegionalDisplayName
------------------------  -------------------  -------------------------------------
East US                   eastus               (US) East US
East US 2                 eastus2              (US) East US 2
South Central US          southcentralus       (US) South Central US
West US 2                 westus2              (US) West US 2
Australia East            australiaeast        (Asia Pacific) Australia East

@B-Art
Copy link

B-Art commented May 17, 2022

Start powershell-core

pwsh

Then combine az and pwsh command's:

$a = az account list-locations | ConvertFrom-Json -AsHashtable
$a.Where({$_.name -like "*west*"}).ForEach({ "$($_.name),$($_.metadata.latitude),$($_.metadata.longitude)" })

Will output:

westus2,47.233,-119.852
westus3,33.448376,-112.074036
westeurope,52.3667,4.9
germanywestcentral,50.110924,8.682127
westusstage,,
westus2stage,,
westus,37.783,-122.417
jioindiawest,22.470701,70.05773
westcentralus,40.890,-110.234
southafricawest,-34.075691,18.843266
japanwest,34.6939,135.5022
westindia,19.088,72.868
norwaywest,58.969975,5.733107
switzerlandwest,46.204391,6.143158
ukwest,53.427,-3.084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants