Skip to content

_azure

sc_crawler.vendors._azure #

Functions:

Name Description
inventory_compliance_frameworks

Manual list of known compliance frameworks at Azure.

inventory_regions

List all regions via API call.

inventory_zones

List all availability zones.

inventory_servers

List all available instance types in all regions.

inventory_server_prices

List all known server ondemand prices in all regions using the Azure Retail Pricing API.

inventory_server_prices_spot

List all known server spot prices in all regions using the Azure Retail Pricing API.

inventory_storages

List all storage options via the Compute resource manager client.

inventory_storage_prices

Look up Storage prices via the Azure Retail Prices API.

inventory_traffic_prices

Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

inventory_ipv4_prices

Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

Attributes:

Name Type Description
SERVER_FEATURES

Map lowercase chars from the server name to features.

STORAGE_METER_MAPPING

Map Storage price meter names to the storage type ID and the disk size in GiB.

STORAGE_PRICE_UNIT_MAPPING dict[str, float | None]

Storage capacity units → multiplier to convert the raw API price to $/GB/month.

SERVER_FEATURES module-attribute #

SERVER_FEATURES = {'a': 'AMD processor', 'p': 'ARM processor', 'b': 'Block Storage performance', 'd': 'Local Disk', 'i': 'Isolated', 'l': 'Low Memory', 'm': 'Memory Intensive', 't': 'Tiny Memory', 's': 'Premium Storage capable', 'r': 'RDMA capable', 'e': 'Memory Optimized', 'x': 'Unmatched Memory Capacity', 'o': 'o'}

Map lowercase chars from the server name to features.

STORAGE_METER_MAPPING module-attribute #

