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

Update logic used to determins current storage acct name

Enis Afgan 7 лет назад
Родитель
Сommit
082097f8ab
2 измененных файлов с 10 добавлено и 5 удалено
  1. 1 1
      cloudbridge/cloud/base/resources.py
  2. 9 4
      cloudbridge/cloud/providers/azure/provider.py

+ 1 - 1
cloudbridge/cloud/base/resources.py

@@ -202,7 +202,7 @@ class BaseCloudResource(CloudResource):
     @staticmethod
     @staticmethod
     def assert_valid_resource_name(name):
     def assert_valid_resource_name(name):
         if not BaseCloudResource.is_valid_resource_name(name):
         if not BaseCloudResource.is_valid_resource_name(name):
-            log.debug("InvalidNameException raised on %s", name, exc_info=True)
+            log.debug("InvalidNameException raised on %s", name)
             raise InvalidNameException(
             raise InvalidNameException(
                 u"Invalid name: %s. Name must be at most 63 characters "
                 u"Invalid name: %s. Name must be at most 63 characters "
                 "long and consist of lowercase letters, numbers, "
                 "long and consist of lowercase letters, numbers, "

+ 9 - 4
cloudbridge/cloud/providers/azure/provider.py

@@ -38,12 +38,17 @@ class AzureCloudProvider(BaseCloudProvider):
         self.resource_group = self._get_config_value(
         self.resource_group = self._get_config_value(
             'azure_resource_group', os.environ.get('AZURE_RESOURCE_GROUP',
             'azure_resource_group', os.environ.get('AZURE_RESOURCE_GROUP',
                                                    'cloudbridge'))
                                                    'cloudbridge'))
-        # Storage account name is limited to a max length of 24 characters
-        # so take part of the client id to keep it unique
+        # Storage account name is limited to a max length of 24 alphanum chars
+        # and unique across an account. Yet, all our operations are tied to a
+        # resource group, making it impossible to use a storage account
+        # defined in a different resource group from the one used by the
+        # current session. With that, base the name of the storage account on
+        # the current resource group, up to 24 chars in length.
         self.storage_account = self._get_config_value(
         self.storage_account = self._get_config_value(
             'azure_storage_account',
             'azure_storage_account',
-            os.environ.get('AZURE_STORAGE_ACCOUNT',
-                           'storageacc' + self.client_id[-12:]))
+            os.environ.get(
+                'AZURE_STORAGE_ACCOUNT', 'storageacc' + ''.join(
+                    ch for ch in self.resource_group if ch.isalnum())[-12:]))
 
 
         self.vm_default_user_name = self._get_config_value(
         self.vm_default_user_name = self._get_config_value(
             'azure_vm_default_user_name', os.environ.get
             'azure_vm_default_user_name', os.environ.get