From 3c20cf34ac900afaa3ebfc3370a473631764b3a8 Mon Sep 17 00:00:00 2001 From: rohita Date: Thu, 14 Mar 2024 06:27:59 +0000 Subject: [PATCH] [PLAT-12558]Create Provider times out after 3h because querying instance types in Azure is hung Summary: It looks like we are using an older deprecated API for [[ https://learn.microsoft.com/en-us/azure/virtual-machines/sizes | Getting VM Sizes with Their Costs ]]. Instead, we should be using [[ https://learn.microsoft.com/en-us/rest/api/compute/resource-skus/list?view=rest-compute-2023-10-02&tabs=HTTP | ComputeManagementClient::resource_skus_list ]]. Test Plan: Tested manually and the azu provider creation and universe is successful. Yet to test on the time crunch. Reviewers: svarshney, daniel Reviewed By: svarshney Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D33145 --- .../devops/opscli/ybops/cloud/azure/utils.py | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/managed/devops/opscli/ybops/cloud/azure/utils.py b/managed/devops/opscli/ybops/cloud/azure/utils.py index c7a475ffa40e..0ad4b891adc3 100644 --- a/managed/devops/opscli/ybops/cloud/azure/utils.py +++ b/managed/devops/opscli/ybops/cloud/azure/utils.py @@ -988,11 +988,17 @@ def get_zone_to_subnets(self, vnet, region): subnet = self.network().get_default_subnet(vnet) return {zone: subnet for zone in zones} - def parse_vm_info(self, vm): + def parse_vm_info(self, capabilities): vm_info = {} - vm_info["numCores"] = vm.get("numberOfCores") - vm_info["memSizeGb"] = float(vm.get("memoryInMB")) / 1000.0 - vm_info["maxDiskCount"] = vm.get("maxDataDiskCount") + for capability in capabilities: + name = capability.name + value = capability.value + if name == "vCPUs": + vm_info["numCores"] = int(value or 0) + elif name == "MemoryGB": + vm_info["memSizeGb"] = float(value or 0) + elif name == "MaxDataDiskCount": + vm_info["maxDiskCount"] = int(value or 0) vm_info['prices'] = {} return vm_info @@ -1006,15 +1012,22 @@ def get_instance_types(self, regions): all_vms = {} # Base list of VMs to check for. - vm_list = [vm.serialize() for vm in - self.compute_client.virtual_machine_sizes.list(location=regions[0])] + vm_list = self.compute_client.resource_skus.list(filter="location eq '{}'" + .format(regions[0])) for vm in vm_list: - vm_size = vm.get("name") + # We only care about virtual machines + if vm.resource_type != "virtualMachines": + continue + # No capabilities + capabilities = vm.capabilities + if not capabilities: + continue + vm_size = vm.name # We only care about VMs that support Premium storage. Promo is pricing special. if (vm_size.startswith(burstable_prefix) or not regex.match(vm_size) or vm_size.endswith("Promo")): continue - vm_info = self.parse_vm_info(vm) + vm_info = self.parse_vm_info(capabilities) if vm_info["memSizeGb"] < MIN_MEM_SIZE_GB or vm_info["numCores"] < MIN_NUM_CORES: continue all_vms[vm_size] = vm_info