STORAGE_METER_MAPPING = {'P1 LRS Disk': ('Premium_LRS', 4), 'P2 LRS Disk': ('Premium_LRS', 8), 'P3 LRS Disk': ('Premium_LRS', 16), 'P4 LRS Disk': ('Premium_LRS', 32), 'P6 LRS Disk': ('Premium_LRS', 64), 'P10 LRS Disk': ('Premium_LRS', 128), 'P15 LRS Disk': ('Premium_LRS', 256), 'P20 LRS Disk': ('Premium_LRS', 512), 'P30 LRS Disk': ('Premium_LRS', 1024), 'P40 LRS Disk': ('Premium_LRS', 2048), 'P50 LRS Disk': ('Premium_LRS', 4096), 'P60 LRS Disk': ('Premium_LRS', 8192), 'P70 LRS Disk': ('Premium_LRS', 16384), 'P80 LRS Disk': ('Premium_LRS', 32767), 'P1 ZRS Disk': ('Premium_ZRS', 4), 'P2 ZRS Disk': ('Premium_ZRS', 8), 'P3 ZRS Disk': ('Premium_ZRS', 16), 'P4 ZRS Disk': ('Premium_ZRS', 32), 'P6 ZRS Disk': ('Premium_ZRS', 64), 'P10 ZRS Disk': ('Premium_ZRS', 128), 'P15 ZRS Disk': ('Premium_ZRS', 256), 'P20 ZRS Disk': ('Premium_ZRS', 512), 'P30 ZRS Disk': ('Premium_ZRS', 1024), 'P40 ZRS Disk': ('Premium_ZRS', 2048), 'P50 ZRS Disk': ('Premium_ZRS', 4096), 'P60 ZRS Disk': ('Premium_ZRS', 8192), 'P70 ZRS Disk': ('Premium_ZRS', 16384), 'P80 ZRS Disk': ('Premium_ZRS', 32767), 'E1 LRS Disk': ('StandardSSD_LRS', 4), 'E2 LRS Disk': ('StandardSSD_LRS', 8), 'E3 LRS Disk': ('StandardSSD_LRS', 16), 'E4 LRS Disk': ('StandardSSD_LRS', 32), 'E6 LRS Disk': ('StandardSSD_LRS', 64), 'E10 LRS Disk': ('StandardSSD_LRS', 128), 'E15 LRS Disk': ('StandardSSD_LRS', 256), 'E20 LRS Disk': ('StandardSSD_LRS', 512), 'E30 LRS Disk': ('StandardSSD_LRS', 1024), 'E40 LRS Disk': ('StandardSSD_LRS', 2048), 'E50 LRS Disk': ('StandardSSD_LRS', 4096), 'E60 LRS Disk': ('StandardSSD_LRS', 8192), 'E70 LRS Disk': ('StandardSSD_LRS', 16384), 'E80 LRS Disk': ('StandardSSD_LRS', 32767), 'E1 ZRS Disk': ('StandardSSD_ZRS', 4), 'E2 ZRS Disk': ('StandardSSD_ZRS', 8), 'E3 ZRS Disk': ('StandardSSD_ZRS', 16), 'E4 ZRS Disk': ('StandardSSD_ZRS', 32), 'E6 ZRS Disk': ('StandardSSD_ZRS', 64), 'E10 ZRS Disk': ('StandardSSD_ZRS', 128), 'E15 ZRS Disk': ('StandardSSD_ZRS', 256), 'E20 ZRS Disk': ('StandardSSD_ZRS', 512), 'E30 ZRS Disk': ('StandardSSD_ZRS', 1024), 'E40 ZRS Disk': ('StandardSSD_ZRS', 2048), 'E50 ZRS Disk': ('StandardSSD_ZRS', 4096), 'E60 ZRS Disk': ('StandardSSD_ZRS', 8192), 'E70 ZRS Disk': ('StandardSSD_ZRS', 16384), 'E80 ZRS Disk': ('StandardSSD_ZRS', 32767), 'S4 LRS Disk': ('Standard_LRS', 32), 'S6 LRS Disk': ('Standard_LRS', 64), 'S10 LRS Disk': ('Standard_LRS', 128), 'S15 LRS Disk': ('Standard_LRS', 256), 'S20 LRS Disk': ('Standard_LRS', 512), 'S30 LRS Disk': ('Standard_LRS', 1024), 'S40 LRS Disk': ('Standard_LRS', 2048), 'S50 LRS Disk': ('Standard_LRS', 4096), 'S60 LRS Disk': ('Standard_LRS', 8192), 'S70 LRS Disk': ('Standard_LRS', 16384), 'S80 LRS Disk': ('Standard_LRS', 32767), 'Ultra LRS Provisioned Capacity': ('UltraSSD_LRS', 1), 'Premium LRS Provisioned Capacity': ('PremiumV2_LRS', 1)}

Map Storage price meter names to the storage type ID and the disk size in GiB.

Disk sizes sourced from the Azure Managed Disks pricing page: https://azure.microsoft.com/en-us/pricing/details/managed-disks/

Meter names sourced from the Azure Retail Prices API: https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices

The disk size (second tuple element) is used to convert per-disk (1/Month) prices to $/GiB/month by dividing the retail price by this value. For provisioned-capacity meters (1 GiB/Hour) the divisor is 1 because the price is already expressed per GiB.

The following meter categories are intentionally not included:

  • * Disk Mount — the extra monthly fee charged per VM when a disk is attached to more than one VM simultaneously (Azure Shared Disks feature). This is an access/ attach charge, not a storage-capacity charge.
  • Confidential Compute Encryption * Provisioned Capacity — surcharge for customer-managed key (CMK) encryption on confidential VMs.
  • LRS/ZRS Burst Enablement — monthly fee to permanently enable burst IOPS on Premium SSD disks.
  • * Disk - Free / SAP Special * — zero-price promotional entries.
  • Instant Access Snapshots — snapshot restore-access fee.
  • Standard HDD ZRS is not offered as per-disk pricing (only as per-GiB/month).

STORAGE_PRICE_UNIT_MAPPING module-attribute #

