Просмотр исходного кода

Filter out instance type by region. xref: https://github.com/CloudVE/cloudbridge/issues/153

Nuwan Goonasekera 7 лет назад
Родитель
Сommit
5c0bb4a674
1 измененных файлов с 6 добавлено и 3 удалено
  1. 6 3
      cloudbridge/cloud/providers/aws/services.py

+ 6 - 3
cloudbridge/cloud/providers/aws/services.py

@@ -616,13 +616,16 @@ class AWSVMTypeService(BaseVMTypeService):
         https://github.com/powdahound/ec2instances.info (in particular, this
         https://github.com/powdahound/ec2instances.info (in particular, this
         file: https://raw.githubusercontent.com/powdahound/ec2instances.info/
         file: https://raw.githubusercontent.com/powdahound/ec2instances.info/
         master/www/instances.json).
         master/www/instances.json).
-
-        TODO: Needs a caching function with timeout
         """
         """
         r = requests.get(self.provider.config.get(
         r = requests.get(self.provider.config.get(
             "aws_instance_info_url",
             "aws_instance_info_url",
             self.provider.AWS_INSTANCE_DATA_DEFAULT_URL))
             self.provider.AWS_INSTANCE_DATA_DEFAULT_URL))
-        return r.json()
+        # Some instances are only available in certain regions. Use pricing
+        # info to determine and filter out instance types that are not
+        # available in the current region
+        vm_types_list = r.json()
+        return [vm_type for vm_type in vm_types_list
+                if vm_type.get('pricing', {}).get(self.provider.region_name)]
 
 
     def list(self, limit=None, marker=None):
     def list(self, limit=None, marker=None):
         vm_types = [AWSVMType(self.provider, vm_type)
         vm_types = [AWSVMType(self.provider, vm_type)