STORAGE_PRICE_UNIT_MAPPING = {'1/Month': None, '1 GiB/Month': _GIB_TO_GB, '1 GB/Month': 1.0, '1 GiB/Hour': _HOURS_PER_MONTH * _GIB_TO_GB, '1 GB/Hour': float(_HOURS_PER_MONTH)}

Storage capacity units → multiplier to convert the raw API price to $/GB/month.

inventory_compliance_frameworks #

inventory_compliance_frameworks(vendor)

Manual list of known compliance frameworks at Azure.

Data collected from https://learn.microsoft.com/en-us/azure/compliance/.

Source code in sc_crawler/vendors/_azure.py
def inventory_compliance_frameworks(vendor):
    """Manual list of known compliance frameworks at Azure.

    Data collected from <https://learn.microsoft.com/en-us/azure/compliance/>.
    """
    return map_compliance_frameworks_to_vendor(
        vendor.vendor_id, ["hipaa", "soc2t2", "iso27001"]
    )

inventory_regions #

inventory_regions(vendor)

List all regions via API call.

Location (country and state) and founding year were collected manually from https://datacenters.microsoft.com/globe/explore/ and its underlying JSON at https://datacenters.microsoft.com/globe/data/geo/regions.json.

City and the energy source information was collected from the sustainability fact sheets referenced in the above page and JSON.

Coordinates were provided by the Microsoft API, which doesn't seem to be very reliable.

Source code in sc_crawler/vendors/_azure.py
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
def inventory_regions(vendor):
    """List all regions via API call.

    Location (country and state) and founding year
    were collected manually from
    <https://datacenters.microsoft.com/globe/explore/>
    and its underlying JSON at
    <https://datacenters.microsoft.com/globe/data/geo/regions.json>.

    City and the energy source information was collected from
    the sustainability fact sheets referenced in the above page and JSON.

    Coordinates were provided by the Microsoft API, which doesn't seem
    to be very reliable.
    """

    manual_datas = {
        # Canada
        "canadaeast": {
            "country_id": "CA",
            "state": "Quebec",
            "city": "Quebec City",
            "founding_year": 2016,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "canadacentral": {
            "country_id": "CA",
            "city": "Toronto",
            "founding_year": 2016,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # United States
        "centralus": {
            "country_id": "US",
            "state": "Iowa",
            "founding_year": 2014,
            "green_energy": True,
        },
        "centraluseuap": {
            "country_id": "US",
            "state": "Iowa",
            "green_energy": True,
        },
        "eastus": {
            "country_id": "US",
            "city": "Boydton",
            "state": "Virginia",
            # official site says 2014 with a dead link, but it was 2012 as per
            # https://web.archive.org/web/20120530115120/http:/blogs.msdn.com/b/windowsazure/archive/2012/04/05/announcing-new-datacenter-options-for-windows-azure.aspx
            "founding_year": 2012,
            "green_energy": False,
        },
        "eastusstg": {
            "country_id": "US",
            "state": "Virginia",
            "green_energy": False,
        },
        "eastus2": {
            "country_id": "US",
            "city": "Boydton",
            "state": "Virginia",
            # official site says 2012 with a dead link, but it was 2014 as per
            # https://azure.microsoft.com/en-us/updates/general-availability-microsoft-azure-us-central-and-us-east-2-regions/
            "founding_year": 2014,
            "green_energy": False,
        },
        "eastus2euap": {
            "country_id": "US",
            "state": "Virginia",
            "green_energy": False,
        },
        "northcentralus": {
            "country_id": "US",
            "city": "Chicago",
            "state": "Illinois",
            "founding_year": 2009,
            "green_energy": False,
        },
        "southcentralus": {
            "country_id": "US",
            "state": "Texas",
            "city": "San Antonio",
            "founding_year": 2008,
            "green_energy": True,
        },
        "southcentralusstg": {
            "country_id": "US",
            "state": "Texas",
            "city": "San Antonio",
        },
        "westcentralus": {
            "country_id": "US",
            "state": "Wyoming",
            "city": "Cheyenne",
            "founding_year": 2016,
            "green_energy": False,
        },
        "westus": {
            "country_id": "US",
            "state": "California",
            "founding_year": 2012,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "westus2": {
            "country_id": "US",
            "state": "Washington",
            "founding_year": 2007,
            "green_energy": False,
        },
        "westus3": {
            "country_id": "US",
            "state": "Arizona",
            "city": "Phoenix",
            "founding_year": 2021,
            "green_energy": False,
        },
        # Mexico
        "mexicocentral": {
            "country_id": "ZA",
            "state": "Querétaro",
            "founding_year": 2024,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # South America
        "brazilsouth": {
            "country_id": "BR",
            "state": "Campinas",
            "founding_year": 2014,
            "green_energy": False,
        },
        "brazilsoutheast": {
            "country_id": "US",
            "city": "Rio de Janeiro",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "chilecentral": {
            "country_id": "CL",
            "city": "Santiago",
            # coming soon
            "founding_year": 2025,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # not production region?
        # https://github.com/Azure/azure-dev/issues/2165#issuecomment-1542948509
        "brazilus": {
            "country_id": "BR",
        },
        # Asia Pacific
        "australiacentral": {
            "country_id": "AU",
            "city": "Canberra",
            "founding_year": 2018,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "australiacentral2": {
            "country_id": "AU",
            "city": "Canberra",
            "founding_year": 2018,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "australiaeast": {
            "country_id": "AU",
            "city": "Sydney",
            "state": "New South Wales",
            "founding_year": 2014,
            "green_energy": False,
        },
        "australiasoutheast": {
            "country_id": "AU",
            "city": "Melbourne",
            "state": "Victoria",
            "founding_year": 2014,
            "green_energy": False,
        },
        "eastasia": {
            "country_id": "HK",
            "founding_year": 2010,
            "green_energy": False,
        },
        "southeastasia": {
            "country_id": "SG",
            "city": "Singapore",
            "founding_year": 2010,
            "green_energy": False,
        },
        "japaneast": {
            "country_id": "JP",
            "city": "Tokyo",
            "founding_year": 2014,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "japanwest": {
            "country_id": "JP",
            "city": "Osaka",
            "founding_year": 2014,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "jioindiacentral": {
            "country_id": "IN",
            "city": "Nagpur",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "jioindiawest": {
            "country_id": "IN",
            "city": "Jamnagar",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "centralindia": {
            "country_id": "IN",
            "state": "Pune",
            "founding_year": 2015,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "southindia": {
            "country_id": "IN",
            "state": "Chennai",
            "founding_year": 2015,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "westindia": {
            "country_id": "IN",
            "state": "Mumbai",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "koreacentral": {
            "country_id": "KR",
            "city": "Seoul",
            "founding_year": 2017,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "koreasouth": {
            "country_id": "KR",
            "city": "Busan",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "newzealandnorth": {
            "country_id": "NZ",
            "city": "Auckland",
            "founding_year": 2024,
            "green_energy": False,
        },
        "indonesiacentral": {
            "country_id": "ID",
            "city": "Jakarta",
            # coming soon
            "founding_year": 2025,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "malaysiawest": {
            "country_id": "MY",
            "city": "Kuala Lumpur",
            # coming soon
            "founding_year": 2025,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # Europe
        "denmarkeast": {
            "country_id": "DK",
            "city": "Copenhagen",
            "founding_year": 2026,
            # https://news.microsoft.com/source/emea/features/accelerating-europes-digital-future-microsoft-announces-plans-for-a-new-datacenter-region-in-west-denmark
            "green_energy": True,
        },
        "francecentral": {
            "country_id": "FR",
            "city": "Paris",
            "founding_year": 2018,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "francesouth": {
            "country_id": "FR",
            "city": "Marseille",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "germanynorth": {
            "country_id": "DE",
            "city": "Berlin",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "germanywestcentral": {
            "country_id": "DE",
            "city": "Frankfurt",
            "founding_year": 2019,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "italynorth": {
            "country_id": "IT",
            "city": "Milan",
            "founding_year": 2023,
            "green_energy": False,
        },
        "northeurope": {
            "country_id": "IE",
            "city": "Dublin",
            "founding_year": 2009,
            "green_energy": False,
        },
        "norwayeast": {
            "country_id": "NO",
            "city": "Oslo",
            "founding_year": 2019,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "norwaywest": {
            "country_id": "NO",
        },
        "polandcentral": {
            "country_id": "PL",
            "city": "Warsaw",
            "founding_year": 2023,
            "green_energy": False,
        },
        "spaincentral": {
            "country_id": "ES",
            "city": "Madrid",
            "founding_year": 2024,
            "green_energy": False,
        },
        "swedencentral": {
            "country_id": "SE",
            "city": "Gävle and Sandviken",
            "founding_year": 2021,
            "green_energy": False,
        },
        "switzerlandnorth": {
            "country_id": "CH",
            "city": "Zürich",
            "founding_year": 2019,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "switzerlandwest": {
            "country_id": "CH",
            "city": "Geneva",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "uksouth": {
            "country_id": "GB",
            "city": "London",
            "founding_year": 2016,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "ukwest": {
            "country_id": "GB",
            "city": "Cardiff",
            "founding_year": 2017,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "westeurope": {
            "country_id": "NL",
            "founding_year": 2010,
            "green_energy": False,
        },
        "belgiumcentral": {
            "country_id": "BE",
            "founding_year": 2025,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # Middle East
        "israelcentral": {
            "country_id": "IL",
            "founding_year": 2023,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "qatarcentral": {
            "country_id": "QA",
            "city": "Doha",
            "founding_year": 2022,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "uaecentral": {
            "country_id": "AE",
            "city": "Abu Dhabi",
        },
        "uaenorth": {
            "country_id": "AE",
            "city": "Dubai",
            "founding_year": 2019,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "austriaeast": {
            "country_id": "AT",
            "city": "Vienna",
            "founding_year": 2025,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # Africa
        "southafricanorth": {
            "country_id": "ZA",
            "city": "Johannesburg",
            "founding_year": 2019,
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        "southafricawest": {
            "country_id": "ZA",
            "city": "Cape Town",
            # unknown as no sustainability fact sheet found
            "green_energy": False,
        },
        # China TODO enable
    }

    items = []
    for region in _regions():
        with sentry_capture_or_raise(vendor=vendor):
            # TODO drop this once the metadata field doesn't show up randomly anymore
            # as the non-metadata responses do not seem to have these logical regions anymore
            if region.get("metadata", {}).get("region_type", "Physical") != "Physical":
                continue
            # no idea what are these
            if region["name"].endswith("stg"):
                continue
            # not production region?
            # https://github.com/Azure/azure-dev/issues/2165#issuecomment-1542948509
            if region["name"] == "brazilus":
                continue
            # exclude for now as this new region is popping up and being removed
            # from their API response randomly, so messing with git history
            if region["name"] == "newzealandnorth":
                continue
            manual_data = manual_datas.get(region["name"])
            if not manual_data:
                raise KeyError(f"No manual data found for {region['name']}.")
            items.append(
                {
                    "vendor_id": vendor.vendor_id,
                    "region_id": region["name"],
                    "name": region["display_name"],
                    "api_reference": region["name"],
                    "display_name": (
                        region["display_name"] + " (" + manual_data["country_id"] + ")"
                    ),
                    "country_id": manual_data["country_id"],
                    "state": manual_data.get("state"),
                    "city": manual_data.get("city"),
                    "address_line": None,
                    "zip_code": None,
                    # sometimes the API passes "metadata" and the lat/long nested, sometimes it's not
                    # TODO revisit after a few days passed since this change:
                    # https://github.com/Azure/azure-sdk-for-python/blob/azure-mgmt-resource_25.0.0/sdk/resources/azure-mgmt-resource/CHANGELOG.md#2500-2026-02-04
                    "lat": region.get("metadata", {}).get(
                        "latitude", region.get("latitude")
                    ),
                    "lon": region.get("metadata", {}).get(
                        "longitude", region.get("longitude")
                    ),
                    "founding_year": manual_data.get("founding_year"),
                    "green_energy": manual_data.get("green_energy"),
                }
            )
    return items

inventory_zones #

inventory_zones(vendor)

List all availability zones.

API call to list existing availability zones ("1", "2", and "3") for each region, and creating a dummy "0" zone for the regions without availability zones.

Source code in sc_crawler/vendors/_azure.py
def inventory_zones(vendor):
    """List all availability zones.

    API call to list existing availability zones ("1", "2", and "3")
    for each region, and creating a dummy "0" zone for the regions
    without availability zones.
    """
    items = []
    resources = _resources("Microsoft.Compute")
    locations = [i for i in resources if i["resource_type"] == "virtualMachines"][0]
    locations = {item["location"]: item["zones"] for item in locations["zone_mappings"]}
    for region in vendor.regions:
        # default to zone with 0 ID if there are no real availability zones
        region_zones = locations.get(region.name, ["0"])
        for zone in region_zones:
            items.append(
                {
                    "vendor_id": vendor.vendor_id,
                    "region_id": region.region_id,
                    "zone_id": zone,
                    "name": zone,
                    "api_reference": zone,
                    "display_name": region.region_id + "-" + zone,
                }
            )
    return items

inventory_servers #

inventory_servers(vendor)

List all available instance types in all regions.

Source code in sc_crawler/vendors/_azure.py
def inventory_servers(vendor):
    """List all available instance types in all regions."""
    servers = _servers()
    for i in range(len(servers) - 1, -1, -1):
        name = servers[i].get("name")
        # drop Basic servers as to be deprecated by Aug 2024
        if name.startswith("Basic"):
            vendor.log(f"Excluding deprecated: {name}")
            servers.pop(i)
        # servers that are likely to be not available, with zero pricing
        if name.endswith("Promo"):
            vendor.log(f"Excluding nonsense pricing: {name}")
            servers.pop(i)
        # servers probably not intended for our eyes
        if "Internal" in name:
            vendor.log(f"Excluding internal server: {name}")
            servers.pop(i)
        # servers randomly switching between active/inactive status
        # TODO review from time to time
        if name in ["Standard_M896ixds_32_v3", "Standard_M64-32bds_1_v3"]:
            vendor.log(f"Excluding server with questionable availability: {name}")
            servers.pop(i)
    servers = preprocess_servers(servers, vendor, _standardize_server)
    return servers

inventory_server_prices #

inventory_server_prices(vendor)

List all known server ondemand prices in all regions using the Azure Retail Pricing API.

More information: https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices.

Source code in sc_crawler/vendors/_azure.py
def inventory_server_prices(vendor):
    """List all known server ondemand prices in all regions using the Azure Retail Pricing API.

    More information: <https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices>.
    """
    return _inventory_server_prices(vendor, Allocation.ONDEMAND)

inventory_server_prices_spot #

inventory_server_prices_spot(vendor)

List all known server spot prices in all regions using the Azure Retail Pricing API.

See details at inventory_server_prices.

Source code in sc_crawler/vendors/_azure.py
def inventory_server_prices_spot(vendor):
    """List all known server spot prices in all regions using the Azure Retail Pricing API.

    See details at [inventory_server_prices][sc_crawler.vendors._azure.inventory_server_prices].
    """
    return _inventory_server_prices(vendor, Allocation.SPOT)

inventory_storages #

inventory_storages(vendor)

List all storage options via the Compute resource manager client.

For more information, see https://learn.microsoft.com/en-us/azure/virtual-machines/disks-types.

Source code in sc_crawler/vendors/_azure.py
def inventory_storages(vendor):
    """List all storage options via the Compute resource manager client.

    For more information, see <https://learn.microsoft.com/en-us/azure/virtual-machines/disks-types>.
    """
    vendor.progress_tracker.start_task(
        name="Fetching list of compute resources", total=None
    )

    disks = []
    for resource in _compute_resources():
        if resource["resource_type"] == "disks":
            disks.append(resource)

    disks = list({d["name"]: d for d in disks}.values())
    vendor.progress_tracker.hide_task()

    items = []
    for disk in disks:

        def _search(values):
            return list_search(disk["capabilities"], "name", values)["value"]

        storage_type = (
            StorageType.HDD
            if "Standard" in disk["name"] and "SSD" not in disk["name"]
            else StorageType.SSD
        )
        redundancy_type = (
            "Locally Redundant Storage"
            if "LRS" in disk["name"]
            else "Zone-Redundant Storage"
        )
        description = f"{disk['tier']} tier {storage_type.name} ({redundancy_type})"

        items.append(
            {
                "storage_id": disk["name"],
                "vendor_id": vendor.vendor_id,
                "name": disk["name"],
                "description": description,
                "storage_type": storage_type,
                "max_iops": _search(["MaxIOpsReadWrite", "MaxIOps"]),
                "max_throughput": _search(
                    ["MaxBandwidthMBpsReadWrite", "MaxBandwidthMBps"]
                ),
                # NOTE this is 16TB for most drives?!
                "min_size": _search("MinSizeGiB"),
                "max_size": _search("MaxSizeGiB"),
            }
        )
    return items

inventory_storage_prices #

inventory_storage_prices(vendor)

Look up Storage prices via the Azure Retail Prices API.

For more information, see https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices.

Source code in sc_crawler/vendors/_azure.py
def inventory_storage_prices(vendor):
    """Look up Storage prices via the Azure Retail Prices API.

    For more information, see <https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices>.
    """
    vendor.progress_tracker.start_task(
        name="Fetching list of storage resources", total=None
    )
    retail_prices = []
    with sentry_capture_or_raise(vendor=vendor):
        retail_prices = _prices("$filter=serviceName eq 'Storage'")
    vendor.progress_tracker.hide_task()

    if not retail_prices:
        return []

    regions = scmodels_to_dict(vendor.regions, keys=["region_id"])
    storages = scmodels_to_dict(vendor.storages, keys=["storage_id"])

    prices = defaultdict(list)
    for p in retail_prices:
        mapping = STORAGE_METER_MAPPING.get(p["meterName"])
        if not (
            mapping
            and mapping[0] in storages.keys()
            and p["armRegionName"] in regions.keys()
        ):
            continue

        unit = p.get("unitOfMeasure")
        if unit == "1/Month":
            # mapping[1] is disk size in GiB, convert to $/GB/month.
            price = p["retailPrice"] / mapping[1] * _GIB_TO_GB
            prices[
                (
                    vendor.vendor_id,
                    p["armRegionName"],
                    mapping[0],
                    PriceUnit.GB_MONTH,
                    p["currencyCode"],
                )
            ].append(
                PriceTier(
                    lower=0,
                    upper=round(mapping[1] * _GIB_TO_GB, 4),
                    price=round(price, 4),
                )
            )
        else:
            multiplier = STORAGE_PRICE_UNIT_MAPPING.get(unit)
            if multiplier is None:
                continue  # not a storage capacity unit
            price = p["retailPrice"] * multiplier
            prices[
                (
                    vendor.vendor_id,
                    p["armRegionName"],
                    mapping[0],
                    PriceUnit.GB_MONTH,
                    p["currencyCode"],
                )
            ].append(PriceTier(lower=0, upper=float("inf"), price=round(price, 4)))

    items = []
    for key, price_tiered in prices.items():
        vendor_id, region_id, storage_id, unit, currency = key
        if len(price_tiered) == 1:
            price = price_tiered[0].price
            price_tiered = []
        else:
            price_tiered.sort(key=lambda x: x.upper)
            lower = 0
            for price_tier in price_tiered:
                price_tier.lower = lower
                lower = price_tier.upper
            price = price_tiered[0].price  # use the price of the lowest tier

        items.append(
            {
                "vendor_id": vendor_id,
                "region_id": region_id,
                "storage_id": storage_id,
                "unit": unit,
                "price": price,
                "price_tiered": price_tiered,
                "currency": currency,
            }
        )

    return items

inventory_traffic_prices #

inventory_traffic_prices(vendor)

Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

For more information, see https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices.

Source code in sc_crawler/vendors/_azure.py
def inventory_traffic_prices(vendor):
    """Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

    For more information, see <https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices>.
    """

    def get_tiers(prices: List[dict]) -> List[dict]:
        def prep_tiers(d: dict) -> dict:
            return {
                "lower": d.get("tierMinimumUnits", 0),
                "price": d["retailPrice"],
            }

        tiers = [prep_tiers(p) for p in prices]
        tiers.sort(key=lambda x: x.get("lower"))
        for i in range(len(tiers)):
            if i == len(tiers) - 1:
                tiers[i]["upper"] = "Infinity"
            else:
                tiers[i]["upper"] = tiers[i + 1]["lower"]
        return tiers

    def by_region(prices: List[dict], region: str) -> List[dict]:
        return [p for p in prices if p["armRegionName"] == region]

    vendor.progress_tracker.start_task(
        name="Fetching list of traffic prices", total=None
    )
    inbound_prices = []
    outbound_prices = []
    with sentry_capture_or_raise(vendor=vendor):
        inbound_prices = _prices(
            "$filter=serviceFamily eq 'Networking' and meterName eq 'Standard Data Transfer In'"
        )
        outbound_prices = _prices(
            "$filter=serviceFamily eq 'Networking' and "
            "meterName eq 'Standard Data Transfer Out' and "
            "productName eq 'Bandwidth - Routing Preference: Internet'"
        )
    vendor.progress_tracker.hide_task()

    if not inbound_prices and not outbound_prices:
        return []

    items = []
    regions = scmodels_to_dict(vendor.regions, keys=["api_reference"])
    for region in regions.values():
        for direction in ["inbound", "outbound"]:
            prices = inbound_prices if direction == "inbound" else outbound_prices
            tiers = get_tiers(by_region(prices, region.api_reference))
            if tiers:
                items.append(
                    {
                        "vendor_id": vendor.vendor_id,
                        "region_id": region.region_id,
                        "price": max([float(t["price"]) for t in tiers]),
                        "price_tiered": tiers,
                        "currency": prices[0].get("currencyCode", "USD"),
                        "unit": PriceUnit.GB_MONTH,
                        "direction": (
                            TrafficDirection.IN
                            if direction == "inbound"
                            else TrafficDirection.OUT
                        ),
                    }
                )
    return items

inventory_ipv4_prices #

inventory_ipv4_prices(vendor)

Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

For more information, see https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices.

Source code in sc_crawler/vendors/_azure.py
def inventory_ipv4_prices(vendor):
    """Look up Internet Egress/Ingress prices via the Azure Retail Prices API.

    For more information, see <https://learn.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices>.
    """

    vendor.progress_tracker.start_task(
        name="Fetching list of traffic prices", total=None
    )
    prices = []
    with sentry_capture_or_raise(vendor=vendor):
        prices = _prices(
            "$filter=serviceFamily eq 'Networking' and "
            "meterName eq 'Basic IPv4 Dynamic Public IP' and "
            "type eq 'Consumption'"
        )
    vendor.progress_tracker.hide_task()

    if not prices:
        return []

    items = []
    regions = scmodels_to_dict(vendor.regions, keys=["api_reference"])
    for region in regions.values():
        price = list_search(prices, "armRegionName", region.api_reference)
        if price:
            items.append(
                {
                    "vendor_id": vendor.vendor_id,
                    "region_id": region.region_id,
                    "price": float(price["retailPrice"]),
                    "currency": price.get("currencyCode", "USD"),
                    "unit": PriceUnit.HOUR,
                }
            )
    return items